Changeset 317
- Timestamp:
- 12/29/09 05:09:42 (15 years ago)
- Files:
-
- branches/dmd-1.x/src/enum.c (modified) (1 diff)
- branches/dmd-1.x/src/mtype.c (modified) (1 diff)
- trunk/src/mtype.c (modified) (1 diff)
- trunk/src/optimize.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/dmd-1.x/src/enum.c
r189 r317 38 38 t = memtype->syntaxCopy(); 39 39 40 40 EnumDeclaration *ed; 41 41 if (s) 42 42 { ed = (EnumDeclaration *)s; 43 43 ed->memtype = t; 44 44 } 45 45 else 46 46 ed = new EnumDeclaration(loc, ident, t); 47 47 ScopeDsymbol::syntaxCopy(ed); 48 48 return ed; 49 49 } 50 50 51 51 void EnumDeclaration::semantic(Scope *sc) 52 52 { int i; 53 53 uinteger_t number; 54 54 Type *t; 55 55 Scope *sce; 56 56 57 57 //printf("EnumDeclaration::semantic(sd = %p, '%s')\n", sc->scopesym, sc->scopesym->toChars()); 58 if (symtab) // if already done59 return;60 58 if (!memtype) 61 59 memtype = Type::tint32; 60 61 if (symtab) // if already done 62 { if (!scope) 63 return; // semantic() already completed 64 } 65 else 66 symtab = new DsymbolTable(); 67 68 Scope *scx = NULL; 69 if (scope) 70 { sc = scope; 71 scx = scope; // save so we don't make redundant copies 72 scope = NULL; 73 } 74 62 75 if (sc->stc & STCdeprecated) 63 76 isdeprecated = 1; 64 77 65 78 parent = sc->scopesym; 66 79 memtype = memtype->semantic(loc, sc); 67 80 68 81 /* Check to see if memtype is forward referenced 69 82 */ 70 83 if (memtype->ty == Tenum) 71 84 { EnumDeclaration *sym = (EnumDeclaration *)memtype->toDsymbol(sc); 72 85 if (!sym->memtype) 73 86 { 74 87 error("base enum %s is forward referenced", sym->toChars()); 75 88 memtype = Type::tint32; 76 89 } 77 90 } 78 91 79 92 if (!memtype->isintegral()) 80 93 { error("base type must be of integral type, not %s", memtype->toChars()); 81 94 memtype = Type::tint32; branches/dmd-1.x/src/mtype.c
r315 r317 3848 3848 unsigned TypeEnum::alignsize() 3849 3849 { 3850 3850 if (!sym->memtype) 3851 3851 { 3852 3852 #ifdef DEBUG 3853 3853 printf("1: "); 3854 3854 #endif 3855 3855 error(0, "enum %s is forward referenced", sym->toChars()); 3856 3856 return 4; 3857 3857 } 3858 3858 return sym->memtype->alignsize(); 3859 3859 } 3860 3860 3861 3861 Dsymbol *TypeEnum::toDsymbol(Scope *sc) 3862 3862 { 3863 3863 return sym; 3864 3864 } 3865 3865 3866 3866 Type *TypeEnum::toBasetype() 3867 3867 { 3868 if (sym->scope) 3869 { 3870 sym->semantic(NULL); // attempt to resolve forward reference 3871 } 3868 3872 if (!sym->memtype) 3869 3873 { 3870 3874 #ifdef DEBUG 3871 3875 printf("2: "); 3872 3876 #endif 3873 3877 error(sym->loc, "enum %s is forward referenced", sym->toChars()); 3874 3878 return terror; 3875 3879 } 3876 3880 return sym->memtype->toBasetype(); 3877 3881 } 3878 3882 3879 3883 void TypeEnum::toDecoBuffer(OutBuffer *buf) 3880 3884 { char *name; 3881 3885 3882 3886 name = sym->mangle(); 3883 3887 // if (name[0] == '_' && name[1] == 'D') 3884 3888 // name += 2; 3885 3889 buf->printf("%c%s", mangleChar[ty], name); 3886 3890 } 3887 3891 trunk/src/mtype.c
r312 r317 5966 5966 unsigned TypeEnum::alignsize() 5967 5967 { 5968 5968 if (!sym->memtype) 5969 5969 { 5970 5970 #ifdef DEBUG 5971 5971 printf("1: "); 5972 5972 #endif 5973 5973 error(0, "enum %s is forward referenced", sym->toChars()); 5974 5974 return 4; 5975 5975 } 5976 5976 return sym->memtype->alignsize(); 5977 5977 } 5978 5978 5979 5979 Dsymbol *TypeEnum::toDsymbol(Scope *sc) 5980 5980 { 5981 5981 return sym; 5982 5982 } 5983 5983 5984 5984 Type *TypeEnum::toBasetype() 5985 5985 { 5986 if (sym->scope) 5987 { 5988 sym->semantic(NULL); // attempt to resolve forward reference 5989 } 5986 5990 if (!sym->memtype) 5987 5991 { 5988 5992 #ifdef DEBUG 5989 5993 printf("2: "); 5990 5994 #endif 5991 5995 error(sym->loc, "enum %s is forward referenced", sym->toChars()); 5992 5996 return tint32; 5993 5997 } 5994 5998 return sym->memtype->toBasetype(); 5995 5999 } 5996 6000 5997 6001 void TypeEnum::toDecoBuffer(OutBuffer *buf, int flag) 5998 6002 { 5999 6003 const char *name = sym->mangle(); 6000 6004 Type::toDecoBuffer(buf, flag); 6001 6005 buf->printf("%s", name); 6002 6006 } 6003 6007 6004 6008 void TypeEnum::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod) 6005 6009 { trunk/src/optimize.c
r304 r317 813 813 } 814 814 815 815 Expression *EqualExp::optimize(int result) 816 816 { Expression *e; 817 817 818 818 //printf("EqualExp::optimize(result = %x) %s\n", result, toChars()); 819 819 e1 = e1->optimize(WANTvalue | (result & WANTinterpret)); 820 820 e2 = e2->optimize(WANTvalue | (result & WANTinterpret)); 821 821 e = this; 822 822 823 823 Expression *e1 = fromConstInitializer(result, this->e1); 824 824 Expression *e2 = fromConstInitializer(result, this->e2); 825 825 826 826 e = Equal(op, type, e1, e2); 827 827 if (e == EXP_CANT_INTERPRET) 828 828 e = this; 829 829 return e; 830 830 } 831 831 832 832 Expression *IdentityExp::optimize(int result) 833 { Expression *e; 834 833 { 835 834 //printf("IdentityExp::optimize(result = %d) %s\n", result, toChars()); 836 835 e1 = e1->optimize(WANTvalue | (result & WANTinterpret)); 837 836 e2 = e2->optimize(WANTvalue | (result & WANTinterpret)); 838 e = this;837 Expression *e = this; 839 838 840 839 if ((this->e1->isConst() && this->e2->isConst()) || 841 840 (this->e1->op == TOKnull && this->e2->op == TOKnull)) 842 841 { 843 842 e = Identity(op, type, this->e1, this->e2); 844 843 if (e == EXP_CANT_INTERPRET) 845 844 e = this; 846 845 } 847 846 return e; 848 847 } 849 848 850 849 Expression *IndexExp::optimize(int result) 851 850 { Expression *e; 852 851 853 852 //printf("IndexExp::optimize(result = %d) %s\n", result, toChars()); 854 853 Expression *e1 = this->e1->optimize(WANTvalue | (result & WANTinterpret)); 855 854 e1 = fromConstInitializer(result, e1); 856 855 if (this->e1->op == TOKvar) 857 856 { VarExp *ve = (VarExp *)this->e1; 858 857 if (ve->var->storage_class & STCmanifest)
