annotate dmd/TypeStruct.d @ 85:8e69d041a99d

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