Bug 753159: Allow empty structs. r=bent
authorChris Jones <jones.chris.g@gmail.com>
Wed, 30 May 2012 15:37:26 -0700
changeset 95300 8fb11da68d816c26c09d7b5716b7b32e6e5dbe62
parent 95299 4f8a0cf03399941cebd783427c8f6af615841a32
child 95301 4c96e5b05cb7d4642eaccf1a6319d357b013a82c
push id10052
push usercjones@mozilla.com
push dateWed, 30 May 2012 22:37:33 +0000
treeherdermozilla-inbound@4c96e5b05cb7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbent
bugs753159
milestone15.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 753159: Allow empty structs. r=bent
ipc/ipdl/ipdl/lower.py
ipc/ipdl/ipdl/parser.py
--- a/ipc/ipdl/ipdl/lower.py
+++ b/ipc/ipdl/ipdl/lower.py
@@ -1811,20 +1811,24 @@ def _generateCxxStruct(sd):
 
     def fieldsAsParamList():
         return [ Decl(f.inType(), f.argVar().name) for f in sd.fields ]
 
     def assignFromOther(oexpr):
         return ExprCall(assignvar,
                         args=[ f.initExpr(oexpr) for f in sd.fields ])
 
-    # Struct()
-    defctor = ConstructorDefn(ConstructorDecl(sd.name))
-    defctor.addstmt(StmtExpr(callinit))
-    struct.addstmts([ defctor, Whitespace.NL ])
+    # If this is an empty struct (no fields), then the default ctor
+    # and "create-with-fields" ctors are equivalent.  So don't bother
+    # with the default ctor.
+    if len(sd.fields):
+        # Struct()
+        defctor = ConstructorDefn(ConstructorDecl(sd.name))
+        defctor.addstmt(StmtExpr(callinit))
+        struct.addstmts([ defctor, Whitespace.NL ])
 
     # Struct(const field1& _f1, ...)
     valctor = ConstructorDefn(ConstructorDecl(sd.name,
                                               params=fieldsAsParamList(),
                                               force_inline=1))
     valctor.addstmts([
         StmtExpr(callinit),
         StmtExpr(ExprCall(assignvar,
--- a/ipc/ipdl/ipdl/parser.py
+++ b/ipc/ipdl/ipdl/parser.py
@@ -269,18 +269,22 @@ def p_NamespaceThing(p):
     if 2 == len(p):
         p[0] = [ p[1] ]
     else:
         for thing in p[4]:
             thing.addOuterNamespace(Namespace(locFromTok(p, 1), p[2]))
         p[0] = p[4]
 
 def p_StructDecl(p):
-    """StructDecl : STRUCT ID '{' StructFields  '}' ';'"""
-    p[0] = StructDecl(locFromTok(p, 1), p[2], p[4])
+    """StructDecl : STRUCT ID '{' StructFields '}' ';'
+                  | STRUCT ID '{' '}' ';'"""
+    if 7 == len(p):
+        p[0] = StructDecl(locFromTok(p, 1), p[2], p[4])
+    else:
+        p[0] = StructDecl(locFromTok(p, 1), p[2], [ ])
 
 def p_StructFields(p):
     """StructFields : StructFields StructField ';'
                     | StructField ';'"""
     if 3 == len(p):
         p[0] = [ p[1] ]
     else:
         p[1].append(p[2])