Changeset 591
- Timestamp:
- 08/02/10 08:28:28 (14 years ago)
- Files:
-
- branches/dmd-1.x/src/declaration.h (modified) (4 diffs)
- branches/dmd-1.x/src/glue.c (modified) (8 diffs)
- branches/dmd-1.x/src/module.c (modified) (1 diff)
- branches/dmd-1.x/src/module.h (modified) (1 diff)
- trunk/src/declaration.h (modified) (1 diff)
- trunk/src/glue.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/dmd-1.x/src/declaration.h
r453 r591 81 81 #define STCsafe 0x200000000LL 82 82 #define STCtrusted 0x400000000LL 83 83 #define STCsystem 0x800000000LL 84 84 #define STCctfe 0x1000000000LL // can be used in CTFE, even if it is static 85 85 86 86 struct Match 87 87 { 88 88 int count; // number of matches found 89 89 MATCH last; // match level of lastf 90 90 FuncDeclaration *lastf; // last matching function we found 91 91 FuncDeclaration *nextf; // current matching function 92 92 FuncDeclaration *anyf; // pick a func, any func, to use for error recovery 93 93 }; 94 94 95 95 void overloadResolveX(Match *m, FuncDeclaration *f, 96 96 Expression *ethis, Expressions *arguments); 97 97 int overloadApply(FuncDeclaration *fstart, 98 98 int (*fp)(void *, FuncDeclaration *), 99 99 void *param); 100 100 101 enum Semantic 102 { 103 SemanticStart, // semantic has not been run 104 SemanticIn, // semantic() is in progress 105 SemanticDone, // semantic() has been run 106 Semantic2Done, // semantic2() has been run 107 }; 108 101 109 /**************************************************************/ 102 110 103 111 struct Declaration : Dsymbol 104 112 { 105 113 Type *type; 106 114 Type *originalType; // before semantic analysis 107 115 StorageClass storage_class; 108 116 enum PROT protection; 109 117 enum LINK linkage; 110 118 int inuse; // used to detect cycles 111 119 112 120 Declaration(Identifier *id); 113 121 void semantic(Scope *sc); 114 122 const char *kind(); 115 123 unsigned size(Loc loc); 116 124 void checkModify(Loc loc, Scope *sc, Type *t); 117 125 118 126 void emitComment(Scope *sc); 119 127 void toJsonBuffer(OutBuffer *buf); 120 128 void toDocBuffer(OutBuffer *buf); … … 436 444 }; 437 445 438 446 #if DMDV2 439 447 struct TypeInfoConstDeclaration : TypeInfoDeclaration 440 448 { 441 449 TypeInfoConstDeclaration(Type *tinfo); 442 450 443 451 void toDt(dt_t **pdt); 444 452 }; 445 453 446 454 struct TypeInfoInvariantDeclaration : TypeInfoDeclaration 447 455 { 448 456 TypeInfoInvariantDeclaration(Type *tinfo); 449 457 450 458 void toDt(dt_t **pdt); 451 459 }; 452 460 453 461 struct TypeInfoSharedDeclaration : TypeInfoDeclaration 454 462 { 455 463 TypeInfoSharedDeclaration(Type *tinfo); 464 465 void toDt(dt_t **pdt); 466 }; 467 468 struct TypeInfoWildDeclaration : TypeInfoDeclaration 469 { 470 TypeInfoWildDeclaration(Type *tinfo); 456 471 457 472 void toDt(dt_t **pdt); 458 473 }; 459 474 #endif 460 475 461 476 /**************************************************************/ 462 477 463 478 struct ThisDeclaration : VarDeclaration 464 479 { 465 480 ThisDeclaration(Loc loc, Type *t); 466 481 Dsymbol *syntaxCopy(Dsymbol *); 467 482 ThisDeclaration *isThisDeclaration() { return this; } 468 483 }; 469 484 470 485 enum ILS 471 486 { 472 487 ILSuninitialized, // not computed yet 473 488 ILSno, // cannot inline 474 489 ILSyes, // can inline 475 490 }; … … 581 596 FuncDeclaration *overloadResolve(Loc loc, Expression *ethis, Expressions *arguments, int flags = 0); 582 597 MATCH leastAsSpecialized(FuncDeclaration *g); 583 598 LabelDsymbol *searchLabel(Identifier *ident); 584 599 AggregateDeclaration *isThis(); 585 600 AggregateDeclaration *isMember2(); 586 601 int getLevel(Loc loc, FuncDeclaration *fd); // lexical nesting level difference 587 602 void appendExp(Expression *e); 588 603 void appendState(Statement *s); 589 604 char *mangle(); 590 605 const char *toPrettyChars(); 591 606 int isMain(); 592 607 int isWinMain(); 593 608 int isDllMain(); 594 609 enum BUILTIN isBuiltin(); 595 610 int isExport(); 596 611 int isImportedSymbol(); 597 612 int isAbstract(); 598 613 int isCodeseg(); 599 614 int isOverloadable(); 600 615 int isPure(); 616 int isSafe(); 617 int isTrusted(); 601 618 virtual int isNested(); 602 619 int needThis(); 603 620 virtual int isVirtual(); 604 621 virtual int isFinal(); 605 622 virtual int addPreInvariant(); 606 623 virtual int addPostInvariant(); 607 624 Expression *interpret(InterState *istate, Expressions *arguments, Expression *thisexp = NULL); 608 625 void inlineScan(); 609 626 int canInline(int hasthis, int hdrscan = 0); 610 627 Expression *doInline(InlineScanState *iss, Expression *ethis, Array *arguments); 611 628 const char *kind(); 612 629 void toDocBuffer(OutBuffer *buf); 613 630 FuncDeclaration *isUnique(); 614 631 int needsClosure(); 615 632 Statement *mergeFrequire(Statement *); 616 633 Statement *mergeFensure(Statement *); 617 634 Parameters *getParameters(int *pvarargs); 618 635 619 636 static FuncDeclaration *genCfunc(Type *treturn, const char *name); 620 637 static FuncDeclaration *genCfunc(Type *treturn, Identifier *id); … … 718 735 DtorDeclaration *isDtorDeclaration() { return this; } 719 736 }; 720 737 721 738 struct StaticCtorDeclaration : FuncDeclaration 722 739 { 723 740 StaticCtorDeclaration(Loc loc, Loc endloc); 724 741 Dsymbol *syntaxCopy(Dsymbol *); 725 742 void semantic(Scope *sc); 726 743 AggregateDeclaration *isThis(); 727 744 int isStaticConstructor(); 728 745 int isVirtual(); 729 746 int addPreInvariant(); 730 747 int addPostInvariant(); 731 748 void emitComment(Scope *sc); 732 749 void toJsonBuffer(OutBuffer *buf); 733 750 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 734 751 735 752 StaticCtorDeclaration *isStaticCtorDeclaration() { return this; } 736 753 }; 737 754 755 #if DMDV2 756 struct SharedStaticCtorDeclaration : StaticCtorDeclaration 757 { 758 SharedStaticCtorDeclaration(Loc loc, Loc endloc); 759 Dsymbol *syntaxCopy(Dsymbol *); 760 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 761 762 SharedStaticCtorDeclaration *isSharedStaticCtorDeclaration() { return this; } 763 }; 764 #endif 765 738 766 struct StaticDtorDeclaration : FuncDeclaration 739 767 { VarDeclaration *vgate; // 'gate' variable 740 768 741 769 StaticDtorDeclaration(Loc loc, Loc endloc); 742 770 Dsymbol *syntaxCopy(Dsymbol *); 743 771 void semantic(Scope *sc); 744 772 AggregateDeclaration *isThis(); 745 773 int isStaticDestructor(); 746 774 int isVirtual(); 747 775 int addPreInvariant(); 748 776 int addPostInvariant(); 749 777 void emitComment(Scope *sc); 750 778 void toJsonBuffer(OutBuffer *buf); 751 779 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 752 780 753 781 StaticDtorDeclaration *isStaticDtorDeclaration() { return this; } 754 782 }; 755 783 784 #if DMDV2 785 struct SharedStaticDtorDeclaration : StaticDtorDeclaration 786 { 787 SharedStaticDtorDeclaration(Loc loc, Loc endloc); 788 Dsymbol *syntaxCopy(Dsymbol *); 789 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 790 791 SharedStaticDtorDeclaration *isSharedStaticDtorDeclaration() { return this; } 792 }; 793 #endif 794 756 795 struct InvariantDeclaration : FuncDeclaration 757 796 { 758 797 InvariantDeclaration(Loc loc, Loc endloc); 759 798 Dsymbol *syntaxCopy(Dsymbol *); 760 799 void semantic(Scope *sc); 761 800 int isVirtual(); 762 801 int addPreInvariant(); 763 802 int addPostInvariant(); 764 803 void emitComment(Scope *sc); 765 804 void toJsonBuffer(OutBuffer *buf); 766 805 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 767 806 768 807 InvariantDeclaration *isInvariantDeclaration() { return this; } 769 808 }; 770 809 771 810 772 811 struct UnitTestDeclaration : FuncDeclaration 773 812 { 774 813 UnitTestDeclaration(Loc loc, Loc endloc); 775 814 Dsymbol *syntaxCopy(Dsymbol *); branches/dmd-1.x/src/glue.c
r428 r591 1 1 2 2 // Compiler implementation of the D programming language 3 // Copyright (c) 1999-20 09by Digital Mars3 // Copyright (c) 1999-2010 by Digital Mars 4 4 // All Rights Reserved 5 5 // written by Walter Bright 6 6 // http://www.digitalmars.com 7 7 8 8 #include <stdio.h> 9 9 #include <stddef.h> 10 10 #include <time.h> 11 11 #include <assert.h> 12 12 13 13 #if __sun&&__SVR4 14 14 #include <alloca.h> 15 15 #endif 16 16 17 17 #include "mars.h" 18 18 #include "module.h" 19 19 #include "mtype.h" 20 20 #include "declaration.h" 21 21 #include "statement.h" 22 22 #include "enum.h" 23 23 #include "aggregate.h" … … 36 36 #include "type.h" 37 37 #include "dt.h" 38 38 #include "cgcv.h" 39 39 #include "outbuf.h" 40 40 #include "irstate.h" 41 41 42 42 struct Environment; 43 43 44 44 Environment *benv; 45 45 46 46 void out_config_init(); 47 47 void slist_add(Symbol *s); 48 48 void slist_reset(); 49 49 void clearStringTab(); 50 50 51 51 #define STATICCTOR 0 52 52 53 53 elem *eictor; 54 54 symbol *ictorlocalgot; 55 55 elem *ector; 56 Array ectorgates; 56 57 elem *edtor; 57 58 elem *etest; 58 59 60 elem *esharedctor; 61 Array esharedctorgates; 62 elem *eshareddtor; 63 59 64 int dtorcount; 65 int shareddtorcount; 60 66 61 67 char *lastmname; 62 68 63 69 /************************************** 64 70 * Append s to list of object files to generate later. 65 71 */ 66 72 67 73 Array obj_symbols_towrite; 68 74 69 75 void obj_append(Dsymbol *s) 70 76 { 71 77 obj_symbols_towrite.push(s); 72 78 } 73 79 74 80 void obj_write_deferred(Library *library) 75 81 { 76 82 for (int i = 0; i < obj_symbols_towrite.dim; i++) 77 83 { Dsymbol *s = (Dsymbol *)obj_symbols_towrite.data[i]; 78 84 Module *m = s->getModule(); 79 85 … … 87 93 //mname = s->ident->toChars(); 88 94 mname = lastmname; 89 95 assert(mname); 90 96 } 91 97 92 98 obj_start(mname); 93 99 94 100 static int count; 95 101 count++; // sequence for generating names 96 102 97 103 /* Create a module that's a doppelganger of m, with just 98 104 * enough to be able to create the moduleinfo. 99 105 */ 100 106 OutBuffer idbuf; 101 107 idbuf.printf("%s.%d", m ? m->ident->toChars() : mname, count); 102 108 char *idstr = idbuf.toChars(); 103 109 idbuf.data = NULL; 104 110 Identifier *id = new Identifier(idstr, TOKidentifier); 105 111 106 112 Module *md = new Module(mname, id, 0, 0); 107 md->members = new Array();113 md->members = new Dsymbols(); 108 114 md->members->push(s); // its only 'member' is s 109 115 if (m) 110 116 { 111 117 md->doppelganger = 1; // identify this module as doppelganger 112 118 md->md = m->md; 113 119 md->aimports.push(m); // it only 'imports' m 114 120 md->massert = m->massert; 121 md->munittest = m->munittest; 115 122 md->marray = m->marray; 116 123 } 117 124 118 125 md->genobjfile(0); 119 126 120 127 /* Set object file name to be source name with sequence number, 121 128 * as mangled symbol names get way too long. 122 129 */ 123 130 char *fname = FileName::removeExt(mname); 124 131 OutBuffer namebuf; 125 132 unsigned hash = 0; 126 133 for (char *p = s->toChars(); *p; p++) 127 134 hash += *p; 128 135 namebuf.printf("%s_%x_%x.%s", fname, count, hash, global.obj_ext); 129 136 namebuf.writeByte(0); 130 137 mem.free(fname); 131 138 fname = (char *)namebuf.extractData(); 132 139 133 140 //printf("writing '%s'\n", fname); 134 141 File *objfile = new File(fname); … … 189 196 objbuf.inc = 0; 190 197 } 191 198 192 199 /************************************** 193 200 * Generate .obj file for Module. 194 201 */ 195 202 196 203 void Module::genobjfile(int multiobj) 197 204 { 198 205 //EEcontext *ee = env->getEEcontext(); 199 206 200 207 //printf("Module::genobjfile(multiobj = %d) %s\n", multiobj, toChars()); 201 208 202 209 lastmname = srcfile->toChars(); 203 210 204 211 obj_initfile(lastmname, NULL, toPrettyChars()); 205 212 206 213 eictor = NULL; 207 214 ictorlocalgot = NULL; 208 215 ector = NULL; 216 ectorgates.setDim(0); 209 217 edtor = NULL; 218 esharedctor = NULL; 219 esharedctorgates.setDim(0); 220 eshareddtor = NULL; 210 221 etest = NULL; 211 222 dtorcount = 0; 223 shareddtorcount = 0; 212 224 213 225 if (doppelganger) 214 226 { 215 227 /* Generate a reference to the moduleinfo, so the module constructors 216 228 * and destructors get linked in. 217 229 */ 218 230 Module *m = (Module *)aimports.data[0]; 219 231 assert(m); 220 232 if (m->sictor || m->sctor || m->sdtor) 221 233 { 222 234 Symbol *s = m->toSymbol(); 223 235 //objextern(s); 224 236 //if (!s->Sxtrnnum) objextdef(s->Sident); 225 237 if (!s->Sxtrnnum) 226 238 { 227 239 //printf("%s\n", s->Sident); 228 240 #if 0 /* This should work, but causes optlink to fail in common/newlib.asm */ 229 241 objextdef(s->Sident); 230 242 #else 231 243 #if ELFOBJ || MACHOBJ … … 326 338 t->Tnext = tsvoid; 327 339 tsvoid->Tcount++; 328 340 329 341 static char moddeco[] = "FZv"; 330 342 331 343 if (eictor) 332 344 { 333 345 localgot = ictorlocalgot; 334 346 335 347 block *b = block_calloc(); 336 348 b->BC = BCret; 337 349 b->Belem = eictor; 338 350 sictor->Sfunc->Fstartblock = b; 339 351 writefunc(sictor); 340 352 } 341 353 342 354 if (ector) 343 355 { 344 356 localgot = NULL; 345 357 sctor = toSymbolX("__modctor", SCglobal, t, moddeco); 358 #if DMDV2 359 cstate.CSpsymtab = &sctor->Sfunc->Flocsym; 360 361 for (int i = 0; i < ectorgates.dim; i++) 362 { StaticDtorDeclaration *f = (StaticDtorDeclaration *)ectorgates.data[i]; 363 364 Symbol *s = f->vgate->toSymbol(); 365 elem *e = el_var(s); 366 e = el_bin(OPaddass, TYint, e, el_long(TYint, 1)); 367 ector = el_combine(ector, e); 368 } 369 #endif 346 370 347 371 block *b = block_calloc(); 348 372 b->BC = BCret; 349 373 b->Belem = ector; 350 374 sctor->Sfunc->Fstartblock = b; 351 375 writefunc(sctor); 352 376 #if STATICCTOR 353 377 obj_staticctor(sctor, dtorcount, 1); 354 378 #endif 355 379 } 356 380 357 381 if (edtor) 358 382 { 359 383 localgot = NULL; 360 384 sdtor = toSymbolX("__moddtor", SCglobal, t, moddeco); 361 385 362 386 block *b = block_calloc(); 363 387 b->BC = BCret; 364 388 b->Belem = edtor; 365 389 sdtor->Sfunc->Fstartblock = b; 366 390 writefunc(sdtor); 367 391 } 368 392 393 #if DMDV2 394 if (esharedctor || esharedctorgates.dim) 395 { 396 localgot = NULL; 397 ssharedctor = toSymbolX("__modsharedctor", SCglobal, t, moddeco); 398 cstate.CSpsymtab = &ssharedctor->Sfunc->Flocsym; 399 400 for (int i = 0; i < esharedctorgates.dim; i++) 401 { SharedStaticDtorDeclaration *f = (SharedStaticDtorDeclaration *)esharedctorgates.data[i]; 402 403 Symbol *s = f->vgate->toSymbol(); 404 elem *e = el_var(s); 405 e = el_bin(OPaddass, TYint, e, el_long(TYint, 1)); 406 esharedctor = el_combine(esharedctor, e); 407 } 408 409 block *b = block_calloc(); 410 b->BC = BCret; 411 b->Belem = esharedctor; 412 ssharedctor->Sfunc->Fstartblock = b; 413 writefunc(ssharedctor); 414 #if STATICCTOR 415 obj_staticctor(ssharedctor, shareddtorcount, 1); 416 #endif 417 } 418 419 if (eshareddtor) 420 { 421 localgot = NULL; 422 sshareddtor = toSymbolX("__modshareddtor", SCglobal, t, moddeco); 423 424 block *b = block_calloc(); 425 b->BC = BCret; 426 b->Belem = eshareddtor; 427 sshareddtor->Sfunc->Fstartblock = b; 428 writefunc(sshareddtor); 429 } 430 #endif 431 369 432 if (etest) 370 433 { 371 434 localgot = NULL; 372 435 stest = toSymbolX("__modtest", SCglobal, t, moddeco); 373 436 374 437 block *b = block_calloc(); 375 438 b->BC = BCret; 376 439 b->Belem = etest; 377 440 stest->Sfunc->Fstartblock = b; 378 441 writefunc(stest); 379 442 } 380 443 381 444 if (doppelganger) 382 445 genmoduleinfo(); 383 446 } 384 447 385 448 if (doppelganger) 386 449 { 387 450 obj_termfile(); 388 451 return; 389 452 } 390 453 391 454 if (global.params.multiobj) 392 455 { /* This is necessary because the main .obj for this module is written 393 * first, but determining whether marray or massert are needed is done456 * first, but determining whether marray or massert or munittest are needed is done 394 457 * possibly later in the doppelganger modules. 395 458 * Another way to fix it is do the main one last. 396 459 */ 397 460 toModuleAssert(); 398 461 toModuleArray(); 399 462 } 400 463 401 464 #if 1 402 465 // If module assert 403 466 for (int i = 0; i < 2; i++) 404 467 { 405 Symbol *ma = i ? marray : massert; 468 Symbol *ma; 469 unsigned rt; 470 switch (i) 471 { 472 case 0: ma = marray; rt = RTLSYM_DARRAY; break; 473 case 1: ma = massert; rt = RTLSYM_DASSERT; break; 474 case 2: ma = munittest; rt = RTLSYM_DUNITTESTM; break; 475 default: assert(0); 476 } 406 477 407 478 if (ma) 408 479 { 409 480 elem *elinnum; 410 elem *efilename;411 481 412 482 localgot = NULL; 413 483 414 484 // Call dassert(filename, line) 415 485 // Get sole parameter, linnum 416 486 { 417 Symbol *sp; 418 419 sp = symbol_calloc("linnum"); 487 Symbol *sp = symbol_calloc("linnum"); 420 488 sp->Stype = type_fake(TYint); 421 489 sp->Stype->Tcount++; 422 490 sp->Sclass = SCfastpar; 423 491 sp->Spreg = AX; 424 492 sp->Sflags &= ~SFLspill; 425 493 sp->Sfl = FLpara; // FLauto? 426 494 cstate.CSpsymtab = &ma->Sfunc->Flocsym; 427 495 symbol_add(sp); 428 496 429 497 elinnum = el_var(sp); 430 498 } 431 499 432 e filename = toEmodulename();433 434 elem *e = el_var(rtlsym[ i ? RTLSYM_DARRAY : RTLSYM_DASSERT]);500 elem *efilename = toEmodulename(); 501 502 elem *e = el_var(rtlsym[rt]); 435 503 e = el_bin(OPcall, TYvoid, e, el_param(elinnum, efilename)); 436 504 437 505 block *b = block_calloc(); 438 506 b->BC = BCret; 439 507 b->Belem = e; 440 508 ma->Sfunc->Fstartblock = b; 441 509 ma->Sclass = SCglobal; 442 510 ma->Sfl = 0; 443 511 writefunc(ma); 444 512 } 445 513 } 446 514 #endif 447 515 448 516 #if 1 449 517 // Always generate module info, because of templates and -cov 450 518 if (1 || needModuleInfo()) 451 519 genmoduleinfo(); 452 520 #endif 453 521 454 522 obj_termfile(); 455 523 } 456 524 457 525 458 526 /* ================================================================== */ 459 527 460 528 void FuncDeclaration::toObjFile(int multiobj) 461 529 { 462 Symbol *s;463 func_t *f;464 530 Symbol *senter; 465 531 Symbol *sexit; 466 532 FuncDeclaration *func = this; 467 533 ClassDeclaration *cd = func->parent->isClassDeclaration(); 468 534 int reverse; 469 535 int i; 470 536 int has_arguments; 471 537 472 //printf("FuncDeclaration::toObjFile(%p, %s )\n", func, func->toChars());538 //printf("FuncDeclaration::toObjFile(%p, %s.%s)\n", func, parent->toChars(), func->toChars()); 473 539 #if 0 474 540 //printf("line = %d\n",func->getWhere() / LINEINC); 475 541 EEcontext *ee = env->getEEcontext(); 476 542 if (ee->EEcompile == 2) 477 543 { 478 544 if (ee->EElinnum < (func->getWhere() / LINEINC) || 479 545 ee->EElinnum > (func->endwhere / LINEINC) 480 546 ) 481 547 return; // don't compile this function 482 548 ee->EEfunc = func->toSymbol(); 483 549 } 484 550 #endif 485 551 486 552 if (multiobj && !isStaticDtorDeclaration() && !isStaticCtorDeclaration()) 487 553 { obj_append(this); 488 554 return; 489 555 } 490 556 491 557 if (semanticRun >= PASSobj) // if toObjFile() already run 492 558 return; 493 559 semanticRun = PASSobj; 494 560 495 561 if (!func->fbody) 496 562 { 497 563 return; 498 564 } 499 565 if (func->isUnitTestDeclaration() && !global.params.useUnitTests) 500 566 return; 501 567 502 568 if (global.params.verbose) 503 569 printf("function %s\n",func->toChars()); 504 570 505 s = func->toSymbol();506 f = s->Sfunc;571 Symbol *s = func->toSymbol(); 572 func_t *f = s->Sfunc; 507 573 508 574 #if TARGET_WINDOS 509 575 /* This is done so that the 'this' pointer on the stack is the same 510 576 * distance away from the function parameters, so that an overriding 511 577 * function can call the nested fdensure or fdrequire of its overridden function 512 578 * and the stack offsets are the same. 513 579 */ 514 580 if (isVirtual() && (fensure || frequire)) 515 581 f->Fflags3 |= Ffakeeh; 516 582 #endif 517 583 518 584 #if TARGET_OSX 519 585 s->Sclass = SCcomdat; 520 586 #else 521 587 s->Sclass = SCglobal; 522 588 #endif 523 589 for (Dsymbol *p = parent; p; p = p->parent) 524 590 { 525 591 if (p->isTemplateInstance()) 526 592 { … … 736 802 } 737 803 } 738 804 739 805 if (func->fbody) 740 806 { block *b; 741 807 Blockx bx; 742 808 Statement *sbody; 743 809 744 810 localgot = NULL; 745 811 746 812 sbody = func->fbody; 747 813 memset(&bx,0,sizeof(bx)); 748 814 bx.startblock = block_calloc(); 749 815 bx.curblock = bx.startblock; 750 816 bx.funcsym = s; 751 817 bx.scope_index = -1; 752 818 bx.classdec = cd; 753 819 bx.member = func; 754 820 bx.module = getModule(); 755 821 irs.blx = &bx; 822 #if DMDV2 823 buildClosure(&irs); 824 #endif 756 825 757 826 #if 0 758 827 if (func->isSynchronized()) 759 828 { 760 829 if (cd) 761 830 { elem *esync; 762 831 if (func->isStatic()) 763 832 { // monitor is in ClassInfo 764 833 esync = el_ptr(cd->toSymbol()); 765 834 } 766 835 else 767 836 { // 'this' is the monitor 768 837 esync = el_var(sthis); 769 838 } 770 839 771 840 if (func->isStatic() || sbody->usesEH() || 772 841 !(config.flags2 & CFG2seh)) 773 842 { // BUG: what if frequire or fensure uses EH? 774 843 775 844 sbody = new SynchronizedStatement(func->loc, esync, sbody); … … 809 878 bx.curblock->BC = BCret; 810 879 811 880 f->Fstartblock = bx.startblock; 812 881 // einit = el_combine(einit,bx.init); 813 882 814 883 if (isCtorDeclaration()) 815 884 { 816 885 assert(sthis); 817 886 for (b = f->Fstartblock; b; b = b->Bnext) 818 887 { 819 888 if (b->BC == BCret) 820 889 { 821 890 b->BC = BCretexp; 822 891 b->Belem = el_combine(b->Belem, el_var(sthis)); 823 892 } 824 893 } 825 894 } 826 895 } 827 896 828 897 // If static constructor 829 if (isStaticConstructor()) 898 #if DMDV2 899 if (isSharedStaticCtorDeclaration()) // must come first because it derives from StaticCtorDeclaration 900 { 901 elem *e = el_una(OPucall, TYvoid, el_var(s)); 902 esharedctor = el_combine(esharedctor, e); 903 } 904 else 905 #endif 906 if (isStaticCtorDeclaration()) 830 907 { 831 908 elem *e = el_una(OPucall, TYvoid, el_var(s)); 832 909 ector = el_combine(ector, e); 833 910 } 834 911 835 912 // If static destructor 836 if (isStaticDestructor()) 913 #if DMDV2 914 if (isSharedStaticDtorDeclaration()) // must come first because it derives from StaticDtorDeclaration 915 { 916 elem *e; 917 918 #if STATICCTOR 919 e = el_bin(OPcall, TYvoid, el_var(rtlsym[RTLSYM_FATEXIT]), el_ptr(s)); 920 esharedctor = el_combine(esharedctor, e); 921 shareddtorcount++; 922 #else 923 SharedStaticDtorDeclaration *f = isSharedStaticDtorDeclaration(); 924 assert(f); 925 if (f->vgate) 926 { /* Increment destructor's vgate at construction time 927 */ 928 esharedctorgates.push(f); 929 } 930 931 e = el_una(OPucall, TYvoid, el_var(s)); 932 eshareddtor = el_combine(e, eshareddtor); 933 #endif 934 } 935 else 936 #endif 937 if (isStaticDtorDeclaration()) 837 938 { 838 939 elem *e; 839 940 840 941 #if STATICCTOR 841 942 e = el_bin(OPcall, TYvoid, el_var(rtlsym[RTLSYM_FATEXIT]), el_ptr(s)); 842 943 ector = el_combine(ector, e); 843 944 dtorcount++; 844 945 #else 845 946 StaticDtorDeclaration *f = isStaticDtorDeclaration(); 846 947 assert(f); 847 948 if (f->vgate) 848 { /* Increment vgate at construction time949 { /* Increment destructor's vgate at construction time 849 950 */ 850 951 Symbol *s = f->vgate->toSymbol(); 851 952 e = el_var(s); 852 953 e = el_bin(OPaddass, TYint, e, el_long(TYint, 1)); 853 954 ector = el_combine(ector, e); 854 955 } 855 956 856 957 e = el_una(OPucall, TYvoid, el_var(s)); 857 958 edtor = el_combine(e, edtor); 858 959 #endif 859 960 } 860 961 861 962 // If unit test 862 963 if (isUnitTestDeclaration()) 863 964 { 864 965 elem *e = el_una(OPucall, TYvoid, el_var(s)); 865 966 etest = el_combine(etest, e); 866 967 } 867 968 868 969 if (global.errors) … … 923 1024 case Tcomplex80: t = TYcldouble; break; 924 1025 //case Tbit: t = TYuchar; break; 925 1026 case Tbool: t = TYbool; break; 926 1027 case Tchar: t = TYchar; break; 927 1028 #if TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_SOLARIS 928 1029 case Twchar: t = TYwchar_t; break; 929 1030 case Tdchar: t = TYdchar; break; 930 1031 #else 931 1032 case Twchar: t = TYwchar_t; break; 932 1033 case Tdchar: 933 1034 t = (global.params.symdebug == 1) ? TYdchar : TYulong; 934 1035 break; 935 1036 #endif 936 1037 937 1038 case Taarray: t = TYaarray; break; 938 1039 case Tclass: 939 1040 case Treference: 940 1041 case Tpointer: t = TYnptr; break; 941 1042 case Tdelegate: t = TYdelegate; break; 942 1043 case Tarray: t = TYdarray; break; 1044 #if SARRAYVALUE 1045 case Tsarray: t = TYstruct; break; 1046 #else 943 1047 case Tsarray: t = TYarray; break; 1048 #endif 944 1049 case Tstruct: t = TYstruct; break; 945 1050 946 1051 case Tenum: 947 1052 case Ttypedef: 948 1053 t = toBasetype()->totym(); 949 1054 break; 950 1055 951 1056 case Tident: 952 1057 case Ttypeof: 953 1058 #ifdef DEBUG 954 1059 printf("ty = %d, '%s'\n", ty, toChars()); 955 1060 #endif 956 1061 error(0, "forward reference of %s", toChars()); 957 1062 t = TYint; 958 1063 break; 959 1064 960 1065 default: 961 1066 #ifdef DEBUG 962 1067 printf("ty = %d, '%s'\n", ty, toChars()); 963 1068 halt(); 964 1069 #endif 965 1070 assert(0); 966 1071 } 967 1072 968 1073 #if DMDV2 969 1074 // Add modifiers 970 1075 switch (mod) 971 1076 { 972 1077 case 0: 973 1078 break; 974 1079 case MODconst: 1080 case MODwild: 975 1081 t |= mTYconst; 976 1082 break; 977 1083 case MODimmutable: 978 1084 t |= mTYimmutable; 979 1085 break; 980 1086 case MODshared: 981 1087 t |= mTYshared; 982 1088 break; 1089 case MODshared | MODwild: 983 1090 case MODshared | MODconst: 984 1091 t |= mTYshared | mTYconst; 985 1092 break; 986 1093 default: 987 1094 assert(0); 988 1095 } 989 1096 #endif 990 1097 991 1098 return t; 992 1099 } 993 1100 994 1101 unsigned TypeFunction::totym() 995 1102 { 996 1103 tym_t tyf; 997 1104 998 1105 //printf("TypeFunction::totym(), linkage = %d\n", linkage); 999 1106 switch (linkage) 1000 1107 { 1001 1108 case LINKwindows: 1002 1109 tyf = (varargs == 1) ? TYnfunc : TYnsfunc; branches/dmd-1.x/src/module.c
r583 r591 72 72 md = NULL; 73 73 errors = 0; 74 74 numlines = 0; 75 75 members = NULL; 76 76 isHtml = 0; 77 77 isDocFile = 0; 78 78 needmoduleinfo = 0; 79 79 #ifdef IN_GCC 80 80 strictlyneedmoduleinfo = 0; 81 81 #endif 82 82 selfimports = 0; 83 83 insearch = 0; 84 84 searchCacheIdent = NULL; 85 85 searchCacheSymbol = NULL; 86 86 searchCacheFlags = 0; 87 87 semanticstarted = 0; 88 88 semanticRun = 0; 89 89 decldefs = NULL; 90 90 vmoduleinfo = NULL; 91 91 massert = NULL; 92 munittest = NULL; 92 93 marray = NULL; 93 94 sictor = NULL; 94 95 sctor = NULL; 95 96 sdtor = NULL; 96 97 stest = NULL; 97 98 sfilename = NULL; 98 99 root = 0; 99 100 importedFrom = NULL; 100 101 srcfile = NULL; 101 102 docfile = NULL; 102 103 103 104 debuglevel = 0; 104 105 debugids = NULL; 105 106 debugidsNot = NULL; 106 107 versionlevel = 0; 107 108 versionids = NULL; 108 109 versionidsNot = NULL; 109 110 110 111 macrotable = NULL; 111 112 escapetable = NULL; branches/dmd-1.x/src/module.h
r428 r591 143 143 static void runDeferredSemantic(); 144 144 static void clearCache(); 145 145 int imports(Module *m); 146 146 147 147 // Back end 148 148 149 149 int doppelganger; // sub-module 150 150 Symbol *cov; // private uint[] __coverage; 151 151 unsigned *covb; // bit array of valid code line numbers 152 152 153 153 Symbol *sictor; // module order independent constructor 154 154 Symbol *sctor; // module constructor 155 155 Symbol *sdtor; // module destructor 156 156 Symbol *stest; // module unit test 157 157 158 158 Symbol *sfilename; // symbol for filename 159 159 160 160 Symbol *massert; // module assert function 161 161 Symbol *toModuleAssert(); // get module assert function 162 162 163 Symbol *munittest; // module unittest failure function 164 Symbol *toModuleUnittest(); // get module unittest failure function 165 163 166 Symbol *marray; // module array bounds function 164 167 Symbol *toModuleArray(); // get module array bounds function 165 168 166 169 167 170 static Symbol *gencritsec(); 168 171 elem *toEfilename(); 169 172 elem *toEmodulename(); 170 173 171 174 Symbol *toSymbol(); 172 175 void genmoduleinfo(); 173 176 174 177 Module *isModule() { return this; } 175 178 }; 176 179 177 180 178 181 struct ModuleDeclaration 179 182 { 180 183 Identifier *id; 181 184 Array *packages; // array of Identifier's representing packages 182 185 bool safe; trunk/src/declaration.h
r521 r591 728 728 DtorDeclaration *isDtorDeclaration() { return this; } 729 729 }; 730 730 731 731 struct StaticCtorDeclaration : FuncDeclaration 732 732 { 733 733 StaticCtorDeclaration(Loc loc, Loc endloc); 734 734 StaticCtorDeclaration(Loc loc, Loc endloc, const char *name); 735 735 Dsymbol *syntaxCopy(Dsymbol *); 736 736 void semantic(Scope *sc); 737 737 AggregateDeclaration *isThis(); 738 738 int isVirtual(); 739 739 int addPreInvariant(); 740 740 int addPostInvariant(); 741 741 void emitComment(Scope *sc); 742 742 void toJsonBuffer(OutBuffer *buf); 743 743 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 744 744 745 745 StaticCtorDeclaration *isStaticCtorDeclaration() { return this; } 746 746 }; 747 747 748 #if DMDV2 748 749 struct SharedStaticCtorDeclaration : StaticCtorDeclaration 749 750 { 750 751 SharedStaticCtorDeclaration(Loc loc, Loc endloc); 751 752 Dsymbol *syntaxCopy(Dsymbol *); 752 753 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 753 754 754 755 SharedStaticCtorDeclaration *isSharedStaticCtorDeclaration() { return this; } 755 756 }; 757 #endif 756 758 757 759 struct StaticDtorDeclaration : FuncDeclaration 758 760 { VarDeclaration *vgate; // 'gate' variable 759 761 760 762 StaticDtorDeclaration(Loc loc, Loc endloc); 761 763 StaticDtorDeclaration(Loc loc, Loc endloc, const char *name); 762 764 Dsymbol *syntaxCopy(Dsymbol *); 763 765 void semantic(Scope *sc); 764 766 AggregateDeclaration *isThis(); 765 767 int isVirtual(); 766 768 int addPreInvariant(); 767 769 int addPostInvariant(); 768 770 void emitComment(Scope *sc); 769 771 void toJsonBuffer(OutBuffer *buf); 770 772 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 771 773 772 774 StaticDtorDeclaration *isStaticDtorDeclaration() { return this; } 773 775 }; 774 776 777 #if DMDV2 775 778 struct SharedStaticDtorDeclaration : StaticDtorDeclaration 776 779 { 777 780 SharedStaticDtorDeclaration(Loc loc, Loc endloc); 778 781 Dsymbol *syntaxCopy(Dsymbol *); 779 782 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 780 783 781 784 SharedStaticDtorDeclaration *isSharedStaticDtorDeclaration() { return this; } 782 785 }; 786 #endif 783 787 784 788 struct InvariantDeclaration : FuncDeclaration 785 789 { 786 790 InvariantDeclaration(Loc loc, Loc endloc); 787 791 Dsymbol *syntaxCopy(Dsymbol *); 788 792 void semantic(Scope *sc); 789 793 int isVirtual(); 790 794 int addPreInvariant(); 791 795 int addPostInvariant(); 792 796 void emitComment(Scope *sc); 793 797 void toJsonBuffer(OutBuffer *buf); 794 798 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 795 799 796 800 InvariantDeclaration *isInvariantDeclaration() { return this; } 797 801 }; 798 802 799 803 struct UnitTestDeclaration : FuncDeclaration 800 804 { 801 805 UnitTestDeclaration(Loc loc, Loc endloc); 802 806 Dsymbol *syntaxCopy(Dsymbol *); trunk/src/glue.c
r455 r591 1 1 2 2 // Compiler implementation of the D programming language 3 // Copyright (c) 1999-20 09by Digital Mars3 // Copyright (c) 1999-2010 by Digital Mars 4 4 // All Rights Reserved 5 5 // written by Walter Bright 6 6 // http://www.digitalmars.com 7 7 8 8 #include <stdio.h> 9 9 #include <stddef.h> 10 10 #include <time.h> 11 11 #include <assert.h> 12 12 13 13 #if __sun&&__SVR4 14 14 #include <alloca.h> 15 15 #endif 16 16 17 17 #include "mars.h" 18 18 #include "module.h" 19 19 #include "mtype.h" 20 20 #include "declaration.h" 21 21 #include "statement.h" 22 22 #include "enum.h" 23 23 #include "aggregate.h" … … 339 339 t->Tnext = tsvoid; 340 340 tsvoid->Tcount++; 341 341 342 342 static char moddeco[] = "FZv"; 343 343 344 344 if (eictor) 345 345 { 346 346 localgot = ictorlocalgot; 347 347 348 348 block *b = block_calloc(); 349 349 b->BC = BCret; 350 350 b->Belem = eictor; 351 351 sictor->Sfunc->Fstartblock = b; 352 352 writefunc(sictor); 353 353 } 354 354 355 355 if (ector || ectorgates.dim) 356 356 { 357 357 localgot = NULL; 358 358 sctor = toSymbolX("__modctor", SCglobal, t, moddeco); 359 #if DMDV2 359 360 cstate.CSpsymtab = &sctor->Sfunc->Flocsym; 360 361 361 362 for (int i = 0; i < ectorgates.dim; i++) 362 363 { StaticDtorDeclaration *f = (StaticDtorDeclaration *)ectorgates.data[i]; 363 364 364 365 Symbol *s = f->vgate->toSymbol(); 365 366 elem *e = el_var(s); 366 367 e = el_bin(OPaddass, TYint, e, el_long(TYint, 1)); 367 368 ector = el_combine(ector, e); 368 369 } 370 #endif 369 371 370 372 block *b = block_calloc(); 371 373 b->BC = BCret; 372 374 b->Belem = ector; 373 375 sctor->Sfunc->Fstartblock = b; 374 376 writefunc(sctor); 375 377 #if STATICCTOR 376 378 obj_staticctor(sctor, dtorcount, 1); 377 379 #endif 378 380 } 379 381 380 382 if (edtor) 381 383 { 382 384 localgot = NULL; 383 385 sdtor = toSymbolX("__moddtor", SCglobal, t, moddeco); 384 386 385 387 block *b = block_calloc(); 386 388 b->BC = BCret; 387 389 b->Belem = edtor; 388 390 sdtor->Sfunc->Fstartblock = b; 389 391 writefunc(sdtor); 390 392 } 391 393 394 #if DMDV2 392 395 if (esharedctor || esharedctorgates.dim) 393 396 { 394 397 localgot = NULL; 395 398 ssharedctor = toSymbolX("__modsharedctor", SCglobal, t, moddeco); 396 399 cstate.CSpsymtab = &ssharedctor->Sfunc->Flocsym; 397 400 398 401 for (int i = 0; i < esharedctorgates.dim; i++) 399 402 { SharedStaticDtorDeclaration *f = (SharedStaticDtorDeclaration *)esharedctorgates.data[i]; 400 403 401 404 Symbol *s = f->vgate->toSymbol(); 402 405 elem *e = el_var(s); 403 406 e = el_bin(OPaddass, TYint, e, el_long(TYint, 1)); 404 407 esharedctor = el_combine(esharedctor, e); 405 408 } 406 409 407 410 block *b = block_calloc(); 408 411 b->BC = BCret; 409 412 b->Belem = esharedctor; 410 413 ssharedctor->Sfunc->Fstartblock = b; 411 414 writefunc(ssharedctor); 412 415 #if STATICCTOR 413 416 obj_staticctor(ssharedctor, shareddtorcount, 1); 414 417 #endif 415 418 } 416 419 417 420 if (eshareddtor) 418 421 { 419 422 localgot = NULL; 420 423 sshareddtor = toSymbolX("__modshareddtor", SCglobal, t, moddeco); 421 424 422 425 block *b = block_calloc(); 423 426 b->BC = BCret; 424 427 b->Belem = eshareddtor; 425 428 sshareddtor->Sfunc->Fstartblock = b; 426 429 writefunc(sshareddtor); 427 430 } 431 #endif 428 432 429 433 if (etest) 430 434 { 431 435 localgot = NULL; 432 436 stest = toSymbolX("__modtest", SCglobal, t, moddeco); 433 437 434 438 block *b = block_calloc(); 435 439 b->BC = BCret; 436 440 b->Belem = etest; 437 441 stest->Sfunc->Fstartblock = b; 438 442 writefunc(stest); 439 443 } 440 444 441 445 if (doppelganger) 442 446 genmoduleinfo(); 443 447 } 444 448 445 449 if (doppelganger) 446 450 { 447 451 obj_termfile(); … … 798 802 } 799 803 } 800 804 801 805 if (func->fbody) 802 806 { block *b; 803 807 Blockx bx; 804 808 Statement *sbody; 805 809 806 810 localgot = NULL; 807 811 808 812 sbody = func->fbody; 809 813 memset(&bx,0,sizeof(bx)); 810 814 bx.startblock = block_calloc(); 811 815 bx.curblock = bx.startblock; 812 816 bx.funcsym = s; 813 817 bx.scope_index = -1; 814 818 bx.classdec = cd; 815 819 bx.member = func; 816 820 bx.module = getModule(); 817 821 irs.blx = &bx; 818 822 #if DMDV2 819 823 buildClosure(&irs); 824 #endif 820 825 821 826 #if 0 822 827 if (func->isSynchronized()) 823 828 { 824 829 if (cd) 825 830 { elem *esync; 826 831 if (func->isStatic()) 827 832 { // monitor is in ClassInfo 828 833 esync = el_ptr(cd->toSymbol()); 829 834 } 830 835 else 831 836 { // 'this' is the monitor 832 837 esync = el_var(sthis); 833 838 } 834 839 835 840 if (func->isStatic() || sbody->usesEH() || 836 841 !(config.flags2 & CFG2seh)) 837 842 { // BUG: what if frequire or fensure uses EH? 838 843 839 844 sbody = new SynchronizedStatement(func->loc, esync, sbody); … … 873 878 bx.curblock->BC = BCret; 874 879 875 880 f->Fstartblock = bx.startblock; 876 881 // einit = el_combine(einit,bx.init); 877 882 878 883 if (isCtorDeclaration()) 879 884 { 880 885 assert(sthis); 881 886 for (b = f->Fstartblock; b; b = b->Bnext) 882 887 { 883 888 if (b->BC == BCret) 884 889 { 885 890 b->BC = BCretexp; 886 891 b->Belem = el_combine(b->Belem, el_var(sthis)); 887 892 } 888 893 } 889 894 } 890 895 } 891 896 892 897 // If static constructor 898 #if DMDV2 893 899 if (isSharedStaticCtorDeclaration()) // must come first because it derives from StaticCtorDeclaration 894 900 { 895 901 elem *e = el_una(OPucall, TYvoid, el_var(s)); 896 902 esharedctor = el_combine(esharedctor, e); 897 903 } 898 else if (isStaticCtorDeclaration()) 904 else 905 #endif 906 if (isStaticCtorDeclaration()) 899 907 { 900 908 elem *e = el_una(OPucall, TYvoid, el_var(s)); 901 909 ector = el_combine(ector, e); 902 910 } 903 911 904 912 // If static destructor 913 #if DMDV2 905 914 if (isSharedStaticDtorDeclaration()) // must come first because it derives from StaticDtorDeclaration 906 915 { 907 916 elem *e; 908 917 909 918 #if STATICCTOR 910 919 e = el_bin(OPcall, TYvoid, el_var(rtlsym[RTLSYM_FATEXIT]), el_ptr(s)); 911 920 esharedctor = el_combine(esharedctor, e); 912 921 shareddtorcount++; 913 922 #else 914 923 SharedStaticDtorDeclaration *f = isSharedStaticDtorDeclaration(); 915 924 assert(f); 916 925 if (f->vgate) 917 926 { /* Increment destructor's vgate at construction time 918 927 */ 919 928 esharedctorgates.push(f); 920 929 } 921 930 922 931 e = el_una(OPucall, TYvoid, el_var(s)); 923 932 eshareddtor = el_combine(e, eshareddtor); 924 933 #endif 925 934 } 926 else if (isStaticDtorDeclaration()) 935 else 936 #endif 937 if (isStaticDtorDeclaration()) 927 938 { 928 939 elem *e; 929 940 930 941 #if STATICCTOR 931 942 e = el_bin(OPcall, TYvoid, el_var(rtlsym[RTLSYM_FATEXIT]), el_ptr(s)); 932 943 ector = el_combine(ector, e); 933 944 dtorcount++; 934 945 #else 935 946 StaticDtorDeclaration *f = isStaticDtorDeclaration(); 936 947 assert(f); 937 948 if (f->vgate) 938 949 { /* Increment destructor's vgate at construction time 939 950 */ 940 951 ectorgates.push(f); 941 952 } 942 953 943 954 e = el_una(OPucall, TYvoid, el_var(s)); 944 955 edtor = el_combine(e, edtor); 945 956 #endif 946 957 }
