Skip to content

Commit

Permalink
Refactor: Rename BaseClass::base to sym
Browse files Browse the repository at this point in the history
When I see such the code `b->base`, it looks very confusing. I think `b->sym` is much better.
  • Loading branch information
9rnsr committed Jul 18, 2015
1 parent 80a326e commit 1378b1c
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 68 deletions.
8 changes: 4 additions & 4 deletions src/access.c
Expand Up @@ -63,7 +63,7 @@ Prot getAccess(AggregateDeclaration *ad, Dsymbol *smember)
{
BaseClass *b = (*cd->baseclasses)[i];

Prot access = getAccess(b->base, smember);
Prot access = getAccess(b->sym, smember);
switch (access.kind)
{
case PROTnone:
Expand Down Expand Up @@ -130,9 +130,9 @@ static bool isAccessible(
for (size_t i = 0; i < cdthis->baseclasses->dim; i++)
{
BaseClass *b = (*cdthis->baseclasses)[i];
Prot access = getAccess(b->base, smember);
Prot access = getAccess(b->sym, smember);
if (access.kind >= PROTprotected ||
isAccessible(smember, sfunc, b->base, cdscope))
isAccessible(smember, sfunc, b->sym, cdscope))
{
return true;
}
Expand All @@ -148,7 +148,7 @@ static bool isAccessible(
for (size_t i = 0; i < cdthis->baseclasses->dim; i++)
{
BaseClass *b = (*cdthis->baseclasses)[i];
if (isAccessible(smember, sfunc, b->base, cdscope))
if (isAccessible(smember, sfunc, b->sym, cdscope))
return true;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/aggregate.h
Expand Up @@ -200,9 +200,9 @@ class UnionDeclaration : public StructDeclaration
struct BaseClass
{
Type *type; // (before semantic processing)
Prot protection; // protection for the base interface
Prot protection; // protection for the base interface

ClassDeclaration *base;
ClassDeclaration *sym;
unsigned offset; // 'this' pointer offset
FuncDeclarations vtbl; // for interfaces: Array of FuncDeclaration's
// making up the vtbl[]
Expand Down
82 changes: 41 additions & 41 deletions src/class.c
Expand Up @@ -419,7 +419,7 @@ void ClassDeclaration::semantic(Scope *sc)
* we need to set baseClass field for class covariance check.
*/
baseClass = tc->sym;
b->base = baseClass;
b->sym = baseClass;

if (tc->sym->scope && tc->sym->baseok < BASEOKdone)
tc->sym->semantic(NULL); // Try to resolve forward reference
Expand Down Expand Up @@ -452,9 +452,9 @@ void ClassDeclaration::semantic(Scope *sc)
for (size_t j = (baseClass ? 1 : 0); j < i; j++)
{
BaseClass *b2 = (*baseclasses)[j];
if (b2->base == tc->sym)
if (b2->sym == tc->sym)
{
error("inherits from duplicate interface %s", b2->base->toChars());
error("inherits from duplicate interface %s", b2->sym->toChars());
baseclasses->remove(i);
continue;
}
Expand All @@ -471,7 +471,7 @@ void ClassDeclaration::semantic(Scope *sc)
}
}

b->base = tc->sym;
b->sym = tc->sym;

if (tc->sym->scope && tc->sym->baseok < BASEOKdone)
tc->sym->semantic(NULL); // Try to resolve forward reference
Expand Down Expand Up @@ -514,7 +514,7 @@ void ClassDeclaration::semantic(Scope *sc)

baseClass = tc->sym;
assert(!baseClass->isInterfaceDeclaration());
b->base = baseClass;
b->sym = baseClass;
}
if (baseClass)
{
Expand All @@ -540,11 +540,11 @@ void ClassDeclaration::semantic(Scope *sc)
BaseClass *b = interfaces[i];
// If this is an interface, and it derives from a COM interface,
// then this is a COM interface too.
if (b->base->isCOMinterface())
if (b->sym->isCOMinterface())
com = true;
if (cpp && !b->base->isCPPinterface())
if (cpp && !b->sym->isCPPinterface())
{
::error(loc, "C++ class '%s' cannot implement D interface '%s'", toPrettyChars(), b->base->toPrettyChars());
::error(loc, "C++ class '%s' cannot implement D interface '%s'", toPrettyChars(), b->sym->toPrettyChars());
}
}

Expand Down Expand Up @@ -849,7 +849,7 @@ bool ClassDeclaration::isBaseOf2(ClassDeclaration *cd)
for (size_t i = 0; i < cd->baseclasses->dim; i++)
{
BaseClass *b = (*cd->baseclasses)[i];
if (b->base == this || isBaseOf2(b->base))
if (b->sym == this || isBaseOf2(b->sym))
return true;
}
return false;
Expand Down Expand Up @@ -925,13 +925,13 @@ Dsymbol *ClassDeclaration::search(Loc loc, Identifier *ident, int flags)
{
BaseClass *b = (*baseclasses)[i];

if (b->base)
if (b->sym)
{
if (!b->base->symtab)
error("base %s is forward referenced", b->base->ident->toChars());
if (!b->sym->symtab)
error("base %s is forward referenced", b->sym->ident->toChars());
else
{
s = b->base->search(loc, ident, flags);
s = b->sym->search(loc, ident, flags);
if (s == this) // happens if s is nested in this and derives from this
s = NULL;
else if (s)
Expand Down Expand Up @@ -1407,9 +1407,9 @@ void InterfaceDeclaration::semantic(Scope *sc)
for (size_t j = 0; j < i; j++)
{
BaseClass *b2 = (*baseclasses)[j];
if (b2->base == tc->sym)
if (b2->sym == tc->sym)
{
error("inherits from duplicate interface %s", b2->base->toChars());
error("inherits from duplicate interface %s", b2->sym->toChars());
baseclasses->remove(i);
continue;
}
Expand All @@ -1433,7 +1433,7 @@ void InterfaceDeclaration::semantic(Scope *sc)
}
}

b->base = tc->sym;
b->sym = tc->sym;

if (tc->sym->scope && tc->sym->baseok < BASEOKdone)
tc->sym->semantic(NULL); // Try to resolve forward reference
Expand Down Expand Up @@ -1464,9 +1464,9 @@ void InterfaceDeclaration::semantic(Scope *sc)
BaseClass *b = interfaces[i];
// If this is an interface, and it derives from a COM interface,
// then this is a COM interface too.
if (b->base->isCOMinterface())
if (b->sym->isCOMinterface())
com = true;
if (b->base->isCPPinterface())
if (b->sym->isCPPinterface())
cpp = true;
}

Expand Down Expand Up @@ -1522,19 +1522,19 @@ void InterfaceDeclaration::semantic(Scope *sc)
}

// Copy vtbl[] from base class
if (b->base->vtblOffset())
if (b->sym->vtblOffset())
{
size_t d = b->base->vtbl.dim;
size_t d = b->sym->vtbl.dim;
if (d > 1)
{
vtbl.reserve(d - 1);
for (size_t j = 1; j < d; j++)
vtbl.push(b->base->vtbl[j]);
vtbl.push(b->sym->vtbl[j]);
}
}
else
{
vtbl.append(&b->base->vtbl);
vtbl.append(&b->sym->vtbl);
}

Lcontinue:
Expand Down Expand Up @@ -1634,8 +1634,8 @@ bool InterfaceDeclaration::isBaseOf(ClassDeclaration *cd, int *poffset)
{
BaseClass *b = cd->interfaces[j];

//printf("\tbase %s\n", b->base->toChars());
if (this == b->base)
//printf("\tbase %s\n", b->sym->toChars());
if (this == b->sym)
{
//printf("\tfound at offset %d\n", b->offset);
if (poffset)
Expand Down Expand Up @@ -1665,24 +1665,24 @@ bool InterfaceDeclaration::isBaseOf(ClassDeclaration *cd, int *poffset)

bool InterfaceDeclaration::isBaseOf(BaseClass *bc, int *poffset)
{
//printf("%s.InterfaceDeclaration::isBaseOf(bc = '%s')\n", toChars(), bc->base->toChars());
//printf("%s.InterfaceDeclaration::isBaseOf(bc = '%s')\n", toChars(), bc->sym->toChars());
for (size_t j = 0; j < bc->baseInterfaces_dim; j++)
{
BaseClass *b = &bc->baseInterfaces[j];

if (this == b->base)
if (this == b->sym)
{
if (poffset)
{
*poffset = b->offset;
if (j && bc->base->isInterfaceDeclaration())
if (j && bc->sym->isInterfaceDeclaration())
*poffset = OFFSET_RUNTIME;
}
return true;
}
if (isBaseOf(b, poffset))
{
if (j && poffset && bc->base->isInterfaceDeclaration())
if (j && poffset && bc->sym->isInterfaceDeclaration())
*poffset = OFFSET_RUNTIME;
return true;
}
Expand Down Expand Up @@ -1737,11 +1737,11 @@ BaseClass::BaseClass(Type *type, Prot protection)
//printf("BaseClass(this = %p, '%s')\n", this, type->toChars());
this->type = type;
this->protection = protection;
base = NULL;
offset = 0;
this->sym = NULL;
this->offset = 0;

baseInterfaces_dim = 0;
baseInterfaces = NULL;
this->baseInterfaces_dim = 0;
this->baseInterfaces = NULL;
}

/****************************************
Expand All @@ -1759,14 +1759,14 @@ bool BaseClass::fillVtbl(ClassDeclaration *cd, FuncDeclarations *vtbl, int newin
{
bool result = false;

//printf("BaseClass::fillVtbl(this='%s', cd='%s')\n", base->toChars(), cd->toChars());
//printf("BaseClass::fillVtbl(this='%s', cd='%s')\n", sym->toChars(), cd->toChars());
if (vtbl)
vtbl->setDim(base->vtbl.dim);
vtbl->setDim(sym->vtbl.dim);

// first entry is ClassInfo reference
for (size_t j = base->vtblOffset(); j < base->vtbl.dim; j++)
for (size_t j = sym->vtblOffset(); j < sym->vtbl.dim; j++)
{
FuncDeclaration *ifd = base->vtbl[j]->isFuncDeclaration();
FuncDeclaration *ifd = sym->vtbl[j]->isFuncDeclaration();
FuncDeclaration *fd;
TypeFunction *tf;

Expand All @@ -1787,7 +1787,7 @@ bool BaseClass::fillVtbl(ClassDeclaration *cd, FuncDeclarations *vtbl, int newin
// Check that it is current
if (newinstance &&
fd->toParent() != cd &&
ifd->toParent() == base)
ifd->toParent() == sym)
cd->error("interface function '%s' is not implemented", ifd->toFullSignature());

if (fd->toParent() == cd)
Expand All @@ -1811,18 +1811,18 @@ bool BaseClass::fillVtbl(ClassDeclaration *cd, FuncDeclarations *vtbl, int newin

void BaseClass::copyBaseInterfaces(BaseClasses *vtblInterfaces)
{
//printf("+copyBaseInterfaces(), %s\n", base->toChars());
//printf("+copyBaseInterfaces(), %s\n", sym->toChars());
// if (baseInterfaces_dim)
// return;

baseInterfaces_dim = base->interfaces_dim;
baseInterfaces_dim = sym->interfaces_dim;
baseInterfaces = (BaseClass *)mem.xcalloc(baseInterfaces_dim, sizeof(BaseClass));

//printf("%s.copyBaseInterfaces()\n", base->toChars());
//printf("%s.copyBaseInterfaces()\n", sym->toChars());
for (size_t i = 0; i < baseInterfaces_dim; i++)
{
BaseClass *b = &baseInterfaces[i];
BaseClass *b2 = base->interfaces[i];
BaseClass *b2 = sym->interfaces[i];

assert(b2->vtbl.dim == 0); // should not be filled yet
memcpy(b, b2, sizeof(BaseClass));
Expand Down
6 changes: 3 additions & 3 deletions src/doc.c
Expand Up @@ -1205,7 +1205,7 @@ void toDocBuffer(Dsymbol *s, OutBuffer *buf, Scope *sc)

if (bc->protection.kind == PROTprivate)
continue;
if (bc->base && bc->base->ident == Id::Object)
if (bc->sym && bc->sym->ident == Id::Object)
continue;

if (any)
Expand All @@ -1216,9 +1216,9 @@ void toDocBuffer(Dsymbol *s, OutBuffer *buf, Scope *sc)
any = 1;
}
emitProtection(buf, bc->protection);
if (bc->base)
if (bc->sym)
{
buf->printf("$(DDOC_PSUPER_SYMBOL %s)", bc->base->toPrettyChars());
buf->printf("$(DDOC_PSUPER_SYMBOL %s)", bc->sym->toPrettyChars());
}
else
{
Expand Down
12 changes: 6 additions & 6 deletions src/func.c
Expand Up @@ -921,7 +921,7 @@ void FuncDeclaration::semantic(Scope *sc)
for (size_t i = 0; i < cd->interfaces_dim; i++)
{
BaseClass *b = cd->interfaces[i];
vi = findVtblIndex((Dsymbols *)&b->base->vtbl, (int)b->base->vtbl.dim);
vi = findVtblIndex((Dsymbols *)&b->sym->vtbl, (int)b->sym->vtbl.dim);
switch (vi)
{
case -1:
Expand All @@ -934,7 +934,7 @@ void FuncDeclaration::semantic(Scope *sc)

default:
{
FuncDeclaration *fdv = (FuncDeclaration *)b->base->vtbl[vi];
FuncDeclaration *fdv = (FuncDeclaration *)b->sym->vtbl[vi];
Type *ti = NULL;

/* Remember which functions this overrides
Expand Down Expand Up @@ -995,7 +995,7 @@ void FuncDeclaration::semantic(Scope *sc)
Dsymbol *s = NULL;
for (size_t i = 0; i < cd->baseclasses->dim; i++)
{
s = (*cd->baseclasses)[i]->base->search_correct(ident);
s = (*cd->baseclasses)[i]->sym->search_correct(ident);
if (s) break;
}

Expand All @@ -1013,17 +1013,17 @@ void FuncDeclaration::semantic(Scope *sc)
for (size_t i = 0; i < cd->interfaces_dim; i++)
{
BaseClass *b = cd->interfaces[i];
if (b->base)
if (b->sym)
{
Dsymbol *s = search_function(b->base, ident);
Dsymbol *s = search_function(b->sym, ident);
if (s)
{
FuncDeclaration *f2 = s->isFuncDeclaration();
if (f2)
{
f2 = f2->overloadExactMatch(type);
if (f2 && f2->isFinalFunc() && f2->prot().kind != PROTprivate)
error("cannot override final function %s.%s", b->base->toChars(), f2->toPrettyChars());
error("cannot override final function %s.%s", b->sym->toChars(), f2->toPrettyChars());
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/json.c
Expand Up @@ -651,7 +651,7 @@ class ToJsonVisitor : public Visitor
for (size_t i = 0; i < cd->interfaces_dim; i++)
{
BaseClass *b = cd->interfaces[i];
item(b->base->toPrettyChars(true));
item(b->sym->toPrettyChars(true));
}
arrayEnd();
}
Expand Down
4 changes: 2 additions & 2 deletions src/template.c
Expand Up @@ -4122,7 +4122,7 @@ MATCH deduceType(RootObject *o, Scope *sc, Type *tparam, TemplateParameters *par
Scope *sc, Type *tparam, TemplateParameters *parameters, Objects *dedtypes,
Objects *best, int &numBaseClassMatches)
{
TemplateInstance *parti = b->base ? b->base->parent->isTemplateInstance() : NULL;
TemplateInstance *parti = b->sym ? b->sym->parent->isTemplateInstance() : NULL;
if (parti)
{
// Make a temporary copy of dedtypes so we don't destroy it
Expand Down Expand Up @@ -4235,7 +4235,7 @@ MATCH deduceType(RootObject *o, Scope *sc, Type *tparam, TemplateParameters *par
deduceBaseClassParameters(b, sc, tparam, parameters, dedtypes,
best, numBaseClassMatches);
}
s = (*s->baseclasses)[0]->base;
s = (*s->baseclasses)[0]->sym;
}

if (numBaseClassMatches == 0)
Expand Down
2 changes: 1 addition & 1 deletion src/tocvdebug.c
Expand Up @@ -676,7 +676,7 @@ void toDebug(ClassDeclaration *cd)
for (size_t i = 0; i < cd->baseclasses->dim; i++)
{
BaseClass *bc = (*cd->baseclasses)[i];
idx_t typidx = cv4_typidx(Type_toCtype(bc->base->type)->Tnext);
idx_t typidx = cv4_typidx(Type_toCtype(bc->sym->type)->Tnext);
unsigned attribute = PROTtoATTR(bc->protection);

unsigned elementlen;
Expand Down

0 comments on commit 1378b1c

Please sign in to comment.