# HG changeset patch # User korDen # Date 1285841390 -14400 # Node ID 96c0fff6897d138e4128aef9050ece8a8320dc67 # Parent e7769d53e750a93e0fc28d6ef5d4c82a539c4e89 more global state cleanup diff -r e7769d53e750 -r 96c0fff6897d dmd/Global.d --- a/dmd/Global.d Thu Sep 30 13:29:54 2010 +0400 +++ b/dmd/Global.d Thu Sep 30 14:09:50 2010 +0400 @@ -8,7 +8,12 @@ import dmd.StringTable; import dmd.OutBuffer; import dmd.Token; +import dmd.Scope; import dmd.Module; +import dmd.Id; + +import dmd.codegen.Util; +import dmd.backend.Classsym; import core.stdc.time; import core.stdc.stdio; @@ -81,8 +86,18 @@ Array amodules; // array of all modules Array deferred; // deferred Dsymbol's needing semantic() run on them uint dprogress; // progress resolving the deferred list + int nested; + Classsym* scc; + ClassDeclaration moduleinfo; - ClassDeclaration moduleinfo; + // Used in PowExp + bool importMathChecked = false; + + // Used in Scope + Scope scope_freelist; + + // Used in TemplateMixin + int nest; this() { @@ -98,6 +113,11 @@ init_time(); } + void initClasssym() + { + scc = fake_classsym(Id.ClassInfo); + } + void init_time() { time_t tm; diff -r e7769d53e750 -r 96c0fff6897d dmd/Id.d --- a/dmd/Id.d Thu Sep 30 13:29:54 2010 +0400 +++ b/dmd/Id.d Thu Sep 30 14:09:50 2010 +0400 @@ -9,7 +9,7 @@ string res = "struct Id\n{\n"; foreach(entry; ts) - res ~= "\tstatic Identifier " ~ entry.ident ~ ";\n"; + res ~= "\tstatic __gshared Identifier " ~ entry.ident ~ ";\n"; res ~= "\tstatic void initialize()\n\t{\n"; string tmp; diff -r e7769d53e750 -r 96c0fff6897d dmd/Module.d --- a/dmd/Module.d Thu Sep 30 13:29:54 2010 +0400 +++ b/dmd/Module.d Thu Sep 30 14:09:50 2010 +0400 @@ -1061,7 +1061,7 @@ t.Tnext = tsvoid; tsvoid.Tcount++; - static string moddeco = "FZv"; + enum moddeco = "FZv"; if (eictor) { @@ -1287,14 +1287,13 @@ void runDeferredSemantic() { + if (global.nested) + return; + //if (deferred.dim) printf("+Module.runDeferredSemantic('%s'), len = %d\n", toChars(), deferred.dim); + global.nested++; + size_t len; - static int nested; - if (nested) - return; - //if (deferred.dim) printf("+Module.runDeferredSemantic('%s'), len = %d\n", toChars(), deferred.dim); - nested++; - auto deferred = global.deferred; do @@ -1330,7 +1329,7 @@ } //printf("\tdeferred.dim = %d, len = %d, dprogress = %d\n", deferred.dim, len, dprogress); } while (deferred.dim < len || global.dprogress); // while making progress - nested--; + global.nested--; //printf("-Module.runDeferredSemantic('%s'), len = %d\n", toChars(), deferred.dim); } @@ -1499,13 +1498,8 @@ if (!csym) { Symbol* s; - static Classsym* scc; - if (!scc) { - scc = fake_classsym(Id.ClassInfo); - } - - s = toSymbolX("__ModuleInfo", SC.SCextern, scc.Stype, "Z"); + s = toSymbolX("__ModuleInfo", SC.SCextern, global.scc.Stype, "Z"); s.Sfl = FL.FLextern; s.Sflags |= SFL.SFLnodebug; csym = s; diff -r e7769d53e750 -r 96c0fff6897d dmd/PowExp.d --- a/dmd/PowExp.d Thu Sep 30 13:29:54 2010 +0400 +++ b/dmd/PowExp.d Thu Sep 30 14:09:50 2010 +0400 @@ -109,10 +109,9 @@ return e; } - static int importMathChecked = 0; - if (!importMathChecked) + if (!global.importMathChecked) { - importMathChecked = 1; + global.importMathChecked = true; auto amodules = global.amodules; for (int i = 0; i < amodules.dim; i++) { diff -r e7769d53e750 -r 96c0fff6897d dmd/RealExp.d --- a/dmd/RealExp.d Thu Sep 30 13:29:54 2010 +0400 +++ b/dmd/RealExp.d Thu Sep 30 14:09:50 2010 +0400 @@ -192,7 +192,7 @@ return el_const(ty, &c); } - static private char[6] zeropad; + private enum char[6] zeropad = [0]; override dt_t** toDt(dt_t** pdt) { diff -r e7769d53e750 -r 96c0fff6897d dmd/Scope.d --- a/dmd/Scope.d Thu Sep 30 13:29:54 2010 +0400 +++ b/dmd/Scope.d Thu Sep 30 14:09:50 2010 +0400 @@ -88,7 +88,6 @@ uint lastoffset; // offset in docbuf of where to insert next dec OutBuffer docbuf; // buffer for documentation output - static Scope freelist; /// static void *operator new(size_t sz); static Scope createGlobal(Module module_) { @@ -201,8 +200,8 @@ if (!nofree) { - enclosing = freelist; - freelist = this; + enclosing = global.scope_freelist; + global.scope_freelist = this; flags |= SCOPE.SCOPEfree; } diff -r e7769d53e750 -r 96c0fff6897d dmd/StorageClassDeclaration.d --- a/dmd/StorageClassDeclaration.d Thu Sep 30 13:29:54 2010 +0400 +++ b/dmd/StorageClassDeclaration.d Thu Sep 30 14:09:50 2010 +0400 @@ -96,7 +96,7 @@ TOK tok; }; - static SCstring[] table = + enum SCstring[] table = [ { STCauto, TOKauto }, { STCscope, TOKscope }, diff -r e7769d53e750 -r 96c0fff6897d dmd/TemplateAliasParameter.d --- a/dmd/TemplateAliasParameter.d Thu Sep 30 13:29:54 2010 +0400 +++ b/dmd/TemplateAliasParameter.d Thu Sep 30 14:09:50 2010 +0400 @@ -47,6 +47,13 @@ return o; } +__gshared Dsymbol sdummy; + +shared static this() +{ + sdummy = new Dsymbol(); +} + class TemplateAliasParameter : TemplateParameter { /* Syntax: @@ -57,8 +64,6 @@ Object specAlias; Object defaultAlias; - static Dsymbol sdummy; - this(Loc loc, Identifier ident, Type specType, Object specAlias, Object defaultAlias) { super(loc, ident); @@ -215,7 +220,7 @@ } if (specAlias) { - if (sa == sdummy) + if (sa is sdummy) goto Lnomatch; if (sa != specAlias) goto Lnomatch; @@ -253,15 +258,10 @@ override Object dummyArg() { - Object s; - - s = specAlias; - if (!s) + if (!specAlias) { - if (!sdummy) - sdummy = new Dsymbol(); - s = sdummy; + return sdummy; } - return s; + return specAlias; } } diff -r e7769d53e750 -r 96c0fff6897d dmd/TemplateInstance.d --- a/dmd/TemplateInstance.d Thu Sep 30 13:29:54 2010 +0400 +++ b/dmd/TemplateInstance.d Thu Sep 30 14:09:50 2010 +0400 @@ -859,7 +859,7 @@ OutBuffer buf = new OutBuffer(); string id; - static if (0) { + static if (false) { printf("TemplateInstance.mangle() %s", toChars()); if (parent) printf(" parent = %s %s", parent.kind(), parent.toChars()); diff -r e7769d53e750 -r 96c0fff6897d dmd/TemplateMixin.d --- a/dmd/TemplateMixin.d Thu Sep 30 13:29:54 2010 +0400 +++ b/dmd/TemplateMixin.d Thu Sep 30 14:09:50 2010 +0400 @@ -299,10 +299,8 @@ sc2 = argscope.push(this); sc2.offset = sc.offset; - - static int nest; - //printf("%d\n", nest); - if (++nest > 500) + //printf("%d\n", global.nest); + if (++global.nest > 500) { global.gag = 0; // ensure error message gets printed error("recursive expansion"); @@ -312,7 +310,7 @@ foreach(Dsymbol s; members) s.semantic(sc2); - nest--; + global.nest--; sc.offset = sc2.offset; diff -r e7769d53e750 -r 96c0fff6897d dmd/TemplateValueParameter.d --- a/dmd/TemplateValueParameter.d Thu Sep 30 13:29:54 2010 +0400 +++ b/dmd/TemplateValueParameter.d Thu Sep 30 14:09:50 2010 +0400 @@ -24,6 +24,12 @@ import dmd.Dsymbol : isExpression; +static __gshared Expression edummy; +shared static this() +{ + edummy = new Expression(Loc(0), TOK.init, 0); +} + class TemplateValueParameter : TemplateParameter { /* Syntax: @@ -34,8 +40,6 @@ Expression specValue; Expression defaultValue; - static Expression edummy; - this(Loc loc, Identifier ident, Type valType, Expression specValue, Expression defaultValue) { super(loc, ident); @@ -205,7 +209,7 @@ if (specValue) { - if (!ei || ei == edummy) + if (!ei || ei is edummy) goto Lnomatch; Expression e = specValue; @@ -259,16 +263,11 @@ override Object dummyArg() { - Expression e; - - e = specValue; - if (!e) + if (!specValue) { - // Create a dummy value - if (!edummy) - edummy = valType.defaultInit(Loc(0)); - e = edummy; + return edummy; } - return e; + + return specValue; } } diff -r e7769d53e750 -r 96c0fff6897d dmd/Type.d --- a/dmd/Type.d Thu Sep 30 13:29:54 2010 +0400 +++ b/dmd/Type.d Thu Sep 30 14:09:50 2010 +0400 @@ -2220,10 +2220,12 @@ return salign; } - ///Expression defaultInit(Loc loc = Loc(0)) Expression defaultInit(Loc loc) { - assert(false); + version (LOGDEFAULTINIT) { + printf("Type.defaultInit() '%.*s'\n", toChars()); + } + return null; } /*************************************** diff -r e7769d53e750 -r 96c0fff6897d main.d --- a/main.d Thu Sep 30 13:29:54 2010 +0400 +++ b/main.d Thu Sep 30 14:09:50 2010 +0400 @@ -776,6 +776,7 @@ Type.init(); Id.initialize(); initPrecedence(); + global.initClasssym(); backend_init();