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