Changeset 319
- Timestamp:
- 12/30/09 00:11:16 (15 years ago)
- Files:
-
- branches/dmd-1.x/src/class.c (modified) (1 diff)
- branches/dmd-1.x/src/struct.c (modified) (1 diff)
- trunk/src/class.c (modified) (1 diff)
- trunk/src/mars.c (modified) (1 diff)
- trunk/src/struct.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/dmd-1.x/src/class.c
r262 r319 572 572 #endif 573 573 } 574 574 sc->protection = PROTpublic; 575 575 sc->explicitProtection = 0; 576 576 sc->structalign = 8; 577 577 structalign = sc->structalign; 578 578 if (baseClass) 579 579 { sc->offset = baseClass->structsize; 580 580 alignsize = baseClass->alignsize; 581 581 // if (isnested) 582 582 // sc->offset += PTRSIZE; // room for uplevel context pointer 583 583 } 584 584 else 585 585 { sc->offset = PTRSIZE * 2; // allow room for __vptr and __monitor 586 586 alignsize = PTRSIZE; 587 587 } 588 588 structsize = sc->offset; 589 589 Scope scsave = *sc; 590 590 int members_dim = members->dim; 591 591 sizeok = 0; 592 593 /* Set scope so if there are forward references, we still might be able to 594 * resolve individual members like enums. 595 */ 592 596 for (i = 0; i < members_dim; i++) 593 { 594 Dsymbol *s = (Dsymbol *)members->data[i]; 597 { Dsymbol *s = (Dsymbol *)members->data[i]; 598 /* There are problems doing this in the general case because 599 * Scope keeps track of things like 'offset' 600 */ 601 if (s->isEnumDeclaration() || (s->isAggregateDeclaration() && s->ident)) 602 { 603 //printf("setScope %s %s\n", s->kind(), s->toChars()); 604 s->setScope(sc); 605 } 606 } 607 608 for (i = 0; i < members_dim; i++) 609 { Dsymbol *s = (Dsymbol *)members->data[i]; 595 610 s->semantic(sc); 596 611 } 597 612 598 613 if (sizeok == 2) 599 614 { // semantic() failed because of forward references. 600 615 // Unwind what we did, and defer it for later 601 616 fields.setDim(0); 602 617 structsize = 0; 603 618 alignsize = 0; 604 619 structalign = 0; 605 620 606 621 sc = sc->pop(); 607 622 608 623 scope = scx ? scx : new Scope(*sc); 609 624 scope->setNoFree(); 610 625 scope->module->addDeferredSemantic(this); 611 626 612 627 //printf("\tsemantic('%s') failed due to forward references\n", toChars()); 613 628 return; 614 629 } branches/dmd-1.x/src/struct.c
r318 r319 280 280 if (sizeok == 0) // if not already done the addMember step 281 281 { 282 282 for (i = 0; i < members->dim; i++) 283 283 { 284 284 Dsymbol *s = (Dsymbol *)members->data[i]; 285 285 //printf("adding member '%s' to '%s'\n", s->toChars(), this->toChars()); 286 286 s->addMember(sc, this, 1); 287 287 } 288 288 } 289 289 290 290 sizeok = 0; 291 291 sc2 = sc->push(this); 292 292 sc2->stc = 0; 293 293 sc2->parent = this; 294 294 if (isUnionDeclaration()) 295 295 sc2->inunion = 1; 296 296 sc2->protection = PROTpublic; 297 297 sc2->explicitProtection = 0; 298 298 299 299 int members_dim = members->dim; 300 301 /* Set scope so if there are forward references, we still might be able to 302 * resolve individual members like enums. 303 */ 304 for (int i = 0; i < members_dim; i++) 305 { Dsymbol *s = (Dsymbol *)members->data[i]; 306 /* There are problems doing this in the general case because 307 * Scope keeps track of things like 'offset' 308 */ 309 if (s->isEnumDeclaration() || (s->isAggregateDeclaration() && s->ident)) 310 { 311 //printf("setScope %s %s\n", s->kind(), s->toChars()); 312 s->setScope(sc2); 313 } 314 } 315 300 316 for (i = 0; i < members_dim; i++) 301 317 { 302 318 Dsymbol *s = (Dsymbol *)members->data[i]; 303 319 s->semantic(sc2); 304 320 if (isUnionDeclaration()) 305 321 sc2->offset = 0; 306 322 #if 0 307 323 if (sizeok == 2) 308 324 { //printf("forward reference\n"); 309 325 break; 310 326 } 311 327 #endif 312 328 } 313 329 314 330 /* The TypeInfo_Struct is expecting an opEquals and opCmp with 315 331 * a parameter that is a pointer to the struct. But if there 316 332 * isn't one, but is an opEquals or opCmp with a value, write 317 333 * another that is a shell around the value: 318 334 * int opCmp(struct *p) { return opCmp(*p); } 319 335 */ trunk/src/class.c
r305 r319 589 589 #endif 590 590 } 591 591 sc->protection = PROTpublic; 592 592 sc->explicitProtection = 0; 593 593 sc->structalign = 8; 594 594 structalign = sc->structalign; 595 595 if (baseClass) 596 596 { sc->offset = baseClass->structsize; 597 597 alignsize = baseClass->alignsize; 598 598 // if (isnested) 599 599 // sc->offset += PTRSIZE; // room for uplevel context pointer 600 600 } 601 601 else 602 602 { sc->offset = PTRSIZE * 2; // allow room for __vptr and __monitor 603 603 alignsize = PTRSIZE; 604 604 } 605 605 structsize = sc->offset; 606 606 Scope scsave = *sc; 607 607 int members_dim = members->dim; 608 608 sizeok = 0; 609 610 /* Set scope so if there are forward references, we still might be able to 611 * resolve individual members like enums. 612 */ 609 613 for (i = 0; i < members_dim; i++) 610 { 611 Dsymbol *s = (Dsymbol *)members->data[i]; 614 { Dsymbol *s = (Dsymbol *)members->data[i]; 615 /* There are problems doing this in the general case because 616 * Scope keeps track of things like 'offset' 617 */ 618 if (s->isEnumDeclaration() || (s->isAggregateDeclaration() && s->ident)) 619 { 620 //printf("setScope %s %s\n", s->kind(), s->toChars()); 621 s->setScope(sc); 622 } 623 } 624 625 for (i = 0; i < members_dim; i++) 626 { Dsymbol *s = (Dsymbol *)members->data[i]; 612 627 s->semantic(sc); 613 628 } 614 629 615 630 if (sizeok == 2) 616 631 { // semantic() failed because of forward references. 617 632 // Unwind what we did, and defer it for later 618 633 fields.setDim(0); 619 634 structsize = 0; 620 635 alignsize = 0; 621 636 structalign = 0; 622 637 623 638 sc = sc->pop(); 624 639 625 640 scope = scx ? scx : new Scope(*sc); 626 641 scope->setNoFree(); 627 642 scope->module->addDeferredSemantic(this); 628 643 629 644 //printf("\tsemantic('%s') failed due to forward references\n", toChars()); 630 645 return; 631 646 } trunk/src/mars.c
r286 r319 151 151 { 152 152 if (!global.gag) 153 153 { 154 154 char *p = loc.toChars(); 155 155 156 156 if (*p) 157 157 fprintf(stdmsg, "%s: ", p); 158 158 mem.free(p); 159 159 160 160 fprintf(stdmsg, "Error: "); 161 161 #if _MSC_VER 162 162 // MS doesn't recognize %zu format 163 163 OutBuffer tmp; 164 164 tmp.vprintf(format, ap); 165 165 fprintf(stdmsg, "%s", tmp.toChars()); 166 166 #else 167 167 vfprintf(stdmsg, format, ap); 168 168 #endif 169 169 fprintf(stdmsg, "\n"); 170 170 fflush(stdmsg); 171 //halt();171 halt(); 172 172 } 173 173 global.errors++; 174 174 } 175 175 176 176 /*************************************** 177 177 * Call this after printing out fatal error messages to clean up and exit 178 178 * the compiler. 179 179 */ 180 180 181 181 void fatal() 182 182 { 183 183 #if 0 184 184 halt(); 185 185 #endif 186 186 exit(EXIT_FAILURE); 187 187 } 188 188 189 189 /************************************** 190 190 * Try to stop forgetting to remove the breakpoints from 191 191 * release builds. trunk/src/struct.c
r318 r319 340 340 t = Type::tvoidptr; // t should not be a ref type 341 341 assert(!vthis); 342 342 vthis = new ThisDeclaration(loc, t); 343 343 //vthis->storage_class |= STCref; 344 344 members->push(vthis); 345 345 } 346 346 } 347 347 } 348 348 } 349 349 350 350 sizeok = 0; 351 351 sc2 = sc->push(this); 352 352 sc2->stc &= storage_class & STC_TYPECTOR; 353 353 sc2->parent = this; 354 354 if (isUnionDeclaration()) 355 355 sc2->inunion = 1; 356 356 sc2->protection = PROTpublic; 357 357 sc2->explicitProtection = 0; 358 358 359 359 int members_dim = members->dim; 360 361 /* Set scope so if there are forward references, we still might be able to 362 * resolve individual members like enums. 363 */ 364 for (int i = 0; i < members_dim; i++) 365 { Dsymbol *s = (Dsymbol *)members->data[i]; 366 /* There are problems doing this in the general case because 367 * Scope keeps track of things like 'offset' 368 */ 369 if (s->isEnumDeclaration() || (s->isAggregateDeclaration() && s->ident)) 370 { 371 //printf("setScope %s %s\n", s->kind(), s->toChars()); 372 s->setScope(sc2); 373 } 374 } 375 360 376 for (int i = 0; i < members_dim; i++) 361 377 { 362 378 Dsymbol *s = (Dsymbol *)members->data[i]; 363 379 s->semantic(sc2); 364 380 if (isUnionDeclaration()) 365 381 sc2->offset = 0; 366 382 #if 0 367 383 if (sizeok == 2) 368 384 { //printf("forward reference\n"); 369 385 break; 370 386 } 371 387 #endif 372 388 Type *t; 373 389 if (s->isDeclaration() && 374 390 (t = s->isDeclaration()->type) != NULL && 375 391 t->toBasetype()->ty == Tstruct) 376 392 { StructDeclaration *sd = (StructDeclaration *)t->toDsymbol(sc); 377 393 if (sd->isnested) 378 394 error("inner struct %s cannot be a field", sd->toChars()); 379 395 }
