annotate dmd/TypeStruct.d @ 130:60bb0fe4563e

dmdfe 2.037 first main iteration
author Eldar Insafutdinov <e.insafutdinov@gmail.com>
date Thu, 09 Sep 2010 22:51:44 +0100
parents e28b18c23469
children af1bebfd96a4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.TypeStruct;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 85
diff changeset
3 import dmd.common;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.Type;
55
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 0
diff changeset
5 import dmd.TypeInstance;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.StructDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.Declaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.STC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.MOD;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.DotVarExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.TemplateMixin;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.DotTemplateExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.DsymbolExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.TypeExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.EnumMember;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.Id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.DotIdExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.ScopeExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.TupleExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.TemplateDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import dmd.OverloadSet;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import dmd.Import;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 import dmd.DotExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 import dmd.ErrorExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 import dmd.Dsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 import dmd.Expression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 import dmd.Identifier;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 import dmd.MATCH;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 import dmd.ArrayTypes;
55
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 0
diff changeset
34 import dmd.DYNCAST;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 import dmd.TemplateInstance;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 import dmd.FuncDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 import dmd.VarExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 import dmd.CommaExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 import dmd.ThisExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 import dmd.SymbolDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 import dmd.TypeInfoDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 import dmd.TypeInfoStructDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 import dmd.TY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 import dmd.Global;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 import dmd.VarDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 import dmd.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 import dmd.expression.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 import dmd.backend.TYPE;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 import dmd.backend.dt_t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 import dmd.backend.Symbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 import dmd.backend.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 import dmd.backend.STR;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 import dmd.backend.TYM;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 import dmd.backend.Classsym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 import dmd.backend.SC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 import dmd.backend.LIST;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 import std.string : toStringz;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 class TypeStruct : Type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 StructDeclaration sym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 this(StructDeclaration sym)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 super(TY.Tstruct);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 this.sym = sym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 version (DumbClone) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 final TypeStruct cloneTo(TypeStruct t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 super.cloneTo(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 assert(t.sym is sym);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 return t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 TypeStruct clone()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 assert(this.classinfo == TypeStruct.classinfo);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 return cloneTo(new TypeStruct(sym));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 55
diff changeset
86 override ulong size(Loc loc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 return sym.size(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 55
diff changeset
91 override uint alignsize()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 uint sz;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 sym.size(Loc(0)); // give error for forward references
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 sz = sym.alignsize;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 if (sz > sym.structalign)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 sz = sym.structalign;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 return sz;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 55
diff changeset
102 override string toChars()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 {
55
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 0
diff changeset
104 //printf("sym.parent: %s, deco = %s\n", sym.parent.toChars(), deco);
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 0
diff changeset
105 if (mod)
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 0
diff changeset
106 return Type.toChars();
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 0
diff changeset
107 TemplateInstance ti = sym.parent.isTemplateInstance();
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 0
diff changeset
108 if (ti && ti.toAlias() == sym)
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 0
diff changeset
109 {
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 0
diff changeset
110 return ti.toChars();
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 0
diff changeset
111 }
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 0
diff changeset
112 return sym.toChars();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 55
diff changeset
115 override Type syntaxCopy()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 55
diff changeset
120 override Type semantic(Loc loc, Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 //printf("TypeStruct.semantic('%s')\n", sym.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 /* Cannot do semantic for sym because scope chain may not
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 * be right.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 //sym.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 return merge();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 55
diff changeset
132 override Dsymbol toDsymbol(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 return sym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 55
diff changeset
137 override void toDecoBuffer(OutBuffer buf, int flag)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 string name = sym.mangle();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 //printf("TypeStruct.toDecoBuffer('%s') = '%s'\n", toChars(), name);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 Type.toDecoBuffer(buf, flag);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 buf.printf("%s", name);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 55
diff changeset
145 override void toCBuffer2(OutBuffer buf, HdrGenState* hgs, MOD mod)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 if (mod != this.mod)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149 toCBuffer3(buf, hgs, mod);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152 TemplateInstance ti = sym.parent.isTemplateInstance();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153 if (ti && ti.toAlias() == sym)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154 buf.writestring(ti.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
156 buf.writestring(sym.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 55
diff changeset
159 override Expression dotExp(Scope sc, Expression e, Identifier ident)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
161 uint offset;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163 VarDeclaration v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
164 Dsymbol s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165 DotVarExp de;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
166 Declaration d;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
167
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
168 version (LOGDOTEXP) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
169 printf("TypeStruct.dotExp(e = '%s', ident = '%s')\n", e.toChars(), ident.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
171 if (!sym.members)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
172 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173 error(e.loc, "struct %s is forward referenced", sym.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
174 return new ErrorExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
176
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
177 /* If e.tupleof
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
178 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179 if (ident is Id.tupleof_)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
181 /* Create a TupleExp out of the fields of the struct e:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
182 * (e.field0, e.field1, e.field2, ...)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
183 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
184 e = e.semantic(sc); // do this before turning on noaccesscheck
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
185 auto exps = new Expressions;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
186 exps.reserve(sym.fields.dim);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
187 for (size_t i = 0; i < sym.fields.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
188 {
79
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
189 VarDeclaration v2 = cast(VarDeclaration)sym.fields[i];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
190 Expression fe = new DotVarExp(e.loc, e, v2);
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
191 exps.push(fe);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
192 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
193 e = new TupleExp(e.loc, exps);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
194 sc = sc.push();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
195 sc.noaccesscheck = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
196 e = e.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
197 sc.pop();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
198 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
199 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
200
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
201 if (e.op == TOK.TOKdotexp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
202 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
203 DotExp de2 = cast(DotExp)e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
204
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
205 if (de2.e1.op == TOK.TOKimport)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
206 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
207 assert(0); // cannot find a case where this happens; leave
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
208 // assert in until we do
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
209 ScopeExp se = cast(ScopeExp)de2.e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
210
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
211 s = se.sds.search(e.loc, ident, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
212 e = de2.e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
213 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
214 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
215 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
216
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
217 s = sym.search(e.loc, ident, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
218 L1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
219 if (!s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
220 {
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
221 return noMember(sc, e, ident);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
222 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
223
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
224 if (!s.isFuncDeclaration()) // because of overloading
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
225 s.checkDeprecated(e.loc, sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
226
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
227 s = s.toAlias();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
228
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
229 v = s.isVarDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
230 if (v && !v.isDataseg())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
231 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
232 Expression ei = v.getConstInitializer();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
233 if (ei)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
234 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
235 e = ei.copy(); // need to copy it if it's a StringExp
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
236 e = e.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
237 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
238 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
239 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
240
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
241 if (s.getType())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
242 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
243 //return new DotTypeExp(e.loc, e, s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
244 return new TypeExp(e.loc, s.getType());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
245 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
246
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
247 EnumMember em = s.isEnumMember();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
248 if (em)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
249 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
250 assert(em.value);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
251 return em.value.copy();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
252 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
253
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
254 TemplateMixin tm = s.isTemplateMixin();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
255 if (tm)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
256 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
257 Expression de2 = new DotExp(e.loc, e, new ScopeExp(e.loc, tm));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
258 de2.type = e.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
259 return de2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
260 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
261
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
262 TemplateDeclaration td = s.isTemplateDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
263 if (td)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
264 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
265 e = new DotTemplateExp(e.loc, e, td);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
266 e.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
267 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
268 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
269
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
270 TemplateInstance ti = s.isTemplateInstance();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
271 if (ti)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
272 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
273 if (!ti.semanticRun)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
274 ti.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
275 s = ti.inst.toAlias();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
276 if (!s.isTemplateInstance())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
277 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
278 Expression de2 = new DotExp(e.loc, e, new ScopeExp(e.loc, ti));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
279 de2.type = e.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
280 return de2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
281 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
282
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
283 Import timp = s.isImport();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
284 if (timp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
285 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
286 e = new DsymbolExp(e.loc, s, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
287 e = e.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
288 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
289 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
290
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
291 OverloadSet o = s.isOverloadSet();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
292 if (o)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
293 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
294 /* We really should allow this, triggered by:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
295 * template c()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
296 * {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
297 * void a();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
298 * void b () { this.a(); }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
299 * }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
300 * struct S
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
301 * {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
302 * mixin c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
303 * mixin c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
304 * }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
305 * alias S e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
306 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
307 error(e.loc, "overload set for %s.%s not allowed in struct declaration", e.toChars(), ident.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
308 return new ErrorExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
309 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
310
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
311 d = s.isDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
312
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
313 debug {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
314 if (!d)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
315 writef("d = %s '%s'\n", s.kind(), s.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
316 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
317 assert(d);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
318
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
319 if (e.op == TOK.TOKtype)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
320 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
321 FuncDeclaration fd = sc.func;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
322
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
323 if (d.isTupleDeclaration())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
324 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
325 e = new TupleExp(e.loc, d.isTupleDeclaration());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
326 e = e.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
327 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
328 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
329
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
330 if (d.needThis() && fd && fd.vthis)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
331 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
332 e = new DotVarExp(e.loc, new ThisExp(e.loc), d);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
333 e = e.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
334 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
335 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
336
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
337 return new VarExp(e.loc, d, 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
338 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
339
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
340 if (d.isDataseg())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
341 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
342 // (e, d)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
343 accessCheck(e.loc, sc, e, d);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
344 VarExp ve = new VarExp(e.loc, d);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
345 e = new CommaExp(e.loc, e, ve);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
346 e.type = d.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
347 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
348 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
349
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
350 if (v)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
351 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
352 if (v.toParent() != sym)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
353 sym.error(e.loc, "'%s' is not a member", v.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
354
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
355 // *(&e + offset)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
356 accessCheck(e.loc, sc, e, d);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
357 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
358 Expression b = new AddrExp(e.loc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
359 b.type = e.type.pointerTo();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
360 b = new AddExp(e.loc, b, new IntegerExp(e.loc, v.offset, Type.tint32));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
361 b.type = v.type.pointerTo();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
362 b = new PtrExp(e.loc, b);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
363 b.type = v.type.addMod(e.type.mod);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
364 return b;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
365 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
366 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
367
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
368 de = new DotVarExp(e.loc, e, d);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
369 return de.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
370 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
371
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 55
diff changeset
372 override uint memalign(uint salign)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
373 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
374 sym.size(Loc(0)); // give error for forward references
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
375 return sym.structalign;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
376 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
377
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 55
diff changeset
378 override Expression defaultInit(Loc loc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
379 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
380 Symbol* s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
381 Declaration d;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
382
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
383 version (LOGDEFAULTINIT) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
384 printf("TypeStruct::defaultInit() '%s'\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
385 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
386 s = sym.toInitializer();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
387 d = new SymbolDeclaration(sym.loc, s, sym);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
388 assert(d);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
389 d.type = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
390 return new VarExp(sym.loc, d);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
391 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
392
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 55
diff changeset
393 override bool isZeroInit(Loc loc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
394 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
395 return sym.zeroInit;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
396 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
397
73
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
398 override bool isAssignable()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
399 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
400 /* If any of the fields are const or invariant,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
401 * then one cannot assign this struct.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
402 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
403 for (size_t i = 0; i < sym.fields.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
404 {
79
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
405 VarDeclaration v = cast(VarDeclaration)sym.fields[i];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
406 if (v.isConst() || v.isInvariant())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
407 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
408 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
409 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
410 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
411
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 55
diff changeset
412 override bool checkBoolean()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
413 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
414 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
415 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
416
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 55
diff changeset
417 override dt_t** toDt(dt_t** pdt)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
418 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
419 sym.toDt(pdt);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
420 return pdt;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
421 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
422
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 55
diff changeset
423 override MATCH deduceType(Scope sc, Type tparam, TemplateParameters parameters, Objects dedtypes)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
424 {
55
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 0
diff changeset
425 //printf("TypeStruct.deduceType()\n");
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 0
diff changeset
426 //printf("\tthis.parent = %s, ", sym.parent.toChars()); print();
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 0
diff changeset
427 //printf("\ttparam = %d, ", tparam.ty); tparam.print();
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 0
diff changeset
428
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 0
diff changeset
429 /* If this struct is a template struct, and we're matching
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 0
diff changeset
430 * it against a template instance, convert the struct type
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 0
diff changeset
431 * to a template instance, too, and try again.
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 0
diff changeset
432 */
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 0
diff changeset
433 TemplateInstance ti = sym.parent.isTemplateInstance();
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 0
diff changeset
434
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 0
diff changeset
435 if (tparam && tparam.ty == Tinstance)
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 0
diff changeset
436 {
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 0
diff changeset
437 if (ti && ti.toAlias() == sym)
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 0
diff changeset
438 {
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 0
diff changeset
439 TypeInstance t = new TypeInstance(Loc(0), ti);
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 0
diff changeset
440 return t.deduceType(sc, tparam, parameters, dedtypes);
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 0
diff changeset
441 }
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 0
diff changeset
442
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 0
diff changeset
443 /* Match things like:
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 0
diff changeset
444 * S!(T).foo
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 0
diff changeset
445 */
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 0
diff changeset
446 TypeInstance tpi = cast(TypeInstance)tparam;
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 0
diff changeset
447 if (tpi.idents.dim)
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 0
diff changeset
448 { Identifier id = cast(Identifier)tpi.idents.data[tpi.idents.dim - 1];
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 0
diff changeset
449 if (id.dyncast() == DYNCAST.DYNCAST_IDENTIFIER && sym.ident.equals(id))
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 0
diff changeset
450 {
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 0
diff changeset
451 Type tparent = sym.parent.getType();
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 0
diff changeset
452 if (tparent)
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 0
diff changeset
453 {
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 0
diff changeset
454 /* Slice off the .foo in S!(T).foo
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 0
diff changeset
455 */
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 0
diff changeset
456 tpi.idents.dim--;
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 0
diff changeset
457 MATCH m = tparent.deduceType(sc, tpi, parameters, dedtypes);
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 0
diff changeset
458 tpi.idents.dim++;
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 0
diff changeset
459 return m;
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 0
diff changeset
460 }
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 0
diff changeset
461 }
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 0
diff changeset
462 }
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 0
diff changeset
463 }
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 0
diff changeset
464
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 0
diff changeset
465 // Extra check
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 0
diff changeset
466 if (tparam && tparam.ty == Tstruct)
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 0
diff changeset
467 {
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 0
diff changeset
468 TypeStruct tp = cast(TypeStruct)tparam;
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 0
diff changeset
469
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 0
diff changeset
470 if (sym != tp.sym)
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 0
diff changeset
471 return MATCHnomatch;
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 0
diff changeset
472 }
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 0
diff changeset
473 return Type.deduceType(sc, tparam, parameters, dedtypes);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
474 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
475
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 55
diff changeset
476 override TypeInfoDeclaration getTypeInfoDeclaration()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
477 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
478 return new TypeInfoStructDeclaration(this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
479 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
480
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 55
diff changeset
481 override bool hasPointers()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
482 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
483 StructDeclaration s = sym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
484
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
485 sym.size(Loc(0)); // give error for forward references
85
8e69d041a99d Previous commit didn't compile. Fixed.
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 84
diff changeset
486 foreach (VarDeclaration sm; s.fields)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
487 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
488 Declaration d = sm.isDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
489 if (d.storage_class & STC.STCref || d.hasPointers())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
490 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
491 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
492
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
493 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
494 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
495
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 55
diff changeset
496 override MATCH implicitConvTo(Type to)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
497 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
498 MATCH m;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
499
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
500 //printf("TypeStruct.implicitConvTo(%s => %s)\n", toChars(), to.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
501 if (ty == to.ty && sym == (cast(TypeStruct)to).sym)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
502 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
503 m = MATCHexact; // exact match
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
504 if (mod != to.mod)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
505 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
506 if (to.mod == MODconst)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
507 m = MATCHconst;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
508 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
509 { /* Check all the fields. If they can all be converted,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
510 * allow the conversion.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
511 */
85
8e69d041a99d Previous commit didn't compile. Fixed.
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 84
diff changeset
512 foreach (VarDeclaration v; sym.fields)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
513 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
514 assert(v && v.storage_class & STCfield);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
515
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
516 // 'from' type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
517 Type tvf = v.type.addMod(mod);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
518
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
519 // 'to' type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
520 Type tv = v.type.castMod(to.mod);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
521
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
522 //printf("\t%s => %s, match = %d\n", v.type.toChars(), tv.toChars(), tvf.implicitConvTo(tv));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
523 if (tvf.implicitConvTo(tv) < MATCHconst)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
524 return MATCHnomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
525 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
526 m = MATCHconst;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
527 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
528 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
529 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
530 else if (sym.aliasthis)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
531 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
532 m = MATCHnomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
533 Declaration d = sym.aliasthis.isDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
534 if (d)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
535 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
536 assert(d.type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
537 Type t = d.type.addMod(mod);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
538 m = t.implicitConvTo(to);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
539 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
540 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
541 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
542 m = MATCHnomatch; // no match
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
543 return m;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
544 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
545
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 55
diff changeset
546 override MATCH constConv(Type to)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
547 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
548 if (equals(to))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
549 return MATCHexact;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
550 if (ty == to.ty && sym == (cast(TypeStruct)to).sym && to.mod == MODconst)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
551 return MATCHconst;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
552 return MATCHnomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
553 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
554
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 55
diff changeset
555 override Type toHeadMutable()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
556 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
557 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
558 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
559
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
560 version (CPP_MANGLE) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
561 void toCppMangle(OutBuffer buf, CppMangleState* cms)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
562 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
563 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
564 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
565 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
566
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 55
diff changeset
567 override type* toCtype()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
568 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
569 type* t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
570 Symbol* s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
571
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
572 if (ctype)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
573 return ctype;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
574
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
575 //printf("TypeStruct.toCtype() '%s'\n", sym.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
576 s = symbol_calloc(toStringz(sym.toPrettyChars()));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
577 s.Sclass = SC.SCstruct;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
578 s.Sstruct = struct_calloc();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
579 s.Sstruct.Sflags |= 0; /// huh?
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
580 s.Sstruct.Salignsize = sym.alignsize;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
581 s.Sstruct.Sstructalign = cast(ubyte)sym.structalign;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
582 s.Sstruct.Sstructsize = sym.structsize;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
583
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
584 if (sym.isUnionDeclaration())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
585 s.Sstruct.Sflags |= STR.STRunion;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
586
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
587 t = type_alloc(TYM.TYstruct);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
588 t.Ttag = cast(Classsym*)s; // structure tag name
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
589 t.Tcount++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
590 s.Stype = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
591 slist_add(s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
592 ctype = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
593
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
594 /* Add in fields of the struct
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
595 * (after setting ctype to avoid infinite recursion)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
596 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
597 if (global.params.symdebug) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
598 for (int i = 0; i < sym.fields.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
599 {
79
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
600 VarDeclaration v = cast(VarDeclaration)sym.fields[i];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
601
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
602 Symbol* s2 = symbol_name(toStringz(v.ident.toChars()), SC.SCmember, v.type.toCtype());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
603 s2.Smemoff = v.offset;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
604 list_append(&s.Sstruct.Sfldlst, s2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
605 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
606 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
607
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
608 //printf("t = %p, Tflags = x%x\n", t, t.Tflags);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
609 return t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
610 }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 55
diff changeset
611 }