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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.TypedefDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 72
diff changeset
3 import dmd.common;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.Declaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.Initializer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.Identifier;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
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
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.ExpInitializer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.TypeTypedef;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.Global;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.STC;
68
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 22
diff changeset
18 import dmd.Id;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.backend.SC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
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
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import dmd.backend.Symbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
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
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 class TypedefDeclaration : Declaration
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 Type basetype;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 Initializer init;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 int sem = 0;// 0: semantic() has not been run
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 // 1: semantic() is in progress
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 // 2: semantic() has been run
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 // 3: semantic2() has been run
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 this(Loc loc, Identifier id, Type basetype, Initializer init)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 super(id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 this.type = new TypeTypedef(this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 this.basetype = basetype.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 this.init = init;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 version (_DH) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 this.htype = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 this.hbasetype = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 this.loc = loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 this.sinit = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 version (DumbClone) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 Type clone()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
61 override Dsymbol syntaxCopy(Dsymbol)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
66 override void semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 //printf("TypedefDeclaration::semantic(%s) sem = %d\n", toChars(), sem);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 if (sem == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 sem = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 basetype = basetype.semantic(loc, sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 sem = 2;
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
74 version(DMDV2) {
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
75 type = type.addStorageClass(storage_class);
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
76 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 type = type.semantic(loc, sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 if (sc.parent.isFuncDeclaration() && init)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 semantic2(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 storage_class |= sc.stc & STCdeprecated;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 else if (sem == 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 error("circular definition");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
88 override void semantic2(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 //printf("TypedefDeclaration::semantic2(%s) sem = %d\n", toChars(), sem);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 if (sem == 2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 sem = 3;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 if (init)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 init = init.semantic(sc, basetype);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 ExpInitializer ie = init.isExpInitializer();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 if (ie)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 if (ie.exp.type == basetype)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 ie.exp.type = type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
108 override string mangle()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 //printf("TypedefDeclaration::mangle() '%s'\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 return Dsymbol.mangle();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
114 override string kind()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
119 override Type getType()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 return type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
124 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 version (_DH) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 Type htype;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 Type hbasetype;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
134 override void toDocBuffer(OutBuffer buf)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
139 override void toObjFile(int multiobj) // compile to .obj file
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 //printf("TypedefDeclaration::toObjFile('%s')\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 if (global.params.symdebug)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 toDebug();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 type.getTypeInfo(null); // generate TypeInfo
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 TypeTypedef tc = cast(TypeTypedef)type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 if (type.isZeroInit(Loc(0)) || !tc.sym.init) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149 ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 } else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152 SC scclass = SCglobal;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153 if (inTemplateInstance())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154 scclass = SCcomdat;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
156 // Generate static initializer
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157 toInitializer();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158 sinit.Sclass = scclass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
159 sinit.Sfl = FLdata;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
161 version (ELFOBJ) { // Burton
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162 sinit.Sseg = Segment.CDATA;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
164 version (MACHOBJ) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165 sinit.Sseg = Segment.DATA;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
166 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
167 sinit.Sdt = tc.sym.init.toDt();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
168 outdata(sinit);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
169 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
171
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
172 void toDebug()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
174 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
176
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
177 override int cvMember(ubyte* p)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
178 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
181
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
182 override TypedefDeclaration isTypedefDeclaration() { return this; }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
183
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
184 Symbol* sinit;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
185 Symbol* toInitializer()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
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
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
200 }
22
fd4acc376c45 Implemented object file output and linking on linux.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
201 }