Changeset 235
- Timestamp:
- 11/04/09 07:24:58 (15 years ago)
- Files:
-
- trunk/src/declaration.c (modified) (1 diff)
- trunk/src/expression.c (modified) (1 diff)
- trunk/src/func.c (modified) (3 diffs)
- trunk/src/module.c (modified) (1 diff)
- trunk/src/mtype.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/declaration.c
r233 r235 1074 1074 /* Before calling the constructor, initialize 1075 1075 * variable with a bit copy of the default 1076 1076 * initializer 1077 1077 */ 1078 1078 Expression *e = new AssignExp(loc, new VarExp(loc, this), t->defaultInit(loc)); 1079 1079 e->op = TOKblit; 1080 1080 e->type = t; 1081 1081 ei->exp = new CommaExp(loc, e, ei->exp); 1082 1082 1083 1083 /* Replace __ctmp being constructed with e1 1084 1084 */ 1085 1085 dve->e1 = e1; 1086 1086 return; 1087 1087 } 1088 1088 } 1089 1089 } 1090 1090 } 1091 1091 #endif 1092 1092 if (!ei->exp->implicitConvTo(type)) 1093 1093 { 1094 Type *ti = ei->exp->type->toBasetype(); 1095 // Look for constructor first 1096 if (sd->ctor && 1097 /* Initializing with the same type is done differently 1098 */ 1099 !(ti->ty == Tstruct && t->toDsymbol(sc) == ti->toDsymbol(sc))) 1100 { 1101 // Rewrite as e1.ctor(arguments) 1102 Expression *ector = new DotIdExp(loc, e1, Id::ctor); 1103 ei->exp = new CallExp(loc, ector, ei->exp); 1104 } 1105 else 1094 1106 /* Look for opCall 1095 1107 * See bugzilla 2702 for more discussion 1096 1108 */ 1097 Type *ti = ei->exp->type->toBasetype();1098 1109 // Don't cast away invariant or mutability in initializer 1099 1110 if (search_function(sd, Id::call) && 1100 1111 /* Initializing with the same type is done differently 1101 1112 */ 1102 1113 !(ti->ty == Tstruct && t->toDsymbol(sc) == ti->toDsymbol(sc))) 1103 1114 { // Rewrite as e1.call(arguments) 1104 1115 Expression * eCall = new DotIdExp(loc, e1, Id::call); 1105 1116 ei->exp = new CallExp(loc, eCall, ei->exp); 1106 1117 } 1107 1118 } 1108 1119 } 1109 1120 ei->exp = new AssignExp(loc, e1, ei->exp); 1110 1121 ei->exp->op = op; 1111 1122 canassign++; 1112 1123 ei->exp = ei->exp->semantic(sc); 1113 1124 canassign--; 1114 1125 ei->exp->optimize(WANTvalue); 1115 1126 } 1116 1127 else 1117 1128 { trunk/src/expression.c
r233 r235 321 321 return fd; 322 322 323 323 Lno: 324 324 return NULL; // don't have 'this' available 325 325 } 326 326 327 327 328 328 /*************************************** 329 329 * Pull out any properties. 330 330 */ 331 331 332 332 Expression *resolveProperties(Scope *sc, Expression *e) 333 333 { 334 334 //printf("resolveProperties(%s)\n", e->toChars()); 335 335 if (e->type) 336 336 { 337 337 Type *t = e->type->toBasetype(); 338 338 339 339 if (t->ty == Tfunction || e->op == TOKoverloadset) 340 340 { 341 #if 0 342 if (t->ty == Tfunction && !((TypeFunction *)t)->isproperty) 343 error(e->loc, "not a property %s\n", e->toChars()); 344 #endif 341 345 e = new CallExp(e->loc, e); 342 346 e = e->semantic(sc); 343 347 } 344 348 345 349 /* Look for e being a lazy parameter; rewrite as delegate call 346 350 */ 347 351 else if (e->op == TOKvar) 348 352 { VarExp *ve = (VarExp *)e; 349 353 350 354 if (ve->var->storage_class & STClazy) 351 355 { 352 356 e = new CallExp(e->loc, e); 353 357 e = e->semantic(sc); 354 358 } 355 359 } 356 360 357 361 else if (e->op == TOKdotexp) 358 362 { 359 363 e->error("expression has no value"); 360 364 } trunk/src/func.c
r219 r235 2934 2934 Statement *s = new DeclarationStatement(0, v); 2935 2935 sa->push(s); 2936 2936 Expression *e = new IdentifierExp(0, id); 2937 2937 e = new AddAssignExp(0, e, new IntegerExp(1)); 2938 2938 e = new EqualExp(TOKnotequal, 0, e, new IntegerExp(1)); 2939 2939 s = new IfStatement(0, NULL, e, new ReturnStatement(0, NULL), NULL); 2940 2940 sa->push(s); 2941 2941 if (fbody) 2942 2942 sa->push(fbody); 2943 2943 fbody = new CompoundStatement(0, sa); 2944 2944 } 2945 2945 2946 2946 FuncDeclaration::semantic(sc); 2947 2947 2948 2948 // We're going to need ModuleInfo 2949 2949 Module *m = getModule(); 2950 2950 if (!m) 2951 2951 m = sc->module; 2952 2952 if (m) 2953 2953 { m->needmoduleinfo = 1; 2954 //printf("module1 %s needs moduleinfo\n", m->toChars()); 2954 2955 #ifdef IN_GCC 2955 2956 m->strictlyneedmoduleinfo = 1; 2956 2957 #endif 2957 2958 } 2958 2959 } 2959 2960 2960 2961 AggregateDeclaration *StaticCtorDeclaration::isThis() 2961 2962 { 2962 2963 return NULL; 2963 2964 } 2964 2965 2965 2966 int StaticCtorDeclaration::isStaticConstructor() 2966 2967 { 2967 2968 return TRUE; 2968 2969 } 2969 2970 2970 2971 int StaticCtorDeclaration::isVirtual() 2971 2972 { 2972 2973 return FALSE; 2973 2974 } … … 3043 3044 sa->push(s); 3044 3045 Expression *e = new IdentifierExp(0, id); 3045 3046 e = new AddAssignExp(0, e, new IntegerExp(-1)); 3046 3047 e = new EqualExp(TOKnotequal, 0, e, new IntegerExp(0)); 3047 3048 s = new IfStatement(0, NULL, e, new ReturnStatement(0, NULL), NULL); 3048 3049 sa->push(s); 3049 3050 if (fbody) 3050 3051 sa->push(fbody); 3051 3052 fbody = new CompoundStatement(0, sa); 3052 3053 vgate = v; 3053 3054 } 3054 3055 3055 3056 FuncDeclaration::semantic(sc); 3056 3057 3057 3058 // We're going to need ModuleInfo 3058 3059 Module *m = getModule(); 3059 3060 if (!m) 3060 3061 m = sc->module; 3061 3062 if (m) 3062 3063 { m->needmoduleinfo = 1; 3064 //printf("module2 %s needs moduleinfo\n", m->toChars()); 3063 3065 #ifdef IN_GCC 3064 3066 m->strictlyneedmoduleinfo = 1; 3065 3067 #endif 3066 3068 } 3067 3069 } 3068 3070 3069 3071 AggregateDeclaration *StaticDtorDeclaration::isThis() 3070 3072 { 3071 3073 return NULL; 3072 3074 } 3073 3075 3074 3076 int StaticDtorDeclaration::isStaticDestructor() 3075 3077 { 3076 3078 return TRUE; 3077 3079 } 3078 3080 3079 3081 int StaticDtorDeclaration::isVirtual() 3080 3082 { 3081 3083 return FALSE; 3082 3084 } … … 3195 3197 assert(!s); 3196 3198 utd = new UnitTestDeclaration(loc, endloc); 3197 3199 return FuncDeclaration::syntaxCopy(utd); 3198 3200 } 3199 3201 3200 3202 3201 3203 void UnitTestDeclaration::semantic(Scope *sc) 3202 3204 { 3203 3205 if (global.params.useUnitTests) 3204 3206 { 3205 3207 type = new TypeFunction(NULL, Type::tvoid, FALSE, LINKd); 3206 3208 Scope *sc2 = sc->push(); 3207 3209 sc2->linkage = LINKd; 3208 3210 FuncDeclaration::semantic(sc2); 3209 3211 sc2->pop(); 3210 3212 } 3211 3213 3212 3214 // We're going to need ModuleInfo even if the unit tests are not 3213 3215 // compiled in, because other modules may import this module and refer 3214 3216 // to this ModuleInfo. 3217 // (This doesn't make sense to me?) 3215 3218 Module *m = getModule(); 3216 3219 if (!m) 3217 3220 m = sc->module; 3218 3221 if (m) 3222 { 3223 //printf("module3 %s needs moduleinfo\n", m->toChars()); 3219 3224 m->needmoduleinfo = 1; 3225 } 3220 3226 } 3221 3227 3222 3228 AggregateDeclaration *UnitTestDeclaration::isThis() 3223 3229 { 3224 3230 return NULL; 3225 3231 } 3226 3232 3227 3233 int UnitTestDeclaration::isVirtual() 3228 3234 { 3229 3235 return FALSE; 3230 3236 } 3231 3237 3232 3238 int UnitTestDeclaration::addPreInvariant() 3233 3239 { 3234 3240 return FALSE; 3235 3241 } 3236 3242 3237 3243 int UnitTestDeclaration::addPostInvariant() 3238 3244 { 3239 3245 return FALSE; trunk/src/module.c
r205 r235 851 851 for (int i = 0; i < members->dim; i++) 852 852 { Dsymbol *s = (Dsymbol *)members->data[i]; 853 853 854 854 s->toCBuffer(&buf, &hgs); 855 855 } 856 856 857 857 // Transfer image to file 858 858 symfile->setbuffer(buf.data, buf.offset); 859 859 buf.data = NULL; 860 860 861 861 symfile->writev(); 862 862 } 863 863 864 864 /********************************** 865 865 * Determine if we need to generate an instance of ModuleInfo 866 866 * for this Module. 867 867 */ 868 868 869 869 int Module::needModuleInfo() 870 870 { 871 //printf("needModuleInfo() %s, %d, %d\n", toChars(), needmoduleinfo, global.params.cov); 871 872 return needmoduleinfo || global.params.cov; 872 873 } 873 874 874 875 Dsymbol *Module::search(Loc loc, Identifier *ident, int flags) 875 876 { 876 877 /* Since modules can be circularly referenced, 877 878 * need to stop infinite recursive searches. 878 879 * This is done with the cache. 879 880 */ 880 881 881 882 //printf("%s Module::search('%s', flags = %d) insearch = %d\n", toChars(), ident->toChars(), flags, insearch); 882 883 Dsymbol *s; 883 884 if (insearch) 884 885 s = NULL; 885 886 else if (searchCacheIdent == ident && searchCacheFlags == flags) 886 887 { 887 888 s = searchCacheSymbol; 888 889 //printf("%s Module::search('%s', flags = %d) insearch = %d searchCacheSymbol = %s\n", toChars(), ident->toChars(), flags, insearch, searchCacheSymbol ? searchCacheSymbol->toChars() : "null"); 889 890 } 890 891 else trunk/src/mtype.c
r233 r235 5105 5105 break; 5106 5106 } 5107 5107 sd = s->isStructDeclaration(); 5108 5108 if (sd) 5109 5109 { 5110 5110 if (exp->op == TOKsuper) 5111 5111 { 5112 5112 error(loc, "struct %s has no 'super'", sd->toChars()); 5113 5113 goto Lerr; 5114 5114 } 5115 5115 t = sd->type->pointerTo(); 5116 5116 break; 5117 5117 } 5118 5118 } 5119 5119 } 5120 5120 else 5121 5121 #endif 5122 5122 { 5123 5123 sc->intypeof++; 5124 5124 exp = exp->semantic(sc); 5125 //exp = resolveProperties(sc, exp); 5125 if (exp->type && exp->type->ty == Tfunction && 5126 ((TypeFunction *)exp->type)->isproperty) 5127 exp = resolveProperties(sc, exp); 5126 5128 sc->intypeof--; 5127 5129 if (exp->op == TOKtype) 5128 5130 { 5129 5131 error(loc, "argument %s to typeof is not an expression", exp->toChars()); 5130 5132 } 5131 5133 t = exp->type; 5132 5134 if (!t) 5133 5135 { 5134 5136 error(loc, "expression (%s) has no type", exp->toChars()); 5135 5137 goto Lerr; 5136 5138 } 5137 5139 if (t->ty == Ttypeof) 5138 5140 error(loc, "forward reference to %s", toChars()); 5139 5141 5140 5142 /* typeof should reflect the true type, 5141 5143 * not what 'auto' would have gotten us. 5142 5144 */ 5143 5145 //t = t->toHeadMutable(); 5144 5146 } 5145 5147 if (idents.dim)
