From aa9d9dda1e65274b799c37a435f1d972855e33d5 Mon Sep 17 00:00:00 2001 From: Walter Bright Date: Sat, 30 Jan 2016 23:11:59 -0800 Subject: [PATCH] refactor: change baseInterface from length/ptr to [] --- src/dclass.d | 13 ++++++------- src/dtemplate.d | 10 +++++----- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/dclass.d b/src/dclass.d index 9d982bc04f29..9cb816619c2a 100644 --- a/src/dclass.d +++ b/src/dclass.d @@ -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) { @@ -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]; @@ -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; @@ -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()); diff --git a/src/dtemplate.d b/src/dtemplate.d index 1e58483e8c40..c4258810d8e7 100644 --- a/src/dtemplate.d +++ b/src/dtemplate.d @@ -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) @@ -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); } } @@ -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; }