This commit is contained in:
Christian Kamm
2008-10-30 10:17:05 +01:00
10 changed files with 81 additions and 24 deletions

View File

@@ -501,9 +501,6 @@ AlignDeclaration::AlignDeclaration(Loc loc, unsigned sa, Array *decl)
{
this->loc = loc;
salign = sa;
if (global.params.warnings && salign != 1)
warning("%s: align(%d) is not implemented and specified to be unportable anyway, use align(1) and manual fillers instead", loc.toChars(), salign);
}
Dsymbol *AlignDeclaration::syntaxCopy(Dsymbol *s)
@@ -517,21 +514,33 @@ Dsymbol *AlignDeclaration::syntaxCopy(Dsymbol *s)
void AlignDeclaration::semantic(Scope *sc)
{
// LDC
// we only support packed structs, as from the spec: align(1) struct Packed { ... }
// other alignments are simply ignored. my tests show this is what llvm-gcc does too ...
//printf("\tAlignDeclaration::semantic '%s'\n",toChars());
if (decl)
{ unsigned salign_save = sc->structalign;
sc->structalign = salign;
for (unsigned i = 0; i < decl->dim; i++)
{
Dsymbol *s = (Dsymbol *)decl->data[i];
s->semantic(sc);
if (s->isStructDeclaration() && salign == 1)
{
sc->structalign = salign;
s->semantic(sc);
sc->structalign = salign_save;
}
else
{
s->semantic(sc);
}
}
sc->structalign = salign_save;
}
else
sc->structalign = salign;
assert(0 && "what kind of align use triggers this?");
}
@@ -658,12 +667,17 @@ void AnonDeclaration::semantic(Scope *sc)
//printf("sc->offset = %d\n", sc->offset);
// Add members of aad to ad
//printf("\tadding members of aad to '%s'\n", ad->toChars());
//printf("\tadding members of aad (%p) to '%s'\n", &aad, ad->toChars());
for (unsigned i = 0; i < aad.fields.dim; i++)
{
VarDeclaration *v = (VarDeclaration *)aad.fields.data[i];
v->offset += sc->offset;
// LDC
if (!v->anonDecl)
v->anonDecl = this;
ad->fields.push(v);
}

View File

@@ -621,6 +621,9 @@ VarDeclaration::VarDeclaration(Loc loc, Type *type, Identifier *id, Initializer
onstack = 0;
canassign = 0;
value = NULL;
// LDC
anonDecl = NULL;
}
Dsymbol *VarDeclaration::syntaxCopy(Dsymbol *s)

View File

@@ -37,6 +37,7 @@ struct StructDeclaration;
struct TupleType;
struct InterState;
struct IRState;
struct AnonDeclaration;
enum PROT;
enum LINK;
@@ -269,6 +270,9 @@ struct VarDeclaration : Declaration
// Eliminate need for dynamic_cast
VarDeclaration *isVarDeclaration() { return (VarDeclaration *)this; }
// LDC
AnonDeclaration* anonDecl;
};
/**************************************************************/

View File

@@ -349,6 +349,9 @@ Array *Parser::parseDeclDefs(int once)
case TOKalign:
{ unsigned n;
// LDC better align code locations
Loc alignloc = loc;
s = NULL;
nextToken();
if (token.value == TOKlparen)
@@ -367,7 +370,7 @@ Array *Parser::parseDeclDefs(int once)
n = global.structalign; // default
a = parseBlock();
s = new AlignDeclaration(loc, n, a);
s = new AlignDeclaration(alignloc, n, a);
break;
}

View File

@@ -30,6 +30,7 @@ struct AnonymousAggregateDeclaration;
struct FuncDeclaration;
struct DocComment;
struct EnclosingHandler;
struct AnonDeclaration;
enum LINK;
enum PROT;