annotate dmd/TypeStruct.d @ 187:b0d41ff5e0df

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