Bug 753159: Allow empty structs. r=bent

This commit is contained in:
Chris Jones 2012-05-30 15:37:26 -07:00
parent 045aefbfce
commit e52fe0f199
2 changed files with 14 additions and 6 deletions

View File

@ -1816,10 +1816,14 @@ def _generateCxxStruct(sd):
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,

View File

@ -274,8 +274,12 @@ def p_NamespaceThing(p):
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 ';'