Mercurial > projects > ddmd
annotate dmd/TypedefDeclaration.d @ 154:14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
and enabled warnings
+ reduced warnings by adding appriopriate overrides
+ IfStatement.interpret()
+ ScopeStatement.interpret()
+ TypeSArray.constConv()
+ TypedefDeclaration.syntaxCopy()
* fixed a bug in StringExp
author | trass3r |
---|---|
date | Wed, 15 Sep 2010 15:32:31 +0200 |
parents | af1bebfd96a4 |
children | e3afd1303184 |
rev | line source |
---|---|
0 | 1 module dmd.TypedefDeclaration; |
2 | |
114 | 3 import dmd.common; |
0 | 4 import dmd.Declaration; |
5 import dmd.Initializer; | |
6 import dmd.Type; | |
7 import dmd.Loc; | |
8 import dmd.Identifier; | |
9 import dmd.Dsymbol; | |
22
fd4acc376c45
Implemented object file output and linking on linux.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
10 import dmd.Module; |
0 | 11 import dmd.Scope; |
12 import dmd.OutBuffer; | |
13 import dmd.ExpInitializer; | |
14 import dmd.HdrGenState; | |
15 import dmd.TypeTypedef; | |
16 import dmd.Global; | |
17 import dmd.STC; | |
68
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
22
diff
changeset
|
18 import dmd.Id; |
0 | 19 |
20 import dmd.backend.SC; | |
21 import dmd.backend.FL; | |
68
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
22
diff
changeset
|
22 import dmd.backend.SFL; |
0 | 23 import dmd.backend.Symbol; |
24 import dmd.backend.Util; | |
68
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
22
diff
changeset
|
25 import dmd.backend.LIST; |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
22
diff
changeset
|
26 import dmd.backend.Classsym; |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
22
diff
changeset
|
27 import dmd.codegen.Util; |
0 | 28 |
29 class TypedefDeclaration : Declaration | |
30 { | |
31 Type basetype; | |
32 Initializer init; | |
33 int sem = 0;// 0: semantic() has not been run | |
34 // 1: semantic() is in progress | |
35 // 2: semantic() has been run | |
36 // 3: semantic2() has been run | |
37 | |
38 this(Loc loc, Identifier id, Type basetype, Initializer init) | |
39 { | |
40 super(id); | |
41 | |
42 this.type = new TypeTypedef(this); | |
43 this.basetype = basetype.toBasetype(); | |
44 this.init = init; | |
45 | |
46 version (_DH) { | |
47 this.htype = null; | |
48 this.hbasetype = null; | |
49 } | |
50 this.loc = loc; | |
51 this.sinit = null; | |
52 } | |
53 | |
54 version (DumbClone) { | |
55 } else { | |
56 Type clone() | |
57 { | |
58 assert(false); | |
59 } | |
60 } | |
154
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
61 override Dsymbol syntaxCopy(Dsymbol s) |
0 | 62 { |
154
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
63 Type basetype = this.basetype.syntaxCopy(); |
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
64 |
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
65 Initializer init = null; |
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
66 if (this.init) |
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
67 init = this.init.syntaxCopy(); |
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
68 |
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
69 assert(!s); |
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
70 TypedefDeclaration st; |
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
71 st = new TypedefDeclaration(loc, ident, basetype, init); |
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
72 version(_DH) |
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
73 { |
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
74 // Syntax copy for header file |
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
75 if (!htype) // Don't overwrite original |
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
76 { |
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
77 if (type) // Make copy for both old and new instances |
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
78 { |
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
79 htype = type.syntaxCopy(); |
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
80 st.htype = type.syntaxCopy(); |
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
81 } |
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
82 } |
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
83 else // Make copy of original for new instance |
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
84 st.htype = htype.syntaxCopy(); |
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
85 if (!hbasetype) |
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
86 { |
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
87 if (basetype) |
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
88 { |
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
89 hbasetype = basetype.syntaxCopy(); |
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
90 st.hbasetype = basetype.syntaxCopy(); |
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
91 } |
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
92 } |
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
93 else |
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
94 st.hbasetype = hbasetype.syntaxCopy(); |
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
95 } |
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
96 return st; |
0 | 97 } |
98 | |
72 | 99 override void semantic(Scope sc) |
0 | 100 { |
101 //printf("TypedefDeclaration::semantic(%s) sem = %d\n", toChars(), sem); | |
102 if (sem == 0) | |
103 { | |
104 sem = 1; | |
105 basetype = basetype.semantic(loc, sc); | |
106 sem = 2; | |
135 | 107 version(DMDV2) { |
108 type = type.addStorageClass(storage_class); | |
109 } | |
0 | 110 type = type.semantic(loc, sc); |
111 if (sc.parent.isFuncDeclaration() && init) | |
112 semantic2(sc); | |
113 storage_class |= sc.stc & STCdeprecated; | |
114 } | |
115 else if (sem == 1) | |
116 { | |
117 error("circular definition"); | |
118 } | |
119 } | |
120 | |
72 | 121 override void semantic2(Scope sc) |
0 | 122 { |
123 //printf("TypedefDeclaration::semantic2(%s) sem = %d\n", toChars(), sem); | |
124 if (sem == 2) | |
125 { | |
126 sem = 3; | |
127 if (init) | |
128 { | |
129 init = init.semantic(sc, basetype); | |
130 | |
131 ExpInitializer ie = init.isExpInitializer(); | |
132 if (ie) | |
133 { | |
134 if (ie.exp.type == basetype) | |
135 ie.exp.type = type; | |
136 } | |
137 } | |
138 } | |
139 } | |
140 | |
72 | 141 override string mangle() |
0 | 142 { |
143 //printf("TypedefDeclaration::mangle() '%s'\n", toChars()); | |
144 return Dsymbol.mangle(); | |
145 } | |
146 | |
72 | 147 override string kind() |
0 | 148 { |
149 assert(false); | |
150 } | |
151 | |
72 | 152 override Type getType() |
0 | 153 { |
154 return type; | |
155 } | |
156 | |
72 | 157 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 158 { |
159 assert(false); | |
160 } | |
161 | |
162 version (_DH) { | |
163 Type htype; | |
164 Type hbasetype; | |
165 } | |
166 | |
72 | 167 override void toDocBuffer(OutBuffer buf) |
0 | 168 { |
169 assert(false); | |
170 } | |
171 | |
72 | 172 override void toObjFile(int multiobj) // compile to .obj file |
0 | 173 { |
174 //printf("TypedefDeclaration::toObjFile('%s')\n", toChars()); | |
175 if (global.params.symdebug) | |
176 toDebug(); | |
177 | |
178 type.getTypeInfo(null); // generate TypeInfo | |
179 | |
180 TypeTypedef tc = cast(TypeTypedef)type; | |
181 if (type.isZeroInit(Loc(0)) || !tc.sym.init) { | |
182 ; | |
183 } else | |
184 { | |
185 SC scclass = SCglobal; | |
186 if (inTemplateInstance()) | |
187 scclass = SCcomdat; | |
188 | |
189 // Generate static initializer | |
190 toInitializer(); | |
191 sinit.Sclass = scclass; | |
192 sinit.Sfl = FLdata; | |
193 | |
194 version (ELFOBJ) { // Burton | |
195 sinit.Sseg = Segment.CDATA; | |
196 } | |
197 version (MACHOBJ) { | |
198 sinit.Sseg = Segment.DATA; | |
199 } | |
200 sinit.Sdt = tc.sym.init.toDt(); | |
201 outdata(sinit); | |
202 } | |
203 } | |
204 | |
205 void toDebug() | |
206 { | |
207 assert(false); | |
208 } | |
209 | |
72 | 210 override int cvMember(ubyte* p) |
0 | 211 { |
212 assert(false); | |
213 } | |
214 | |
72 | 215 override TypedefDeclaration isTypedefDeclaration() { return this; } |
0 | 216 |
217 Symbol* sinit; | |
218 Symbol* toInitializer() | |
219 { | |
68
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
22
diff
changeset
|
220 Symbol* s; |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
22
diff
changeset
|
221 Classsym* stag; |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
22
diff
changeset
|
222 |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
22
diff
changeset
|
223 if (!sinit) |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
22
diff
changeset
|
224 { |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
22
diff
changeset
|
225 stag = fake_classsym(Id.ClassInfo); |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
22
diff
changeset
|
226 s = toSymbolX("__init", SCextern, stag.Stype, "Z"); |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
22
diff
changeset
|
227 s.Sfl = FLextern; |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
22
diff
changeset
|
228 s.Sflags |= SFLnodebug; |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
22
diff
changeset
|
229 slist_add(s); |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
22
diff
changeset
|
230 sinit = s; |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
22
diff
changeset
|
231 } |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
22
diff
changeset
|
232 return sinit; |
0 | 233 } |
22
fd4acc376c45
Implemented object file output and linking on linux.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
234 } |