add "power-user" ctor interface method that accepts pre-constructed actors
authorChris Jones <jones.chris.g@gmail.com>
Wed, 19 Aug 2009 15:39:10 -0500
changeset 35862 cf6452d52b6b28e4128f59fc271e5c582aca8ccb
parent 35861 4820aee8bc0265a24fa50ccd10eaf3dc61cdcd9a
child 35863 8bf0b53a83c5c9367bf3513ec4e81fd191202764
push idunknown
push userunknown
push dateunknown
milestone1.9.2a1pre
add "power-user" ctor interface method that accepts pre-constructed actors
ipc/ipdl/ipdl/lower.py
--- a/ipc/ipdl/ipdl/lower.py
+++ b/ipc/ipdl/ipdl/lower.py
@@ -933,28 +933,54 @@ class GenerateProtocolActorHeader(Visito
             if md.decl.type.isCtor():
                 mdecl.ret = objtype
             elif md.decl.type.isDtor():
                 mdecl.params.insert(0, cxx.Decl(objtype, '__a'))
                 objvar = cxx.ExprVar('__a')
             impl = cxx.MethodDefn(mdecl)
 
             if md.decl.type.isCtor():
-                impl.addstmt(cxx.StmtDecl(cxx.Decl(objtype, '__a')))
+                #
+                # for ctor messages, we construct two interface methods:
+                #
+                #   Actor* SendActorCtor(...)
+                #   Actor* SendActorCtor(Actor*, ...)
+                #
+                # the first uses the ActorCtor() method provided
+                # by the subclass implementing this interface,
+                # and internally passes through to the second
+                # SendActorCtor(Actor*, ...) method
+                #
+                # the second relies on the user to pass in a valid
+                # concrete Actor* instantiation
+                #
+
+                # here |impl| is the first ctor interface above
+                callctor = cxx.ExprCall(cxx.ExprVar(md._cxx.method.name),
+                                        [ cxx.ExprVar(p.name) for
+                                          p in md._cxx.method.params ])
+                impl.addstmt(cxx.StmtReturn(
+                    cxx.ExprCall(cxx.ExprVar(mdecl.name),
+                                 ([ callctor ] +
+                                  [ cxx.ExprVar(p.name) for
+                                    p in md._cxx.method.params ]))))
+                self.cls.addstmt(impl)
+                self.cls.addstmt(cxx.Whitespace.NL)
+
+                # now we make the second ctor interface
+                mdecl2 = deepcopy(mdecl)
+                mdecl2.params.insert(0, cxx.Decl(objtype, '__a'))
+                impl = cxx.MethodDefn(mdecl2)
+
                 objvar = cxx.ExprVar('__a')
 
                 okcode = objvar
                 failerrcode = cxx.ExprLiteral.ZERO
                 valueerrcode = cxx.ExprLiteral.ZERO
 
-                impl.addstmt(cxx.StmtExpr(cxx.ExprAssn(
-                            objvar,
-                            cxx.ExprCall(cxx.ExprVar(md._cxx.method.name),
-                                         [ cxx.ExprVar(p.name) for
-                                           p in md._cxx.method.params ]))))
                 failif = cxx.StmtIf(cxx.ExprPrefixUnop(objvar, '!'))
                 failif.ifb.addstmt(cxx.StmtReturn(cxx.ExprLiteral.ZERO))
                 impl.addstmt(failif)
 
                 objid = cxx.ExprSelect(objvar, '->', 'mId')
                 impl.addstmt(cxx.StmtExpr(
                         cxx.ExprAssn(objid,
                                      cxx.ExprCall(cxx.ExprVar('Register'),