# HG changeset patch # User korDen # Date 1286673765 -14400 # Node ID fa9a71a9f5a87a2661d80d1b0eda51ac444be5ff # Parent 94b6033c07f30b110aff3fb4bc3a8da41859190a Moved all the mutable globals to Global diff -r 94b6033c07f3 -r fa9a71a9f5a8 dmd/AggregateDeclaration.d --- a/dmd/AggregateDeclaration.d Sun Oct 10 03:48:06 2010 +0400 +++ b/dmd/AggregateDeclaration.d Sun Oct 10 05:22:45 2010 +0400 @@ -15,6 +15,7 @@ import dmd.TypeClass; import dmd.TOK; import dmd.ThisExp; +import dmd.Global; import dmd.PROT; import dmd.Expression; import dmd.STC; @@ -110,7 +111,7 @@ if (cdthis) { foreach (b; cdthis.baseclasses) - { + { PROT access = b.base.getAccess(smember); if (access >= PROT.PROTprotected || accessCheckX(smember, sfunc, b.base, cdscope)) @@ -127,7 +128,7 @@ if (cdthis) { foreach (b; cdthis.baseclasses) - { + { if (accessCheckX(smember, sfunc, b.base, cdscope)) return true; } @@ -154,7 +155,7 @@ // 1: size is correct // 2: cannot determine size; fwd referenced bool isdeprecated; // true if deprecated - + version (DMDV2) { bool isnested; // true if is nested VarDeclaration vthis; // 'this' parameter if this aggregate is nested @@ -182,7 +183,7 @@ { super(id); this.loc = loc; - + fields = new VarDeclarations(); /// dtors = new FuncDeclarations(); } @@ -191,7 +192,7 @@ { //printf("AggregateDeclaration.semantic2(%s)\n", toChars()); if (scope_ && members) - { + { error("has forward references"); return; } @@ -228,7 +229,7 @@ } } } - + override uint size(Loc loc) { //printf("AggregateDeclaration.size() = %d\n", structsize); @@ -236,14 +237,14 @@ error(loc, "unknown size"); if (sizeok != 1) - { + { error(loc, "no size yet for forward reference"); //*(char*)0=0; } return structsize; } - + /**************************** * Do byte or word alignment as necessary. * Align sizes of 0, as we may not know array sizes yet. @@ -261,12 +262,12 @@ } //printf("result = %d\n",offset); } - + override Type getType() { return type; } - + void addField(Scope sc, VarDeclaration v) { uint memsize; // size of member @@ -280,7 +281,7 @@ Type t = v.type.toBasetype(); if (v.storage_class & STC.STCref) { // References are the size of a pointer - t = Type.tvoidptr; + t = global.tvoidptr; } if (t.ty == TY.Tstruct /*&& isStructDeclaration()*/) { TypeStruct ts = cast(TypeStruct)t; @@ -321,7 +322,7 @@ //printf(" addField '%s' to '%s' at offset %d, size = %d\n", v.toChars(), toChars(), v.offset, memsize); fields.push(v); } - + override bool isDeprecated() // is aggregate deprecated? { return isdeprecated; @@ -357,7 +358,7 @@ { TypeStruct ts = cast(TypeStruct)tv; StructDeclaration sd = ts.sym; if (sd.dtor) - { + { Expression ex; // this.v @@ -365,7 +366,7 @@ ex = new DotVarExp(Loc(0), ex, v, 0); if (dim == 1) - { + { // this.v.dtor() ex = new DotVarExp(Loc(0), ex, sd.dtor, 0); ex = new CallExp(Loc(0), ex); @@ -389,7 +390,7 @@ /* Build our own "destructor" which executes e */ if (e) - { + { //printf("Building __fieldDtor()\n"); DtorDeclaration dd = new DtorDeclaration(Loc(0), Loc(0), Lexer.idPool("__fieldDtor")); dd.fbody = new ExpStatement(Loc(0), e); @@ -437,19 +438,19 @@ { assert(false); } - + override void toJsonBuffer(OutBuffer buf) { //writef("AggregateDeclaration.toJsonBuffer()\n"); buf.writestring("{\n"); - + JsonProperty(buf, Pname, toChars()); JsonProperty(buf, Pkind, kind()); if (comment) JsonProperty(buf, Pcomment, comment); if (loc.linnum) JsonProperty(buf, Pline, loc.linnum); - + ClassDeclaration cd = isClassDeclaration(); if (cd) { @@ -476,7 +477,7 @@ buf.writestring("],\n"); } } - + JsonString(buf, Pmembers); buf.writestring(" : [\n"); size_t offset = buf.offset; @@ -491,7 +492,7 @@ } JsonRemoveComma(buf); buf.writestring("]\n"); - + buf.writestring("}\n"); } @@ -532,7 +533,7 @@ } return false; } - + /********************************** * Determine if smember has access to private members of this declaration. */ @@ -559,7 +560,7 @@ // If both are members of the same module, grant access while (true) - { + { Dsymbol sp = smember.toParent(); if (sp.isFuncDeclaration() && smember.isFuncDeclaration()) smember = sp; @@ -586,7 +587,7 @@ } return false; } - + /******************************* * Do access check for member of this class, this class being the * type of the 'this' pointer used to access smember. @@ -616,7 +617,7 @@ //assert(smember.parent.isBaseOf(this, null)); if (smemberparent == this) - { + { PROT access2 = smember.prot(); result = access2 >= PROT.PROTpublic || diff -r 94b6033c07f3 -r fa9a71a9f5a8 dmd/AsmStatement.d --- a/dmd/AsmStatement.d Sun Oct 10 03:48:06 2010 +0400 +++ b/dmd/AsmStatement.d Sun Oct 10 05:22:45 2010 +0400 @@ -90,7 +90,9 @@ if (!tokens) return null; - memset(&asmstate, 0, asmstate.sizeof); + auto asmstate = &global.asmstate; + + memset(asmstate, 0, (*asmstate).sizeof); asmstate.statement = this; asmstate.sc = sc; @@ -122,17 +124,17 @@ asmstate.loc = loc; - asmtok = tokens; - asm_token_trans(asmtok); + global.asmtok = tokens; + asm_token_trans(global.asmtok); if (setjmp(asmstate.env)) { - asmtok = null; // skip rest of line - tok_value = TOK.TOKeof; + global.asmtok = null; // skip rest of line + global.tok_value = TOK.TOKeof; exit(EXIT_FAILURE); goto AFTER_EMIT; } - switch (cast(int)tok_value) + switch (cast(int)global.tok_value) { case ASMTK.ASMTKnaked: naked = true; @@ -171,7 +173,7 @@ goto Lopcode; case TOK.TOKidentifier: - o = asm_op_lookup(asmtok.ident.toChars()); + o = asm_op_lookup(global.asmtok.ident.toChars()); if (!o) goto OPCODE_EXPECTED; @@ -196,12 +198,12 @@ } // get the first part of an expr o1 = asm_cond_exp(); - if (tok_value == TOK.TOKcomma) + if (global.tok_value == TOK.TOKcomma) { asm_token(); o2 = asm_cond_exp(); } - if (tok_value == TOK.TOKcomma) + if (global.tok_value == TOK.TOKcomma) { asm_token(); o3 = asm_cond_exp(); @@ -249,7 +251,7 @@ default: OPCODE_EXPECTED: - asmerr(ASMERRMSGS.EM_opcode_exp, asmtok.toChars()); // assembler opcode expected + asmerr(ASMERRMSGS.EM_opcode_exp, global.asmtok.toChars()); // assembler opcode expected break; } @@ -259,7 +261,7 @@ opnd_free(o3); o1 = o2 = o3 = null; - if (tok_value != TOK.TOKeof) + if (global.tok_value != TOK.TOKeof) asmerr(ASMERRMSGS.EM_eol); // end of line expected //return asmstate.bReturnax; diff -r 94b6033c07f3 -r fa9a71a9f5a8 dmd/BinExp.d --- a/dmd/BinExp.d Sun Oct 10 03:48:06 2010 +0400 +++ b/dmd/BinExp.d Sun Oct 10 05:22:45 2010 +0400 @@ -18,6 +18,7 @@ import dmd.Expression; import dmd.interpret.Util; import dmd.GlobalExpressions; +import dmd.Global; import dmd.Cast; import dmd.CastExp; import dmd.VarDeclaration; @@ -97,8 +98,6 @@ * Hash table of array op functions already generated or known about. */ -__gshared StringTable arrayfuncs; - int typeMerge(Scope sc, Expression e, Type* pt, Expression* pe1, Expression* pe2) { //printf("typeMerge() %.*s op %.*s\n", (*pe1).toChars(), (*pe2).toChars()); @@ -1486,9 +1485,7 @@ /* Look up name in hash table */ - if (arrayfuncs is null) arrayfuncs = new StringTable(); /// HACK! - - StringValue* sv = arrayfuncs.update(name[0..namelen]); + StringValue* sv = global.arrayfuncs.update(name[0..namelen]); FuncDeclaration fd = cast(FuncDeclaration)sv.ptrvalue; if (!fd) { diff -r 94b6033c07f3 -r fa9a71a9f5a8 dmd/ClassDeclaration.d --- 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) { diff -r 94b6033c07f3 -r fa9a71a9f5a8 dmd/FuncDeclaration.d --- a/dmd/FuncDeclaration.d Sun Oct 10 03:48:06 2010 +0400 +++ b/dmd/FuncDeclaration.d Sun Oct 10 05:22:45 2010 +0400 @@ -125,8 +125,6 @@ import std.string; -__gshared static int hiddenparami; // how many we've generated so far - class FuncDeclaration : Declaration { Array fthrows; // Array of Type's of exceptions (not used) @@ -3411,7 +3409,7 @@ // as the first argument .type* thidden = tf.next.pointerTo().toCtype(); char hiddenparam[5+4+1]; - sprintf(hiddenparam.ptr, "__HID%d".ptr, ++hiddenparami); + sprintf(hiddenparam.ptr, "__HID%d".ptr, ++global.hiddenparami); shidden = symbol_name(hiddenparam.ptr, SC.SCparameter, thidden); shidden.Sflags |= SFL.SFLtrue | SFL.SFLfree; @@ -3551,7 +3549,7 @@ Blockx bx; Statement sbody; - localgot = null; + global.localgot = null; sbody = func.fbody; ///memset(&bx, 0, (bx).sizeof); @@ -3642,7 +3640,7 @@ if (isStaticConstructor()) { elem* e = el_una(OPER.OPucall, TYM.TYvoid, el_var(s)); - ector = el_combine(ector, e); + global.ector = el_combine(global.ector, e); } // If static destructor @@ -3661,11 +3659,11 @@ { /* Increment destructor's vgate at construction time */ - ectorgates.push(cast(void*)f2); + global.ectorgates.push(cast(void*)f2); } e = el_una(OPER.OPucall, TYM.TYvoid, el_var(s)); - edtor = el_combine(e, edtor); + global.edtor = el_combine(e, global.edtor); } } @@ -3673,7 +3671,7 @@ if (isUnitTestDeclaration()) { elem* e = el_una(OPER.OPucall, TYM.TYvoid, el_var(s)); - etest = el_combine(etest, e); + global.etest = el_combine(global.etest, e); } if (global.errors) @@ -3753,7 +3751,7 @@ } //printf("FuncDeclaration.buildClosure()\n"); Symbol* sclosure; - sclosure = symbol_name("__closptr".ptr, SC.SCauto, Type.tvoidptr.toCtype()); + sclosure = symbol_name("__closptr".ptr, SC.SCauto, global.tvoidptr.toCtype()); sclosure.Sflags |= SFL.SFLtrue | SFL.SFLfree; symbol_add(sclosure); irs.sclosure = sclosure; diff -r 94b6033c07f3 -r fa9a71a9f5a8 dmd/Global.d --- a/dmd/Global.d Sun Oct 10 03:48:06 2010 +0400 +++ b/dmd/Global.d Sun Oct 10 05:22:45 2010 +0400 @@ -10,10 +10,23 @@ import dmd.Token; import dmd.Scope; import dmd.Module; +import dmd.Type; +import dmd.TypeInfoDeclaration; import dmd.Id; +import dmd.TY; +import dmd.LINK; +import dmd.MOD; +import dmd.Loc; +import dmd.TOK; +import dmd.TypeFunction; import dmd.codegen.Util; +import dmd.backend.elem; import dmd.backend.Classsym; +import dmd.backend.Symbol; +import dmd.backend.glue; +import dmd.backend.iasm; +import dmd.backend.StringTab; import core.stdc.time; import core.stdc.stdio; @@ -98,10 +111,13 @@ // Used in TemplateMixin int nest; - + // Used in Type StringTable type_stringtable; - + + Type tvoidptr; // void* + Type tstring; // immutable(char)[] + ClassDeclaration typeinfo; ClassDeclaration typeinfoclass; ClassDeclaration typeinfointerface; @@ -120,11 +136,57 @@ ClassDeclaration typeinfoshared; ClassDeclaration typeinfowild; + Type basic[TY.TMAX]; + TypeInfoDeclaration internalTI[TMAX]; + + // Used in BinExp + StringTable arrayfuncs; + + // Used in FuncDeclaration + int hiddenparami; // how many we've generated so far + + // Used in TypeAArray + // Dumb linear symbol table - should use associative array! + Array sarray; + Symbol* AArray_s; + + // Used in TypeDelegate + Symbol* Delegate_s; + + // Used in TypeInfoStructDeclaration + TypeFunction tftohash; + TypeFunction tftostring; + + // Used in backend.glue + Array obj_symbols_towrite; + Outbuffer objbuf; + string lastmname; + int count; + + // Used in backend.iasm + ASM_STATE asmstate; + Token* asmtok; + TOK tok_value; + + // Used in backend.StringTab + StringTab[STSIZE] stringTab; + size_t stidx; + + // Used in backend.Util + elem* eictor; + Symbol* ictorlocalgot; + elem* ector; + Array ectorgates; + elem* edtor; + elem* etest; + int dtorcount; + Symbol* localgot; + this() { params.versionids = new Array(); params.imppath = new Array(); - + st = new DsymbolTable(); stringtable = new StringTable(); stringbuffer = new OutBuffer(); @@ -132,9 +194,26 @@ modules = new DsymbolTable(); amodules = new Array(); deferred = new Array(); - + type_stringtable = new StringTable(); + arrayfuncs = new StringTable(); + + sarray = new Array(); + + scope Scope sc = new Scope(); + + tftohash = new TypeFunction(null, Type.thash_t, 0, LINK.LINKd); + tftohash.mod = MOD.MODconst; + tftohash = cast(TypeFunction)tftohash.semantic(Loc(0), sc); + + tftostring = new TypeFunction(null, Type.tchar.invariantOf().arrayOf(), 0, LINK.LINKd); + tftostring = cast(TypeFunction)tftostring.semantic(Loc(0), sc); + + obj_symbols_towrite = new Array(); + + ectorgates = new Array(); + init_time(); } diff -r 94b6033c07f3 -r fa9a71a9f5a8 dmd/Id.d --- a/dmd/Id.d Sun Oct 10 03:48:06 2010 +0400 +++ b/dmd/Id.d Sun Oct 10 05:22:45 2010 +0400 @@ -6,7 +6,7 @@ private string idgen(T...)(T ts) { - string res = "struct Id\n{\n"; + string res = "struct Ids\n{\n"; foreach(entry; ts) res ~= "\tstatic __gshared Identifier " ~ entry.ident ~ ";\n"; @@ -19,7 +19,7 @@ tmp = entry.ident; else tmp = entry.name_; - res ~= "\t\t" ~ entry.ident ~ ` = Lexer.idPool("` ~ tmp ~ "\");\n"; + res ~= "\t\tId." ~ entry.ident ~ ` = Lexer.idPool("` ~ tmp ~ "\");\n"; } res ~= "\t}\n}"; @@ -307,4 +307,6 @@ ID( "derivedMembers" ), ID( "isSame" ), ID( "compiles" ) - )); \ No newline at end of file + )); + +__gshared Ids Id; \ No newline at end of file diff -r 94b6033c07f3 -r fa9a71a9f5a8 dmd/InterfaceDeclaration.d --- a/dmd/InterfaceDeclaration.d Sun Oct 10 03:48:06 2010 +0400 +++ b/dmd/InterfaceDeclaration.d Sun Oct 10 05:22:45 2010 +0400 @@ -40,14 +40,14 @@ this(Loc loc, Identifier id, BaseClasses baseclasses) { super(loc, id, baseclasses); - + if (id is Id.IUnknown) // IUnknown is the root of all COM interfaces { com = true; cpp = true; // IUnknown is also a C++ interface } } - + override Dsymbol syntaxCopy(Dsymbol s) { InterfaceDeclaration id; @@ -60,7 +60,7 @@ ClassDeclaration.syntaxCopy(id); return id; } - + override void semantic(Scope sc) { //printf("InterfaceDeclaration.semantic(%s), type = %p\n", toChars(), type); @@ -76,12 +76,12 @@ handle = type; if (!members) // if forward reference - { + { //printf("\tinterface '%s' is forward referenced\n", toChars()); return; } if (symtab) // if already done - { + { if (!scope_) return; } @@ -90,7 +90,7 @@ Scope scx = null; if (scope_) - { + { sc = scope_; scx = scope_; // save so we don't make redundant copies scope_ = null; @@ -103,7 +103,7 @@ // Expand any tuples in baseclasses[] for (size_t i = 0; i < baseclasses.dim; ) - { + { auto b = baseclasses[0]; b.type = b.type.semantic(loc, sc); Type tb = b.type.toBasetype(); @@ -128,7 +128,7 @@ // Check for errors, handle forward references for (size_t i = 0; i < baseclasses.dim; ) - { + { TypeClass tc; BaseClass b; Type tb; @@ -164,7 +164,7 @@ continue; } if (!b.base.symtab) - { + { // Try to resolve forward reference if (sc.mustsemantic && b.base.scope_) b.base.semantic(null); @@ -197,7 +197,7 @@ // Cat together the vtbl[]'s from base interfaces for (size_t i = 0; i < interfaces_dim; i++) - { + { BaseClass b = interfaces[i]; // Skip if b has already appeared @@ -252,7 +252,7 @@ sc.pop(); //printf("-InterfaceDeclaration.semantic(%s), type = %p\n", toChars(), type); } - + override bool isBaseOf(ClassDeclaration cd, int* poffset) { uint j; @@ -268,7 +268,7 @@ { //printf("\tfound at offset %d\n", b.offset); if (poffset) - { + { *poffset = b.offset; if (j && cd.isInterfaceDeclaration()) *poffset = OFFSET_RUNTIME; @@ -276,7 +276,7 @@ return true; } if (isBaseOf(b, poffset)) - { + { if (j && poffset && cd.isInterfaceDeclaration()) *poffset = OFFSET_RUNTIME; return true; @@ -290,7 +290,7 @@ *poffset = 0; return false; } - + bool isBaseOf(BaseClass bc, int* poffset) { //printf("%s.InterfaceDeclaration.isBaseOf(bc = '%s')\n", toChars(), bc.base.toChars()); @@ -301,7 +301,7 @@ if (this == b.base) { if (poffset) - { + { *poffset = b.offset; if (j && bc.base.isInterfaceDeclaration()) *poffset = OFFSET_RUNTIME; @@ -309,7 +309,7 @@ return true; } if (isBaseOf(b, poffset)) - { + { if (j && poffset && bc.base.isInterfaceDeclaration()) *poffset = OFFSET_RUNTIME; return true; @@ -319,12 +319,12 @@ *poffset = 0; return false; } - + override string kind() { assert(false); } - + /**************************************** * Determine if slot 0 of the vtbl[] is reserved for something else. * For class objects, yes, this is where the ClassInfo ptr goes. @@ -337,7 +337,7 @@ return 0; return 1; } - + version (DMDV2) { override bool isCPPinterface() { @@ -481,7 +481,7 @@ offset += vtblInterfaces.dim * (4 * PTRSIZE); foreach (b; vtblInterfaces) - { + { ClassDeclaration id = b.base; // ClassInfo @@ -516,10 +516,7 @@ { Symbol *s; - if (!scc) - scc = fake_classsym(Id.ClassInfo); - - s = toSymbolX("__Interface", SCextern, scc.Stype, "Z"); + s = toSymbolX("__Interface", SCextern, global.scc.Stype, "Z"); s.Sfl = FLextern; s.Sflags |= SFLnodebug; csym = s; diff -r 94b6033c07f3 -r fa9a71a9f5a8 dmd/Module.d --- a/dmd/Module.d Sun Oct 10 03:48:06 2010 +0400 +++ b/dmd/Module.d Sun Oct 10 05:22:45 2010 +0400 @@ -937,17 +937,17 @@ //printf("Module.genobjfile(multiobj = %d) %s\n", multiobj, toChars()); - lastmname = srcfile.toChars(); /// global mutation + auto lastmname = global.lastmname = srcfile.toChars(); obj_initfile(toStringz(lastmname), null, toStringz(toPrettyChars())); - eictor = null; - ictorlocalgot = null; - ector = null; - ectorgates.setDim(0); - edtor = null; - etest = null; - dtorcount = 0; + global.eictor = null; + global.ictorlocalgot = null; + global.ector = null; + global.ectorgates.setDim(0); + global.edtor = null; + global.etest = null; + global.dtorcount = 0; if (doppelganger) { @@ -1039,7 +1039,7 @@ sictor = toSymbolX("__modictor", SC.SCglobal, t, "FZv"); cstate.CSpsymtab = &sictor.Sfunc.Flocsym; - localgot = ictorlocalgot; + global.localgot = global.ictorlocalgot; elem* e; e = el_params(el_ptr(cov), el_long(TYM.TYuint, numlines), @@ -1047,12 +1047,12 @@ toEfilename(), null); e = el_bin(OPER.OPcall, TYM.TYvoid, el_var(rtlsym[RTLSYM.RTLSYM_DCOVER]), e); - eictor = el_combine(e, eictor); - ictorlocalgot = localgot; + global.eictor = el_combine(e, global.eictor); + global.ictorlocalgot = global.localgot; } // If coverage / static constructor / destructor / unittest calls - if (eictor || ector || ectorgates.dim || edtor || etest) + if (global.eictor || global.ector || global.ectorgates.dim || global.edtor || global.etest) { /* t will be the type of the functions generated: * extern (C) void func(); @@ -1065,36 +1065,36 @@ enum moddeco = "FZv"; - if (eictor) + if (global.eictor) { - localgot = ictorlocalgot; + global.localgot = global.ictorlocalgot; block* b = block_calloc(); b.BC = BC.BCret; - b.Belem = eictor; + b.Belem = global.eictor; sictor.Sfunc.Fstartblock = b; writefunc(sictor); } - if (ector || ectorgates.dim) + if (global.ector || global.ectorgates.dim) { - localgot = null; + global.localgot = null; sctor = toSymbolX("__modctor", SC.SCglobal, t, moddeco); cstate.CSpsymtab = &sctor.Sfunc.Flocsym; - for (int i = 0; i < ectorgates.dim; i++) + for (int i = 0; i < global.ectorgates.dim; i++) { - StaticDtorDeclaration f = cast(StaticDtorDeclaration)ectorgates.data[i]; + StaticDtorDeclaration f = cast(StaticDtorDeclaration)global.ectorgates.data[i]; Symbol* s = f.vgate.toSymbol(); elem* e = el_var(s); e = el_bin(OPER.OPaddass, TYM.TYint, e, el_long(TYM.TYint, 1)); - ector = el_combine(ector, e); + global.ector = el_combine(global.ector, e); } block* b = block_calloc(); b.BC = BC.BCret; - b.Belem = ector; + b.Belem = global.ector; sctor.Sfunc.Fstartblock = b; writefunc(sctor); version (STATICCTOR) { @@ -1102,26 +1102,26 @@ } } - if (edtor) + if (global.edtor) { - localgot = null; + global.localgot = null; sdtor = toSymbolX("__moddtor", SC.SCglobal, t, moddeco); block* b = block_calloc(); b.BC = BC.BCret; - b.Belem = edtor; + b.Belem = global.edtor; sdtor.Sfunc.Fstartblock = b; writefunc(sdtor); } - if (etest) + if (global.etest) { - localgot = null; + global.localgot = null; stest = toSymbolX("__modtest", SC.SCglobal, t, moddeco); block* b = block_calloc(); b.BC = BC.BCret; - b.Belem = etest; + b.Belem = global.etest; stest.Sfunc.Fstartblock = b; writefunc(stest); } @@ -1156,7 +1156,7 @@ elem* elinnum; elem* efilename; - localgot = null; + global.localgot = null; // Call dassert(filename, line) // Get sole parameter, linnum diff -r 94b6033c07f3 -r fa9a71a9f5a8 dmd/StringExp.d --- a/dmd/StringExp.d Sun Oct 10 03:48:06 2010 +0400 +++ b/dmd/StringExp.d Sun Oct 10 05:22:45 2010 +0400 @@ -17,6 +17,7 @@ import dmd.Scope; import dmd.IRState; import dmd.StringExp; +import dmd.Global; import dmd.HdrGenState; import dmd.Utf; import dmd.Util; @@ -788,7 +789,7 @@ } for (size_t i = 0; i < STSIZE; i++) { - st = &stringTab[(stidx + i) % STSIZE]; + st = &global.stringTab[(global.stidx + i) % STSIZE]; //if (!st.m) continue; //printf(" st.m = %s\n", st.m.toChars()); //printf(" st.len = %d\n", st.len); @@ -805,8 +806,8 @@ } } - stidx = (stidx + 1) % STSIZE; - st = &stringTab[stidx]; + global.stidx = (global.stidx + 1) % STSIZE; + st = &global.stringTab[global.stidx]; dt = null; toDt(&dt); diff -r 94b6033c07f3 -r fa9a71a9f5a8 dmd/StructDeclaration.d --- a/dmd/StructDeclaration.d Sun Oct 10 03:48:06 2010 +0400 +++ b/dmd/StructDeclaration.d Sun Oct 10 05:22:45 2010 +0400 @@ -70,7 +70,7 @@ class StructDeclaration : AggregateDeclaration { bool zeroInit; // true if initialize with 0 fill - + version (DMDV2) { int hasIdentityAssign; // !=0 if has identity opAssign FuncDeclaration cpctor; // generated copy-constructor, if any @@ -86,10 +86,10 @@ // For forward references type = new TypeStruct(this); - + postblits = new FuncDeclarations(); /// } - + override Dsymbol syntaxCopy(Dsymbol s) { StructDeclaration sd; @@ -101,7 +101,7 @@ ScopeDsymbol.syntaxCopy(sd); return sd; } - + override void semantic(Scope sc) { Scope sc2; @@ -183,17 +183,17 @@ if (ad) t = ad.handle; else if (fd) - { + { AggregateDeclaration add = fd.isMember2(); if (add) t = add.handle; else - t = Type.tvoidptr; + t = global.tvoidptr; } else assert(0); if (t.ty == TY.Tstruct) - t = Type.tvoidptr; // t should not be a ref type + t = global.tvoidptr; // t should not be a ref type assert(!vthis); vthis = new ThisDeclaration(loc, t); //vthis.storage_class |= STC.STCref; @@ -240,7 +240,7 @@ } } if (auto d = s.isDeclaration()) - { + { if (auto t = d.type) { if (t.toBasetype().ty == TY.Tstruct) { auto ad = t.toDsymbol(sc).isThis(); @@ -431,7 +431,7 @@ semantic3(sc); } } - + override Dsymbol search(Loc loc, Identifier ident, int flags) { //printf("%s.StructDeclaration::search('%s')\n", toChars(), ident->toChars()); @@ -452,13 +452,13 @@ { assert(false); } - + override string mangle() { //printf("StructDeclaration.mangle() '%s'\n", toChars()); return Dsymbol.mangle(); } - + override string kind() { assert(false); @@ -522,7 +522,7 @@ } return true; } - + /******************************************* * We need an opEquals for the struct if * any fields has an opEquals. @@ -562,7 +562,7 @@ static if (X) printf("\tneed\n"); return true; } - + /****************************************** * Build opAssign for struct. * S* opAssign(S s) { ... } @@ -617,7 +617,7 @@ } else { e2 = new PtrExp(Loc(0), new ThisExp(Loc(0))); } - + ec = new AssignExp(Loc(0), e2, new IdentifierExp(Loc(0), Id.p)); ec.op = TOK.TOKblit; e = Expression.combine(e, ec); @@ -669,7 +669,7 @@ return fop; } - + /****************************************** * Build opEquals for struct. * const bool opEquals(const ref S s) { ... } @@ -767,11 +767,11 @@ StructDeclaration sd = ts.sym; if (sd.postblit) { Expression ex; - + // this.v ex = new ThisExp(Loc(0)); ex = new DotVarExp(Loc(0), ex, v, 0); - + if (dim == 1) { // this.v.postblit() ex = new DotVarExp(Loc(0), ex, sd.postblit, 0); @@ -782,10 +782,10 @@ // Typeinfo.postblit(cast(void*)&this.v); Expression ea = new AddrExp(Loc(0), ex); ea = new CastExp(Loc(0), ea, Type.tvoid.pointerTo()); - + Expression et = v.type.getTypeInfo(sc); et = new DotIdExp(Loc(0), et, Id._postblit); - + ex = new CallExp(Loc(0), et, ea); } e = Expression.combine(e, ex); // combine in forward order @@ -899,7 +899,7 @@ { assert(false); } - + override PROT getAccess(Dsymbol smember) // determine access to smember { assert(false); @@ -910,7 +910,7 @@ //printf("StructDeclaration.toObjFile('%s')\n", toChars()); if (multiobj) - { + { obj_append(this); return; } @@ -982,7 +982,7 @@ member.toObjFile(0); } } - + void toDt(dt_t** pdt) { uint offset; @@ -1010,7 +1010,7 @@ sz = cast(uint)v.type.size(); Initializer init = v.init; if (init) - { + { //printf("\t\thas initializer %s\n", init.toChars()); ExpInitializer ei = init.isExpInitializer(); Type tb = v.type.toBasetype(); @@ -1041,7 +1041,7 @@ dt_optimize(*pdt); } - + void toDebug() // to symbolic debug info { assert(false); diff -r 94b6033c07f3 -r fa9a71a9f5a8 dmd/Type.d --- a/dmd/Type.d Sun Oct 10 03:48:06 2010 +0400 +++ b/dmd/Type.d Sun Oct 10 05:22:45 2010 +0400 @@ -259,7 +259,6 @@ type* ctype; // for back end - static __gshared Type basic[TY.TMAX]; static __gshared ubyte mangleChar[TY.TMAX]; static __gshared ubyte sizeTy[TY.TMAX]; @@ -740,8 +739,8 @@ basic[TY.Terror] = basic[TY.Tint32]; - tvoidptr = tvoid.pointerTo(); - tstring = tchar.invariantOf().arrayOf(); + global.tvoidptr = tvoid.pointerTo(); + global.tstring = tchar.invariantOf().arrayOf(); if (global.params.isX86_64) { PTRSIZE = 8; @@ -2503,8 +2502,6 @@ *pe = null; *ps = null; } - - static __gshared TypeInfoDeclaration internalTI[TMAX]; /******************************************* * Get a canonicalized form of the TypeInfo for use with the internal @@ -2546,11 +2543,11 @@ case Tdelegate: case Tpointer: Linternal: - tid = internalTI[t.ty]; + tid = global.internalTI[t.ty]; if (!tid) { tid = new TypeInfoDeclaration(t, 1); - internalTI[t.ty] = tid; + global.internalTI[t.ty] = tid; } e = new VarExp(Loc(0), tid); e = e.addressOf(sc); @@ -2850,6 +2847,12 @@ { return null; } + + @property + static ref Type[TY.TMAX] basic() + { + return basic; + } static Type tvoid() { @@ -2983,9 +2986,6 @@ return tint32; // array/ptr index } - static __gshared Type tvoidptr; // void* - static __gshared Type tstring; // immutable(char)[] - static Type terror() { return basic[TY.Terror]; // for error recovery diff -r 94b6033c07f3 -r fa9a71a9f5a8 dmd/TypeAArray.d --- a/dmd/TypeAArray.d Sun Oct 10 03:48:06 2010 +0400 +++ b/dmd/TypeAArray.d Sun Oct 10 05:22:45 2010 +0400 @@ -414,13 +414,6 @@ assert(false); } } - // Dumb linear symbol table - should use associative array! - static __gshared Array sarray; - - shared static this() - { - sarray = new Array(); - } // Back end /******************************************** @@ -473,9 +466,9 @@ } // See if symbol is already in sarray - for (i = 0; i < sarray.dim; i++) + for (i = 0; i < global.sarray.dim; i++) { - s = cast(Symbol*)sarray.data[i]; + s = cast(Symbol*)global.sarray.data[i]; if (strcmp(id, s.Sident.ptr) == 0) return s; // use existing Symbol } @@ -497,11 +490,9 @@ t.Tcount++; s.Stype = t; - sarray.push(s); // remember it + global.sarray.push(s); // remember it return s; } - - static __gshared Symbol* s; override type* toCtype() { @@ -516,9 +507,10 @@ * struct AArray { size_t length; void* ptr; } */ + auto s = global.AArray_s; if (!s) { - s = symbol_calloc("_AArray"); + global.AArray_s = s = symbol_calloc("_AArray"); s.Sclass = SCstruct; s.Sstruct = struct_calloc(); s.Sstruct.Sflags |= 0; @@ -530,7 +522,7 @@ Symbol* s1 = symbol_name("length", SCmember, Type.tsize_t.toCtype()); list_append(&s.Sstruct.Sfldlst, s1); - Symbol* s2 = symbol_name("data", SCmember, Type.tvoidptr.toCtype()); + Symbol* s2 = symbol_name("data", SCmember, global.tvoidptr.toCtype()); s2.Smemoff = cast(uint)Type.tsize_t.size(); list_append(&s.Sstruct.Sfldlst, s2); } diff -r 94b6033c07f3 -r fa9a71a9f5a8 dmd/TypeClass.d --- a/dmd/TypeClass.d Sun Oct 10 03:48:06 2010 +0400 +++ b/dmd/TypeClass.d Sun Oct 10 05:22:45 2010 +0400 @@ -243,7 +243,7 @@ /* The pointer to the vtbl[] * *cast(invariant(void*)**)e */ - e = e.castTo(sc, tvoidptr.invariantOf().pointerTo().pointerTo()); + e = e.castTo(sc, global.tvoidptr.invariantOf().pointerTo().pointerTo()); e = new PtrExp(e.loc, e); e = e.semantic(sc); return e; @@ -253,7 +253,7 @@ { /* The handle to the monitor (call it a void*) * *(cast(void**)e + 1) */ - e = e.castTo(sc, tvoidptr.pointerTo()); + e = e.castTo(sc, global.tvoidptr.pointerTo()); e = new AddExp(e.loc, e, new IntegerExp(1)); e = new PtrExp(e.loc, e); e = e.semantic(sc); diff -r 94b6033c07f3 -r fa9a71a9f5a8 dmd/TypeDArray.d --- a/dmd/TypeDArray.d Sun Oct 10 03:48:06 2010 +0400 +++ b/dmd/TypeDArray.d Sun Oct 10 05:22:45 2010 +0400 @@ -127,7 +127,7 @@ toCBuffer3(buf, hgs, mod); return; } - if (equals(tstring)) + if (equals(global.tstring)) buf.writestring("string"); else { diff -r 94b6033c07f3 -r fa9a71a9f5a8 dmd/TypeDelegate.d --- a/dmd/TypeDelegate.d Sun Oct 10 03:48:06 2010 +0400 +++ b/dmd/TypeDelegate.d Sun Oct 10 05:22:45 2010 +0400 @@ -136,6 +136,7 @@ version (LOGDOTEXP) { printf("TypeDelegate.dotExp(e = '%s', ident = '%s')\n", e.toChars(), ident.toChars()); } + auto tvoidptr = global.tvoidptr; if (ident == Id.ptr) { e.type = tvoidptr; @@ -170,8 +171,6 @@ } } - static __gshared Symbol* s; - override type* toCtype() { type* t; @@ -185,9 +184,10 @@ * _Delegate { void* frameptr; Function *funcptr; } */ + auto s = global.Delegate_s; if (!s) { - s = symbol_calloc("_Delegate"); + global.Delegate_s = s = symbol_calloc("_Delegate"); s.Sclass = SC.SCstruct; s.Sstruct = struct_calloc(); s.Sstruct.Sflags |= 0; /// huh? @@ -196,11 +196,13 @@ s.Sstruct.Sstructsize = cast(uint)size(Loc(0)); slist_add(s); - Symbol* s1 = symbol_name("frameptr", SC.SCmember, Type.tvoidptr.toCtype()); + auto tvoidptr = global.tvoidptr; + + Symbol* s1 = symbol_name("frameptr", SC.SCmember, tvoidptr.toCtype()); list_append(&s.Sstruct.Sfldlst, s1); - Symbol* s2 = symbol_name("funcptr", SC.SCmember, Type.tvoidptr.toCtype()); - s2.Smemoff = cast(uint)Type.tvoidptr.size(); + Symbol* s2 = symbol_name("funcptr", SC.SCmember, tvoidptr.toCtype()); + s2.Smemoff = cast(uint)tvoidptr.size(); list_append(&s.Sstruct.Sfldlst, s2); } diff -r 94b6033c07f3 -r fa9a71a9f5a8 dmd/TypeInfoStructDeclaration.d --- a/dmd/TypeInfoStructDeclaration.d Sun Oct 10 03:48:06 2010 +0400 +++ b/dmd/TypeInfoStructDeclaration.d Sun Oct 10 05:22:45 2010 +0400 @@ -33,9 +33,6 @@ type = global.typeinfostruct.type; } - static __gshared TypeFunction tftohash; - static __gshared TypeFunction tftostring; - override void toDt(dt_t** pdt) { //printf("TypeInfoStructDeclaration.toDt() '%s'\n", toChars()); @@ -85,18 +82,6 @@ Type ta; Dsymbol s; - if (!tftohash) - { - scope Scope sc = new Scope(); - - tftohash = new TypeFunction(null, Type.thash_t, 0, LINK.LINKd); - tftohash.mod = MOD.MODconst; - tftohash = cast(TypeFunction)tftohash.semantic(Loc(0), sc); - - tftostring = new TypeFunction(null, Type.tchar.invariantOf().arrayOf(), 0, LINK.LINKd); - tftostring = cast(TypeFunction)tftostring.semantic(Loc(0), sc); - } - TypeFunction tfeqptr; { // bool opEqual(const T*) const; @@ -155,7 +140,7 @@ fdx = s ? s.isFuncDeclaration() : null; if (fdx) { - fd = fdx.overloadExactMatch(tftohash); + fd = fdx.overloadExactMatch(global.tftohash); if (fd) dtxoff(pdt, fd.toSymbol(), 0, TYM.TYnptr); else @@ -192,7 +177,7 @@ fdx = s ? s.isFuncDeclaration() : null; if (fdx) { - fd = fdx.overloadExactMatch(tftostring); + fd = fdx.overloadExactMatch(global.tftostring); if (fd) dtxoff(pdt, fd.toSymbol(), 0, TYM.TYnptr); else diff -r 94b6033c07f3 -r fa9a71a9f5a8 dmd/backend/StringTab.d --- a/dmd/backend/StringTab.d Sun Oct 10 03:48:06 2010 +0400 +++ b/dmd/backend/StringTab.d Sun Oct 10 05:22:45 2010 +0400 @@ -13,6 +13,4 @@ size_t len; } -enum STSIZE = 16; -__gshared StringTab[STSIZE] stringTab; -__gshared size_t stidx; \ No newline at end of file +enum STSIZE = 16; \ No newline at end of file diff -r 94b6033c07f3 -r fa9a71a9f5a8 dmd/backend/Util.d --- a/dmd/backend/Util.d Sun Oct 10 03:48:06 2010 +0400 +++ b/dmd/backend/Util.d Sun Oct 10 05:22:45 2010 +0400 @@ -35,22 +35,6 @@ enum SYM_PREDEF_SZ = 22; } -//extern (C++) extern { - __gshared elem* eictor; - __gshared Symbol* ictorlocalgot; - __gshared elem* ector; - __gshared Array ectorgates; - __gshared elem* edtor; - __gshared elem* etest; - __gshared int dtorcount; - __gshared Symbol* localgot; -//} - -shared static this() -{ - ectorgates = new Array(); -} - alias size_t tym_t; // data type big enough for type masks //alias ulong tym_t; // data type big enough for type masks alias elem* elem_p; // data type big enough for type masks diff -r 94b6033c07f3 -r fa9a71a9f5a8 dmd/backend/glue.d --- a/dmd/backend/glue.d Sun Oct 10 03:48:06 2010 +0400 +++ b/dmd/backend/glue.d Sun Oct 10 05:22:45 2010 +0400 @@ -19,9 +19,6 @@ import core.stdc.string; -__gshared Array obj_symbols_towrite; -__gshared Outbuffer objbuf; - version (Windows) { extern (C++) extern @@ -48,8 +45,6 @@ import std.exception; import std.string; -__gshared string lastmname; - struct Outbuffer { ubyte* buf; // the buffer itself @@ -275,18 +270,13 @@ } } -static this() -{ - obj_symbols_towrite = new Array(); -} - /************************************** * Append s to list of object files to generate later. */ void obj_append(Dsymbol s) { - obj_symbols_towrite.push(cast(void*)s); + global.obj_symbols_towrite.push(cast(void*)s); } version (Bug4059) @@ -315,8 +305,8 @@ void clearStringTab() { //printf("clearStringTab()\n"); - memset(stringTab.ptr, 0, stringTab.sizeof); - stidx = 0; + memset(global.stringTab.ptr, 0, global.stringTab.sizeof); + global.stidx = 0; // assertexp_sfilename = null; // assertexp_name = null; @@ -333,7 +323,7 @@ slist_reset(); clearStringTab(); - obj_init(&objbuf, srcfile, null); + obj_init(&global.objbuf, srcfile, null); el_reset(); cg87_reset(); @@ -343,6 +333,8 @@ void obj_end(Library library, File objfile) { obj_term(); + + auto objbuf = &global.objbuf; if (library) { @@ -370,10 +362,9 @@ objbuf.inc = 0; } -static __gshared int count; - void obj_write_deferred(Library library) { + auto obj_symbols_towrite = global.obj_symbols_towrite; for (int i = 0; i < obj_symbols_towrite.dim; i++) { Dsymbol s = cast(Dsymbol)obj_symbols_towrite.data[i]; @@ -383,18 +374,18 @@ if (m) { mname = m.srcfile.toChars(); - lastmname = mname; + global.lastmname = mname; } else { //mname = s->ident->toChars(); - mname = lastmname; + mname = global.lastmname; assert(mname.length != 0); } obj_start(cast(char*)toStringz(mname)); - count++; // sequence for generating names + int count = ++global.count; // sequence for generating names /* Create a module that's a doppelganger of m, with just * enough to be able to create the moduleinfo. diff -r 94b6033c07f3 -r fa9a71a9f5a8 dmd/backend/iasm.d --- a/dmd/backend/iasm.d Sun Oct 10 03:48:06 2010 +0400 +++ b/dmd/backend/iasm.d Sun Oct 10 05:22:45 2010 +0400 @@ -106,7 +106,7 @@ const(char)* asm_opstr(OP* pop); } -static __gshared ubyte asm_TKlbra_seen = false; +__gshared ubyte asm_TKlbra_seen = 0; struct REG { @@ -572,9 +572,30 @@ alias IT.ITMASK ITMASK; alias IT.ITSIZE ITSIZE; -__gshared ASM_STATE asmstate; -__gshared Token* asmtok; -__gshared TOK tok_value; +ref ASM_STATE asmstate() +{ + return global.asmstate; +} + +ref Token* asmtok() +{ + return global.asmtok; +} + +void asmtok(Token* value) +{ + global.asmtok = value; +} + +ref TOK tok_value() +{ + return global.tok_value; +} + +void tok_value(TOK value) +{ + global.tok_value = value; +} // Additional tokens for the inline assembler enum ASMTK