Changeset 477
- Timestamp:
- 05/10/10 02:59:48 (15 years ago)
- Files:
-
- branches/dmd-1.x/src/class.c (modified) (2 diffs)
- branches/dmd-1.x/src/template.c (modified) (1 diff)
- trunk/src/class.c (modified) (2 diffs)
- trunk/src/declaration.c (modified) (1 diff)
- trunk/src/expression.c (modified) (2 diffs)
- trunk/src/mtype.c (modified) (1 diff)
- trunk/src/template.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/dmd-1.x/src/class.c
r451 r477 319 319 320 320 tc->checkDeprecated(loc, sc); 321 321 } 322 322 } 323 323 324 324 if (tc->sym->isInterfaceDeclaration()) 325 325 ; 326 326 else 327 327 { 328 328 for (ClassDeclaration *cdb = tc->sym; cdb; cdb = cdb->baseClass) 329 329 { 330 330 if (cdb == this) 331 331 { 332 332 error("circular inheritance"); 333 333 baseclasses.remove(0); 334 334 goto L7; 335 335 } 336 336 } 337 337 if (!tc->sym->symtab || tc->sym->sizeok == 0) 338 338 { // Try to resolve forward reference 339 if ( sc->mustsemantic &&tc->sym->scope)339 if (/*sc->mustsemantic &&*/ tc->sym->scope) 340 340 tc->sym->semantic(NULL); 341 341 } 342 342 if (!tc->sym->symtab || tc->sym->scope || tc->sym->sizeok == 0) 343 343 { 344 344 //printf("%s: forward reference of base class %s\n", toChars(), tc->sym->toChars()); 345 345 //error("forward reference of base class %s", baseClass->toChars()); 346 346 // Forward reference of base class, try again later 347 347 //printf("\ttry later, forward reference of base class %s\n", tc->sym->toChars()); 348 348 scope = scx ? scx : new Scope(*sc); 349 349 scope->setNoFree(); 350 350 if (tc->sym->scope) 351 351 tc->sym->scope->module->addDeferredSemantic(tc->sym); 352 352 scope->module->addDeferredSemantic(this); 353 353 return; 354 354 } 355 355 else 356 356 { baseClass = tc->sym; 357 357 b->base = baseClass; 358 358 } 359 359 L7: ; … … 387 387 { 388 388 if (!isDeprecated()) 389 389 { 390 390 // Deriving from deprecated class makes this one deprecated too 391 391 isdeprecated = 1; 392 392 393 393 tc->checkDeprecated(loc, sc); 394 394 } 395 395 } 396 396 397 397 // Check for duplicate interfaces 398 398 for (size_t j = (baseClass ? 1 : 0); j < i; j++) 399 399 { 400 400 BaseClass *b2 = (BaseClass *)baseclasses.data[j]; 401 401 if (b2->base == tc->sym) 402 402 error("inherits from duplicate interface %s", b2->base->toChars()); 403 403 } 404 404 405 405 if (!tc->sym->symtab) 406 406 { // Try to resolve forward reference 407 if ( sc->mustsemantic &&tc->sym->scope)407 if (/*sc->mustsemantic &&*/ tc->sym->scope) 408 408 tc->sym->semantic(NULL); 409 409 } 410 410 411 411 b->base = tc->sym; 412 412 if (!b->base->symtab || b->base->scope) 413 413 { 414 414 //error("forward reference of base class %s", baseClass->toChars()); 415 415 // Forward reference of base, try again later 416 416 //printf("\ttry later, forward reference of base %s\n", baseClass->toChars()); 417 417 scope = scx ? scx : new Scope(*sc); 418 418 scope->setNoFree(); 419 419 if (tc->sym->scope) 420 420 tc->sym->scope->module->addDeferredSemantic(tc->sym); 421 421 scope->module->addDeferredSemantic(this); 422 422 return; 423 423 } 424 424 } 425 425 i++; 426 426 } 427 427 branches/dmd-1.x/src/template.c
r428 r477 3485 3485 } 3486 3486 #endif 3487 3487 } 3488 3488 3489 3489 Laftersemantic: 3490 3490 sc2->pop(); 3491 3491 3492 3492 scope->pop(); 3493 3493 3494 3494 // Give additional context info if error occurred during instantiation 3495 3495 if (global.errors != errorsave) 3496 3496 { 3497 3497 error("error instantiating"); 3498 3498 if (tinst) 3499 3499 { tinst->printInstantiationTrace(); 3500 3500 if (!global.gag) 3501 3501 fatal(); 3502 3502 } 3503 3503 errors = 1; 3504 3504 if (global.gag) 3505 { // Try to reset things so we can try again later to instantiate it 3505 3506 tempdecl->instances.remove(tempdecl_instance_idx); 3507 semanticRun = 0; 3508 inst = NULL; 3509 } 3506 3510 } 3507 3511 3508 3512 #if LOG 3509 3513 printf("-TemplateInstance::semantic('%s', this=%p)\n", toChars(), this); 3510 3514 #endif 3511 3515 } 3512 3516 3513 3517 3514 3518 void TemplateInstance::semanticTiargs(Scope *sc) 3515 3519 { 3516 3520 //printf("+TemplateInstance::semanticTiargs() %s\n", toChars()); 3517 3521 if (semantictiargsdone) 3518 3522 return; 3519 3523 semantictiargsdone = 1; 3520 3524 semanticTiargs(loc, sc, tiargs, 0); 3521 3525 } 3522 3526 3523 3527 /********************************** 3524 3528 * Input: 3525 3529 * flags 1: replace const variables with their initializers trunk/src/class.c
r450 r477 327 327 328 328 tc->checkDeprecated(loc, sc); 329 329 } 330 330 } 331 331 332 332 if (tc->sym->isInterfaceDeclaration()) 333 333 ; 334 334 else 335 335 { 336 336 for (ClassDeclaration *cdb = tc->sym; cdb; cdb = cdb->baseClass) 337 337 { 338 338 if (cdb == this) 339 339 { 340 340 error("circular inheritance"); 341 341 baseclasses.remove(0); 342 342 goto L7; 343 343 } 344 344 } 345 345 if (!tc->sym->symtab || tc->sym->sizeok == 0) 346 346 { // Try to resolve forward reference 347 if ( sc->mustsemantic &&tc->sym->scope)347 if (/*sc->mustsemantic &&*/ tc->sym->scope) 348 348 tc->sym->semantic(NULL); 349 349 } 350 350 if (!tc->sym->symtab || tc->sym->scope || tc->sym->sizeok == 0) 351 351 { 352 //printf("%s: forward reference of base class %s\n", toChars(), tc->sym->toChars());352 printf("%s: forward reference of base class %s\n", toChars(), tc->sym->toChars()); 353 353 //error("forward reference of base class %s", baseClass->toChars()); 354 354 // Forward reference of base class, try again later 355 355 //printf("\ttry later, forward reference of base class %s\n", tc->sym->toChars()); 356 356 scope = scx ? scx : new Scope(*sc); 357 357 scope->setNoFree(); 358 358 if (tc->sym->scope) 359 359 tc->sym->scope->module->addDeferredSemantic(tc->sym); 360 360 scope->module->addDeferredSemantic(this); 361 361 return; 362 362 } 363 363 else 364 364 { baseClass = tc->sym; 365 365 b->base = baseClass; 366 366 } 367 367 L7: ; 368 368 } 369 369 } 370 370 } 371 371 372 372 // Treat the remaining entries in baseclasses as interfaces … … 395 395 { 396 396 if (!isDeprecated()) 397 397 { 398 398 // Deriving from deprecated class makes this one deprecated too 399 399 isdeprecated = 1; 400 400 401 401 tc->checkDeprecated(loc, sc); 402 402 } 403 403 } 404 404 405 405 // Check for duplicate interfaces 406 406 for (size_t j = (baseClass ? 1 : 0); j < i; j++) 407 407 { 408 408 BaseClass *b2 = (BaseClass *)baseclasses.data[j]; 409 409 if (b2->base == tc->sym) 410 410 error("inherits from duplicate interface %s", b2->base->toChars()); 411 411 } 412 412 413 413 if (!tc->sym->symtab) 414 414 { // Try to resolve forward reference 415 if ( sc->mustsemantic &&tc->sym->scope)415 if (/*sc->mustsemantic &&*/ tc->sym->scope) 416 416 tc->sym->semantic(NULL); 417 417 } 418 418 419 419 b->base = tc->sym; 420 420 if (!b->base->symtab || b->base->scope) 421 421 { 422 422 //error("forward reference of base class %s", baseClass->toChars()); 423 423 // Forward reference of base, try again later 424 424 //printf("\ttry later, forward reference of base %s\n", baseClass->toChars()); 425 425 scope = scx ? scx : new Scope(*sc); 426 426 scope->setNoFree(); 427 427 if (tc->sym->scope) 428 428 tc->sym->scope->module->addDeferredSemantic(tc->sym); 429 429 scope->module->addDeferredSemantic(this); 430 430 return; 431 431 } 432 432 } 433 433 i++; 434 434 } 435 435 trunk/src/declaration.c
r474 r477 511 511 if (f) 512 512 { 513 513 if (overnext) 514 514 { 515 515 FuncAliasDeclaration *fa = new FuncAliasDeclaration(f); 516 516 if (!fa->overloadInsert(overnext)) 517 517 ScopeDsymbol::multiplyDefined(0, f, overnext); 518 518 overnext = NULL; 519 519 s = fa; 520 520 s->parent = sc->parent; 521 521 } 522 522 } 523 523 if (overnext) 524 524 ScopeDsymbol::multiplyDefined(0, s, overnext); 525 525 if (s == this) 526 526 { 527 527 assert(global.errors); 528 528 s = NULL; 529 529 } 530 530 } 531 //printf("setting aliassym % p to %p\n", this, s);531 //printf("setting aliassym %s to %s %s\n", toChars(), s->kind(), s->toChars()); 532 532 aliassym = s; 533 533 this->inSemantic = 0; 534 534 } 535 535 536 536 int AliasDeclaration::overloadInsert(Dsymbol *s) 537 537 { 538 538 /* Don't know yet what the aliased symbol is, so assume it can 539 539 * be overloaded and check later for correctness. 540 540 */ 541 541 542 542 //printf("AliasDeclaration::overloadInsert('%s')\n", s->toChars()); 543 543 if (aliassym) // see test/test56.d 544 544 { 545 545 Dsymbol *a = aliassym->toAlias(); 546 546 FuncDeclaration *f = a->isFuncDeclaration(); 547 547 if (f) // BUG: what if it's a template? 548 548 { 549 549 FuncAliasDeclaration *fa = new FuncAliasDeclaration(f); 550 550 aliassym = fa; 551 551 return fa->overloadInsert(s); trunk/src/expression.c
r473 r477 258 258 s = s->toParent()) 259 259 { FuncDeclaration *f = s->isFuncDeclaration(); 260 260 if (f->vthis) 261 261 { 262 262 //printf("rewriting e1 to %s's this\n", f->toChars()); 263 263 n++; 264 264 e1 = new VarExp(loc, f->vthis); 265 265 } 266 266 } 267 267 if (s && s->isClassDeclaration()) 268 268 { e1->type = s->isClassDeclaration()->type; 269 269 if (n > 1) 270 270 e1 = e1->semantic(sc); 271 271 } 272 272 else 273 273 e1 = e1->semantic(sc); 274 274 goto L1; 275 275 } 276 276 /* Can't find a path from e1 to ad 277 277 */ 278 printf("t->ty = %d\n", t->ty); 278 279 e1->error("this for %s needs to be type %s not type %s", 279 280 var->toChars(), ad->toChars(), t->toChars()); 280 281 e1 = new ErrorExp(); 281 282 } 282 283 } 283 284 return e1; 284 285 } 285 286 286 287 /***************************************** 287 288 * Determine if 'this' is available. 288 289 * If it is, return the FuncDeclaration that has it. 289 290 */ 290 291 291 292 FuncDeclaration *hasThis(Scope *sc) 292 293 { FuncDeclaration *fd; 293 294 FuncDeclaration *fdthis; 294 295 295 296 //printf("hasThis()\n"); 296 297 fdthis = sc->parent->isFuncDeclaration(); 297 298 //printf("fdthis = %p, '%s'\n", fdthis, fdthis ? fdthis->toChars() : ""); … … 1059 1060 1060 1061 Expression *Expression::semantic(Scope *sc) 1061 1062 { 1062 1063 #if LOGSEMANTIC 1063 1064 printf("Expression::semantic() %s\n", toChars()); 1064 1065 #endif 1065 1066 if (type) 1066 1067 type = type->semantic(loc, sc); 1067 1068 else 1068 1069 type = Type::tvoid; 1069 1070 return this; 1070 1071 } 1071 1072 1072 1073 /********************************** 1073 1074 * Try to run semantic routines. 1074 1075 * If they fail, return NULL. 1075 1076 */ 1076 1077 1077 1078 Expression *Expression::trySemantic(Scope *sc) 1078 1079 { 1080 //printf("+trySemantic(%s)\n", toChars()); 1079 1081 unsigned errors = global.errors; 1080 1082 global.gag++; 1081 1083 Expression *e = semantic(sc); 1082 1084 global.gag--; 1083 1085 if (errors != global.errors) 1084 1086 { 1085 1087 global.errors = errors; 1086 1088 e = NULL; 1087 1089 } 1090 //printf("-trySemantic(%s)\n", toChars()); 1088 1091 return e; 1089 1092 } 1090 1093 1091 1094 void Expression::print() 1092 1095 { 1093 1096 fprintf(stdmsg, "%s\n", toChars()); 1094 1097 fflush(stdmsg); 1095 1098 } 1096 1099 1097 1100 char *Expression::toChars() 1098 1101 { OutBuffer *buf; 1099 1102 HdrGenState hgs; 1100 1103 1101 1104 memset(&hgs, 0, sizeof(hgs)); 1102 1105 buf = new OutBuffer(); 1103 1106 toCBuffer(buf, &hgs); 1104 1107 return buf->toChars(); 1105 1108 } 1106 1109 1107 1110 void Expression::error(const char *format, ...) trunk/src/mtype.c
r462 r477 298 298 } 299 299 300 300 d_uns64 Type::size(Loc loc) 301 301 { 302 302 error(loc, "no size for type %s", toChars()); 303 303 return 1; 304 304 } 305 305 306 306 unsigned Type::alignsize() 307 307 { 308 308 return size(0); 309 309 } 310 310 311 311 Type *Type::semantic(Loc loc, Scope *sc) 312 312 { 313 313 return merge(); 314 314 } 315 315 316 316 Type *Type::trySemantic(Loc loc, Scope *sc) 317 317 { 318 //printf("+trySemantic(%s) %d\n", toChars(), global.errors); 318 319 unsigned errors = global.errors; 319 320 global.gag++; // suppress printing of error messages 320 321 Type *t = semantic(loc, sc); 321 322 global.gag--; 322 323 if (errors != global.errors) // if any errors happened 323 324 { 324 325 global.errors = errors; 325 326 t = NULL; 326 327 } 328 //printf("-trySemantic(%s) %d\n", toChars(), global.errors); 327 329 return t; 328 330 } 329 331 330 332 /******************************* 331 333 * Determine if converting 'this' to 'to' is an identity operation, 332 334 * a conversion to const operation, or the types aren't the same. 333 335 * Returns: 334 336 * MATCHequal 'this' == 'to' 335 337 * MATCHconst 'to' is const 336 338 * MATCHnomatch conversion to mutable or invariant 337 339 */ 338 340 339 341 MATCH Type::constConv(Type *to) 340 342 { 341 343 if (equals(to)) 342 344 return MATCHexact; 343 345 if (ty == to->ty && MODimplicitConv(mod, to->mod)) 344 346 return MATCHconst; 345 347 return MATCHnomatch; 346 348 } trunk/src/template.c
r448 r477 3509 3509 3510 3510 if (s) 3511 3511 ti = (TemplateInstance *)s; 3512 3512 else 3513 3513 ti = new TemplateInstance(loc, name); 3514 3514 3515 3515 ti->tiargs = arraySyntaxCopy(tiargs); 3516 3516 3517 3517 ScopeDsymbol::syntaxCopy(ti); 3518 3518 return ti; 3519 3519 } 3520 3520 3521 3521 3522 3522 void TemplateInstance::semantic(Scope *sc) 3523 3523 { 3524 3524 semantic(sc, NULL); 3525 3525 } 3526 3526 3527 3527 void TemplateInstance::semantic(Scope *sc, Expressions *fargs) 3528 3528 { 3529 //printf("TemplateInstance::semantic('%s', this=%p)\n", toChars(), this); 3529 3530 if (global.errors && name != Id::AssociativeArray) 3530 3531 { 3532 //printf("not instantiating %s due to %d errors\n", toChars(), global.errors); 3531 3533 if (!global.gag) 3532 3534 { 3533 3535 /* Trying to soldier on rarely generates useful messages 3534 3536 * at this point. 3535 3537 */ 3536 3538 fatal(); 3537 3539 } 3538 return;3540 // return; 3539 3541 } 3540 3542 #if LOG 3541 3543 printf("\n+TemplateInstance::semantic('%s', this=%p)\n", toChars(), this); 3542 3544 #endif 3543 3545 if (inst) // if semantic() was already run 3544 3546 { 3545 3547 #if LOG 3546 3548 printf("-TemplateInstance::semantic('%s', this=%p) already run\n", inst->toChars(), inst); 3547 3549 #endif 3548 3550 return; 3549 3551 } 3550 3552 3551 3553 // get the enclosing template instance from the scope tinst 3552 3554 tinst = sc->tinst; 3553 3555 3554 3556 if (semanticRun != 0) 3555 3557 { 3558 #if LOG 3559 printf("Recursive template expansion\n"); 3560 #endif 3556 3561 error(loc, "recursive template expansion"); 3557 3562 // inst = this; 3558 3563 return; 3559 3564 } 3560 3565 semanticRun = 1; 3561 3566 3562 3567 #if LOG 3563 3568 printf("\tdo semantic\n"); 3564 3569 #endif 3565 3570 if (havetempdecl) 3566 3571 { 3567 3572 assert((size_t)tempdecl->scope > 0x10000); 3568 3573 // Deduce tdtypes 3569 3574 tdtypes.setDim(tempdecl->parameters->dim); 3570 3575 if (!tempdecl->matchWithInstance(this, &tdtypes, 2)) 3571 3576 { 3572 3577 error("incompatible arguments for template instantiation"); 3573 3578 inst = this; 3574 3579 return; 3575 3580 } … … 3901 3906 error("recursive expansion"); 3902 3907 fatal(); 3903 3908 } 3904 3909 #endif 3905 3910 } 3906 3911 3907 3912 Laftersemantic: 3908 3913 sc2->pop(); 3909 3914 3910 3915 scope->pop(); 3911 3916 3912 3917 // Give additional context info if error occurred during instantiation 3913 3918 if (global.errors != errorsave) 3914 3919 { 3915 3920 error("error instantiating"); 3916 3921 if (tinst) 3917 3922 { tinst->printInstantiationTrace(); 3918 3923 } 3919 3924 errors = 1; 3920 3925 if (global.gag) 3926 { // Try to reset things so we can try again later to instantiate it 3921 3927 tempdecl->instances.remove(tempdecl_instance_idx); 3928 semanticRun = 0; 3929 inst = NULL; 3930 } 3922 3931 } 3923 3932 3924 3933 #if LOG 3925 3934 printf("-TemplateInstance::semantic('%s', this=%p)\n", toChars(), this); 3926 3935 #endif 3927 3936 } 3928 3937 3929 3938 3930 3939 void TemplateInstance::semanticTiargs(Scope *sc) 3931 3940 { 3932 3941 //printf("+TemplateInstance::semanticTiargs() %s\n", toChars()); 3933 3942 if (semantictiargsdone) 3934 3943 return; 3935 3944 semantictiargsdone = 1; 3936 3945 semanticTiargs(loc, sc, tiargs, 0); 3937 3946 } 3938 3947 3939 3948 /********************************** 3940 3949 * Input: 3941 3950 * flags 1: replace const variables with their initializers
