Mercurial > projects > ddmd
annotate dmd/TypedefDeclaration.d @ 192:eb38fdcb3e62 default tip
updated to compile with dmd2.062
author | korDen |
---|---|
date | Sat, 02 Mar 2013 01:25:52 -0800 |
parents | b0d41ff5e0df |
children |
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 |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
29 import dmd.DDMDExtensions; |
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
30 |
0 | 31 class TypedefDeclaration : Declaration |
32 { | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
33 mixin insertMemberExtension!(typeof(this)); |
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
34 |
0 | 35 Type basetype; |
36 Initializer init; | |
37 int sem = 0;// 0: semantic() has not been run | |
38 // 1: semantic() is in progress | |
39 // 2: semantic() has been run | |
40 // 3: semantic2() has been run | |
41 | |
42 this(Loc loc, Identifier id, Type basetype, Initializer init) | |
43 { | |
178 | 44 register(); |
0 | 45 super(id); |
46 | |
47 this.type = new TypeTypedef(this); | |
48 this.basetype = basetype.toBasetype(); | |
49 this.init = init; | |
50 | |
51 version (_DH) { | |
52 this.htype = null; | |
53 this.hbasetype = null; | |
54 } | |
55 this.loc = loc; | |
56 this.sinit = null; | |
57 } | |
58 | |
154
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
59 override Dsymbol syntaxCopy(Dsymbol s) |
0 | 60 { |
154
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
61 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
|
62 |
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
63 Initializer init = null; |
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
64 if (this.init) |
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
65 init = this.init.syntaxCopy(); |
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
66 |
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
67 assert(!s); |
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
68 TypedefDeclaration st; |
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
69 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
|
70 version(_DH) |
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
71 { |
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
72 // 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
|
73 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
|
74 { |
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
75 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
|
76 { |
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
77 htype = type.syntaxCopy(); |
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
78 st.htype = type.syntaxCopy(); |
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
79 } |
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
80 } |
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
81 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
|
82 st.htype = htype.syntaxCopy(); |
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
83 if (!hbasetype) |
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
84 { |
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
85 if (basetype) |
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 hbasetype = basetype.syntaxCopy(); |
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
88 st.hbasetype = basetype.syntaxCopy(); |
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
89 } |
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
90 } |
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
91 else |
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
92 st.hbasetype = hbasetype.syntaxCopy(); |
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
93 } |
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
94 return st; |
0 | 95 } |
96 | |
72 | 97 override void semantic(Scope sc) |
0 | 98 { |
99 //printf("TypedefDeclaration::semantic(%s) sem = %d\n", toChars(), sem); | |
100 if (sem == 0) | |
101 { | |
102 sem = 1; | |
103 basetype = basetype.semantic(loc, sc); | |
104 sem = 2; | |
135 | 105 version(DMDV2) { |
106 type = type.addStorageClass(storage_class); | |
107 } | |
0 | 108 type = type.semantic(loc, sc); |
109 if (sc.parent.isFuncDeclaration() && init) | |
110 semantic2(sc); | |
111 storage_class |= sc.stc & STCdeprecated; | |
112 } | |
113 else if (sem == 1) | |
114 { | |
115 error("circular definition"); | |
116 } | |
117 } | |
118 | |
72 | 119 override void semantic2(Scope sc) |
0 | 120 { |
121 //printf("TypedefDeclaration::semantic2(%s) sem = %d\n", toChars(), sem); | |
122 if (sem == 2) | |
123 { | |
124 sem = 3; | |
125 if (init) | |
126 { | |
127 init = init.semantic(sc, basetype); | |
128 | |
129 ExpInitializer ie = init.isExpInitializer(); | |
130 if (ie) | |
131 { | |
132 if (ie.exp.type == basetype) | |
133 ie.exp.type = type; | |
134 } | |
135 } | |
136 } | |
137 } | |
138 | |
72 | 139 override string mangle() |
0 | 140 { |
141 //printf("TypedefDeclaration::mangle() '%s'\n", toChars()); | |
142 return Dsymbol.mangle(); | |
143 } | |
144 | |
72 | 145 override string kind() |
0 | 146 { |
147 assert(false); | |
148 } | |
149 | |
72 | 150 override Type getType() |
0 | 151 { |
152 return type; | |
153 } | |
154 | |
72 | 155 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 156 { |
157 assert(false); | |
158 } | |
159 | |
160 version (_DH) { | |
161 Type htype; | |
162 Type hbasetype; | |
163 } | |
164 | |
72 | 165 override void toDocBuffer(OutBuffer buf) |
0 | 166 { |
167 assert(false); | |
168 } | |
169 | |
72 | 170 override void toObjFile(int multiobj) // compile to .obj file |
0 | 171 { |
172 //printf("TypedefDeclaration::toObjFile('%s')\n", toChars()); | |
173 if (global.params.symdebug) | |
174 toDebug(); | |
175 | |
176 type.getTypeInfo(null); // generate TypeInfo | |
177 | |
178 TypeTypedef tc = cast(TypeTypedef)type; | |
179 if (type.isZeroInit(Loc(0)) || !tc.sym.init) { | |
180 ; | |
181 } else | |
182 { | |
183 SC scclass = SCglobal; | |
184 if (inTemplateInstance()) | |
185 scclass = SCcomdat; | |
186 | |
187 // Generate static initializer | |
188 toInitializer(); | |
189 sinit.Sclass = scclass; | |
190 sinit.Sfl = FLdata; | |
191 | |
192 version (ELFOBJ) { // Burton | |
193 sinit.Sseg = Segment.CDATA; | |
194 } | |
195 version (MACHOBJ) { | |
196 sinit.Sseg = Segment.DATA; | |
197 } | |
198 sinit.Sdt = tc.sym.init.toDt(); | |
199 outdata(sinit); | |
200 } | |
201 } | |
202 | |
203 void toDebug() | |
204 { | |
205 assert(false); | |
206 } | |
207 | |
72 | 208 override int cvMember(ubyte* p) |
0 | 209 { |
210 assert(false); | |
211 } | |
212 | |
72 | 213 override TypedefDeclaration isTypedefDeclaration() { return this; } |
0 | 214 |
215 Symbol* sinit; | |
216 Symbol* toInitializer() | |
217 { | |
68
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
22
diff
changeset
|
218 Symbol* s; |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
22
diff
changeset
|
219 Classsym* stag; |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
22
diff
changeset
|
220 |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
22
diff
changeset
|
221 if (!sinit) |
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 stag = fake_classsym(Id.ClassInfo); |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
22
diff
changeset
|
224 s = toSymbolX("__init", SCextern, stag.Stype, "Z"); |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
22
diff
changeset
|
225 s.Sfl = FLextern; |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
22
diff
changeset
|
226 s.Sflags |= SFLnodebug; |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
22
diff
changeset
|
227 slist_add(s); |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
22
diff
changeset
|
228 sinit = s; |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
22
diff
changeset
|
229 } |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
22
diff
changeset
|
230 return sinit; |
0 | 231 } |
22
fd4acc376c45
Implemented object file output and linking on linux.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
232 } |