Mercurial > projects > ddmd
diff dmd/TypedefDeclaration.d @ 0:10317f0c89a5
Initial commit
author | korDen |
---|---|
date | Sat, 24 Oct 2009 08:42:06 +0400 |
parents | |
children | fd4acc376c45 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dmd/TypedefDeclaration.d Sat Oct 24 08:42:06 2009 +0400 @@ -0,0 +1,179 @@ +module dmd.TypedefDeclaration; + +import dmd.Declaration; +import dmd.Initializer; +import dmd.Type; +import dmd.Loc; +import dmd.Identifier; +import dmd.Dsymbol; +import dmd.Scope; +import dmd.OutBuffer; +import dmd.ExpInitializer; +import dmd.HdrGenState; +import dmd.TypeTypedef; +import dmd.Global; +import dmd.STC; + +import dmd.backend.SC; +import dmd.backend.FL; +import dmd.backend.Symbol; +import dmd.backend.Util; + +class TypedefDeclaration : Declaration +{ + Type basetype; + Initializer init; + int sem = 0;// 0: semantic() has not been run + // 1: semantic() is in progress + // 2: semantic() has been run + // 3: semantic2() has been run + + this(Loc loc, Identifier id, Type basetype, Initializer init) + { + super(id); + + this.type = new TypeTypedef(this); + this.basetype = basetype.toBasetype(); + this.init = init; + + version (_DH) { + this.htype = null; + this.hbasetype = null; + } + this.loc = loc; + this.sinit = null; + } + +version (DumbClone) { +} else { + Type clone() + { + assert(false); + } +} + Dsymbol syntaxCopy(Dsymbol) + { + assert(false); + } + + void semantic(Scope sc) + { + //printf("TypedefDeclaration::semantic(%s) sem = %d\n", toChars(), sem); + if (sem == 0) + { + sem = 1; + basetype = basetype.semantic(loc, sc); + sem = 2; + type = type.semantic(loc, sc); + if (sc.parent.isFuncDeclaration() && init) + semantic2(sc); + storage_class |= sc.stc & STCdeprecated; + } + else if (sem == 1) + { + error("circular definition"); + } + } + + void semantic2(Scope sc) + { + //printf("TypedefDeclaration::semantic2(%s) sem = %d\n", toChars(), sem); + if (sem == 2) + { + sem = 3; + if (init) + { + init = init.semantic(sc, basetype); + + ExpInitializer ie = init.isExpInitializer(); + if (ie) + { + if (ie.exp.type == basetype) + ie.exp.type = type; + } + } + } + } + + string mangle() + { + //printf("TypedefDeclaration::mangle() '%s'\n", toChars()); + return Dsymbol.mangle(); + } + + string kind() + { + assert(false); + } + + Type getType() + { + return type; + } + + void toCBuffer(OutBuffer buf, HdrGenState* hgs) + { + assert(false); + } + +version (_DH) { + Type htype; + Type hbasetype; +} + + void toDocBuffer(OutBuffer buf) + { + assert(false); + } + + void toObjFile(int multiobj) // compile to .obj file + { + //printf("TypedefDeclaration::toObjFile('%s')\n", toChars()); + if (global.params.symdebug) + toDebug(); + + type.getTypeInfo(null); // generate TypeInfo + + TypeTypedef tc = cast(TypeTypedef)type; + if (type.isZeroInit(Loc(0)) || !tc.sym.init) { + ; + } else + { + SC scclass = SCglobal; + if (inTemplateInstance()) + scclass = SCcomdat; + + // Generate static initializer + toInitializer(); + sinit.Sclass = scclass; + sinit.Sfl = FLdata; + + version (ELFOBJ) { // Burton + sinit.Sseg = Segment.CDATA; + } + version (MACHOBJ) { + sinit.Sseg = Segment.DATA; + } + sinit.Sdt = tc.sym.init.toDt(); + outdata(sinit); + } + } + + void toDebug() + { + assert(false); + } + + int cvMember(ubyte* p) + { + assert(false); + } + + TypedefDeclaration isTypedefDeclaration() { return this; } + + Symbol* sinit; + Symbol* toInitializer() + { + assert(false); + } +} \ No newline at end of file