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 312385 1477881ee551854e3b136225083e8d85a41aca38
parent 312384 47f3a6275d66fe0a7d88cba05e375011be35b6c8
child 312386 ad48a00323b3d435e1b46ff6befbdcce17c61f36
push id81366
push usernfroyd@mozilla.com
push dateFri, 02 Sep 2016 12:16:26 +0000
treeherdermozilla-inbound@1b874fea3cbc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbillm
bugs1297804
milestone51.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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('}')