Bug 1297804 - part 0 - add a RangedFor stament type to IPDL's code generator; r=billm
authorNathan Froyd <froydnj@gmail.com>
Fri, 02 Sep 2016 16:14:28 -0400
changeset 312411 1477881ee551854e3b136225083e8d85a41aca38
parent 312410 47f3a6275d66fe0a7d88cba05e375011be35b6c8
child 312412 ad48a00323b3d435e1b46ff6befbdcce17c61f36
push id20447
push userkwierso@gmail.com
push dateFri, 02 Sep 2016 20:36:44 +0000
treeherderfx-team@969397f22187 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbillm
bugs1297804
milestone51.0a1
Bug 1297804 - part 0 - add a RangedFor stament type to IPDL's code generator; r=billm This addition makes many of the upcoming patches significantly easier to write, and enables us to avoid unpleasantness trying to fiddle with ipdl.py's notions of C++ types. (For instance, there's no good way, when you have a type in-hand, to say the moral equivalent of std::add_pointer<T>::type.)
ipc/ipdl/ipdl/cxx/ast.py
ipc/ipdl/ipdl/cxx/cgen.py
--- a/ipc/ipdl/ipdl/cxx/ast.py
+++ b/ipc/ipdl/ipdl/cxx/ast.py
@@ -752,16 +752,25 @@ class StmtIf(Node):
 
 class StmtFor(Block):
     def __init__(self, init=None, cond=None, update=None):
         Block.__init__(self)
         self.init = init
         self.cond = cond
         self.update = update
 
+class StmtRangedFor(Block):
+    def __init__(self, var, iteree):
+        assert isinstance(var, ExprVar)
+        assert iteree
+
+        Block.__init__(self)
+        self.var = var
+        self.iteree = iteree
+
 class StmtSwitch(Block):
     def __init__(self, expr):
         Block.__init__(self)
         self.expr = expr
         self.nr_cases = 0
 
     def addcase(self, case, block):
         '''NOTE: |case| is not checked for uniqueness'''
--- a/ipc/ipdl/ipdl/cxx/cgen.py
+++ b/ipc/ipdl/ipdl/cxx/cgen.py
@@ -431,16 +431,29 @@ class CxxCodeGen(CodePrinter, Visitor):
         self.println(') {')
 
         self.indent()
         self.visitBlock(sf)
         self.dedent()
         self.printdentln('}')
 
 
+    def visitStmtRangedFor(self, rf):
+        self.printdent('for (auto& ')
+        rf.var.accept(self)
+        self.write(' : ')
+        rf.iteree.accept(self)
+        self.println(') {')
+
+        self.indent()
+        self.visitBlock(rf)
+        self.dedent()
+        self.printdentln('}')
+
+
     def visitStmtSwitch(self, sw):
         self.printdent('switch (')
         sw.expr.accept(self)
         self.println(') {')
         self.indent()
         self.visitBlock(sw)
         self.dedent()
         self.printdentln('}')