Mercurial > projects > ddmd
diff dmd/ClassDeclaration.d @ 176:fa9a71a9f5a8
Moved all the mutable globals to Global
author | korDen |
---|---|
date | Sun, 10 Oct 2010 05:22:45 +0400 |
parents | af724d3510d7 |
children | e3afd1303184 |
line wrap: on
line diff
--- a/dmd/ClassDeclaration.d Sun Oct 10 03:48:06 2010 +0400 +++ b/dmd/ClassDeclaration.d Sun Oct 10 05:22:45 2010 +0400 @@ -78,7 +78,7 @@ //printf("param = %p, fd = %p %s\n", param, fd, fd.toChars()); return fd is fd2; } - + FuncDeclaration fd; } @@ -117,10 +117,10 @@ this(Loc loc, Identifier id, BaseClasses baseclasses) { super(loc, id); - + vtbl = new Array(); vtblFinal = new Array(); - + enum msg = "only object.d can define this reserved class name"; if (baseclasses) { @@ -145,51 +145,51 @@ if (id.toChars()[0] == 'T') { if (id is Id.TypeInfo) - { + { if (global.typeinfo) { global.typeinfo.error("%s", msg); } - + global.typeinfo = this; } if (id is Id.TypeInfo_Class) - { + { if (global.typeinfoclass) global.typeinfoclass.error("%s", msg); global.typeinfoclass = this; } if (id is Id.TypeInfo_Interface) - { + { if (global.typeinfointerface) global.typeinfointerface.error("%s", msg); global.typeinfointerface = this; } if (id is Id.TypeInfo_Struct) - { + { if (global.typeinfostruct) global.typeinfostruct.error("%s", msg); global.typeinfostruct = this; } if (id is Id.TypeInfo_Typedef) - { + { if (global.typeinfotypedef) global.typeinfotypedef.error("%s", msg); global.typeinfotypedef = this; } if (id is Id.TypeInfo_Pointer) - { + { if (global.typeinfopointer) global.typeinfopointer.error("%s", msg); global.typeinfopointer = this; } if (id is Id.TypeInfo_Array) - { + { if (global.typeinfoarray) global.typeinfoarray.error("%s", msg); global.typeinfoarray = this; @@ -202,35 +202,35 @@ } if (id is Id.TypeInfo_AssociativeArray) - { + { if (global.typeinfoassociativearray) global.typeinfoassociativearray.error("%s", msg); global.typeinfoassociativearray = this; } if (id is Id.TypeInfo_Enum) - { + { if (global.typeinfoenum) global.typeinfoenum.error("%s", msg); global.typeinfoenum = this; } if (id is Id.TypeInfo_Function) - { + { if (global.typeinfofunction) global.typeinfofunction.error("%s", msg); global.typeinfofunction = this; } if (id is Id.TypeInfo_Delegate) - { + { if (global.typeinfodelegate) global.typeinfodelegate.error("%s", msg); global.typeinfodelegate = this; } if (id is Id.TypeInfo_Tuple) - { + { if (global.typeinfotypelist) global.typeinfotypelist.error("%s", msg); global.typeinfotypelist = this; @@ -238,21 +238,21 @@ version (DMDV2) { if (id is Id.TypeInfo_Const) - { + { if (global.typeinfoconst) global.typeinfoconst.error("%s", msg); global.typeinfoconst = this; } if (id is Id.TypeInfo_Invariant) - { + { if (global.typeinfoinvariant) global.typeinfoinvariant.error("%s", msg); global.typeinfoinvariant = this; } if (id is Id.TypeInfo_Shared) - { + { if (global.typeinfoshared) global.typeinfoshared.error("%s", msg); global.typeinfoshared = this; @@ -268,7 +268,7 @@ } if (id is Id.Object_) - { + { if (global.object) global.object.error("%s", msg); global.object = this; @@ -276,14 +276,14 @@ // if (id is Id.ClassInfo) if (id is Id.TypeInfo_Class) - { + { if (global.classinfo) global.classinfo.error("%s", msg); global.classinfo = this; } if (id is Id.ModuleInfo) - { + { if (global.moduleinfo) global.moduleinfo.error("%s", msg); global.moduleinfo = this; @@ -295,7 +295,7 @@ isabstract = false; inuse = 0; } - + override Dsymbol syntaxCopy(Dsymbol s) { ClassDeclaration cd; @@ -319,7 +319,7 @@ ScopeDsymbol.syntaxCopy(cd); return cd; } - + override void semantic(Scope sc) { uint offset; @@ -331,7 +331,7 @@ //{ static int n; if (++n == 20) *(char*)0=0; } if (!ident) // if anonymous class - { + { string id = "__anonclass"; ident = Identifier.generateId(id); } @@ -346,7 +346,7 @@ handle = type; if (!members) // if forward reference - { + { //printf("\tclass '%s' is forward referenced\n", toChars()); return; } @@ -379,7 +379,7 @@ // Expand any tuples in baseclasses[] for (size_t i = 0; i < baseclasses.dim; ) - { + { auto b = baseclasses[i]; //printf("test1 %s %s\n", toChars(), b.type.toChars()); b.type = b.type.semantic(loc, sc); @@ -387,13 +387,13 @@ Type tb = b.type.toBasetype(); if (tb.ty == TY.Ttuple) - { + { TypeTuple tup = cast(TypeTuple)tb; enum PROT protection = b.protection; baseclasses.remove(i); size_t dim = Parameter.dim(tup.arguments); for (size_t j = 0; j < dim; j++) - { + { auto arg = Parameter.getNth(tup.arguments, j); b = new BaseClass(arg.type, protection); baseclasses.insert(i + j, b); @@ -405,7 +405,7 @@ // See if there's a base class as first in baseclasses[] if (baseclasses.dim) - { + { TypeClass tc; BaseClass b; Type tb; @@ -625,7 +625,7 @@ } } else if (!(storage_class & STC.STCstatic)) - { + { Dsymbol s = toParent2(); if (s) { @@ -638,19 +638,19 @@ if (ad) t = ad.handle; else if (fd) - { + { AggregateDeclaration ad2 = fd.isMember2(); if (ad2) t = ad2.handle; else { - t = Type.tvoidptr; + t = global.tvoidptr; } } else assert(0); if (t.ty == TY.Tstruct) // ref to struct - t = Type.tvoidptr; + t = global.tvoidptr; assert(!vthis); vthis = new ThisDeclaration(loc, t); members.push(vthis); @@ -720,7 +720,7 @@ s.setScope(sc); } } - + foreach (Dsymbol s; members) { s.semantic(sc); } @@ -832,7 +832,7 @@ } //printf("-ClassDeclaration.semantic(%s), type = %p\n", toChars(), type); } - + override void toCBuffer(OutBuffer buf, HdrGenState* hgs) { if (!isAnonymous()) @@ -865,7 +865,7 @@ buf.writeByte(';'); buf.writenl(); } - + /********************************************* * Determine if 'this' is a base class of cd. * This is used to detect circular inheritance only. @@ -876,7 +876,7 @@ return 0; //printf("ClassDeclaration::isBaseOf2(this = '%s', cd = '%s')\n", toChars(), cd.toChars()); foreach (b; cd.baseclasses) - { + { if (b.base is this || isBaseOf2(b.base)) return 1; } @@ -893,7 +893,7 @@ return 0; //printf("ClassDeclaration::isBaseOf2(this = '%s', cd = '%s')\n", toChars(), cd.toChars()); foreach (b; cd.baseclasses) - { + { if (b.base == this || isBaseOf2(b.base)) return 1; } @@ -947,29 +947,29 @@ } return s; } - + version (DMDV2) { bool isFuncHidden(FuncDeclaration fd) { //printf("ClassDeclaration::isFuncHidden(class = %s, fd = %s)\n", toChars(), fd.toChars()); Dsymbol s = search(Loc(0), fd.ident, 4|2); if (!s) - { + { //printf("not found\n"); /* Because, due to a hack, if there are multiple definitions * of fd.ident, null is returned. */ return false; } - + FuncDeclarationFinder p; p.fd = fd; s = s.toAlias(); - OverloadSet os = s.isOverloadSet(); + OverloadSet os = s.isOverloadSet(); if (os) { foreach (s2; os.a) - { + { auto f2 = s2.isFuncDeclaration(); if (f2 && overloadApply(f2, p)) return false; @@ -1053,7 +1053,7 @@ { return com; } - + bool isCOMinterface() { return false; @@ -1084,17 +1084,17 @@ return false; } - + int vtblOffset() { assert(false); } - + override string kind() { return "class"; } - + override string mangle() { Dsymbol parentsave = parent; @@ -1105,7 +1105,7 @@ * names for them. */ if (ident is Id.Exception) - { + { if (parent.ident is Id.object) parent = null; } @@ -1128,7 +1128,7 @@ parent = parentsave; return id; } - + override void toDocBuffer(OutBuffer buf) { assert(false); @@ -1156,7 +1156,7 @@ } foreach (b; baseclasses) - { + { access = b.base.getAccess(smember); switch (access) { @@ -1212,7 +1212,7 @@ return; if (multiobj) - { + { obj_append(this); return; } @@ -1234,7 +1234,7 @@ // Build destructor by aggregating dtors[] Symbol* sdtor; switch (dtors.dim) - { + { case 0: // No destructors for this class sdtor = null; @@ -1246,7 +1246,7 @@ break; default: - { + { /* Build a destructor that calls all the * other destructors in dtors[]. */ @@ -1264,7 +1264,7 @@ // Call each of the destructors in dtors[] // in reverse order for (size_t i = 0; i < dtors.dim; i++) - { + { DtorDeclaration d = cast(DtorDeclaration)dtors.data[i]; Symbol* s = d.toSymbol(); elem* e = el_bin(OPcall, TYvoid, el_var(s), el_var(sthis)); @@ -1348,7 +1348,7 @@ { if (global.classinfo.structsize != CLASSINFO_SIZE) error("D compiler and phobos' object.d are mismatched"); - + dtxoff(&dt, global.classinfo.toVtblSymbol(), 0, TYnptr); // vtbl for ClassInfo } else @@ -1367,7 +1367,7 @@ string name = ident.toChars(); size_t namelen = name.length; if (!(namelen > 9 && name[0..9] == "TypeInfo_")) - { + { name = toPrettyChars(); namelen = name.length; } @@ -1463,7 +1463,7 @@ offset += vtblInterfaces.dim * (4 * PTRSIZE); foreach (b; vtblInterfaces) - { + { ClassDeclaration id = b.base; /* The layout is: @@ -1493,7 +1493,7 @@ // This must be mirrored with ClassDeclaration.baseVtblOffset() //printf("putting out %d interface vtbl[]s for '%s'\n", vtblInterfaces.dim, toChars()); foreach (size_t i, BaseClass b; vtblInterfaces) - { + { ClassDeclaration id = b.base; int j; @@ -1508,7 +1508,7 @@ dtxoff(&dt, csym, CLASSINFO_SIZE + i * (4 * PTRSIZE), TYnptr); j = 1; } - + assert(id.vtbl.dim == b.vtbl.dim); for (; j < id.vtbl.dim; j++) { @@ -1541,7 +1541,7 @@ for (cd = this.baseClass; cd; cd = cd.baseClass) { foreach (size_t k, BaseClass bs; cd.vtblInterfaces) - { + { if (bs.fillVtbl(this, bvtbl, 0)) { //printf("\toverriding vtbl[] for %s\n", bs.base.toChars()); @@ -1572,20 +1572,20 @@ } } } - + version (INTERFACE_VIRTUAL) { // Put out the overriding interface vtbl[]s. // This must be mirrored with ClassDeclaration.baseVtblOffset() //printf("putting out overriding interface vtbl[]s for '%s' at offset x%x\n", toChars(), offset); for (size_t i = 0; i < vtblInterfaces.dim; i++) - { + { BaseClass b = cast(BaseClass)vtblInterfaces.data[i]; ClassDeclaration cd; for (cd = this.baseClass; cd; cd = cd.baseClass) { for (int k = 0; k < cd.vtblInterfaces.dim; k++) - { + { BaseClass bs = cast(BaseClass)cd.vtblInterfaces.data[k]; if (b.base == bs.base) @@ -1639,7 +1639,7 @@ if (0) i = 0; else - { + { dtxoff(&dt, csym, 0, TYnptr); // first entry is ClassInfo reference i = 1; } @@ -1649,18 +1649,18 @@ //printf("\tvtbl[%d] = %p\n", i, fd); if (fd && (fd.fbody || !isAbstract())) - { + { Symbol* s = fd.toSymbol(); version (DMDV2) { if (isFuncHidden(fd)) - { + { /* fd is hidden from the view of this class. * If fd overlaps with any function in the vtbl[], then * issue 'hidden' error. */ for (int j = 1; j < vtbl.dim; j++) - { + { if (j == i) continue; FuncDeclaration fd2 = (cast(Dsymbol)vtbl.data[j]).isFuncDeclaration(); @@ -1701,12 +1701,12 @@ if (isExport()) obj_export(vtblsym,0); } - + void toDebug() { assert(false); } - + /****************************************** * Get offset of base class's vtbl[] initializer from start of csym. * Returns ~0 if not this csym. @@ -1736,11 +1736,11 @@ for (cd = this.baseClass; cd; cd = cd.baseClass) { foreach(bs; cd.vtblInterfaces) - { + { if (bs.fillVtbl(this, null, 0)) { if (bc == bs) - { + { //printf("\tcsymoffset = x%x\n", csymoffset); return csymoffset; } @@ -1751,7 +1751,7 @@ } version (INTERFACE_VIRTUAL) { for (size_t i = 0; i < vtblInterfaces.dim; i++) - { + { BaseClass b = cast(BaseClass)vtblInterfaces.data[i]; ClassDeclaration cd; @@ -1759,11 +1759,11 @@ { //printf("\tbase class %s\n", cd.toChars()); for (int k = 0; k < cd.vtblInterfaces.dim; k++) - { + { BaseClass bs = cast(BaseClass)cd.vtblInterfaces.data[k]; if (bc == bs) - { + { //printf("\tcsymoffset = x%x\n", csymoffset); return csymoffset; } @@ -1776,8 +1776,6 @@ return ~0; } - - static private __gshared Classsym* scc; /************************************* * Create the "ClassInfo" symbol @@ -1788,10 +1786,7 @@ { Symbol* s; - if (!scc) - scc = fake_classsym(Id.ClassInfo); - - s = toSymbolX("__Class", SC.SCextern, scc.Stype, "Z"); + s = toSymbolX("__Class", SC.SCextern, global.scc.Stype, "Z"); s.Sfl = FL.FLextern; s.Sflags |= SFL.SFLnodebug; csym = s; @@ -1825,7 +1820,7 @@ } return vtblsym; } - + // Generate the data for the static initializer. void toDt(dt_t **pdt) { @@ -1840,7 +1835,7 @@ //printf("-ClassDeclaration.toDt(this = '%s')\n", toChars()); } - + void toDt2(dt_t** pdt, ClassDeclaration cd) { uint offset; @@ -1871,7 +1866,7 @@ dt = null; init = v.init; if (init) - { + { //printf("\t\t%s has initializer %s\n", v.toChars(), init.toChars()); ExpInitializer ei = init.isExpInitializer(); Type tb = v.type.toBasetype(); @@ -1902,7 +1897,7 @@ toSymbol(); // define csym foreach (b; vtblInterfaces) - { + { /// version (1 || INTERFACE_VIRTUAL) { for (ClassDeclaration cd2 = cd; 1; cd2 = cd2.baseClass) {