# HG changeset patch # User Christian Kamm # Date 1234694788 -3600 # Node ID 369996c08420def36330920aa8e56eed07b4a52c # Parent 8a70b4381369ea12b2a34a377f878dbefc75af32 Change the numbering of static ctors/dtors to be module based instead of being global. This fixes #210 by making sure that the static ctor always gets the same number, regardless of the order of the modules given at the command line. diff -r 8a70b4381369 -r 369996c08420 dmd/func.c --- a/dmd/func.c Sat Feb 14 21:18:47 2009 +0100 +++ b/dmd/func.c Sun Feb 15 11:46:28 2009 +0100 @@ -2420,7 +2420,7 @@ StaticCtorDeclaration::StaticCtorDeclaration(Loc loc, Loc endloc) : FuncDeclaration(loc, endloc, - Identifier::generateId("_staticCtor"), STCstatic, NULL) + Lexer::idPool("_staticCtor"), STCstatic, NULL) { } @@ -2438,6 +2438,9 @@ { //printf("StaticCtorDeclaration::semantic()\n"); + // get ourselves a scope-unique id + ident = sc->module->generateId(ident); + type = new TypeFunction(NULL, Type::tvoid, FALSE, LINKd); /* If the static ctor appears within a template instantiation, @@ -2521,7 +2524,7 @@ StaticDtorDeclaration::StaticDtorDeclaration(Loc loc, Loc endloc) : FuncDeclaration(loc, endloc, - Identifier::generateId("_staticDtor"), STCstatic, NULL) + Lexer::idPool("_staticDtor"), STCstatic, NULL) { vgate = NULL; } @@ -2538,6 +2541,9 @@ void StaticDtorDeclaration::semantic(Scope *sc) { + // get ourselves a scope-unique id + ident = sc->module->generateId(ident); + ClassDeclaration *cd; Type *tret; diff -r 8a70b4381369 -r 369996c08420 dmd/module.c --- a/dmd/module.c Sat Feb 14 21:18:47 2009 +0100 +++ b/dmd/module.c Sun Feb 15 11:46:28 2009 +0100 @@ -130,6 +130,7 @@ llvmForceLogging = false; this->doDocComment = doDocComment; this->doHdrGen = doHdrGen; + uniqueId = 0; } File* Module::buildFilePath(char* forcename, char* path, char* ext) @@ -1007,3 +1008,8 @@ } return dst; } + +Identifier* Module::generateId(Identifier* id) +{ + return Identifier::generateId(id->string, uniqueId++); +} diff -r 8a70b4381369 -r 369996c08420 dmd/module.h --- a/dmd/module.h Sat Feb 14 21:18:47 2009 +0100 +++ b/dmd/module.h Sun Feb 15 11:46:28 2009 +0100 @@ -179,6 +179,10 @@ // array ops emitted in this module already StringTable arrayfuncs; + + // for numbering staticCtors etc. + int uniqueId; + Identifier* generateId(Identifier* id); };