comparison dmd/struct.c @ 1103:b30fe7e1dbb9

- Updated to DMD frontend 1.041. - Removed dmd/inifile.c , it's not under a free license, replaced with libconfig based config file.
author Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
date Thu, 12 Mar 2009 20:37:27 +0100
parents de97188378bc
children 1860414bf3b7
comparison
equal deleted inserted replaced
1102:ae950bd712d3 1103:b30fe7e1dbb9
1 1
2 // Compiler implementation of the D programming language 2 // Compiler implementation of the D programming language
3 // Copyright (c) 1999-2006 by Digital Mars 3 // Copyright (c) 1999-2009 by Digital Mars
4 // All Rights Reserved 4 // All Rights Reserved
5 // written by Walter Bright 5 // written by Walter Bright
6 // http://www.digitalmars.com 6 // http://www.digitalmars.com
7 // License for redistribution is by either the Artistic License 7 // License for redistribution is by either the Artistic License
8 // in artistic.txt, or the GNU General Public License in gnu.txt. 8 // in artistic.txt, or the GNU General Public License in gnu.txt.
42 aggDelete = NULL; 42 aggDelete = NULL;
43 43
44 stag = NULL; 44 stag = NULL;
45 sinit = NULL; 45 sinit = NULL;
46 scope = NULL; 46 scope = NULL;
47 #if V2
48 dtor = NULL;
49
50 ctor = NULL;
51 defaultCtor = NULL;
52 #endif
47 } 53 }
48 54
49 enum PROT AggregateDeclaration::prot() 55 enum PROT AggregateDeclaration::prot()
50 { 56 {
51 return protection; 57 return protection;
126 /**************************** 132 /****************************
127 * Do byte or word alignment as necessary. 133 * Do byte or word alignment as necessary.
128 * Align sizes of 0, as we may not know array sizes yet. 134 * Align sizes of 0, as we may not know array sizes yet.
129 */ 135 */
130 136
131 void AggregateDeclaration::alignmember(unsigned salign, unsigned size, unsigned *poffset) 137 void AggregateDeclaration::alignmember(
132 { 138 unsigned salign, // struct alignment that is in effect
133 //printf("salign = %d, size = %d, offset = %d\n",salign,size,*poffset); 139 unsigned size, // alignment requirement of field
140 unsigned *poffset)
141 {
142 //printf("salign = %d, size = %d, offset = %d\n",salign,size,offset);
134 if (salign > 1) 143 if (salign > 1)
135 { int sa; 144 {
136 145 assert(size != 3);
137 switch (size) 146 int sa = size;
138 { case 1: 147 if (sa == 0 || salign < sa)
139 break; 148 sa = salign;
140 case 2: 149 *poffset = (*poffset + sa - 1) & ~(sa - 1);
141 case_2: 150 }
142 *poffset = (*poffset + 1) & ~1; // align to word 151 //printf("result = %d\n",offset);
143 break;
144 case 3:
145 case 4:
146 if (salign == 2)
147 goto case_2;
148 *poffset = (*poffset + 3) & ~3; // align to dword
149 break;
150 default:
151 *poffset = (*poffset + size - 1) & ~(size - 1);
152 break;
153 }
154 }
155 //printf("result = %d\n",*poffset);
156 } 152 }
157 153
158 154
159 void AggregateDeclaration::addField(Scope *sc, VarDeclaration *v) 155 void AggregateDeclaration::addField(Scope *sc, VarDeclaration *v)
160 { 156 {
166 162
167 // Check for forward referenced types which will fail the size() call 163 // Check for forward referenced types which will fail the size() call
168 Type *t = v->type->toBasetype(); 164 Type *t = v->type->toBasetype();
169 if (t->ty == Tstruct /*&& isStructDeclaration()*/) 165 if (t->ty == Tstruct /*&& isStructDeclaration()*/)
170 { TypeStruct *ts = (TypeStruct *)t; 166 { TypeStruct *ts = (TypeStruct *)t;
167 #if V2
168 if (ts->sym == this)
169 {
170 error("cannot have field %s with same struct type", v->toChars());
171 }
172 #endif
171 173
172 if (ts->sym->sizeok != 1) 174 if (ts->sym->sizeok != 1)
173 { 175 {
174 sizeok = 2; // cannot finish; flag as forward referenced 176 sizeok = 2; // cannot finish; flag as forward referenced
175 return; 177 return;
205 207
206 StructDeclaration::StructDeclaration(Loc loc, Identifier *id) 208 StructDeclaration::StructDeclaration(Loc loc, Identifier *id)
207 : AggregateDeclaration(loc, id) 209 : AggregateDeclaration(loc, id)
208 { 210 {
209 zeroInit = 0; // assume false until we do semantic processing 211 zeroInit = 0; // assume false until we do semantic processing
212 #if V2
213 hasIdentityAssign = 0;
214 cpctor = NULL;
215 postblit = NULL;
216 #endif
210 217
211 // For forward references 218 // For forward references
212 type = new TypeStruct(this); 219 type = new TypeStruct(this);
213 } 220 }
214 221
249 scx = scope; // save so we don't make redundant copies 256 scx = scope; // save so we don't make redundant copies
250 scope = NULL; 257 scope = NULL;
251 } 258 }
252 259
253 parent = sc->parent; 260 parent = sc->parent;
261 #if STRUCTTHISREF
262 handle = type;
263 #else
254 handle = type->pointerTo(); 264 handle = type->pointerTo();
265 #endif
255 structalign = sc->structalign; 266 structalign = sc->structalign;
256 protection = sc->protection; 267 protection = sc->protection;
257 if (sc->stc & STCdeprecated) 268 if (sc->stc & STCdeprecated)
258 isdeprecated = 1; 269 isdeprecated = 1;
259 assert(!isAnonymous()); 270 assert(!isAnonymous());
260 if (sc->stc & STCabstract) 271 if (sc->stc & STCabstract)
261 error("structs, unions cannot be abstract"); 272 error("structs, unions cannot be abstract");
273 #if V2
274 if (storage_class & STCinvariant)
275 type = type->invariantOf();
276 else if (storage_class & STCconst)
277 type = type->constOf();
278 #endif
262 279
263 if (sizeok == 0) // if not already done the addMember step 280 if (sizeok == 0) // if not already done the addMember step
264 { 281 {
265 for (i = 0; i < members->dim; i++) 282 for (i = 0; i < members->dim; i++)
266 { 283 {
349 } 366 }
350 } 367 }
351 368
352 id = Id::cmp; 369 id = Id::cmp;
353 } 370 }
354 371 #if V2
372 dtor = buildDtor(sc2);
373 postblit = buildPostBlit(sc2);
374 cpctor = buildCpCtor(sc2);
375 buildOpAssign(sc2);
376 #endif
355 377
356 sc2->pop(); 378 sc2->pop();
357 379
358 if (sizeok == 2) 380 if (sizeok == 2)
359 { // semantic() failed because of forward references. 381 { // semantic() failed because of forward references.
412 } 434 }
413 } 435 }
414 436
415 /* Look for special member functions. 437 /* Look for special member functions.
416 */ 438 */
439 #if V2
440 ctor = (CtorDeclaration *)search(0, Id::ctor, 0);
441 #endif
417 inv = (InvariantDeclaration *)search(0, Id::classInvariant, 0); 442 inv = (InvariantDeclaration *)search(0, Id::classInvariant, 0);
418 aggNew = (NewDeclaration *)search(0, Id::classNew, 0); 443 aggNew = (NewDeclaration *)search(0, Id::classNew, 0);
419 aggDelete = (DeleteDeclaration *)search(0, Id::classDelete, 0); 444 aggDelete = (DeleteDeclaration *)search(0, Id::classDelete, 0);
420 445
421 if (sc->func) 446 if (sc->func)