annotate dmd/TypeStruct.d @ 178:e3afd1303184

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