Mercurial > projects > ddmd
annotate dmd/TypedefDeclaration.d @ 135:af1bebfd96a4 dmd2037
dmd 2.038
author | Eldar Insafutdinov <e.insafutdinov@gmail.com> |
---|---|
date | Mon, 13 Sep 2010 22:19:42 +0100 |
parents | e28b18c23469 |
children | 14feb7ae01a6 |
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 } | |
72 | 61 override Dsymbol syntaxCopy(Dsymbol) |
0 | 62 { |
63 assert(false); | |
64 } | |
65 | |
72 | 66 override void semantic(Scope sc) |
0 | 67 { |
68 //printf("TypedefDeclaration::semantic(%s) sem = %d\n", toChars(), sem); | |
69 if (sem == 0) | |
70 { | |
71 sem = 1; | |
72 basetype = basetype.semantic(loc, sc); | |
73 sem = 2; | |
135 | 74 version(DMDV2) { |
75 type = type.addStorageClass(storage_class); | |
76 } | |
0 | 77 type = type.semantic(loc, sc); |
78 if (sc.parent.isFuncDeclaration() && init) | |
79 semantic2(sc); | |
80 storage_class |= sc.stc & STCdeprecated; | |
81 } | |
82 else if (sem == 1) | |
83 { | |
84 error("circular definition"); | |
85 } | |
86 } | |
87 | |
72 | 88 override void semantic2(Scope sc) |
0 | 89 { |
90 //printf("TypedefDeclaration::semantic2(%s) sem = %d\n", toChars(), sem); | |
91 if (sem == 2) | |
92 { | |
93 sem = 3; | |
94 if (init) | |
95 { | |
96 init = init.semantic(sc, basetype); | |
97 | |
98 ExpInitializer ie = init.isExpInitializer(); | |
99 if (ie) | |
100 { | |
101 if (ie.exp.type == basetype) | |
102 ie.exp.type = type; | |
103 } | |
104 } | |
105 } | |
106 } | |
107 | |
72 | 108 override string mangle() |
0 | 109 { |
110 //printf("TypedefDeclaration::mangle() '%s'\n", toChars()); | |
111 return Dsymbol.mangle(); | |
112 } | |
113 | |
72 | 114 override string kind() |
0 | 115 { |
116 assert(false); | |
117 } | |
118 | |
72 | 119 override Type getType() |
0 | 120 { |
121 return type; | |
122 } | |
123 | |
72 | 124 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 125 { |
126 assert(false); | |
127 } | |
128 | |
129 version (_DH) { | |
130 Type htype; | |
131 Type hbasetype; | |
132 } | |
133 | |
72 | 134 override void toDocBuffer(OutBuffer buf) |
0 | 135 { |
136 assert(false); | |
137 } | |
138 | |
72 | 139 override void toObjFile(int multiobj) // compile to .obj file |
0 | 140 { |
141 //printf("TypedefDeclaration::toObjFile('%s')\n", toChars()); | |
142 if (global.params.symdebug) | |
143 toDebug(); | |
144 | |
145 type.getTypeInfo(null); // generate TypeInfo | |
146 | |
147 TypeTypedef tc = cast(TypeTypedef)type; | |
148 if (type.isZeroInit(Loc(0)) || !tc.sym.init) { | |
149 ; | |
150 } else | |
151 { | |
152 SC scclass = SCglobal; | |
153 if (inTemplateInstance()) | |
154 scclass = SCcomdat; | |
155 | |
156 // Generate static initializer | |
157 toInitializer(); | |
158 sinit.Sclass = scclass; | |
159 sinit.Sfl = FLdata; | |
160 | |
161 version (ELFOBJ) { // Burton | |
162 sinit.Sseg = Segment.CDATA; | |
163 } | |
164 version (MACHOBJ) { | |
165 sinit.Sseg = Segment.DATA; | |
166 } | |
167 sinit.Sdt = tc.sym.init.toDt(); | |
168 outdata(sinit); | |
169 } | |
170 } | |
171 | |
172 void toDebug() | |
173 { | |
174 assert(false); | |
175 } | |
176 | |
72 | 177 override int cvMember(ubyte* p) |
0 | 178 { |
179 assert(false); | |
180 } | |
181 | |
72 | 182 override TypedefDeclaration isTypedefDeclaration() { return this; } |
0 | 183 |
184 Symbol* sinit; | |
185 Symbol* toInitializer() | |
186 { | |
68
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
22
diff
changeset
|
187 Symbol* s; |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
22
diff
changeset
|
188 Classsym* stag; |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
22
diff
changeset
|
189 |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
22
diff
changeset
|
190 if (!sinit) |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
22
diff
changeset
|
191 { |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
22
diff
changeset
|
192 stag = fake_classsym(Id.ClassInfo); |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
22
diff
changeset
|
193 s = toSymbolX("__init", SCextern, stag.Stype, "Z"); |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
22
diff
changeset
|
194 s.Sfl = FLextern; |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
22
diff
changeset
|
195 s.Sflags |= SFLnodebug; |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
22
diff
changeset
|
196 slist_add(s); |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
22
diff
changeset
|
197 sinit = s; |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
22
diff
changeset
|
198 } |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
22
diff
changeset
|
199 return sinit; |
0 | 200 } |
22
fd4acc376c45
Implemented object file output and linking on linux.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
201 } |