annotate dmd/StructDeclaration.d @ 129:010eb8f0e18d

further work on dmd test suite
author korDen
date Sun, 05 Sep 2010 15:32:22 +0400
parents 1765f3ef917d
children 60bb0fe4563e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.StructDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 103
diff changeset
3 import dmd.common;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.AggregateDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.FuncDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.DeclarationExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.VoidInitializer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.Initializer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.ExpInitializer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.Statement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.VarExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.CompoundStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.AssignExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.DotVarExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.AddrExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.CastExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.PostBlitDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.Lexer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.ExpStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.DotIdExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import dmd.TypeSArray;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import dmd.ThisExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 import dmd.ThisDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 import dmd.TypeFunction;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 import dmd.Argument;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 import dmd.Id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 import dmd.TY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 import dmd.LINK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 import dmd.DsymbolTable;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 import dmd.ArrayTypes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 import dmd.STC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 import dmd.Identifier;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 import dmd.TemplateInstance;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 import dmd.Dsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 import dmd.PROT;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 import dmd.TypeStruct;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 import dmd.expression.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 import dmd.Expression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 import dmd.IdentifierExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 import dmd.PtrExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 import dmd.CallExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 import dmd.ReturnStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 import dmd.ScopeDsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 import dmd.Module;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 import dmd.VarDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 import dmd.InvariantDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 import dmd.NewDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 import dmd.DeleteDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 import dmd.Global;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 import dmd.backend.dt_t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 import dmd.backend.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 import dmd.backend.SC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 import dmd.backend.DT;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 import dmd.backend.FL;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 import dmd.backend.glue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63
129
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
64 import std.stdio;
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
65
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 class StructDeclaration : AggregateDeclaration
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 bool zeroInit; // true if initialize with 0 fill
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 int hasIdentityAssign; // !=0 if has identity opAssign
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 FuncDeclaration cpctor; // generated copy-constructor, if any
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 FuncDeclarations postblits; // Array of postblit functions
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 FuncDeclaration postblit; // aggregate postblit
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 this(Loc loc, Identifier id)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 super(loc, id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 // For forward references
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 type = new TypeStruct(this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 postblits = new FuncDeclarations(); ///
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 49
diff changeset
88 override Dsymbol syntaxCopy(Dsymbol s)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 {
49
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 13
diff changeset
90 StructDeclaration sd;
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 13
diff changeset
91
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 13
diff changeset
92 if (s)
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 13
diff changeset
93 sd = cast(StructDeclaration)s;
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 13
diff changeset
94 else
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 13
diff changeset
95 sd = new StructDeclaration(loc, ident);
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 13
diff changeset
96 ScopeDsymbol.syntaxCopy(sd);
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 13
diff changeset
97 return sd;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 49
diff changeset
100 override void semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 Scope sc2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 //printf("+StructDeclaration.semantic(this=%p, '%s')\n", this, toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 //static int count; if (++count == 20) *(char*)0=0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 assert(type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 if (!members) // if forward reference
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 if (symtab)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 { if (!scope_)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 return; // semantic() already completed
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 symtab = new DsymbolTable();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 Scope scx = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 if (scope_)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 { sc = scope_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 scx = scope_; // save so we don't make redundant copies
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 scope_ = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 parent = sc.parent;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 type = type.semantic(loc, sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 version (STRUCTTHISREF) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 handle = type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 handle = type.pointerTo();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 structalign = sc.structalign;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 protection = sc.protection;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 storage_class |= sc.stc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 if (sc.stc & STC.STCdeprecated)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 isdeprecated = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 assert(!isAnonymous());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 if (sc.stc & STC.STCabstract)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 error("structs, unions cannot be abstract");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 if (storage_class & STC.STCimmutable)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 type = type.invariantOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144 else if (storage_class & STC.STCconst)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 type = type.constOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 else if (storage_class & STC.STCshared)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 type = type.sharedOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 if (sizeok == 0) // if not already done the addMember step
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152 int hasfunctions = 0;
77
ad4792a1cfd6 more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 74
diff changeset
153 foreach(Dsymbol s; members)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155 //printf("adding member '%s' to '%s'\n", s.toChars(), this.toChars());
13
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 0
diff changeset
156 s.addMember(sc, this, true);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157 if (s.isFuncDeclaration())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158 hasfunctions = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
159 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
161 // If nested struct, add in hidden 'this' pointer to outer scope
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162 if (hasfunctions && !(storage_class & STC.STCstatic))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163 { Dsymbol s = toParent2();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
164 if (s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
166 AggregateDeclaration ad = s.isAggregateDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
167 FuncDeclaration fd = s.isFuncDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
168
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
169 TemplateInstance ti;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170 if (ad && (ti = ad.parent.isTemplateInstance()) !is null && ti.isnested || fd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
171 { isnested = true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
172 Type t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173 if (ad)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
174 t = ad.handle;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175 else if (fd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
176 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
177 AggregateDeclaration add = fd.isMember2();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
178 if (add)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179 t = add.handle;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
181 t = Type.tvoidptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
182 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
183 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
184 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
185 if (t.ty == TY.Tstruct)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
186 t = Type.tvoidptr; // t should not be a ref type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
187 assert(!vthis);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
188 vthis = new ThisDeclaration(loc, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
189 //vthis.storage_class |= STC.STCref;
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
190 members.push(vthis);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
191 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
192 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
193 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
194 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
195
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
196 sizeok = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
197 sc2 = sc.push(this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
198 sc2.stc &= storage_class & STC.STC_TYPECTOR;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
199 sc2.parent = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
200 if (isUnionDeclaration())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
201 sc2.inunion = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
202 sc2.protection = PROT.PROTpublic;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
203 sc2.explicitProtection = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
204
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
205 int members_dim = members.dim;
77
ad4792a1cfd6 more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 74
diff changeset
206 foreach(Dsymbol s; members)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
207 {
129
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
208 s.semantic(sc2);
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
209 if (isUnionDeclaration())
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
210 sc2.offset = 0;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
211 static if (false) {
129
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
212 if (sizeok == 2)
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
213 { //printf("forward reference\n");
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
214 break;
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
215 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
216 }
129
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
217 if (auto d = s.isDeclaration())
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
218 {
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
219 if (auto t = d.type) {
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
220 if (t.toBasetype().ty == TY.Tstruct) {
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
221 auto ad = t.toDsymbol(sc).isThis();
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
222 /*
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
223 StructDeclaration sd = cast(StructDeclaration)foo;
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
224 if (foo && !sd) {
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
225 writeln(t.classin);
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
226 writeln(foo.classinfo.name);
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
227 assert(false);
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
228 }
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
229 */
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
230 if (ad && ad.isnested)
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
231 error("inner struct %s cannot be a field", ad.toChars());
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
232 }
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
233 }
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
234 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
235 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
236
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
237 /* The TypeInfo_Struct is expecting an opEquals and opCmp with
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
238 * a parameter that is a pointer to the struct. But if there
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
239 * isn't one, but is an opEquals or opCmp with a value, write
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
240 * another that is a shell around the value:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
241 * int opCmp(struct *p) { return opCmp(*p); }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
242 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
243
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
244 TypeFunction tfeqptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
245 {
129
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
246 Arguments arguments = new Arguments;
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
247 Argument arg = new Argument(STC.STCin, handle, Id.p, null);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
248
129
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
249 arguments.push(arg);
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
250 tfeqptr = new TypeFunction(arguments, Type.tint32, 0, LINK.LINKd);
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
251 tfeqptr = cast(TypeFunction)tfeqptr.semantic(Loc(0), sc);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
252 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
253
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
254 TypeFunction tfeq;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
255 {
129
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
256 Arguments arguments = new Arguments;
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
257 Argument arg = new Argument(STC.STCin, type, null, null);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
258
129
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
259 arguments.push(arg);
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
260 tfeq = new TypeFunction(arguments, Type.tint32, 0, LINK.LINKd);
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
261 tfeq = cast(TypeFunction)tfeq.semantic(Loc(0), sc);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
262 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
263
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
264 Identifier id = Id.eq;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
265 for (int j = 0; j < 2; j++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
266 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
267 Dsymbol s = search_function(this, id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
268 FuncDeclaration fdx = s ? s.isFuncDeclaration() : null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
269 if (fdx)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
270 { FuncDeclaration fd = fdx.overloadExactMatch(tfeqptr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
271 if (!fd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
272 { fd = fdx.overloadExactMatch(tfeq);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
273 if (fd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
274 { // Create the thunk, fdptr
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
275 FuncDeclaration fdptr = new FuncDeclaration(loc, loc, fdx.ident, STC.STCundefined, tfeqptr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
276 Expression e = new IdentifierExp(loc, Id.p);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
277 e = new PtrExp(loc, e);
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
278 auto args = new Expressions();
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
279 args.push(e);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
280 e = new IdentifierExp(loc, id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
281 e = new CallExp(loc, e, args);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
282 fdptr.fbody = new ReturnStatement(loc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
283 ScopeDsymbol ss = fdx.parent.isScopeDsymbol();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
284 assert(ss);
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
285 ss.members.push(fdptr);
13
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 0
diff changeset
286 fdptr.addMember(sc, ss, true);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
287 fdptr.semantic(sc2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
288 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
289 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
290 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
291
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
292 id = Id.cmp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
293 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
294 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
295 dtor = buildDtor(sc2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
296 postblit = buildPostBlit(sc2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
297 cpctor = buildCpCtor(sc2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
298 buildOpAssign(sc2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
299 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
300
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
301 sc2.pop();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
302
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
303 if (sizeok == 2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
304 { // semantic() failed because of forward references.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
305 // Unwind what we did, and defer it for later
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
306 fields.setDim(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
307 structsize = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
308 alignsize = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
309 structalign = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
310
87
b17640f0e4e8 Fixed a bug with a Scope.this(Scope enclosing) being called instead of Scope.clone() method (as a copy ctor replacement)
korDen
parents: 79
diff changeset
311 scope_ = scx ? scx : sc.clone();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
312 scope_.setNoFree();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
313 scope_.module_.addDeferredSemantic(this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
314 //printf("\tdeferring %s\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
315 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
316 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
317
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
318 // 0 sized struct's are set to 1 byte
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
319 if (structsize == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
320 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
321 structsize = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
322 alignsize = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
323 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
324
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
325 // Round struct size up to next alignsize boundary.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
326 // This will ensure that arrays of structs will get their internals
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
327 // aligned properly.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
328 structsize = (structsize + alignsize - 1) & ~(alignsize - 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
329
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
330 sizeok = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
331 Module.dprogress++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
332
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
333 //printf("-StructDeclaration.semantic(this=%p, '%s')\n", this, toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
334
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
335 // Determine if struct is all zeros or not
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
336 zeroInit = true;
85
8e69d041a99d Previous commit didn't compile. Fixed.
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 84
diff changeset
337 foreach (VarDeclaration vd; fields)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
338 {
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
339 if (vd && !vd.isDataseg())
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
340 {
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
341 if (vd.init)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
342 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
343 // Should examine init to see if it is really all 0's
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
344 zeroInit = false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
345 break;
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
346 }
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
347 else
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
348 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
349 if (!vd.type.isZeroInit(loc))
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
350 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
351 zeroInit = false;
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
352 break;
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
353 }
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
354 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
355 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
356 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
357
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
358 /* Look for special member functions.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
359 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
360 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
361 ctor = search(Loc(0), Id.ctor, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
362 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
363 inv = cast(InvariantDeclaration)search(Loc(0), Id.classInvariant, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
364 aggNew = cast(NewDeclaration)search(Loc(0), Id.classNew, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
365 aggDelete = cast(DeleteDeclaration)search(Loc(0), Id.classDelete, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
366
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
367 if (sc.func)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
368 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
369 semantic2(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
370 semantic3(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
371 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
372 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
373
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 49
diff changeset
374 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
375 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
376 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
377 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
378
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 49
diff changeset
379 override string mangle()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
380 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
381 //printf("StructDeclaration.mangle() '%s'\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
382 return Dsymbol.mangle();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
383 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
384
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 49
diff changeset
385 override string kind()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
386 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
387 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
388 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
389
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
390 /*******************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
391 * We need an opAssign for the struct if
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
392 * it has a destructor or a postblit.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
393 * We need to generate one if a user-specified one does not exist.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
394 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
395 bool needOpAssign()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
396 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
397 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
398 printf("StructDeclaration.needOpAssign() %s\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
399 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
400 if (hasIdentityAssign)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
401 goto Ldontneed;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
402
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
403 if (dtor || postblit)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
404 goto Lneed;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
405
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
406 /* If any of the fields need an opAssign, then we
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
407 * need it too.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
408 */
85
8e69d041a99d Previous commit didn't compile. Fixed.
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 84
diff changeset
409 foreach (VarDeclaration v; fields)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
410 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
411 assert(v && v.storage_class & STC.STCfield);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
412 if (v.storage_class & STC.STCref)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
413 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
414 Type tv = v.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
415 while (tv.ty == TY.Tsarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
416 { TypeSArray ta = cast(TypeSArray)tv;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
417 tv = tv.nextOf().toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
418 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
419 if (tv.ty == TY.Tstruct)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
420 { TypeStruct ts = cast(TypeStruct)tv;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
421 StructDeclaration sd = ts.sym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
422 if (sd.needOpAssign())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
423 goto Lneed;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
424 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
425 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
426 Ldontneed:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
427 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
428 printf("\tdontneed\n");
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
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
432 Lneed:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
433 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
434 printf("\tneed\n");
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 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
438
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
439 /******************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
440 * Build opAssign for struct.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
441 * S* opAssign(S s) { ... }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
442 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
443 FuncDeclaration buildOpAssign(Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
444 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
445 if (!needOpAssign())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
446 return null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
447
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
448 //printf("StructDeclaration.buildOpAssign() %s\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
449
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
450 FuncDeclaration fop = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
451
129
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
452 Argument param = new Argument(STC.STCnodtor, type, Id.p, null);
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
453 Arguments fparams = new Arguments;
126
1765f3ef917d ClassDeclarations, Arguments -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
454 fparams.push(param);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
455 Type ftype = new TypeFunction(fparams, handle, false, LINK.LINKd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
456 version (STRUCTTHISREF) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
457 (cast(TypeFunction)ftype).isref = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
458 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
459
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
460 fop = new FuncDeclaration(Loc(0), Loc(0), Id.assign, STC.STCundefined, ftype);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
461
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
462 Expression e = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
463 if (postblit)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
464 { /* Swap:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
465 * tmp = *this; *this = s; tmp.dtor();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
466 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
467 //printf("\tswap copy\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
468 Identifier idtmp = Lexer.uniqueId("__tmp");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
469 VarDeclaration tmp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
470 AssignExp ec = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
471 if (dtor)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
472 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
473 tmp = new VarDeclaration(Loc(0), type, idtmp, new VoidInitializer(Loc(0)));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
474 tmp.noauto = true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
475 e = new DeclarationExp(Loc(0), tmp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
476
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
477 Expression e2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
478 version (STRUCTTHISREF) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
479 e2 = new ThisExp(Loc(0));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
480 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
481 e2 = new PtrExp(Loc(0), new ThisExp(Loc(0)));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
482 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
483 ec = new AssignExp(Loc(0), new VarExp(Loc(0), tmp), e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
484 ec.op = TOK.TOKblit;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
485 e = Expression.combine(e, ec);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
486 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
487 Expression e2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
488 version (STRUCTTHISREF) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
489 e2 = new ThisExp(Loc(0));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
490 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
491 e2 = new PtrExp(Loc(0), new ThisExp(Loc(0)));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
492 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
493
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
494 ec = new AssignExp(Loc(0), e2, new IdentifierExp(Loc(0), Id.p));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
495 ec.op = TOK.TOKblit;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
496 e = Expression.combine(e, ec);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
497 if (dtor)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
498 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
499 /* Instead of running the destructor on s, run it
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
500 * on tmp. This avoids needing to copy tmp back in to s.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
501 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
502 Expression ecc = new DotVarExp(Loc(0), new VarExp(Loc(0), tmp), dtor, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
503 ecc = new CallExp(Loc(0), ecc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
504 e = Expression.combine(e, ecc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
505 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
506 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
507 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
508 { /* Do memberwise copy
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
509 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
510 //printf("\tmemberwise copy\n");
85
8e69d041a99d Previous commit didn't compile. Fixed.
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 84
diff changeset
511 foreach (VarDeclaration v; fields)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
512 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
513 assert(v && v.storage_class & STC.STCfield);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
514 // this.v = s.v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
515 AssignExp ec = new AssignExp(Loc(0), new DotVarExp(Loc(0), new ThisExp(Loc(0)), v, 0), new DotVarExp(Loc(0), new IdentifierExp(Loc(0), Id.p), v, 0));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
516 ec.op = TOK.TOKblit;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
517 e = Expression.combine(e, ec);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
518 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
519 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
520 Statement s1 = new ExpStatement(Loc(0), e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
521
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
522 /* Add:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
523 * return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
524 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
525 e = new ThisExp(Loc(0));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
526 Statement s2 = new ReturnStatement(Loc(0), e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
527
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
528 fop.fbody = new CompoundStatement(Loc(0), s1, s2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
529
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
530 members.push(fop);
13
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 0
diff changeset
531 fop.addMember(sc, this, true);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
532
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
533 sc = sc.push();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
534 sc.stc = STC.STCundefined;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
535 sc.linkage = LINK.LINKd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
536
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
537 fop.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
538
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
539 sc.pop();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
540
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
541 //printf("-StructDeclaration.buildOpAssign() %s\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
542
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
543 return fop;
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 * Create inclusive postblit for struct by aggregating
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
548 * all the postblits in postblits[] with the postblits for
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
549 * all the members.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
550 * Note the close similarity with AggregateDeclaration.buildDtor(),
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
551 * and the ordering changes (runs forward instead of backwards).
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
552 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
553
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
554 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
555 FuncDeclaration buildPostBlit(Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
556 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
557 //printf("StructDeclaration.buildPostBlit() %s\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
558 Expression e = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
559
85
8e69d041a99d Previous commit didn't compile. Fixed.
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 84
diff changeset
560 foreach (VarDeclaration v; fields)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
561 {
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
562 assert(v && v.storage_class & STC.STCfield);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
563 if (v.storage_class & STC.STCref)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
564 continue;
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
565 Type tv = v.type.toBasetype();
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
566 size_t dim = 1;
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
567 while (tv.ty == TY.Tsarray)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
568 { TypeSArray ta = cast(TypeSArray)tv;
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
569 dim *= (cast(TypeSArray)tv).dim.toInteger();
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
570 tv = tv.nextOf().toBasetype();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
571 }
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
572 if (tv.ty == TY.Tstruct)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
573 { TypeStruct ts = cast(TypeStruct)tv;
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
574 StructDeclaration sd = ts.sym;
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
575 if (sd.postblit)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
576 { Expression ex;
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
577
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
578 // this.v
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
579 ex = new ThisExp(Loc(0));
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
580 ex = new DotVarExp(Loc(0), ex, v, 0);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
581
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
582 if (dim == 1)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
583 { // this.v.postblit()
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
584 ex = new DotVarExp(Loc(0), ex, sd.postblit, 0);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
585 ex = new CallExp(Loc(0), ex);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
586 }
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
587 else
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
588 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
589 // Typeinfo.postblit(cast(void*)&this.v);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
590 Expression ea = new AddrExp(Loc(0), ex);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
591 ea = new CastExp(Loc(0), ea, Type.tvoid.pointerTo());
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
592
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
593 Expression et = v.type.getTypeInfo(sc);
103
e6090d1aea7c fixed dmd.Id + some small fixups
Trass3r
parents: 95
diff changeset
594 et = new DotIdExp(Loc(0), et, Id._postblit);
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
595
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
596 ex = new CallExp(Loc(0), et, ea);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
597 }
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
598 e = Expression.combine(e, ex); // combine in forward order
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
599 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
600 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
601 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
602
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
603 /* Build our own "postblit" which executes e
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
604 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
605 if (e)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
606 { //printf("Building __fieldPostBlit()\n");
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
607 auto dd = new PostBlitDeclaration(Loc(0), Loc(0), Lexer.idPool("__fieldPostBlit"));
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
608 dd.fbody = new ExpStatement(Loc(0), e);
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
609 postblits.shift(dd);
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
610 members.push(dd);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
611 dd.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
612 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
613
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
614 switch (postblits.dim)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
615 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
616 case 0:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
617 return null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
618
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
619 case 1:
77
ad4792a1cfd6 more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 74
diff changeset
620 return cast(FuncDeclaration)postblits[0];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
621
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
622 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
623 e = null;
77
ad4792a1cfd6 more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 74
diff changeset
624 foreach(FuncDeclaration fd; postblits)
ad4792a1cfd6 more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 74
diff changeset
625 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
626 Expression ex = new ThisExp(Loc(0));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
627 ex = new DotVarExp(Loc(0), ex, fd, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
628 ex = new CallExp(Loc(0), ex);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
629 e = Expression.combine(e, ex);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
630 }
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
631 auto dd = new PostBlitDeclaration(Loc(0), Loc(0), Lexer.idPool("__aggrPostBlit"));
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
632 dd.fbody = new ExpStatement(Loc(0), e);
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
633 members.push(dd);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
634 dd.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
635 return dd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
636 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
637 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
638 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
639
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
640 /*******************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
641 * Build copy constructor for struct.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
642 * Copy constructors are compiler generated only, and are only
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
643 * callable from the compiler. They are not user accessible.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
644 * A copy constructor is:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
645 * void cpctpr(ref S s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
646 * {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
647 * *this = s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
648 * this.postBlit();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
649 * }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
650 * This is done so:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
651 * - postBlit() never sees uninitialized data
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
652 * - memcpy can be much more efficient than memberwise copy
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
653 * - no fields are overlooked
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
654 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
655 FuncDeclaration buildCpCtor(Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
656 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
657 //printf("StructDeclaration.buildCpCtor() %s\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
658 FuncDeclaration fcp = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
659
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
660 /* Copy constructor is only necessary if there is a postblit function,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
661 * otherwise the code generator will just do a bit copy.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
662 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
663 if (postblit)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
664 {
129
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
665 //printf("generating cpctor\n");
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
666
129
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
667 Argument param = new Argument(STC.STCref, type, Id.p, null);
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
668 Arguments fparams = new Arguments;
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
669 fparams.push(param);
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
670 Type ftype = new TypeFunction(fparams, Type.tvoid, false, LINK.LINKd);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
671
129
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
672 fcp = new FuncDeclaration(Loc(0), Loc(0), Id.cpctor, STC.STCundefined, ftype);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
673
129
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
674 // Build *this = p;
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
675 Expression e = new ThisExp(Loc(0));
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
676 version (STRUCTTHISREF) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
677 } else {
129
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
678 e = new PtrExp(Loc(0), e);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
679 }
129
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
680 AssignExp ea = new AssignExp(Loc(0), e, new IdentifierExp(Loc(0), Id.p));
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
681 ea.op = TOK.TOKblit;
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
682 Statement s = new ExpStatement(Loc(0), ea);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
683
129
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
684 // Build postBlit();
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
685 e = new VarExp(Loc(0), postblit, 0);
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
686 e = new CallExp(Loc(0), e);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
687
129
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
688 s = new CompoundStatement(Loc(0), s, new ExpStatement(Loc(0), e));
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
689 fcp.fbody = s;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
690
129
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
691 members.push(fcp);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
692
129
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
693 sc = sc.push();
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
694 sc.stc = STC.STCundefined;
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
695 sc.linkage = LINK.LINKd;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
696
129
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
697 fcp.semantic(sc);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
698
129
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
699 sc.pop();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
700 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
701
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
702 return fcp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
703 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
704
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 49
diff changeset
705 override void toDocBuffer(OutBuffer buf)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
706 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
707 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
708 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
709
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 49
diff changeset
710 override PROT getAccess(Dsymbol smember) // determine access to smember
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
711 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
712 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
713 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
714
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 49
diff changeset
715 override void toObjFile(int multiobj) // compile to .obj file
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
716 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
717 //printf("StructDeclaration.toObjFile('%s')\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
718
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
719 if (multiobj)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
720 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
721 obj_append(this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
722 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
723 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
724
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
725 // Anonymous structs/unions only exist as part of others,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
726 // do not output forward referenced structs's
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
727 if (!isAnonymous() && members)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
728 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
729 if (global.params.symdebug) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
730 toDebug();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
731 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
732
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
733 type.getTypeInfo(null); // generate TypeInfo
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
734
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
735 if (true)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
736 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
737 // Generate static initializer
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
738 toInitializer();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
739
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
740 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
741 sinit.Sclass = SC.SCcomdat;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
742 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
743 if (inTemplateInstance())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
744 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
745 sinit.Sclass = SC.SCcomdat;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
746 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
747 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
748 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
749 sinit.Sclass = SC.SCglobal;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
750 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
751 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
752 sinit.Sfl = FL.FLdata;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
753
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
754 toDt(&sinit.Sdt);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
755
95
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 89
diff changeset
756 version (OMFOBJ)
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 89
diff changeset
757 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
758 /* For OMF, common blocks aren't pulled in from the library.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
759 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
760 /* ELF comdef's generate multiple
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
761 * definition errors for them from the gnu linker.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
762 * Need to figure out how to generate proper comdef's for ELF.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
763 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
764 // See if we can convert a comdat to a comdef,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
765 // which saves on exe file space.
95
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 89
diff changeset
766 if (0 && // causes multiple def problems with COMMON in one file and COMDAT in library
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 89
diff changeset
767 sinit.Sclass == SCcomdat &&
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
768 sinit.Sdt &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
769 sinit.Sdt.dt == DT.DT_azeros &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
770 sinit.Sdt.DTnext == null &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
771 !global.params.multiobj)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
772 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
773 sinit.Sclass = SC.SCglobal;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
774 sinit.Sdt.dt = DT.DT_common;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
775 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
776 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
777
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
778 version (ELFOBJ) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
779 sinit.Sseg = Segment.CDATA;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
780 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
781 version (MACHOBJ) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
782 sinit.Sseg = Segment.DATA;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
783 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
784 outdata(sinit);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
785 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
786
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
787 // Put out the members
77
ad4792a1cfd6 more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 74
diff changeset
788 foreach(Dsymbol member; members)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
789 member.toObjFile(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
790 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
791 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
792
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
793 void toDt(dt_t** pdt)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
794 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
795 uint offset;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
796 dt_t* dt;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
797
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
798 //printf("StructDeclaration.toDt(), this='%s'\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
799 offset = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
800
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
801 // Note equivalence of this loop to class's
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
802 for (uint i = 0; i < fields.dim; i++)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
803 {
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
804 VarDeclaration v = cast(VarDeclaration)fields[i];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
805 //printf("\tfield '%s' voffset %d, offset = %d\n", v.toChars(), v.offset, offset);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
806 dt = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
807 int sz;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
808
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
809 if (v.storage_class & STC.STCref)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
810 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
811 sz = PTRSIZE;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
812 if (v.offset >= offset)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
813 dtnzeros(&dt, sz);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
814 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
815 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
816 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
817 sz = cast(uint)v.type.size();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
818 Initializer init = v.init;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
819 if (init)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
820 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
821 //printf("\t\thas initializer %s\n", init.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
822 ExpInitializer ei = init.isExpInitializer();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
823 Type tb = v.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
824 if (ei && tb.ty == TY.Tsarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
825 (cast(TypeSArray)tb).toDtElem(&dt, ei.exp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
826 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
827 dt = init.toDt();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
828 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
829 else if (v.offset >= offset)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
830 v.type.toDt(&dt);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
831 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
832 if (dt)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
833 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
834 if (v.offset < offset)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
835 error("overlapping initialization for struct %s.%s", toChars(), v.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
836 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
837 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
838 if (offset < v.offset)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
839 dtnzeros(pdt, v.offset - offset);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
840 dtcat(pdt, dt);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
841 offset = v.offset + sz;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
842 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
843 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
844 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
845
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
846 if (offset < structsize)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
847 dtnzeros(pdt, structsize - offset);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
848
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
849 dt_optimize(*pdt);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
850 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
851
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
852 void toDebug() // to symbolic debug info
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
853 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
854 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
855 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
856
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 49
diff changeset
857 override StructDeclaration isStructDeclaration() { return this; }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 49
diff changeset
858 }