0
|
1 module dmd.TypedefDeclaration;
|
|
2
|
|
3 import dmd.Declaration;
|
|
4 import dmd.Initializer;
|
|
5 import dmd.Type;
|
|
6 import dmd.Loc;
|
|
7 import dmd.Identifier;
|
|
8 import dmd.Dsymbol;
|
|
9 import dmd.Scope;
|
|
10 import dmd.OutBuffer;
|
|
11 import dmd.ExpInitializer;
|
|
12 import dmd.HdrGenState;
|
|
13 import dmd.TypeTypedef;
|
|
14 import dmd.Global;
|
|
15 import dmd.STC;
|
|
16
|
|
17 import dmd.backend.SC;
|
|
18 import dmd.backend.FL;
|
|
19 import dmd.backend.Symbol;
|
|
20 import dmd.backend.Util;
|
|
21
|
|
22 class TypedefDeclaration : Declaration
|
|
23 {
|
|
24 Type basetype;
|
|
25 Initializer init;
|
|
26 int sem = 0;// 0: semantic() has not been run
|
|
27 // 1: semantic() is in progress
|
|
28 // 2: semantic() has been run
|
|
29 // 3: semantic2() has been run
|
|
30
|
|
31 this(Loc loc, Identifier id, Type basetype, Initializer init)
|
|
32 {
|
|
33 super(id);
|
|
34
|
|
35 this.type = new TypeTypedef(this);
|
|
36 this.basetype = basetype.toBasetype();
|
|
37 this.init = init;
|
|
38
|
|
39 version (_DH) {
|
|
40 this.htype = null;
|
|
41 this.hbasetype = null;
|
|
42 }
|
|
43 this.loc = loc;
|
|
44 this.sinit = null;
|
|
45 }
|
|
46
|
|
47 version (DumbClone) {
|
|
48 } else {
|
|
49 Type clone()
|
|
50 {
|
|
51 assert(false);
|
|
52 }
|
|
53 }
|
|
54 Dsymbol syntaxCopy(Dsymbol)
|
|
55 {
|
|
56 assert(false);
|
|
57 }
|
|
58
|
|
59 void semantic(Scope sc)
|
|
60 {
|
|
61 //printf("TypedefDeclaration::semantic(%s) sem = %d\n", toChars(), sem);
|
|
62 if (sem == 0)
|
|
63 {
|
|
64 sem = 1;
|
|
65 basetype = basetype.semantic(loc, sc);
|
|
66 sem = 2;
|
|
67 type = type.semantic(loc, sc);
|
|
68 if (sc.parent.isFuncDeclaration() && init)
|
|
69 semantic2(sc);
|
|
70 storage_class |= sc.stc & STCdeprecated;
|
|
71 }
|
|
72 else if (sem == 1)
|
|
73 {
|
|
74 error("circular definition");
|
|
75 }
|
|
76 }
|
|
77
|
|
78 void semantic2(Scope sc)
|
|
79 {
|
|
80 //printf("TypedefDeclaration::semantic2(%s) sem = %d\n", toChars(), sem);
|
|
81 if (sem == 2)
|
|
82 {
|
|
83 sem = 3;
|
|
84 if (init)
|
|
85 {
|
|
86 init = init.semantic(sc, basetype);
|
|
87
|
|
88 ExpInitializer ie = init.isExpInitializer();
|
|
89 if (ie)
|
|
90 {
|
|
91 if (ie.exp.type == basetype)
|
|
92 ie.exp.type = type;
|
|
93 }
|
|
94 }
|
|
95 }
|
|
96 }
|
|
97
|
|
98 string mangle()
|
|
99 {
|
|
100 //printf("TypedefDeclaration::mangle() '%s'\n", toChars());
|
|
101 return Dsymbol.mangle();
|
|
102 }
|
|
103
|
|
104 string kind()
|
|
105 {
|
|
106 assert(false);
|
|
107 }
|
|
108
|
|
109 Type getType()
|
|
110 {
|
|
111 return type;
|
|
112 }
|
|
113
|
|
114 void toCBuffer(OutBuffer buf, HdrGenState* hgs)
|
|
115 {
|
|
116 assert(false);
|
|
117 }
|
|
118
|
|
119 version (_DH) {
|
|
120 Type htype;
|
|
121 Type hbasetype;
|
|
122 }
|
|
123
|
|
124 void toDocBuffer(OutBuffer buf)
|
|
125 {
|
|
126 assert(false);
|
|
127 }
|
|
128
|
|
129 void toObjFile(int multiobj) // compile to .obj file
|
|
130 {
|
|
131 //printf("TypedefDeclaration::toObjFile('%s')\n", toChars());
|
|
132 if (global.params.symdebug)
|
|
133 toDebug();
|
|
134
|
|
135 type.getTypeInfo(null); // generate TypeInfo
|
|
136
|
|
137 TypeTypedef tc = cast(TypeTypedef)type;
|
|
138 if (type.isZeroInit(Loc(0)) || !tc.sym.init) {
|
|
139 ;
|
|
140 } else
|
|
141 {
|
|
142 SC scclass = SCglobal;
|
|
143 if (inTemplateInstance())
|
|
144 scclass = SCcomdat;
|
|
145
|
|
146 // Generate static initializer
|
|
147 toInitializer();
|
|
148 sinit.Sclass = scclass;
|
|
149 sinit.Sfl = FLdata;
|
|
150
|
|
151 version (ELFOBJ) { // Burton
|
|
152 sinit.Sseg = Segment.CDATA;
|
|
153 }
|
|
154 version (MACHOBJ) {
|
|
155 sinit.Sseg = Segment.DATA;
|
|
156 }
|
|
157 sinit.Sdt = tc.sym.init.toDt();
|
|
158 outdata(sinit);
|
|
159 }
|
|
160 }
|
|
161
|
|
162 void toDebug()
|
|
163 {
|
|
164 assert(false);
|
|
165 }
|
|
166
|
|
167 int cvMember(ubyte* p)
|
|
168 {
|
|
169 assert(false);
|
|
170 }
|
|
171
|
|
172 TypedefDeclaration isTypedefDeclaration() { return this; }
|
|
173
|
|
174 Symbol* sinit;
|
|
175 Symbol* toInitializer()
|
|
176 {
|
|
177 assert(false);
|
|
178 }
|
|
179 } |