Skip to content

Commit

Permalink
refactor: change baseInterface from length/ptr to []
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Jan 31, 2016
1 parent 84f6aaf commit aa9d9dd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
13 changes: 6 additions & 7 deletions src/dclass.d
Expand Up @@ -49,10 +49,9 @@ struct BaseClass
// for interfaces: Array of FuncDeclaration's making up the vtbl[]
FuncDeclarations vtbl;

size_t baseInterfaces_dim;
// if BaseClass is an interface, these
// are a copy of the InterfaceDeclaration::interfaces
BaseClass* baseInterfaces;
BaseClass[] baseInterfaces;

extern (D) this(Type type, Prot protection)
{
Expand Down Expand Up @@ -129,10 +128,10 @@ struct BaseClass
//printf("+copyBaseInterfaces(), %s\n", sym->toChars());
// if (baseInterfaces_dim)
// return;
baseInterfaces_dim = sym.interfaces_dim;
baseInterfaces = cast(BaseClass*)mem.xcalloc(baseInterfaces_dim, BaseClass.sizeof);
auto bc = cast(BaseClass*)mem.xcalloc(sym.interfaces_dim, BaseClass.sizeof);
baseInterfaces = bc[0 .. sym.interfaces_dim];
//printf("%s.copyBaseInterfaces()\n", sym->toChars());
for (size_t i = 0; i < baseInterfaces_dim; i++)
for (size_t i = 0; i < baseInterfaces.length; i++)
{
BaseClass* b = &baseInterfaces[i];
BaseClass* b2 = sym.interfaces[i];
Expand Down Expand Up @@ -1348,7 +1347,7 @@ public:
//printf("\tvtblInterfaces[%d] b->sym = %s, offset = %d\n", i, b->sym->toChars(), b->offset);

// Take care of single inheritance offsets
while (b.baseInterfaces_dim)
while (b.baseInterfaces.length)
{
b = &b.baseInterfaces[0];
b.offset = offset;
Expand Down Expand Up @@ -1850,7 +1849,7 @@ public:
bool isBaseOf(BaseClass* bc, int* poffset)
{
//printf("%s.InterfaceDeclaration::isBaseOf(bc = '%s')\n", toChars(), bc->sym->toChars());
for (size_t j = 0; j < bc.baseInterfaces_dim; j++)
for (size_t j = 0; j < bc.baseInterfaces.length; j++)
{
BaseClass* b = &bc.baseInterfaces[j];
//printf("\tY base %s\n", b->sym->toChars());
Expand Down
10 changes: 5 additions & 5 deletions src/dtemplate.d
Expand Up @@ -3900,7 +3900,7 @@ extern (C++) MATCH deduceType(RootObject o, Scope* sc, Type tparam, TemplatePara
* If a match occurs, numBaseClassMatches is incremented, and the new deduced
* types are ANDed with the current 'best' estimate for dedtypes.
*/
static void deduceBaseClassParameters(BaseClass* b, Scope* sc, Type tparam, TemplateParameters* parameters, Objects* dedtypes, Objects* best, ref int numBaseClassMatches)
static void deduceBaseClassParameters(ref BaseClass b, Scope* sc, Type tparam, TemplateParameters* parameters, Objects* dedtypes, Objects* best, ref int numBaseClassMatches)
{
TemplateInstance parti = b.sym ? b.sym.parent.isTemplateInstance() : null;
if (parti)
Expand Down Expand Up @@ -3928,9 +3928,9 @@ extern (C++) MATCH deduceType(RootObject o, Scope* sc, Type tparam, TemplatePara
}
}
// Now recursively test the inherited interfaces
for (size_t j = 0; j < b.baseInterfaces_dim; ++j)
foreach (ref bi; b.baseInterfaces)
{
deduceBaseClassParameters(&b.baseInterfaces[j], sc, tparam, parameters, dedtypes, best, numBaseClassMatches);
deduceBaseClassParameters(bi, sc, tparam, parameters, dedtypes, best, numBaseClassMatches);
}
}

Expand Down Expand Up @@ -3993,12 +3993,12 @@ extern (C++) MATCH deduceType(RootObject o, Scope* sc, Type tparam, TemplatePara
while (s && s.baseclasses.dim > 0)
{
// Test the base class
deduceBaseClassParameters((*s.baseclasses)[0], sc, tparam, parameters, dedtypes, best, numBaseClassMatches);
deduceBaseClassParameters(*(*s.baseclasses)[0], sc, tparam, parameters, dedtypes, best, numBaseClassMatches);
// Test the interfaces inherited by the base class
for (size_t i = 0; i < s.interfaces_dim; ++i)
{
BaseClass* b = s.interfaces[i];
deduceBaseClassParameters(b, sc, tparam, parameters, dedtypes, best, numBaseClassMatches);
deduceBaseClassParameters(*b, sc, tparam, parameters, dedtypes, best, numBaseClassMatches);
}
s = (*s.baseclasses)[0].sym;
}
Expand Down

0 comments on commit aa9d9dd

Please sign in to comment.