annotate dmd/TypeStruct.d @ 174:af724d3510d7

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