Bug 779013 - Align the mValue union in IPDL-generated code. r=cjones

This commit is contained in:
Chris Dearman 2012-08-08 15:10:03 -04:00
parent 84abd878e1
commit f7e93b5541
2 changed files with 17 additions and 3 deletions

View File

@ -358,9 +358,21 @@ class TypeUnion(Node):
Node.__init__(self)
self.name = name
self.components = [ ] # [ Decl ]
# Expr -- evaluates to a constant value representing
# the maximum alignment of all types in the union
self.alignment = None
def addComponent(self, type, name):
self.components.append(Decl(type, name))
def addComponent(self, c):
self.components.append(Decl(c.unionType(), c.name))
alignme = ExprCall(ExprVar('MOZ_ALIGNOF'), [ c.internalType() ])
if self.alignment:
self.alignment = ExprCall(ExprVar('PR_MAX'), [ alignme, self.alignment ])
else:
self.alignment = alignme
def addAlignment(self):
if self.alignment:
self.components.append(Decl(Type('mozilla::AlignedElem', T=self.alignment), '__align'))
class Typedef(Node):
def __init__(self, fromtype, totypename):

View File

@ -2098,7 +2098,9 @@ def _generateCxxUnion(ud):
# the C++ union the discunion use for storage
valueunion = TypeUnion(valuetype.name)
for c in ud.components:
valueunion.addComponent(c.unionType(), c.name)
valueunion.addComponent(c);
valueunion.addAlignment();
cls.addstmts([ StmtDecl(Decl(valueunion,'')),
Whitespace.NL ])