Changeset 307
- Timestamp:
- 12/24/09 09:38:16 (15 years ago)
- Files:
-
- trunk/src/declaration.c (modified) (2 diffs)
- trunk/src/opover.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/declaration.c
r305 r307 290 290 st->htype = htype->syntaxCopy(); 291 291 if (!hbasetype) 292 292 { if (basetype) 293 293 { hbasetype = basetype->syntaxCopy(); 294 294 st->hbasetype = basetype->syntaxCopy(); 295 295 } 296 296 } 297 297 else 298 298 st->hbasetype = hbasetype->syntaxCopy(); 299 299 #endif 300 300 return st; 301 301 } 302 302 303 303 void TypedefDeclaration::semantic(Scope *sc) 304 304 { 305 305 //printf("TypedefDeclaration::semantic(%s) sem = %d\n", toChars(), sem); 306 306 if (sem == 0) 307 307 { sem = 1; 308 308 basetype = basetype->semantic(loc, sc); 309 309 sem = 2; 310 #if DMDV2 311 type = type->addStorageClass(storage_class); 312 #endif 310 313 type = type->semantic(loc, sc); 311 314 if (sc->parent->isFuncDeclaration() && init) 312 315 semantic2(sc); 313 316 storage_class |= sc->stc & STCdeprecated; 314 317 } 315 318 else if (sem == 1) 316 319 { 317 320 error("circular definition"); 318 321 } 319 322 } 320 323 321 324 void TypedefDeclaration::semantic2(Scope *sc) 322 325 { 323 326 //printf("TypedefDeclaration::semantic2(%s) sem = %d\n", toChars(), sem); 324 327 if (sem == 2) 325 328 { sem = 3; 326 329 if (init) 327 330 { 328 331 init = init->semantic(sc, basetype); 329 332 … … 421 424 sa->haliassym = aliassym->syntaxCopy(s); 422 425 } 423 426 } 424 427 else 425 428 sa->haliassym = haliassym->syntaxCopy(s); 426 429 #endif 427 430 return sa; 428 431 } 429 432 430 433 void AliasDeclaration::semantic(Scope *sc) 431 434 { 432 435 //printf("AliasDeclaration::semantic() %s\n", toChars()); 433 436 if (aliassym) 434 437 { 435 438 if (aliassym->isTemplateInstance()) 436 439 aliassym->semantic(sc); 437 440 return; 438 441 } 439 442 this->inSemantic = 1; 440 443 444 #if DMDV1 // don't really know why this is here 441 445 if (storage_class & STCconst) 442 446 error("cannot be const"); 447 #endif 443 448 444 449 storage_class |= sc->stc & STCdeprecated; 445 450 446 451 // Given: 447 452 // alias foo.bar.abc def; 448 453 // it is not knowable from the syntax whether this is an alias 449 454 // for a type or an alias for a symbol. It is up to the semantic() 450 455 // pass to distinguish. 451 456 // If it is a type, then type is set and getType() will return that 452 457 // type. If it is a symbol, then aliassym is set and type is NULL - 453 458 // toAlias() will return aliasssym. 454 459 455 460 Dsymbol *s; 456 461 Type *t; 457 462 Expression *e; 458 463 459 464 /* This section is needed because resolve() will: 460 465 * const x = 3; 461 466 * alias x y; 462 467 * try to alias y to 3. 463 468 */ 464 469 s = type->toDsymbol(sc); 465 470 if (s && ((s->getType() && type->equals(s->getType())) || s->isEnumMember())) 466 471 goto L2; // it's a symbolic alias 467 472 468 473 #if DMDV2 474 type = type->addStorageClass(storage_class); 469 475 if (storage_class & (STCref | STCnothrow | STCpure)) 470 476 { // For 'ref' to be attached to function types, and picked 471 477 // up by Type::resolve(), it has to go into sc. 472 478 sc = sc->push(); 473 sc->stc |= storage_class & (STCref | STCnothrow | STCpure );479 sc->stc |= storage_class & (STCref | STCnothrow | STCpure | STCshared); 474 480 type->resolve(loc, sc, &e, &t, &s); 475 481 sc = sc->pop(); 476 482 } 477 483 else 478 484 #endif 479 485 type->resolve(loc, sc, &e, &t, &s); 480 486 if (s) 481 487 { 482 488 goto L2; 483 489 } 484 490 else if (e) 485 491 { 486 492 // Try to convert Expression to Dsymbol 487 493 s = getDsymbol(e); 488 494 if (s) 489 495 goto L2; 490 496 491 497 error("cannot alias an expression %s", e->toChars()); 492 498 t = e->type; 493 499 } trunk/src/opover.c
r295 r307 533 533 * Given array of arguments and an aggregate type, 534 534 * if any of the argument types are missing, attempt to infer 535 535 * them from the aggregate type. 536 536 */ 537 537 538 538 void inferApplyArgTypes(enum TOK op, Parameters *arguments, Expression *aggr) 539 539 { 540 540 if (!arguments || !arguments->dim) 541 541 return; 542 542 543 543 /* Return if no arguments need types. 544 544 */ 545 545 for (size_t u = 0; 1; u++) 546 546 { if (u == arguments->dim) 547 547 return; 548 548 Parameter *arg = (Parameter *)arguments->data[u]; 549 549 if (!arg->type) 550 550 break; 551 551 } 552 552 553 Dsymbol *s; 553 554 AggregateDeclaration *ad; 554 555 555 556 Parameter *arg = (Parameter *)arguments->data[0]; 556 557 Type *taggr = aggr->type; 557 558 if (!taggr) 558 559 return; 559 560 Type *tab = taggr->toBasetype(); 560 561 switch (tab->ty) 561 562 { 562 563 case Tarray: 563 564 case Tsarray: 564 565 case Ttuple: 565 566 if (arguments->dim == 2) 566 567 { 567 568 if (!arg->type) 568 569 arg->type = Type::tsize_t; // key type 569 570 arg = (Parameter *)arguments->data[1]; 570 571 } 571 572 if (!arg->type && tab->ty != Ttuple) 572 573 arg->type = tab->nextOf(); // value type … … 578 579 if (arguments->dim == 2) 579 580 { 580 581 if (!arg->type) 581 582 arg->type = taa->index; // key type 582 583 arg = (Parameter *)arguments->data[1]; 583 584 } 584 585 if (!arg->type) 585 586 arg->type = taa->next; // value type 586 587 break; 587 588 } 588 589 589 590 case Tclass: 590 591 ad = ((TypeClass *)tab)->sym; 591 592 goto Laggr; 592 593 593 594 case Tstruct: 594 595 ad = ((TypeStruct *)tab)->sym; 595 596 goto Laggr; 596 597 597 598 Laggr: 598 Dsymbol *s = search_function(ad,599 s = search_function(ad, 599 600 (op == TOKforeach_reverse) ? Id::applyReverse 600 601 : Id::apply); 601 602 if (s) 602 603 goto Lapply; // prefer opApply 603 604 604 605 if (arguments->dim == 1) 605 606 { 606 607 if (!arg->type) 607 608 { 608 609 /* Look for a head() or rear() overload 609 610 */ 610 611 Identifier *id = (op == TOKforeach) ? Id::Fhead : Id::Ftoe; 611 612 Dsymbol *s = search_function(ad, id); 612 613 FuncDeclaration *fd = s ? s->isFuncDeclaration() : NULL; 613 614 if (!fd) 614 615 { if (s && s->isTemplateDeclaration()) 615 616 break; 616 617 goto Lapply; 617 618 } 618 619 arg->type = fd->type->nextOf();
