Skip to content

Commit

Permalink
Merge pull request #3462 from 9rnsr/refactor_offset
Browse files Browse the repository at this point in the history
[Refactoring] Remove Scope::offset
  • Loading branch information
WalterBright committed Apr 18, 2014
2 parents f476978 + afcb8fd commit 49e855f
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 58 deletions.
19 changes: 2 additions & 17 deletions src/attrib.c
Expand Up @@ -106,10 +106,7 @@ void AttribDeclaration::setScopeNewSc(Scope *sc,
s->setScope(newsc); // yes, the only difference from semanticNewSc()
}
if (newsc != sc)
{
sc->offset = newsc->offset;
newsc->pop();
}
}
}

Expand Down Expand Up @@ -141,10 +138,7 @@ void AttribDeclaration::semanticNewSc(Scope *sc,
s->semantic(newsc);
}
if (newsc != sc)
{
sc->offset = newsc->offset;
newsc->pop();
}
}
}

Expand Down Expand Up @@ -215,7 +209,8 @@ void AttribDeclaration::setFieldOffset(AggregateDeclaration *ad, unsigned *poffs
if (d)
{
for (size_t i = 0; i < d->dim; i++)
{ Dsymbol *s = (*d)[i];
{
Dsymbol *s = (*d)[i];
s->setFieldOffset(ad, poffset, isunion);
}
}
Expand Down Expand Up @@ -806,7 +801,6 @@ void AnonDeclaration::semantic(Scope *sc)
sc = sc->push();
sc->stc &= ~(STCauto | STCscope | STCstatic | STCtls | STCgshared);
sc->inunion = isunion;
sc->offset = 0;
sc->flags = 0;

for (size_t i = 0; i < decl->dim; i++)
Expand Down Expand Up @@ -1633,10 +1627,7 @@ void UserAttributeDeclaration::setScope(Scope *sc)
s->setScope(newsc); // yes, the only difference from semantic()
}
if (newsc != sc)
{
sc->offset = newsc->offset;
newsc->pop();
}
}
}

Expand All @@ -1661,10 +1652,7 @@ void UserAttributeDeclaration::semantic(Scope *sc)
s->semantic(newsc);
}
if (newsc != sc)
{
sc->offset = newsc->offset;
newsc->pop();
}
}
}

Expand All @@ -1691,10 +1679,7 @@ void UserAttributeDeclaration::semantic2(Scope *sc)
s->semantic2(newsc);
}
if (newsc != sc)
{
sc->offset = newsc->offset;
newsc->pop();
}
}
}

Expand Down
29 changes: 11 additions & 18 deletions src/class.c
Expand Up @@ -599,22 +599,18 @@ void ClassDeclaration::semantic(Scope *sc)
sc->structalign = STRUCTALIGN_DEFAULT;
if (baseClass)
{
sc->offset = baseClass->structsize;
alignsize = baseClass->alignsize;
sc->offset = (sc->offset + alignsize - 1) & ~(alignsize - 1);
// if (enclosing)
// sc->offset += Target::ptrsize; // room for uplevel context pointer
structsize = (baseClass->structsize + alignsize - 1) & ~(alignsize - 1);
}
else
{
alignsize = Target::ptrsize;
if (cpp)
sc->offset = Target::ptrsize; // allow room for __vptr
structsize = Target::ptrsize; // allow room for __vptr
else
sc->offset = Target::ptrsize * 2; // allow room for __vptr and __monitor
alignsize = Target::ptrsize;
structsize = Target::ptrsize * 2; // allow room for __vptr and __monitor
}
sc->userAttribDecl = NULL;
structsize = sc->offset;
Scope scsave = *sc;
size_t members_dim = members->dim;
sizeok = SIZEOKnone;
Expand Down Expand Up @@ -652,7 +648,6 @@ void ClassDeclaration::semantic(Scope *sc)
Dsymbol *s = (*members)[i];
s->setFieldOffset(this, &offset, false);
}
sc->offset = structsize;

if (global.errors != errors)
{
Expand All @@ -672,7 +667,6 @@ void ClassDeclaration::semantic(Scope *sc)
fields.setDim(0);
structsize = 0;
alignsize = 0;
// structalign = 0;

sc = sc->pop();

Expand Down Expand Up @@ -752,28 +746,28 @@ void ClassDeclaration::semantic(Scope *sc)
#endif

// Allocate instance of each new interface
sc->offset = structsize;
offset = structsize;
for (size_t i = 0; i < vtblInterfaces->dim; i++)
{
BaseClass *b = (*vtblInterfaces)[i];
unsigned thissize = Target::ptrsize;

alignmember(STRUCTALIGN_DEFAULT, thissize, &sc->offset);
alignmember(STRUCTALIGN_DEFAULT, thissize, &offset);
assert(b->offset == 0);
b->offset = sc->offset;
b->offset = offset;

// Take care of single inheritance offsets
while (b->baseInterfaces_dim)
{
b = &b->baseInterfaces[0];
b->offset = sc->offset;
b->offset = offset;
}

sc->offset += thissize;
offset += thissize;
if (alignsize < thissize)
alignsize = thissize;
}
structsize = sc->offset;
structsize = offset;
sizeok = SIZEOKdone;
Module::dprogress++;

Expand Down Expand Up @@ -1450,9 +1444,8 @@ void InterfaceDeclaration::semantic(Scope *sc)
sc->protection = PROTpublic;
sc->explicitProtection = 0;
// structalign = sc->structalign;
sc->offset = Target::ptrsize * 2;
sc->userAttribDecl = NULL;
structsize = sc->offset;
structsize = Target::ptrsize * 2;
inuse++;

/* Set scope so if there are forward references, we still might be able to
Expand Down
2 changes: 0 additions & 2 deletions src/scope.c
Expand Up @@ -73,7 +73,6 @@ Scope::Scope()
this->explicitProtection = 0;
this->stc = 0;
this->depmsg = NULL;
this->offset = 0;
this->inunion = 0;
this->nofree = 0;
this->noctor = 0;
Expand Down Expand Up @@ -123,7 +122,6 @@ Scope::Scope(Scope *enclosing)
this->explicitProtection = enclosing->explicitProtection;
this->depmsg = enclosing->depmsg;
this->stc = enclosing->stc;
this->offset = 0;
this->inunion = enclosing->inunion;
this->nofree = 0;
this->noctor = enclosing->noctor;
Expand Down
5 changes: 0 additions & 5 deletions src/scope.h
Expand Up @@ -80,11 +80,6 @@ struct Scope
Statement *scontinue; // enclosing statement that supports "continue"
ForeachStatement *fes; // if nested function for ForeachStatement, this is it
Scope *callsc; // used for __FUNCTION__, __PRETTY_FUNCTION__ and __MODULE__
unsigned offset; // next offset to use in aggregate
// This really shouldn't be a part of Scope, because it requires
// semantic() to be done in the lexical field order. It should be
// set in a pass after semantic() on all fields so they can be
// semantic'd in any order.
int inunion; // we're processing members of a union
int nofree; // set if shouldn't free it
int noctor; // set if constructor calls aren't allowed
Expand Down
4 changes: 2 additions & 2 deletions src/struct.c
Expand Up @@ -775,7 +775,6 @@ void StructDeclaration::semantic(Scope *sc)
fields.setDim(0);
structsize = 0;
alignsize = 0;
// structalign = 0;

scope = scx ? scx : sc->copy();
scope->setNoFree();
Expand Down Expand Up @@ -926,7 +925,8 @@ void StructDeclaration::finalizeSize(Scope *sc)
unsigned offset = 0;
bool isunion = isUnionDeclaration() != NULL;
for (size_t i = 0; i < members->dim; i++)
{ Dsymbol *s = (*members)[i];
{
Dsymbol *s = (*members)[i];
s->setFieldOffset(this, &offset, isunion);
}
if (sizeok == SIZEOKfwd)
Expand Down
17 changes: 3 additions & 14 deletions src/template.c
Expand Up @@ -7548,14 +7548,7 @@ Dsymbol *TemplateInstance::toAlias()
// Maybe we can resolve it
if (scope)
{
/* Anything that affects scope->offset must be
* done in lexical order. Fwd ref error if it is affected, otherwise allow.
*/
unsigned offset = scope->offset;
Scope *sc = scope;
semantic(scope);
// if (offset != sc->offset)
// inst = NULL; // trigger fwd ref error
}
if (!inst)
{
Expand Down Expand Up @@ -7973,10 +7966,7 @@ void TemplateMixin::semantic(Scope *sc)
#if LOG
printf("\tdo semantic() on template instance members '%s'\n", toChars());
#endif
Scope *sc2;
sc2 = argscope->push(this);
sc2->offset = sc->offset;

Scope *sc2 = argscope->push(this);
size_t deferred_dim = Module::deferred.dim;

static int nest;
Expand Down Expand Up @@ -8008,8 +7998,6 @@ void TemplateMixin::semantic(Scope *sc)

nest--;

sc->offset = sc2->offset;

if (!sc->func && Module::deferred.dim > deferred_dim)
{
sc2->pop();
Expand Down Expand Up @@ -8167,7 +8155,8 @@ void TemplateMixin::setFieldOffset(AggregateDeclaration *ad, unsigned *poffset,
if (members)
{
for (size_t i = 0; i < members->dim; i++)
{ Dsymbol *s = (*members)[i];
{
Dsymbol *s = (*members)[i];
//printf("\t%s\n", s->toChars());
s->setFieldOffset(ad, poffset, isunion);
}
Expand Down

0 comments on commit 49e855f

Please sign in to comment.