Changeset 583
- Timestamp:
- 07/24/10 05:22:54 (14 years ago)
- Files:
-
- branches/dmd-1.x/src/backend/cod3.c (modified) (3 diffs)
- branches/dmd-1.x/src/dsymbol.c (modified) (1 diff)
- branches/dmd-1.x/src/dsymbol.h (modified) (1 diff)
- branches/dmd-1.x/src/enum.c (modified) (1 diff)
- branches/dmd-1.x/src/enum.h (modified) (1 diff)
- branches/dmd-1.x/src/module.c (modified) (1 diff)
- trunk/src/backend/cod3.c (modified) (3 diffs)
- trunk/src/dsymbol.c (modified) (1 diff)
- trunk/src/dsymbol.h (modified) (1 diff)
- trunk/src/enum.c (modified) (1 diff)
- trunk/src/enum.h (modified) (1 diff)
- trunk/src/module.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/dmd-1.x/src/backend/cod3.c
r582 r583 2931 2931 #endif 2932 2932 2933 2933 if (b) 2934 2934 { bn = b->Bnext; 2935 2935 usespace = (config.flags4 & CFG4space && b->BC != BCasm); 2936 2936 useopsize = (I16 || (config.flags4 & CFG4space && b->BC != BCasm)); 2937 2937 } 2938 2938 else 2939 2939 { bn = NULL; 2940 2940 usespace = (config.flags4 & CFG4space); 2941 2941 useopsize = (I16 || config.flags4 & CFG4space); 2942 2942 } 2943 2943 for (; c; c = code_next(c)) 2944 2944 { 2945 2945 L1: 2946 2946 op = c->Iop; 2947 2947 if (op == 0x0F) 2948 2948 ins = inssize2[c->Iop2]; 2949 2949 else 2950 2950 ins = inssize[c->Iop]; 2951 if ( I32 &&ins & M) // if modregrm byte2951 if (ins & M) // if modregrm byte 2952 2952 { int shortop = (c->Iflags & CFopsize) ? !I16 : I16; 2953 2953 int local_BPRM = BPRM; 2954 2954 2955 2955 if (c->Iflags & CFaddrsize) 2956 2956 local_BPRM ^= 5 ^ 6; // toggle between 5 and 6 2957 2957 2958 2958 unsigned rm = c->Irm; 2959 2959 unsigned reg = rm & modregrm(0,7,0); // isolate reg field 2960 2960 unsigned ereg = rm & 7; 2961 2961 //printf("c = %p, op = %02x rm = %02x\n", c, op, rm); 2962 2962 2963 2963 /* If immediate second operand */ 2964 2964 if ((ins & T || op == 0xF6 || op == 0xF7) && 2965 2965 c->IFL2 == FLconst) 2966 2966 { 2967 2967 int flags = c->Iflags & CFpsw; /* if want result in flags */ 2968 2968 targ_long u = c->IEV2.Vuns; 2969 2969 if (ins & E) 2970 2970 u = (signed char) u; 2971 2971 else if (shortop) … … 3308 3308 case 5: rm = modregrm(3,0,DI); goto L6; 3309 3309 case 7: rm = modregrm(3,0,BX); goto L6; 3310 3310 L6: c->Irm = rm + reg; 3311 3311 c->Iop = 0x8B; 3312 3312 break; 3313 3313 } 3314 3314 } 3315 3315 } 3316 3316 3317 3317 /* replace LEA reg,0[BP] with MOV reg,BP */ 3318 3318 else if (mod == modregrm(1,0,0) && rm == local_BPRM && 3319 3319 c->IFL1 == FLconst && c->IEVpointer1 == 0) 3320 3320 { c->Iop = 0x8B; /* MOV reg,BP */ 3321 3321 c->Irm = modregrm(3,0,BP) + reg; 3322 3322 } 3323 3323 } 3324 3324 3325 3325 // Replace [R13] with 0[R13] 3326 3326 if (c->Irex & REX_B && (c->Irm & modregrm(3,0,5)) == modregrm(0,0,5)) 3327 3327 { 3328 printf("test1\n"); 3328 3329 c->Irm |= modregrm(1,0,0); 3329 3330 c->IFL1 = FLconst; 3330 3331 c->IEVpointer1 = 0; 3331 3332 } 3332 3333 } 3333 3334 else 3334 3335 { 3335 3336 switch (op) 3336 3337 { 3337 3338 default: 3338 3339 if ((op & 0xF0) != 0x70) 3339 3340 break; 3340 3341 case JMP: 3341 3342 switch (c->IFL2) 3342 3343 { case FLcode: 3343 3344 if (c->IEV2.Vcode == code_next(c)) 3344 3345 { c->Iop = NOP; 3345 3346 continue; 3346 3347 } 3347 3348 break; … … 3382 3383 } 3383 3384 } 3384 3385 } 3385 3386 #if 0 3386 3387 if (1 || debugc) { 3387 3388 printf("-pinholeopt(%p)\n",cstart); 3388 3389 for (c = cstart; c; c = code_next(c)) 3389 3390 c->print(); 3390 3391 } 3391 3392 #endif 3392 3393 } 3393 3394 3394 3395 #ifdef DEBUG 3395 3396 STATIC void pinholeopt_unittest() 3396 3397 { 3397 3398 //printf("pinholeopt_unittest()\n"); 3398 3399 struct CS { unsigned model,op,ea,ev1,ev2,flags; } tests[][2] = 3399 3400 { 3400 3401 // XOR reg,immed NOT regL 3401 3402 {{ 16,0x81,modregrm(3,6,BX),0,0xFF,0 }, { 0,0xF6,modregrm(3,2,BX),0,0xFF }}, 3403 3404 // MOV 0[BX],3 MOV [BX],3 3405 {{ 16,0xC7,modregrm(2,0,7),0,3}, { 0,0xC7,modregrm(0,0,7),0,3 }}, 3402 3406 3403 3407 #if 0 // only if config.flags4 & CFG4space 3404 3408 // TEST regL,immed8 3405 3409 {{ 0,0xF6,modregrm(3,0,BX),0,0xFF,0 }, { 0,0x84,modregrm(3,BX,BX),0,0xFF }}, 3406 3410 {{ 0,0xF7,modregrm(3,0,BX),0,0xFF,0 }, { 0,0x84,modregrm(3,BX,BX),0,0xFF }}, 3407 3411 {{ 64,0xF6,modregrmx(3,0,R8),0,0xFF,0 }, { 0,0x84,modregxrmx(3,R8,R8),0,0xFF }}, 3408 3412 {{ 64,0xF7,modregrmx(3,0,R8),0,0xFF,0 }, { 0,0x84,modregxrmx(3,R8,R8),0,0xFF }}, 3409 3413 #endif 3410 3414 3411 3415 // PUSH immed => PUSH immed8 3412 3416 {{ 0,0x68,0,0,0 }, { 0,0x6A,0,0,0 }}, 3413 3417 {{ 0,0x68,0,0,0x7F }, { 0,0x6A,0,0,0x7F }}, 3414 3418 {{ 0,0x68,0,0,0x80 }, { 0,0x68,0,0,0x80 }}, 3415 3419 {{ 16,0x68,0,0,0,CFopsize }, { 0,0x6A,0,0,0,CFopsize }}, 3416 3420 {{ 16,0x68,0,0,0x7F,CFopsize }, { 0,0x6A,0,0,0x7F,CFopsize }}, 3417 3421 {{ 16,0x68,0,0,0x80,CFopsize }, { 0,0x68,0,0,0x80,CFopsize }}, 3418 3422 {{ 16,0x68,0,0,0x10000,0 }, { 0,0x6A,0,0,0x10000,0 }}, 3419 3423 {{ 16,0x68,0,0,0x10000,CFopsize }, { 0,0x68,0,0,0x10000,CFopsize }}, 3420 3424 {{ 32,0x68,0,0,0,CFopsize }, { 0,0x6A,0,0,0,CFopsize }}, 3421 3425 {{ 32,0x68,0,0,0x7F,CFopsize }, { 0,0x6A,0,0,0x7F,CFopsize }}, branches/dmd-1.x/src/dsymbol.c
r510 r583 268 268 /************************************* 269 269 * Set scope for future semantic analysis so we can 270 270 * deal better with forward references. 271 271 */ 272 272 273 273 void Dsymbol::setScope(Scope *sc) 274 274 { 275 275 //printf("Dsymbol::setScope() %p %s\n", this, toChars()); 276 276 if (!sc->nofree) 277 277 sc->setNoFree(); // may need it even after semantic() finishes 278 278 scope = sc; 279 279 } 280 280 281 281 void Dsymbol::importAll(Scope *sc) 282 282 { 283 283 } 284 284 285 285 /************************************* 286 286 * Does semantic analysis on the public face of declarations. 287 287 */ 288 289 void Dsymbol::semantic0(Scope *sc) 290 { 291 } 288 292 289 293 void Dsymbol::semantic(Scope *sc) 290 294 { 291 295 error("%p has no semantic routine", this); 292 296 } 293 297 294 298 /************************************* 295 299 * Does semantic analysis on initializers and members of aggregates. 296 300 */ 297 301 298 302 void Dsymbol::semantic2(Scope *sc) 299 303 { 300 304 // Most Dsymbols have no further semantic analysis needed 301 305 } 302 306 303 307 /************************************* 304 308 * Does semantic analysis on function bodies. 305 309 */ 306 310 307 311 void Dsymbol::semantic3(Scope *sc) branches/dmd-1.x/src/dsymbol.h
r473 r583 126 126 int isAnonymous(); 127 127 void error(Loc loc, const char *format, ...); 128 128 void error(const char *format, ...); 129 129 void checkDeprecated(Loc loc, Scope *sc); 130 130 Module *getModule(); 131 131 Dsymbol *pastMixin(); 132 132 Dsymbol *toParent(); 133 133 Dsymbol *toParent2(); 134 134 TemplateInstance *inTemplateInstance(); 135 135 136 136 int dyncast() { return DYNCAST_DSYMBOL; } // kludge for template.isSymbol() 137 137 138 138 static Array *arraySyntaxCopy(Array *a); 139 139 140 140 virtual const char *toPrettyChars(); 141 141 virtual const char *kind(); 142 142 virtual Dsymbol *toAlias(); // resolve real symbol 143 143 virtual int addMember(Scope *sc, ScopeDsymbol *s, int memnum); 144 144 virtual void setScope(Scope *sc); 145 145 virtual void importAll(Scope *sc); 146 virtual void semantic0(Scope *sc); 146 147 virtual void semantic(Scope *sc); 147 148 virtual void semantic2(Scope *sc); 148 149 virtual void semantic3(Scope *sc); 149 150 virtual void inlineScan(); 150 151 virtual Dsymbol *search(Loc loc, Identifier *ident, int flags); 151 152 Dsymbol *search_correct(Identifier *id); 152 153 Dsymbol *searchX(Loc loc, Scope *sc, Identifier *id); 153 154 virtual int overloadInsert(Dsymbol *s); 154 155 #ifdef _DH 155 156 char *toHChars(); 156 157 virtual void toHBuffer(OutBuffer *buf, HdrGenState *hgs); 157 158 #endif 158 159 virtual void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 159 160 virtual void toDocBuffer(OutBuffer *buf); 160 161 virtual void toJsonBuffer(OutBuffer *buf); 161 162 virtual unsigned size(Loc loc); 162 163 virtual int isforwardRef(); 163 164 virtual void defineRef(Dsymbol *s); 164 165 virtual AggregateDeclaration *isThis(); // is a 'this' required to access the member 165 166 virtual ClassDeclaration *isClassMember(); // are we a member of a class? branches/dmd-1.x/src/enum.c
r428 r583 30 30 defaultval = 0; 31 31 sinit = NULL; 32 32 isdeprecated = 0; 33 33 } 34 34 35 35 Dsymbol *EnumDeclaration::syntaxCopy(Dsymbol *s) 36 36 { 37 37 Type *t = NULL; 38 38 if (memtype) 39 39 t = memtype->syntaxCopy(); 40 40 41 41 EnumDeclaration *ed; 42 42 if (s) 43 43 { ed = (EnumDeclaration *)s; 44 44 ed->memtype = t; 45 45 } 46 46 else 47 47 ed = new EnumDeclaration(loc, ident, t); 48 48 ScopeDsymbol::syntaxCopy(ed); 49 49 return ed; 50 } 51 52 void EnumDeclaration::semantic0(Scope *sc) 53 { 54 /* This function is a hack to get around a significant problem. 55 * The members of anonymous enums, like: 56 * enum { A, B, C } 57 * don't get installed into the symbol table until after they are 58 * semantically analyzed, yet they're supposed to go into the enclosing 59 * scope's table. Hence, when forward referenced, they come out as 60 * 'undefined'. The real fix is to add them in at addSymbol() time. 61 * But to get code to compile, we'll just do this quick hack at the moment 62 * to compile it if it doesn't depend on anything else. 63 */ 64 65 if (isdone || !scope) 66 return; 67 if (!isAnonymous() || memtype) 68 return; 69 for (int i = 0; i < members->dim; i++) 70 { 71 EnumMember *em = ((Dsymbol *)members->data[i])->isEnumMember(); 72 if (em && em->value) 73 return; 74 } 75 76 // Can do it 77 semantic(sc); 50 78 } 51 79 52 80 void EnumDeclaration::semantic(Scope *sc) 53 81 { int i; 54 82 uinteger_t number; 55 83 Type *t; 56 84 Scope *sce; 57 85 58 86 //printf("EnumDeclaration::semantic(sd = %p, '%s')\n", sc->scopesym, sc->scopesym->toChars()); 59 87 if (!memtype) 60 88 memtype = Type::tint32; 61 89 62 90 if (symtab) // if already done 63 91 { if (isdone || !scope) 64 92 return; // semantic() already completed 65 93 } 66 94 else 67 95 symtab = new DsymbolTable(); 68 96 69 97 Scope *scx = NULL; branches/dmd-1.x/src/enum.h
r428 r583 30 30 { /* enum ident : memtype { ... } 31 31 */ 32 32 Type *type; // the TypeEnum 33 33 Type *memtype; // type of the members 34 34 35 35 #if DMDV1 36 36 dinteger_t maxval; 37 37 dinteger_t minval; 38 38 dinteger_t defaultval; // default initializer 39 39 #else 40 40 Expression *maxval; 41 41 Expression *minval; 42 42 Expression *defaultval; // default initializer 43 43 #endif 44 44 int isdeprecated; 45 45 int isdone; // 0: not done 46 46 // 1: semantic() successfully completed 47 47 48 48 EnumDeclaration(Loc loc, Identifier *id, Type *memtype); 49 49 Dsymbol *syntaxCopy(Dsymbol *s); 50 void semantic0(Scope *sc); 50 51 void semantic(Scope *sc); 51 52 int oneMember(Dsymbol **ps); 52 53 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 53 54 Type *getType(); 54 55 const char *kind(); 55 56 #if DMDV2 56 57 Dsymbol *search(Loc, Identifier *ident, int flags); 57 58 #endif 58 59 int isDeprecated(); // is Dsymbol deprecated? 59 60 60 61 void emitComment(Scope *sc); 61 62 void toJsonBuffer(OutBuffer *buf); 62 63 void toDocBuffer(OutBuffer *buf); 63 64 64 65 EnumDeclaration *isEnumDeclaration() { return this; } 65 66 66 67 void toObjFile(int multiobj); // compile to .obj file 67 68 void toDebug(); 68 69 int cvMember(unsigned char *p); 69 70 branches/dmd-1.x/src/module.c
r569 r583 744 744 } 745 745 746 746 // Add all symbols into module's symbol table 747 747 symtab = new DsymbolTable(); 748 748 for (int i = 0; i < members->dim; i++) 749 749 { Dsymbol *s = (Dsymbol *)members->data[i]; 750 750 s->addMember(NULL, sc->scopesym, 1); 751 751 } 752 752 753 753 /* Set scope for the symbols so that if we forward reference 754 754 * a symbol, it can possibly be resolved on the spot. 755 755 * If this works out well, it can be extended to all modules 756 756 * before any semantic() on any of them. 757 757 */ 758 758 for (int i = 0; i < members->dim; i++) 759 759 { Dsymbol *s = (Dsymbol *)members->data[i]; 760 760 s->setScope(sc); 761 761 } 762 762 #endif 763 763 764 // Do semantic() on members that don't depend on others 765 for (int i = 0; i < members->dim; i++) 766 { Dsymbol *s = (Dsymbol *)members->data[i]; 767 768 //printf("\tModule('%s'): '%s'.semantic0()\n", toChars(), s->toChars()); 769 s->semantic0(sc); 770 } 771 764 772 // Pass 1 semantic routines: do public side of the definition 765 773 for (int i = 0; i < members->dim; i++) 766 774 { Dsymbol *s = (Dsymbol *)members->data[i]; 767 775 768 776 //printf("\tModule('%s'): '%s'.semantic()\n", toChars(), s->toChars()); 769 777 s->semantic(sc); 770 778 runDeferredSemantic(); 771 779 } 772 780 773 781 if (!scope) 774 782 { sc = sc->pop(); 775 783 sc->pop(); // 2 pops because Scope::createGlobal() created 2 776 784 } 777 785 semanticRun = semanticstarted; 778 786 //printf("-Module::semantic(this = %p, '%s'): parent = %p\n", this, toChars(), parent); 779 787 } 780 788 781 789 void Module::semantic2() 782 790 { int i; 783 791 trunk/src/backend/cod3.c
r582 r583 2931 2931 #endif 2932 2932 2933 2933 if (b) 2934 2934 { bn = b->Bnext; 2935 2935 usespace = (config.flags4 & CFG4space && b->BC != BCasm); 2936 2936 useopsize = (I16 || (config.flags4 & CFG4space && b->BC != BCasm)); 2937 2937 } 2938 2938 else 2939 2939 { bn = NULL; 2940 2940 usespace = (config.flags4 & CFG4space); 2941 2941 useopsize = (I16 || config.flags4 & CFG4space); 2942 2942 } 2943 2943 for (; c; c = code_next(c)) 2944 2944 { 2945 2945 L1: 2946 2946 op = c->Iop; 2947 2947 if (op == 0x0F) 2948 2948 ins = inssize2[c->Iop2]; 2949 2949 else 2950 2950 ins = inssize[c->Iop]; 2951 if ( I32 &&ins & M) // if modregrm byte2951 if (ins & M) // if modregrm byte 2952 2952 { int shortop = (c->Iflags & CFopsize) ? !I16 : I16; 2953 2953 int local_BPRM = BPRM; 2954 2954 2955 2955 if (c->Iflags & CFaddrsize) 2956 2956 local_BPRM ^= 5 ^ 6; // toggle between 5 and 6 2957 2957 2958 2958 unsigned rm = c->Irm; 2959 2959 unsigned reg = rm & modregrm(0,7,0); // isolate reg field 2960 2960 unsigned ereg = rm & 7; 2961 2961 //printf("c = %p, op = %02x rm = %02x\n", c, op, rm); 2962 2962 2963 2963 /* If immediate second operand */ 2964 2964 if ((ins & T || op == 0xF6 || op == 0xF7) && 2965 2965 c->IFL2 == FLconst) 2966 2966 { 2967 2967 int flags = c->Iflags & CFpsw; /* if want result in flags */ 2968 2968 targ_long u = c->IEV2.Vuns; 2969 2969 if (ins & E) 2970 2970 u = (signed char) u; 2971 2971 else if (shortop) … … 3308 3308 case 5: rm = modregrm(3,0,DI); goto L6; 3309 3309 case 7: rm = modregrm(3,0,BX); goto L6; 3310 3310 L6: c->Irm = rm + reg; 3311 3311 c->Iop = 0x8B; 3312 3312 break; 3313 3313 } 3314 3314 } 3315 3315 } 3316 3316 3317 3317 /* replace LEA reg,0[BP] with MOV reg,BP */ 3318 3318 else if (mod == modregrm(1,0,0) && rm == local_BPRM && 3319 3319 c->IFL1 == FLconst && c->IEVpointer1 == 0) 3320 3320 { c->Iop = 0x8B; /* MOV reg,BP */ 3321 3321 c->Irm = modregrm(3,0,BP) + reg; 3322 3322 } 3323 3323 } 3324 3324 3325 3325 // Replace [R13] with 0[R13] 3326 3326 if (c->Irex & REX_B && (c->Irm & modregrm(3,0,5)) == modregrm(0,0,5)) 3327 3327 { 3328 printf("test1\n"); 3328 3329 c->Irm |= modregrm(1,0,0); 3329 3330 c->IFL1 = FLconst; 3330 3331 c->IEVpointer1 = 0; 3331 3332 } 3332 3333 } 3333 3334 else 3334 3335 { 3335 3336 switch (op) 3336 3337 { 3337 3338 default: 3338 3339 if ((op & 0xF0) != 0x70) 3339 3340 break; 3340 3341 case JMP: 3341 3342 switch (c->IFL2) 3342 3343 { case FLcode: 3343 3344 if (c->IEV2.Vcode == code_next(c)) 3344 3345 { c->Iop = NOP; 3345 3346 continue; 3346 3347 } 3347 3348 break; … … 3382 3383 } 3383 3384 } 3384 3385 } 3385 3386 #if 0 3386 3387 if (1 || debugc) { 3387 3388 printf("-pinholeopt(%p)\n",cstart); 3388 3389 for (c = cstart; c; c = code_next(c)) 3389 3390 c->print(); 3390 3391 } 3391 3392 #endif 3392 3393 } 3393 3394 3394 3395 #ifdef DEBUG 3395 3396 STATIC void pinholeopt_unittest() 3396 3397 { 3397 3398 //printf("pinholeopt_unittest()\n"); 3398 3399 struct CS { unsigned model,op,ea,ev1,ev2,flags; } tests[][2] = 3399 3400 { 3400 3401 // XOR reg,immed NOT regL 3401 3402 {{ 16,0x81,modregrm(3,6,BX),0,0xFF,0 }, { 0,0xF6,modregrm(3,2,BX),0,0xFF }}, 3403 3404 // MOV 0[BX],3 MOV [BX],3 3405 {{ 16,0xC7,modregrm(2,0,7),0,3}, { 0,0xC7,modregrm(0,0,7),0,3 }}, 3402 3406 3403 3407 #if 0 // only if config.flags4 & CFG4space 3404 3408 // TEST regL,immed8 3405 3409 {{ 0,0xF6,modregrm(3,0,BX),0,0xFF,0 }, { 0,0x84,modregrm(3,BX,BX),0,0xFF }}, 3406 3410 {{ 0,0xF7,modregrm(3,0,BX),0,0xFF,0 }, { 0,0x84,modregrm(3,BX,BX),0,0xFF }}, 3407 3411 {{ 64,0xF6,modregrmx(3,0,R8),0,0xFF,0 }, { 0,0x84,modregxrmx(3,R8,R8),0,0xFF }}, 3408 3412 {{ 64,0xF7,modregrmx(3,0,R8),0,0xFF,0 }, { 0,0x84,modregxrmx(3,R8,R8),0,0xFF }}, 3409 3413 #endif 3410 3414 3411 3415 // PUSH immed => PUSH immed8 3412 3416 {{ 0,0x68,0,0,0 }, { 0,0x6A,0,0,0 }}, 3413 3417 {{ 0,0x68,0,0,0x7F }, { 0,0x6A,0,0,0x7F }}, 3414 3418 {{ 0,0x68,0,0,0x80 }, { 0,0x68,0,0,0x80 }}, 3415 3419 {{ 16,0x68,0,0,0,CFopsize }, { 0,0x6A,0,0,0,CFopsize }}, 3416 3420 {{ 16,0x68,0,0,0x7F,CFopsize }, { 0,0x6A,0,0,0x7F,CFopsize }}, 3417 3421 {{ 16,0x68,0,0,0x80,CFopsize }, { 0,0x68,0,0,0x80,CFopsize }}, 3418 3422 {{ 16,0x68,0,0,0x10000,0 }, { 0,0x6A,0,0,0x10000,0 }}, 3419 3423 {{ 16,0x68,0,0,0x10000,CFopsize }, { 0,0x68,0,0,0x10000,CFopsize }}, 3420 3424 {{ 32,0x68,0,0,0,CFopsize }, { 0,0x6A,0,0,0,CFopsize }}, 3421 3425 {{ 32,0x68,0,0,0x7F,CFopsize }, { 0,0x6A,0,0,0x7F,CFopsize }}, trunk/src/dsymbol.c
r510 r583 268 268 /************************************* 269 269 * Set scope for future semantic analysis so we can 270 270 * deal better with forward references. 271 271 */ 272 272 273 273 void Dsymbol::setScope(Scope *sc) 274 274 { 275 275 //printf("Dsymbol::setScope() %p %s\n", this, toChars()); 276 276 if (!sc->nofree) 277 277 sc->setNoFree(); // may need it even after semantic() finishes 278 278 scope = sc; 279 279 } 280 280 281 281 void Dsymbol::importAll(Scope *sc) 282 282 { 283 283 } 284 284 285 285 /************************************* 286 286 * Does semantic analysis on the public face of declarations. 287 287 */ 288 289 void Dsymbol::semantic0(Scope *sc) 290 { 291 } 288 292 289 293 void Dsymbol::semantic(Scope *sc) 290 294 { 291 295 error("%p has no semantic routine", this); 292 296 } 293 297 294 298 /************************************* 295 299 * Does semantic analysis on initializers and members of aggregates. 296 300 */ 297 301 298 302 void Dsymbol::semantic2(Scope *sc) 299 303 { 300 304 // Most Dsymbols have no further semantic analysis needed 301 305 } 302 306 303 307 /************************************* 304 308 * Does semantic analysis on function bodies. 305 309 */ 306 310 307 311 void Dsymbol::semantic3(Scope *sc) trunk/src/dsymbol.h
r473 r583 128 128 int isAnonymous(); 129 129 void error(Loc loc, const char *format, ...); 130 130 void error(const char *format, ...); 131 131 void checkDeprecated(Loc loc, Scope *sc); 132 132 Module *getModule(); 133 133 Dsymbol *pastMixin(); 134 134 Dsymbol *toParent(); 135 135 Dsymbol *toParent2(); 136 136 TemplateInstance *inTemplateInstance(); 137 137 138 138 int dyncast() { return DYNCAST_DSYMBOL; } // kludge for template.isSymbol() 139 139 140 140 static Dsymbols *arraySyntaxCopy(Dsymbols *a); 141 141 142 142 virtual const char *toPrettyChars(); 143 143 virtual const char *kind(); 144 144 virtual Dsymbol *toAlias(); // resolve real symbol 145 145 virtual int addMember(Scope *sc, ScopeDsymbol *s, int memnum); 146 146 virtual void setScope(Scope *sc); 147 147 virtual void importAll(Scope *sc); 148 virtual void semantic0(Scope *sc); 148 149 virtual void semantic(Scope *sc); 149 150 virtual void semantic2(Scope *sc); 150 151 virtual void semantic3(Scope *sc); 151 152 virtual void inlineScan(); 152 153 virtual Dsymbol *search(Loc loc, Identifier *ident, int flags); 153 154 Dsymbol *search_correct(Identifier *id); 154 155 Dsymbol *searchX(Loc loc, Scope *sc, Identifier *id); 155 156 virtual int overloadInsert(Dsymbol *s); 156 157 #ifdef _DH 157 158 char *toHChars(); 158 159 virtual void toHBuffer(OutBuffer *buf, HdrGenState *hgs); 159 160 #endif 160 161 virtual void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 161 162 virtual void toDocBuffer(OutBuffer *buf); 162 163 virtual void toJsonBuffer(OutBuffer *buf); 163 164 virtual unsigned size(Loc loc); 164 165 virtual int isforwardRef(); 165 166 virtual void defineRef(Dsymbol *s); 166 167 virtual AggregateDeclaration *isThis(); // is a 'this' required to access the member 167 168 virtual ClassDeclaration *isClassMember(); // are we a member of a class? trunk/src/enum.c
r428 r583 33 33 sinit = NULL; 34 34 isdeprecated = 0; 35 35 isdone = 0; 36 36 } 37 37 38 38 Dsymbol *EnumDeclaration::syntaxCopy(Dsymbol *s) 39 39 { 40 40 Type *t = NULL; 41 41 if (memtype) 42 42 t = memtype->syntaxCopy(); 43 43 44 44 EnumDeclaration *ed; 45 45 if (s) 46 46 { ed = (EnumDeclaration *)s; 47 47 ed->memtype = t; 48 48 } 49 49 else 50 50 ed = new EnumDeclaration(loc, ident, t); 51 51 ScopeDsymbol::syntaxCopy(ed); 52 52 return ed; 53 } 54 55 void EnumDeclaration::semantic0(Scope *sc) 56 { 57 /* This function is a hack to get around a significant problem. 58 * The members of anonymous enums, like: 59 * enum { A, B, C } 60 * don't get installed into the symbol table until after they are 61 * semantically analyzed, yet they're supposed to go into the enclosing 62 * scope's table. Hence, when forward referenced, they come out as 63 * 'undefined'. The real fix is to add them in at addSymbol() time. 64 * But to get code to compile, we'll just do this quick hack at the moment 65 * to compile it if it doesn't depend on anything else. 66 */ 67 68 if (isdone || !scope) 69 return; 70 if (!isAnonymous() || memtype) 71 return; 72 for (int i = 0; i < members->dim; i++) 73 { 74 EnumMember *em = ((Dsymbol *)members->data[i])->isEnumMember(); 75 if (em && (em->type || em->value)) 76 return; 77 } 78 79 // Can do it 80 semantic(sc); 53 81 } 54 82 55 83 void EnumDeclaration::semantic(Scope *sc) 56 84 { 57 85 Type *t; 58 86 Scope *sce; 59 87 60 88 //printf("EnumDeclaration::semantic(sd = %p, '%s') %s\n", sc->scopesym, sc->scopesym->toChars(), toChars()); 61 89 //printf("EnumDeclaration::semantic() %s\n", toChars()); 62 90 if (!members) // enum ident; 63 91 return; 64 92 65 93 if (!memtype && !isAnonymous()) 66 94 { // Set memtype if we can to reduce fwd reference errors 67 95 memtype = Type::tint32; // case 1) enum ident { ... } 68 96 } 69 97 70 98 if (symtab) // if already done 71 99 { if (isdone || !scope) 72 100 return; // semantic() already completed trunk/src/enum.h
r428 r583 30 30 { /* enum ident : memtype { ... } 31 31 */ 32 32 Type *type; // the TypeEnum 33 33 Type *memtype; // type of the members 34 34 35 35 #if DMDV1 36 36 dinteger_t maxval; 37 37 dinteger_t minval; 38 38 dinteger_t defaultval; // default initializer 39 39 #else 40 40 Expression *maxval; 41 41 Expression *minval; 42 42 Expression *defaultval; // default initializer 43 43 #endif 44 44 int isdeprecated; 45 45 int isdone; // 0: not done 46 46 // 1: semantic() successfully completed 47 47 48 48 EnumDeclaration(Loc loc, Identifier *id, Type *memtype); 49 49 Dsymbol *syntaxCopy(Dsymbol *s); 50 void semantic0(Scope *sc); 50 51 void semantic(Scope *sc); 51 52 int oneMember(Dsymbol **ps); 52 53 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 53 54 Type *getType(); 54 55 const char *kind(); 55 56 #if DMDV2 56 57 Dsymbol *search(Loc, Identifier *ident, int flags); 57 58 #endif 58 59 int isDeprecated(); // is Dsymbol deprecated? 59 60 60 61 void emitComment(Scope *sc); 61 62 void toJsonBuffer(OutBuffer *buf); 62 63 void toDocBuffer(OutBuffer *buf); 63 64 64 65 EnumDeclaration *isEnumDeclaration() { return this; } 65 66 66 67 void toObjFile(int multiobj); // compile to .obj file 67 68 void toDebug(); 68 69 int cvMember(unsigned char *p); 69 70 trunk/src/module.c
r569 r583 754 754 } 755 755 756 756 // Add all symbols into module's symbol table 757 757 symtab = new DsymbolTable(); 758 758 for (int i = 0; i < members->dim; i++) 759 759 { Dsymbol *s = (Dsymbol *)members->data[i]; 760 760 s->addMember(NULL, sc->scopesym, 1); 761 761 } 762 762 763 763 /* Set scope for the symbols so that if we forward reference 764 764 * a symbol, it can possibly be resolved on the spot. 765 765 * If this works out well, it can be extended to all modules 766 766 * before any semantic() on any of them. 767 767 */ 768 768 for (int i = 0; i < members->dim; i++) 769 769 { Dsymbol *s = (Dsymbol *)members->data[i]; 770 770 s->setScope(sc); 771 771 } 772 772 #endif 773 773 774 // Do semantic() on members that don't depend on others 775 for (int i = 0; i < members->dim; i++) 776 { Dsymbol *s = (Dsymbol *)members->data[i]; 777 778 //printf("\tModule('%s'): '%s'.semantic0()\n", toChars(), s->toChars()); 779 s->semantic0(sc); 780 } 781 774 782 // Pass 1 semantic routines: do public side of the definition 775 783 for (int i = 0; i < members->dim; i++) 776 784 { Dsymbol *s = (Dsymbol *)members->data[i]; 777 785 778 786 //printf("\tModule('%s'): '%s'.semantic()\n", toChars(), s->toChars()); 779 787 s->semantic(sc); 780 788 runDeferredSemantic(); 781 789 } 782 790 783 791 if (!scope) 784 792 { sc = sc->pop(); 785 793 sc->pop(); // 2 pops because Scope::createGlobal() created 2 786 794 } 787 795 semanticRun = semanticstarted; 788 796 //printf("-Module::semantic(this = %p, '%s'): parent = %p\n", this, toChars(), parent); 789 797 } 790 798 791 799 void Module::semantic2() 792 800 { int i; 793 801
