Bug 1397823 - part 1 - move work into _generateMessageConstructor; r=kanru
authorNathan Froyd <froydnj@mozilla.com>
Fri, 15 Sep 2017 08:06:11 -0400
changeset 665498 1607f6d53f5273361ce35e47f94d3966c26611c6
parent 665439 70f5f23a429f3d621e44307c191fa84c77fb2f61
child 665499 6e7da31ab0b11eb3b4f2e372b350652b8b3e3597
push id80093
push userbmo:ttromey@mozilla.com
push dateFri, 15 Sep 2017 16:41:29 +0000
reviewerskanru
bugs1397823
milestone57.0a1
Bug 1397823 - part 1 - move work into _generateMessageConstructor; r=kanru _generateMessageConstructor takes a lot of `md.FOO`-style parameters, which could be derived inside the function by simply passing `md`. Especially with the upcoming changes to calculate things like reply-ness of messages, sync-ness, etc, we'd be wanting to pass even more parameters like `md.FOO`. So let's just pass `md` in, and then we can make all the necessary future changes in a single place.
ipc/ipdl/ipdl/lower.py
--- a/ipc/ipdl/ipdl/lower.py
+++ b/ipc/ipdl/ipdl/lower.py
@@ -1592,34 +1592,24 @@ class _GenerateProtocolCode(ipdl.ast.Vis
 
             # Look up the segment capacity used for serializing this
             # message. If the capacity is not specified, use '0' for
             # the default capacity (defined in ipc_message.cc)
             name = '%s::%s' % (md.namespace, md.decl.progname)
             segmentcapacity = self.segmentcapacitydict.get(name, 0)
 
             mfDecl, mfDefn = _splitFuncDeclDefn(
-                _generateMessageConstructor(md.msgCtorFunc(), md.msgId(),
-                                            segmentcapacity,
-                                            md.decl.type.nested,
-                                            md.decl.type.prio,
-                                            md.prettyMsgName(p.name+'::'),
-                                            md.decl.type.compress))
+                _generateMessageConstructor(md, segmentcapacity, p,
+                                            forReply=False))
             decls.append(mfDecl)
             self.funcDefns.append(mfDefn)
 
             if md.hasReply():
                 rfDecl, rfDefn = _splitFuncDeclDefn(
-                    _generateMessageConstructor(
-                        md.replyCtorFunc(), md.replyId(),
-                        0,
-                        md.decl.type.nested,
-                        md.decl.type.prio,
-                        md.prettyReplyName(p.name+'::'),
-                        md.decl.type.compress))
+                    _generateMessageConstructor(md, 0, p, forReply=True))
                 decls.append(rfDecl)
                 self.funcDefns.append(rfDefn)
 
             decls.append(Whitespace.NL)
             ns.addstmts(decls)
 
         ns.addstmts([ Whitespace.NL, Whitespace.NL ])
 
@@ -1706,17 +1696,30 @@ class _GenerateProtocolCode(ipdl.ast.Vis
         fromswitch.addcase(DefaultLabel(), unreachedblock)
 
         transitionfunc.addstmt(fromswitch)
 
         return transitionfunc
 
 ##--------------------------------------------------
 
-def _generateMessageConstructor(clsname, msgid, segmentSize, nested, prio, prettyName, compress):
+def _generateMessageConstructor(md, segmentSize, protocol, forReply=False):
+    if forReply:
+        clsname = md.replyCtorFunc()
+        msgid = md.replyId()
+        prettyName = md.prettyReplyName(protocol.name+'::')
+    else:
+        clsname = md.msgCtorFunc()
+        msgid = md.msgId()
+        prettyName = md.prettyMsgName(protocol.name+'::')
+
+    nested = md.decl.type.nested
+    prio = md.decl.type.prio
+    compress = md.decl.type.compress
+
     routingId = ExprVar('routingId')
 
     func = FunctionDefn(FunctionDecl(
         clsname,
         params=[ Decl(Type('int32_t'), routingId.name) ],
         ret=Type('IPC::Message', ptr=1)))
 
     if compress == 'compress':