Bug 1397823 - part 2 - tidy _generateMessageConstructor enums a little; r=kanru
authorNathan Froyd <froydnj@mozilla.com>
Fri, 15 Sep 2017 08:06:11 -0400
changeset 665499 6e7da31ab0b11eb3b4f2e372b350652b8b3e3597
parent 665498 1607f6d53f5273361ce35e47f94d3966c26611c6
child 665500 14acffc2e1eca99806bda3099cdf12938772cd52
push id80093
push userbmo:ttromey@mozilla.com
push dateFri, 15 Sep 2017 16:41:29 +0000
reviewerskanru
bugs1397823
milestone57.0a1
Bug 1397823 - part 2 - tidy _generateMessageConstructor enums a little; r=kanru There's no need to be repeating 'IPC::Message::' prefixes or spreading around more ExprVar calls than we need here. Let's try to improve the signal-to-noise ratio of this code by introducing a helper function to inject some of the boilerplate for us.
ipc/ipdl/ipdl/lower.py
--- a/ipc/ipdl/ipdl/lower.py
+++ b/ipc/ipdl/ipdl/lower.py
@@ -1718,46 +1718,49 @@ def _generateMessageConstructor(md, segm
     routingId = ExprVar('routingId')
 
     func = FunctionDefn(FunctionDecl(
         clsname,
         params=[ Decl(Type('int32_t'), routingId.name) ],
         ret=Type('IPC::Message', ptr=1)))
 
     if compress == 'compress':
-        compression = ExprVar('IPC::Message::COMPRESSION_ENABLED')
+        compression = 'COMPRESSION_ENABLED'
     elif compress:
         assert compress == 'compressall'
-        compression = ExprVar('IPC::Message::COMPRESSION_ALL')
+        compression = 'COMPRESSION_ALL'
     else:
-        compression = ExprVar('IPC::Message::COMPRESSION_NONE')
+        compression = 'COMPRESSION_NONE'
 
     if nested == ipdl.ast.NOT_NESTED:
-        nestedEnum = 'IPC::Message::NOT_NESTED'
+        nestedEnum = 'NOT_NESTED'
     elif nested == ipdl.ast.INSIDE_SYNC_NESTED:
-        nestedEnum = 'IPC::Message::NESTED_INSIDE_SYNC'
+        nestedEnum = 'NESTED_INSIDE_SYNC'
     else:
         assert nested == ipdl.ast.INSIDE_CPOW_NESTED
-        nestedEnum = 'IPC::Message::NESTED_INSIDE_CPOW'
+        nestedEnum = 'NESTED_INSIDE_CPOW'
 
     if prio == ipdl.ast.NORMAL_PRIORITY:
-        prioEnum = 'IPC::Message::NORMAL_PRIORITY'
+        prioEnum = 'NORMAL_PRIORITY'
     elif prio == ipdl.ast.INPUT_PRIORITY:
-        prioEnum = 'IPC::Message::INPUT_PRIORITY'
+        prioEnum = 'INPUT_PRIORITY'
     else:
-        prioEnum = 'IPC::Message::HIGH_PRIORITY'
+        prioEnum = 'HIGH_PRIORITY'
+
+    def messageEnum(valname):
+        return ExprVar('IPC::Message::' + valname)
 
     func.addstmt(
         StmtReturn(ExprNew(Type('IPC::Message'),
                            args=[ routingId,
                                   ExprVar(msgid),
                                   ExprLiteral.Int(int(segmentSize)),
-                                  ExprVar(nestedEnum),
-                                  ExprVar(prioEnum),
-                                  compression,
+                                  messageEnum(nestedEnum),
+                                  messageEnum(prioEnum),
+                                  messageEnum(compression),
                                   ExprLiteral.String(prettyName),
                                   # Pass `true` to recordWriteLatency to collect telemetry
                                   ExprLiteral.TRUE ])))
 
     return func
 
 ##--------------------------------------------------