712 changes: 351 additions & 361 deletions src/tocsym.c

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions src/todt.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ dt_t **ClassReferenceExp_toDt(ClassReferenceExp *e, dt_t **pdt, int off);
dt_t **ClassReferenceExp_toInstanceDt(ClassReferenceExp *ce, dt_t **pdt);
dt_t **membersToDt(ClassReferenceExp *ce, dt_t **pdt, ClassDeclaration *cd, Dts *dts);
dt_t **ClassReferenceExp_toDt(ClassReferenceExp *e, dt_t **pdt, int off);
Symbol *toSymbol(Dsymbol *s);

/* ================================================================ */

Expand Down Expand Up @@ -493,7 +494,7 @@ dt_t **Expression_toDt(Expression *e, dt_t **pdt)
e->error("non-constant expression %s", e->toChars());
return;
}
pdt = dtxoff(pdt, e->var->toSymbol(), e->offset);
pdt = dtxoff(pdt, toSymbol(e->var), e->offset);
}

void visit(VarExp *e)
Expand Down Expand Up @@ -537,7 +538,7 @@ dt_t **Expression_toDt(Expression *e, dt_t **pdt)
e->fd->tok = TOKfunction;
e->fd->vthis = NULL;
}
Symbol *s = e->fd->toSymbol();
Symbol *s = toSymbol(e->fd);
if (e->fd->isNested())
{
e->error("non-constant nested delegate literal expression %s", e->toChars());
Expand Down Expand Up @@ -661,7 +662,7 @@ void membersToDt(ClassDeclaration *cd, dt_t **pdt, ClassDeclaration *concreteTyp
}

// Interface vptr initializations
cd->toSymbol(); // define csym
toSymbol(cd); // define csym

for (size_t i = 0; i < cd->vtblInterfaces->dim; i++)
{
Expand All @@ -675,7 +676,7 @@ void membersToDt(ClassDeclaration *cd, dt_t **pdt, ClassDeclaration *concreteTyp
{
if (offset < b->offset)
dtnzeros(pdt, b->offset - offset);
dtxoff(pdt, cd2->toSymbol(), csymoffset);
dtxoff(pdt, toSymbol(cd2), csymoffset);
break;
}
}
Expand Down Expand Up @@ -954,7 +955,7 @@ dt_t **membersToDt(ClassReferenceExp *ce, dt_t **pdt, ClassDeclaration *cd, Dts
}

// Interface vptr initializations
cd->toSymbol(); // define csym
toSymbol(cd); // define csym

for (size_t i = 0; i < cd->vtblInterfaces->dim; i++)
{
Expand All @@ -967,7 +968,7 @@ dt_t **membersToDt(ClassReferenceExp *ce, dt_t **pdt, ClassDeclaration *cd, Dts
{
if (offset < b->offset)
dtnzeros(pdt, b->offset - offset);
dtxoff(pdt, cd2->toSymbol(), csymoffset);
dtxoff(pdt, toSymbol(cd2), csymoffset);
break;
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/toir.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ bool ISWIN64REF(Declaration *var);

type *Type_toCtype(Type *t);
unsigned totym(Type *tx);
Symbol *toSymbol(Dsymbol *s);

/*********************************************
* Produce elem which increments the usage count for a particular line.
Expand Down Expand Up @@ -573,7 +574,7 @@ elem *resolveLengthVar(VarDeclaration *lengthVar, elem **pe, Type *t1)
elength = el_una(I64 ? OP128_64 : OP64_32, TYsize_t, elength);

L3:
slength = lengthVar->toSymbol();
slength = toSymbol(lengthVar);
//symbol_add(slength);

einit = el_bin(OPeq, TYsize_t, el_var(slength), elength);
Expand Down Expand Up @@ -737,7 +738,7 @@ void buildClosure(FuncDeclaration *fd, IRState *irs)
tym = TYdelegate;
ex = el_bin(OPadd, TYnptr, el_var(sclosure), el_long(TYsize_t, v->offset));
ex = el_una(OPind, tym, ex);
elem *ev = el_var(v->toSymbol());
elem *ev = el_var(toSymbol(v));
if (win64ref)
{
ev->Ety = TYnptr;
Expand Down
46 changes: 24 additions & 22 deletions src/toobj.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ dt_t *Initializer_toDt(Initializer *init);
dt_t **Type_toDt(Type *t, dt_t **pdt);
void ClassDeclaration_toDt(ClassDeclaration *cd, dt_t **pdt);
void StructDeclaration_toDt(StructDeclaration *sd, dt_t **pdt);
Symbol *toSymbol(Dsymbol *s);

void toDebug(TypedefDeclaration *tdd);
void toDebug(EnumDeclaration *ed);
Expand All @@ -65,7 +66,7 @@ void Module::genmoduleinfo()
ObjectNotFound(Id::ModuleInfo);
}

Symbol *msym = toSymbol();
Symbol *msym = toSymbol(this);

//////////////////////////////////////////////

Expand Down Expand Up @@ -141,7 +142,7 @@ void Module::genmoduleinfo()
if (flags & MIdtor)
dtxoff(&dt, sshareddtor, 0, TYnptr);
if (flags & MIxgetMembers)
dtxoff(&dt, sgetmembers->toSymbol(), 0, TYnptr);
dtxoff(&dt, toSymbol(sgetmembers), 0, TYnptr);
if (flags & MIictor)
dtxoff(&dt, sictor, 0, TYnptr);
if (flags & MIunitTest)
Expand All @@ -153,7 +154,8 @@ void Module::genmoduleinfo()
{ Module *m = aimports[i];

if (m->needmoduleinfo)
{ Symbol *s = m->toSymbol();
{
Symbol *s = toSymbol(m);

/* Weak references don't pull objects in from the library,
* they resolve to 0 if not pulled in by something else.
Expand All @@ -170,7 +172,7 @@ void Module::genmoduleinfo()
for (size_t i = 0; i < aclasses.dim; i++)
{
ClassDeclaration *cd = aclasses[i];
dtxoff(&dt, cd->toSymbol(), 0, TYnptr);
dtxoff(&dt, toSymbol(cd), 0, TYnptr);
}
}
if (flags & MIname)
Expand Down Expand Up @@ -243,7 +245,7 @@ void ClassDeclaration::toObjFile(int multiobj)
}

// Generate C symbols
toSymbol();
toSymbol(this);
toVtblSymbol();
sinit = toInitializer();

Expand Down Expand Up @@ -337,19 +339,19 @@ void ClassDeclaration::toObjFile(int multiobj)

// base
if (baseClass)
dtxoff(&dt, baseClass->toSymbol(), 0, TYnptr);
dtxoff(&dt, toSymbol(baseClass), 0, TYnptr);
else
dtsize_t(&dt, 0);

// destructor
if (dtor)
dtxoff(&dt, dtor->toSymbol(), 0, TYnptr);
dtxoff(&dt, toSymbol(dtor), 0, TYnptr);
else
dtsize_t(&dt, 0);

// invariant
if (inv)
dtxoff(&dt, inv->toSymbol(), 0, TYnptr);
dtxoff(&dt, toSymbol(inv), 0, TYnptr);
else
dtsize_t(&dt, 0);

Expand Down Expand Up @@ -383,7 +385,7 @@ void ClassDeclaration::toObjFile(int multiobj)

// deallocator
if (aggDelete)
dtxoff(&dt, aggDelete->toSymbol(), 0, TYnptr);
dtxoff(&dt, toSymbol(aggDelete), 0, TYnptr);
else
dtsize_t(&dt, 0);

Expand All @@ -393,7 +395,7 @@ void ClassDeclaration::toObjFile(int multiobj)

// defaultConstructor
if (defaultCtor)
dtxoff(&dt, defaultCtor->toSymbol(), 0, TYnptr);
dtxoff(&dt, toSymbol(defaultCtor), 0, TYnptr);
else
dtsize_t(&dt, 0);

Expand All @@ -405,7 +407,7 @@ void ClassDeclaration::toObjFile(int multiobj)
else
dtsize_t(&dt, 1);

//dtxoff(&dt, type->vtinfo->toSymbol(), 0, TYnptr); // typeinfo
//dtxoff(&dt, toSymbol(type->vtinfo), 0, TYnptr); // typeinfo

//////////////////////////////////////////////

Expand All @@ -429,7 +431,7 @@ void ClassDeclaration::toObjFile(int multiobj)
// Fill in vtbl[]
b->fillVtbl(this, &b->vtbl, 1);

dtxoff(&dt, id->toSymbol(), 0, TYnptr); // ClassInfo
dtxoff(&dt, toSymbol(id), 0, TYnptr); // ClassInfo

// vtbl[]
dtsize_t(&dt, id->vtbl.dim);
Expand All @@ -452,7 +454,7 @@ void ClassDeclaration::toObjFile(int multiobj)
if (id->vtblOffset())
{
// First entry is ClassInfo reference
//dtxoff(&dt, id->toSymbol(), 0, TYnptr);
//dtxoff(&dt, toSymbol(id), 0, TYnptr);

// First entry is struct Interface reference
dtxoff(&dt, csym, classinfo_size + i * (4 * Target::ptrsize), TYnptr);
Expand Down Expand Up @@ -500,10 +502,10 @@ void ClassDeclaration::toObjFile(int multiobj)
if (id->vtblOffset())
{
// First entry is ClassInfo reference
//dtxoff(&dt, id->toSymbol(), 0, TYnptr);
//dtxoff(&dt, toSymbol(id), 0, TYnptr);

// First entry is struct Interface reference
dtxoff(&dt, cd->toSymbol(), classinfo_size + k * (4 * Target::ptrsize), TYnptr);
dtxoff(&dt, toSymbol(cd), classinfo_size + k * (4 * Target::ptrsize), TYnptr);
j = 1;
}

Expand Down Expand Up @@ -545,7 +547,7 @@ void ClassDeclaration::toObjFile(int multiobj)
// Ensure function has a return value (Bugzilla 4869)
fd->functionSemantic();

Symbol *s = fd->toSymbol();
Symbol *s = toSymbol(fd);

if (isFuncHidden(fd))
{ /* fd is hidden from the view of this class.
Expand Down Expand Up @@ -663,7 +665,7 @@ void InterfaceDeclaration::toObjFile(int multiobj)
}

// Generate C symbols
toSymbol();
toSymbol(this);

//////////////////////////////////////////////

Expand Down Expand Up @@ -775,7 +777,7 @@ void InterfaceDeclaration::toObjFile(int multiobj)
else
dtsize_t(&dt, 0); // no pointers

//dtxoff(&dt, type->vtinfo->toSymbol(), 0, TYnptr); // typeinfo
//dtxoff(&dt, toSymbol(type->vtinfo), 0, TYnptr); // typeinfo

//////////////////////////////////////////////

Expand All @@ -788,7 +790,7 @@ void InterfaceDeclaration::toObjFile(int multiobj)
ClassDeclaration *id = b->base;

// ClassInfo
dtxoff(&dt, id->toSymbol(), 0, TYnptr);
dtxoff(&dt, toSymbol(id), 0, TYnptr);

// vtbl[]
dtsize_t(&dt, 0);
Expand Down Expand Up @@ -896,7 +898,7 @@ void VarDeclaration::toObjFile(int multiobj)

if (isDataseg() && !(storage_class & STCextern))
{
s = toSymbol();
s = toSymbol(this);
sz = type->size();

parent = this->toParent();
Expand Down Expand Up @@ -1070,7 +1072,7 @@ void TypeInfoDeclaration::toObjFile(int multiobj)
return;
}

Symbol *s = toSymbol();
Symbol *s = toSymbol(this);
s->Sclass = SCcomdat;
s->Sfl = FLdata;

Expand Down Expand Up @@ -1144,7 +1146,7 @@ void PragmaDeclaration::toObjFile(int multiobj)
Dsymbol *sa = getDsymbol(e);
FuncDeclaration *f = sa->isFuncDeclaration();
assert(f);
Symbol *s = f->toSymbol();
Symbol *s = toSymbol(f);
obj_startaddress(s);
}
AttribDeclaration::toObjFile(multiobj);
Expand Down
47 changes: 24 additions & 23 deletions src/typinf.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "dt.h"

Parameters *Parameters_create();
Symbol *toSymbol(Dsymbol *s);

/*******************************************
* Get a canonicalized form of the TypeInfo for use with the internal
Expand Down Expand Up @@ -274,7 +275,7 @@ class TypeInfoDtVisitor : public Visitor
Type *tm = d->tinfo->mutableOf();
tm = tm->merge();
tm->genTypeInfo(NULL);
dtxoff(pdt, tm->vtinfo->toSymbol(), 0);
dtxoff(pdt, toSymbol(tm->vtinfo), 0);
}

void visit(TypeInfoInvariantDeclaration *d)
Expand All @@ -287,7 +288,7 @@ class TypeInfoDtVisitor : public Visitor
Type *tm = d->tinfo->mutableOf();
tm = tm->merge();
tm->genTypeInfo(NULL);
dtxoff(pdt, tm->vtinfo->toSymbol(), 0);
dtxoff(pdt, toSymbol(tm->vtinfo), 0);
}

void visit(TypeInfoSharedDeclaration *d)
Expand All @@ -300,7 +301,7 @@ class TypeInfoDtVisitor : public Visitor
Type *tm = d->tinfo->unSharedOf();
tm = tm->merge();
tm->genTypeInfo(NULL);
dtxoff(pdt, tm->vtinfo->toSymbol(), 0);
dtxoff(pdt, toSymbol(tm->vtinfo), 0);
}

void visit(TypeInfoWildDeclaration *d)
Expand All @@ -313,7 +314,7 @@ class TypeInfoDtVisitor : public Visitor
Type *tm = d->tinfo->mutableOf();
tm = tm->merge();
tm->genTypeInfo(NULL);
dtxoff(pdt, tm->vtinfo->toSymbol(), 0);
dtxoff(pdt, toSymbol(tm->vtinfo), 0);
}

void visit(TypeInfoTypedefDeclaration *d)
Expand All @@ -339,7 +340,7 @@ class TypeInfoDtVisitor : public Visitor
sd->basetype = sd->basetype->merge();
sd->basetype->genTypeInfo(NULL); // generate vtinfo
assert(sd->basetype->vtinfo);
dtxoff(pdt, sd->basetype->vtinfo->toSymbol(), 0); // TypeInfo for basetype
dtxoff(pdt, toSymbol(sd->basetype->vtinfo), 0); // TypeInfo for basetype

const char *name = sd->toPrettyChars();
size_t namelen = strlen(name);
Expand Down Expand Up @@ -382,7 +383,7 @@ class TypeInfoDtVisitor : public Visitor
if (sd->memtype)
{
sd->memtype->genTypeInfo(NULL);
dtxoff(pdt, sd->memtype->vtinfo->toSymbol(), 0); // TypeInfo for enum members
dtxoff(pdt, toSymbol(sd->memtype->vtinfo), 0); // TypeInfo for enum members
}
else
dtsize_t(pdt, 0);
Expand Down Expand Up @@ -419,7 +420,7 @@ class TypeInfoDtVisitor : public Visitor
TypePointer *tc = (TypePointer *)d->tinfo;

tc->next->genTypeInfo(NULL);
dtxoff(pdt, tc->next->vtinfo->toSymbol(), 0); // TypeInfo for type being pointed to
dtxoff(pdt, toSymbol(tc->next->vtinfo), 0); // TypeInfo for type being pointed to
}

void visit(TypeInfoArrayDeclaration *d)
Expand All @@ -435,7 +436,7 @@ class TypeInfoDtVisitor : public Visitor
TypeDArray *tc = (TypeDArray *)d->tinfo;

tc->next->genTypeInfo(NULL);
dtxoff(pdt, tc->next->vtinfo->toSymbol(), 0); // TypeInfo for array of type
dtxoff(pdt, toSymbol(tc->next->vtinfo), 0); // TypeInfo for array of type
}

void visit(TypeInfoStaticArrayDeclaration *d)
Expand All @@ -451,7 +452,7 @@ class TypeInfoDtVisitor : public Visitor
TypeSArray *tc = (TypeSArray *)d->tinfo;

tc->next->genTypeInfo(NULL);
dtxoff(pdt, tc->next->vtinfo->toSymbol(), 0); // TypeInfo for array of type
dtxoff(pdt, toSymbol(tc->next->vtinfo), 0); // TypeInfo for array of type

dtsize_t(pdt, tc->dim->toInteger()); // length
}
Expand All @@ -469,7 +470,7 @@ class TypeInfoDtVisitor : public Visitor
TypeVector *tc = (TypeVector *)d->tinfo;

tc->basetype->genTypeInfo(NULL);
dtxoff(pdt, tc->basetype->vtinfo->toSymbol(), 0); // TypeInfo for equivalent static array
dtxoff(pdt, toSymbol(tc->basetype->vtinfo), 0); // TypeInfo for equivalent static array
}

void visit(TypeInfoAssociativeArrayDeclaration *d)
Expand All @@ -485,10 +486,10 @@ class TypeInfoDtVisitor : public Visitor
TypeAArray *tc = (TypeAArray *)d->tinfo;

tc->next->genTypeInfo(NULL);
dtxoff(pdt, tc->next->vtinfo->toSymbol(), 0); // TypeInfo for array of type
dtxoff(pdt, toSymbol(tc->next->vtinfo), 0); // TypeInfo for array of type

tc->index->genTypeInfo(NULL);
dtxoff(pdt, tc->index->vtinfo->toSymbol(), 0); // TypeInfo for array of type
dtxoff(pdt, toSymbol(tc->index->vtinfo), 0); // TypeInfo for array of type
}

void visit(TypeInfoFunctionDeclaration *d)
Expand All @@ -504,7 +505,7 @@ class TypeInfoDtVisitor : public Visitor
TypeFunction *tc = (TypeFunction *)d->tinfo;

tc->next->genTypeInfo(NULL);
dtxoff(pdt, tc->next->vtinfo->toSymbol(), 0); // TypeInfo for function return value
dtxoff(pdt, toSymbol(tc->next->vtinfo), 0); // TypeInfo for function return value

const char *name = d->tinfo->deco;
assert(name);
Expand All @@ -526,7 +527,7 @@ class TypeInfoDtVisitor : public Visitor
TypeDelegate *tc = (TypeDelegate *)d->tinfo;

tc->next->nextOf()->genTypeInfo(NULL);
dtxoff(pdt, tc->next->nextOf()->vtinfo->toSymbol(), 0); // TypeInfo for delegate return value
dtxoff(pdt, toSymbol(tc->next->nextOf()->vtinfo), 0); // TypeInfo for delegate return value

const char *name = d->tinfo->deco;
assert(name);
Expand Down Expand Up @@ -586,7 +587,7 @@ class TypeInfoDtVisitor : public Visitor

if (FuncDeclaration *fd = search_toHash(sd))
{
dtxoff(pdt, fd->toSymbol(), 0);
dtxoff(pdt, toSymbol(fd), 0);
TypeFunction *tf = (TypeFunction *)fd->type;
assert(tf->ty == Tfunction);
/* I'm a little unsure this is the right way to do it. Perhaps a better
Expand All @@ -601,18 +602,18 @@ class TypeInfoDtVisitor : public Visitor
dtsize_t(pdt, 0);

if (sd->xeq)
dtxoff(pdt, sd->xeq->toSymbol(), 0);
dtxoff(pdt, toSymbol(sd->xeq), 0);
else
dtsize_t(pdt, 0);

if (sd->xcmp)
dtxoff(pdt, sd->xcmp->toSymbol(), 0);
dtxoff(pdt, toSymbol(sd->xcmp), 0);
else
dtsize_t(pdt, 0);

if (FuncDeclaration *fd = search_toString(sd))
{
dtxoff(pdt, fd->toSymbol(), 0);
dtxoff(pdt, toSymbol(fd), 0);
}
else
dtsize_t(pdt, 0);
Expand All @@ -626,22 +627,22 @@ class TypeInfoDtVisitor : public Visitor
// xgetMembers
FuncDeclaration *sgetmembers = sd->findGetMembers();
if (sgetmembers)
dtxoff(pdt, sgetmembers->toSymbol(), 0);
dtxoff(pdt, toSymbol(sgetmembers), 0);
else
dtsize_t(pdt, 0); // xgetMembers
#endif

// xdtor
FuncDeclaration *sdtor = sd->dtor;
if (sdtor)
dtxoff(pdt, sdtor->toSymbol(), 0);
dtxoff(pdt, toSymbol(sdtor), 0);
else
dtsize_t(pdt, 0); // xdtor

// xpostblit
FuncDeclaration *spostblit = sd->postblit;
if (spostblit && !(spostblit->storage_class & STCdisable))
dtxoff(pdt, spostblit->toSymbol(), 0);
dtxoff(pdt, toSymbol(spostblit), 0);
else
dtsize_t(pdt, 0); // xpostblit

Expand All @@ -657,7 +658,7 @@ class TypeInfoDtVisitor : public Visitor
if (t)
{
t->genTypeInfo(NULL);
dtxoff(pdt, t->vtinfo->toSymbol(), 0);
dtxoff(pdt, toSymbol(t->vtinfo), 0);
}
else
dtsize_t(pdt, 0);
Expand Down Expand Up @@ -696,7 +697,7 @@ class TypeInfoDtVisitor : public Visitor

if (!tc->sym->vclassinfo)
tc->sym->vclassinfo = TypeInfoClassDeclaration::create(tc);
s = tc->sym->vclassinfo->toSymbol();
s = toSymbol(tc->sym->vclassinfo);
dtxoff(pdt, s, 0); // ClassInfo for tinfo
}

Expand Down