Mercurial > projects > ddmd
annotate dmd/TypedefDeclaration.d @ 68:ee3a9f34dc48
final bits of codegen implementation to compile Phobos
author | korDen |
---|---|
date | Tue, 24 Aug 2010 16:44:34 +0400 |
parents | fd4acc376c45 |
children | 2e2a5c3f943a |
rev | line source |
---|---|
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; | |
22
fd4acc376c45
Implemented object file output and linking on linux.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
9 import dmd.Module; |
0 | 10 import dmd.Scope; |
11 import dmd.OutBuffer; | |
12 import dmd.ExpInitializer; | |
13 import dmd.HdrGenState; | |
14 import dmd.TypeTypedef; | |
15 import dmd.Global; | |
16 import dmd.STC; | |
68
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
22
diff
changeset
|
17 import dmd.Id; |
0 | 18 |
19 import dmd.backend.SC; | |
20 import dmd.backend.FL; | |
68
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
22
diff
changeset
|
21 import dmd.backend.SFL; |
0 | 22 import dmd.backend.Symbol; |
23 import dmd.backend.Util; | |
68
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
22
diff
changeset
|
24 import dmd.backend.LIST; |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
22
diff
changeset
|
25 import dmd.backend.Classsym; |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
22
diff
changeset
|
26 import dmd.codegen.Util; |
0 | 27 |
28 class TypedefDeclaration : Declaration | |
29 { | |
30 Type basetype; | |
31 Initializer init; | |
32 int sem = 0;// 0: semantic() has not been run | |
33 // 1: semantic() is in progress | |
34 // 2: semantic() has been run | |
35 // 3: semantic2() has been run | |
36 | |
37 this(Loc loc, Identifier id, Type basetype, Initializer init) | |
38 { | |
39 super(id); | |
40 | |
41 this.type = new TypeTypedef(this); | |
42 this.basetype = basetype.toBasetype(); | |
43 this.init = init; | |
44 | |
45 version (_DH) { | |
46 this.htype = null; | |
47 this.hbasetype = null; | |
48 } | |
49 this.loc = loc; | |
50 this.sinit = null; | |
51 } | |
52 | |
53 version (DumbClone) { | |
54 } else { | |
55 Type clone() | |
56 { | |
57 assert(false); | |
58 } | |
59 } | |
60 Dsymbol syntaxCopy(Dsymbol) | |
61 { | |
62 assert(false); | |
63 } | |
64 | |
65 void semantic(Scope sc) | |
66 { | |
67 //printf("TypedefDeclaration::semantic(%s) sem = %d\n", toChars(), sem); | |
68 if (sem == 0) | |
69 { | |
70 sem = 1; | |
71 basetype = basetype.semantic(loc, sc); | |
72 sem = 2; | |
73 type = type.semantic(loc, sc); | |
74 if (sc.parent.isFuncDeclaration() && init) | |
75 semantic2(sc); | |
76 storage_class |= sc.stc & STCdeprecated; | |
77 } | |
78 else if (sem == 1) | |
79 { | |
80 error("circular definition"); | |
81 } | |
82 } | |
83 | |
84 void semantic2(Scope sc) | |
85 { | |
86 //printf("TypedefDeclaration::semantic2(%s) sem = %d\n", toChars(), sem); | |
87 if (sem == 2) | |
88 { | |
89 sem = 3; | |
90 if (init) | |
91 { | |
92 init = init.semantic(sc, basetype); | |
93 | |
94 ExpInitializer ie = init.isExpInitializer(); | |
95 if (ie) | |
96 { | |
97 if (ie.exp.type == basetype) | |
98 ie.exp.type = type; | |
99 } | |
100 } | |
101 } | |
102 } | |
103 | |
104 string mangle() | |
105 { | |
106 //printf("TypedefDeclaration::mangle() '%s'\n", toChars()); | |
107 return Dsymbol.mangle(); | |
108 } | |
109 | |
110 string kind() | |
111 { | |
112 assert(false); | |
113 } | |
114 | |
115 Type getType() | |
116 { | |
117 return type; | |
118 } | |
119 | |
120 void toCBuffer(OutBuffer buf, HdrGenState* hgs) | |
121 { | |
122 assert(false); | |
123 } | |
124 | |
125 version (_DH) { | |
126 Type htype; | |
127 Type hbasetype; | |
128 } | |
129 | |
130 void toDocBuffer(OutBuffer buf) | |
131 { | |
132 assert(false); | |
133 } | |
134 | |
135 void toObjFile(int multiobj) // compile to .obj file | |
136 { | |
137 //printf("TypedefDeclaration::toObjFile('%s')\n", toChars()); | |
138 if (global.params.symdebug) | |
139 toDebug(); | |
140 | |
141 type.getTypeInfo(null); // generate TypeInfo | |
142 | |
143 TypeTypedef tc = cast(TypeTypedef)type; | |
144 if (type.isZeroInit(Loc(0)) || !tc.sym.init) { | |
145 ; | |
146 } else | |
147 { | |
148 SC scclass = SCglobal; | |
149 if (inTemplateInstance()) | |
150 scclass = SCcomdat; | |
151 | |
152 // Generate static initializer | |
153 toInitializer(); | |
154 sinit.Sclass = scclass; | |
155 sinit.Sfl = FLdata; | |
156 | |
157 version (ELFOBJ) { // Burton | |
158 sinit.Sseg = Segment.CDATA; | |
159 } | |
160 version (MACHOBJ) { | |
161 sinit.Sseg = Segment.DATA; | |
162 } | |
163 sinit.Sdt = tc.sym.init.toDt(); | |
164 outdata(sinit); | |
165 } | |
166 } | |
167 | |
168 void toDebug() | |
169 { | |
170 assert(false); | |
171 } | |
172 | |
173 int cvMember(ubyte* p) | |
174 { | |
175 assert(false); | |
176 } | |
177 | |
178 TypedefDeclaration isTypedefDeclaration() { return this; } | |
179 | |
180 Symbol* sinit; | |
181 Symbol* toInitializer() | |
182 { | |
68
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
22
diff
changeset
|
183 Symbol* s; |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
22
diff
changeset
|
184 Classsym* stag; |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
22
diff
changeset
|
185 |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
22
diff
changeset
|
186 if (!sinit) |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
22
diff
changeset
|
187 { |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
22
diff
changeset
|
188 stag = fake_classsym(Id.ClassInfo); |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
22
diff
changeset
|
189 s = toSymbolX("__init", SCextern, stag.Stype, "Z"); |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
22
diff
changeset
|
190 s.Sfl = FLextern; |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
22
diff
changeset
|
191 s.Sflags |= SFLnodebug; |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
22
diff
changeset
|
192 slist_add(s); |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
22
diff
changeset
|
193 sinit = s; |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
22
diff
changeset
|
194 } |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
22
diff
changeset
|
195 return sinit; |
0 | 196 } |
22
fd4acc376c45
Implemented object file output and linking on linux.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
197 } |