Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Wilson committed Feb 7, 2012
2 parents becbf13 + 7cd2d8b commit 591d005
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 35 deletions.
1 change: 1 addition & 0 deletions src/aggregate.h
Expand Up @@ -143,6 +143,7 @@ struct StructDeclaration : AggregateDeclaration
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
char *mangle();
const char *kind();
void finalizeSize();
#if DMDV1
Expression *cloneMembers();
#endif
Expand Down
13 changes: 12 additions & 1 deletion src/mtype.c
Expand Up @@ -7948,7 +7948,18 @@ Expression *TypeClass::dotExp(Scope *sc, Expression *e, Identifier *ident)
/* Create a TupleExp
*/
e = e->semantic(sc); // do this before turning on noaccesscheck
e->type->size(); // do semantic of type

/* If this is called in the middle of a class declaration,
* class Inner {
* int x;
* alias typeof(Inner.tupleof) T;
* int y;
* }
* then Inner.y will be omitted from the tuple.
*/
// Detect that error, and at least try to run semantic() on it if we can
sym->size(e->loc);

Expressions *exps = new Expressions;
exps->reserve(sym->fields.dim);

Expand Down
64 changes: 30 additions & 34 deletions src/struct.c
Expand Up @@ -115,7 +115,7 @@ void AggregateDeclaration::inlineScan()

unsigned AggregateDeclaration::size(Loc loc)
{
//printf("AggregateDeclaration::size() = %d\n", structsize);
//printf("AggregateDeclaration::size() %s, scope = %p\n", toChars(), scope);
if (!members)
error(loc, "unknown size");
if (sizeok != 1 && scope)
Expand Down Expand Up @@ -446,7 +446,7 @@ void StructDeclaration::semantic(Scope *sc)
* resolve individual members like enums.
*/
for (size_t i = 0; i < members_dim; i++)
{ Dsymbol *s = members->tdata()[i];
{ Dsymbol *s = (*members)[i];
/* There are problems doing this in the general case because
* Scope keeps track of things like 'offset'
*/
Expand All @@ -459,28 +459,19 @@ void StructDeclaration::semantic(Scope *sc)

for (size_t i = 0; i < members_dim; i++)
{
Dsymbol *s = members->tdata()[i];
s->semantic(sc2);
#if 0
if (sizeok == 2)
{ //printf("forward reference\n");
break;
}
#endif
Dsymbol *s = (*members)[i];

#if 0 /* Decided to allow this because if the field is initialized by copying it from
* a correctly initialized struct, it will work.
/* If this is the last member, see if we can finish setting the size.
* This could be much better - finish setting the size after the last
* field was processed. The problem is the chicken-and-egg determination
* of when that is. See Bugzilla 7426 for more info.
*/
Type *t;
if (s->isDeclaration() &&
(t = s->isDeclaration()->type) != NULL &&
t->toBasetype()->ty == Tstruct)
{ StructDeclaration *sd = (StructDeclaration *)t->toDsymbol(sc);
if (sd->isnested)
error("inner struct %s cannot be the type for field %s as it must embed a reference to its enclosing %s",
sd->toChars(), s->toChars(), sd->toParent2()->toPrettyChars());
if (i + 1 == members_dim)
{
if (sizeok == 0 && s->isAliasDeclaration())
finalizeSize();
}
#endif
s->semantic(sc2);
}

if (sizeok == 2)
Expand All @@ -500,19 +491,7 @@ void StructDeclaration::semantic(Scope *sc)
return;
}

// 0 sized struct's are set to 1 byte
if (structsize == 0)
{
structsize = 1;
alignsize = 1;
}

// Round struct size up to next alignsize boundary.
// This will ensure that arrays of structs will get their internals
// aligned properly.
structsize = (structsize + alignsize - 1) & ~(alignsize - 1);

sizeok = 1;
finalizeSize();
Module::dprogress++;

//printf("-StructDeclaration::semantic(this=%p, '%s')\n", this, toChars());
Expand Down Expand Up @@ -654,6 +633,23 @@ Dsymbol *StructDeclaration::search(Loc loc, Identifier *ident, int flags)
return ScopeDsymbol::search(loc, ident, flags);
}

void StructDeclaration::finalizeSize()
{
// 0 sized struct's are set to 1 byte
if (structsize == 0)
{
structsize = 1;
alignsize = 1;
}

// Round struct size up to next alignsize boundary.
// This will ensure that arrays of structs will get their internals
// aligned properly.
structsize = (structsize + alignsize - 1) & ~(alignsize - 1);

sizeok = 1;
}

void StructDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
{
buf->printf("%s ", kind());
Expand Down
11 changes: 11 additions & 0 deletions test/runnable/inner.d
Expand Up @@ -779,6 +779,17 @@ void test24()

/*******************************************************/

struct S7426
{
static struct Inner
{
int x;
alias typeof(Inner.tupleof) T;
}
}

/*******************************************************/

int main()
{

Expand Down

0 comments on commit 591d005

Please sign in to comment.