Skip to content

Commit

Permalink
Merge pull request #5122 from ibuclaw/anonagg
Browse files Browse the repository at this point in the history
Add virtual method isAnonDeclaration to Dsymbol
  • Loading branch information
9rnsr committed Sep 28, 2015
2 parents 7a7687e + 9a11bc5 commit baf18e7
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/attrib.d
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,9 @@ public:
bool isunion;
structalign_t alignment;
int sem; // 1 if successful semantic()
uint anonoffset; // offset of anonymous struct
uint anonstructsize; // size of anonymous struct
uint anonalignsize; // size of anonymous struct for alignment purposes

extern (D) this(Loc loc, bool isunion, Dsymbols* decl)
{
Expand Down Expand Up @@ -661,8 +664,8 @@ public:
if (this.isunion)
offset = 0;
}
uint anonstructsize = ad.structsize;
uint anonalignsize = ad.alignsize;
anonstructsize = ad.structsize;
anonalignsize = ad.alignsize;
ad.structsize = savestructsize;
ad.alignsize = savealignsize;
if (fieldstart == ad.fields.dim)
Expand All @@ -684,7 +687,7 @@ public:
/* Given the anon 'member's size and alignment,
* go ahead and place it.
*/
uint anonoffset = AggregateDeclaration.placeField(poffset, anonstructsize, anonalignsize, alignment, &ad.structsize, &ad.alignsize, isunion);
anonoffset = AggregateDeclaration.placeField(poffset, anonstructsize, anonalignsize, alignment, &ad.structsize, &ad.alignsize, isunion);
// Add to the anon fields the base offset of this anonymous aggregate
//printf("anon fields, anonoffset = %d\n", anonoffset);
for (size_t i = fieldstart; i < ad.fields.dim; i++)
Expand All @@ -701,6 +704,11 @@ public:
return (isunion ? "anonymous union" : "anonymous struct");
}

override final AnonDeclaration isAnonDeclaration()
{
return this;
}

override void accept(Visitor v)
{
v.visit(this);
Expand Down
4 changes: 4 additions & 0 deletions src/attrib.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,16 @@ class AnonDeclaration : public AttribDeclaration
bool isunion;
structalign_t alignment;
int sem; // 1 if successful semantic()
unsigned anonoffset; // offset of anonymous struct
unsigned anonstructsize; // size of anonymous struct
unsigned anonalignsize; // size of anonymous struct for alignment purposes

AnonDeclaration(Loc loc, bool isunion, Dsymbols *decl);
Dsymbol *syntaxCopy(Dsymbol *s);
void semantic(Scope *sc);
void setFieldOffset(AggregateDeclaration *ad, unsigned *poffset, bool isunion);
const char *kind();
AnonDeclaration *isAnonDeclaration() { return this; }
void accept(Visitor *v) { v->visit(this); }
};

Expand Down
5 changes: 5 additions & 0 deletions src/dsymbol.d
Original file line number Diff line number Diff line change
Expand Up @@ -1143,6 +1143,11 @@ public:
return null;
}

AnonDeclaration isAnonDeclaration()
{
return null;
}

OverloadSet isOverloadSet()
{
return null;
Expand Down
1 change: 1 addition & 0 deletions src/dsymbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ class Dsymbol : public RootObject
virtual DeleteDeclaration *isDeleteDeclaration() { return NULL; }
virtual SymbolDeclaration *isSymbolDeclaration() { return NULL; }
virtual AttribDeclaration *isAttribDeclaration() { return NULL; }
virtual AnonDeclaration *isAnonDeclaration() { return NULL; }
virtual OverloadSet *isOverloadSet() { return NULL; }
virtual void accept(Visitor *v) { v->visit(this); }
};
Expand Down

0 comments on commit baf18e7

Please sign in to comment.