From f4a054ab8d57122a08d550bc2a4fb2246088b6e3 Mon Sep 17 00:00:00 2001 From: Nathan Froyd Date: Fri, 15 Sep 2017 08:06:11 -0400 Subject: [PATCH] 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 | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/ipc/ipdl/ipdl/lower.py b/ipc/ipdl/ipdl/lower.py index 2c449ec8fa35..67b2a9063847 100644 --- a/ipc/ipdl/ipdl/lower.py +++ b/ipc/ipdl/ipdl/lower.py @@ -1597,24 +1597,14 @@ class _GenerateProtocolCode(ipdl.ast.Visitor): 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) @@ -1711,7 +1701,20 @@ class _GenerateProtocolCode(ipdl.ast.Visitor): ##-------------------------------------------------- -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(