Changeset 230
- Timestamp:
- 11/01/09 04:09:34 (15 years ago)
- Files:
-
- branches/dmd-1.x/src/declaration.c (modified) (1 diff)
- branches/dmd-1.x/src/expression.c (modified) (1 diff)
- trunk/src/declaration.c (modified) (1 diff)
- trunk/src/expression.c (modified) (1 diff)
- trunk/src/mars.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/dmd-1.x/src/declaration.c
r215 r230 1090 1090 ei->exp = new CallExp(loc, eCall, ei->exp); 1091 1091 } 1092 1092 } 1093 1093 } 1094 1094 ei->exp = new AssignExp(loc, e1, ei->exp); 1095 1095 ei->exp->op = TOKconstruct; 1096 1096 canassign++; 1097 1097 ei->exp = ei->exp->semantic(sc); 1098 1098 canassign--; 1099 1099 ei->exp->optimize(WANTvalue); 1100 1100 } 1101 1101 else 1102 1102 { 1103 1103 init = init->semantic(sc, type); 1104 1104 if (fd && isConst() && !isStatic()) 1105 1105 { // Make it static 1106 1106 storage_class |= STCstatic; 1107 1107 } 1108 1108 } 1109 1109 } 1110 else if (isConst() || isFinal()) 1110 else if (isConst() || isFinal() || 1111 parent->isAggregateDeclaration()) 1111 1112 { 1112 1113 /* Because we may need the results of a const declaration in a 1113 1114 * subsequent type, such as an array dimension, before semantic2() 1114 1115 * gets ordinarily run, try to run semantic2() now. 1115 1116 * Ignore failure. 1116 1117 */ 1117 1118 1118 1119 if (!global.errors && !inferred) 1119 1120 { 1120 1121 unsigned errors = global.errors; 1121 1122 global.gag++; 1122 1123 //printf("+gag\n"); 1123 1124 Expression *e; 1124 1125 Initializer *i2 = init; 1125 1126 inuse++; 1126 1127 if (ei) 1127 1128 { 1128 1129 e = ei->exp->syntaxCopy(); 1129 1130 e = e->semantic(sc); 1130 1131 e = e->implicitCastTo(sc, type); branches/dmd-1.x/src/expression.c
r220 r230 3136 3136 3137 3137 elements->data[i] = (void *)e; 3138 3138 } 3139 3139 3140 3140 /* Fill out remainder of elements[] with default initializers for fields[] 3141 3141 */ 3142 3142 for (size_t i = elements->dim; i < sd->fields.dim; i++) 3143 3143 { Dsymbol *s = (Dsymbol *)sd->fields.data[i]; 3144 3144 VarDeclaration *v = s->isVarDeclaration(); 3145 3145 assert(v); 3146 3146 3147 3147 if (v->offset < offset) 3148 3148 { e = NULL; 3149 3149 sd->hasUnions = 1; 3150 3150 } 3151 3151 else 3152 3152 { 3153 3153 if (v->init) 3154 3154 { e = v->init->toExpression(); 3155 3155 if (!e) 3156 error("cannot make expression out of initializer for %s", v->toChars()); 3156 { error("cannot make expression out of initializer for %s", v->toChars()); 3157 e = new ErrorExp(); 3158 } 3159 else if (v->scope) 3160 { // Do deferred semantic anaylsis 3161 Initializer *i2 = v->init->syntaxCopy(); 3162 i2 = i2->semantic(v->scope, v->type); 3163 e = i2->toExpression(); 3164 v->scope = NULL; 3165 } 3157 3166 } 3158 3167 else 3159 3168 { e = v->type->defaultInit(); 3160 3169 e->loc = loc; 3161 3170 } 3162 3171 offset = v->offset + v->type->size(); 3163 3172 } 3164 3173 elements->push(e); 3165 3174 } 3166 3175 3167 3176 type = sd->type; 3168 3177 return this; 3169 3178 } 3170 3179 3171 3180 /************************************** 3172 3181 * Gets expression at offset of type. 3173 3182 * Returns NULL if not found. 3174 3183 */ 3175 3184 3176 3185 Expression *StructLiteralExp::getField(Type *type, unsigned offset) trunk/src/declaration.c
r225 r230 1097 1097 !(ti->ty == Tstruct && t->toDsymbol(sc) == ti->toDsymbol(sc))) 1098 1098 { // Rewrite as e1.call(arguments) 1099 1099 Expression * eCall = new DotIdExp(loc, e1, Id::call); 1100 1100 ei->exp = new CallExp(loc, eCall, ei->exp); 1101 1101 } 1102 1102 } 1103 1103 } 1104 1104 ei->exp = new AssignExp(loc, e1, ei->exp); 1105 1105 ei->exp->op = op; 1106 1106 canassign++; 1107 1107 ei->exp = ei->exp->semantic(sc); 1108 1108 canassign--; 1109 1109 ei->exp->optimize(WANTvalue); 1110 1110 } 1111 1111 else 1112 1112 { 1113 1113 init = init->semantic(sc, type); 1114 1114 } 1115 1115 } 1116 1116 else if (storage_class & (STCconst | STCimmutable | STCmanifest) || 1117 type->isConst() || type->isInvariant()) 1117 type->isConst() || type->isInvariant() || 1118 parent->isAggregateDeclaration()) 1118 1119 { 1119 1120 /* Because we may need the results of a const declaration in a 1120 1121 * subsequent type, such as an array dimension, before semantic2() 1121 1122 * gets ordinarily run, try to run semantic2() now. 1122 1123 * Ignore failure. 1123 1124 */ 1124 1125 1125 1126 if (!global.errors && !inferred) 1126 1127 { 1127 1128 unsigned errors = global.errors; 1128 1129 global.gag++; 1129 1130 //printf("+gag\n"); 1130 1131 Expression *e; 1131 1132 Initializer *i2 = init; 1132 1133 inuse++; 1133 1134 if (ei) 1134 1135 { 1135 1136 e = ei->exp->syntaxCopy(); 1136 1137 e = e->semantic(sc); 1137 1138 e = e->implicitCastTo(sc, type); trunk/src/expression.c
r223 r230 3258 3258 elements->data[i] = (void *)e; 3259 3259 } 3260 3260 3261 3261 /* Fill out remainder of elements[] with default initializers for fields[] 3262 3262 */ 3263 3263 for (size_t i = elements->dim; i < nfields; i++) 3264 3264 { Dsymbol *s = (Dsymbol *)sd->fields.data[i]; 3265 3265 VarDeclaration *v = s->isVarDeclaration(); 3266 3266 assert(v); 3267 3267 assert(!v->isThisDeclaration()); 3268 3268 3269 3269 if (v->offset < offset) 3270 3270 { e = NULL; 3271 3271 sd->hasUnions = 1; 3272 3272 } 3273 3273 else 3274 3274 { 3275 3275 if (v->init) 3276 3276 { e = v->init->toExpression(); 3277 3277 if (!e) 3278 error("cannot make expression out of initializer for %s", v->toChars()); 3278 { error("cannot make expression out of initializer for %s", v->toChars()); 3279 e = new ErrorExp(); 3280 } 3281 else if (v->scope) 3282 { // Do deferred semantic anaylsis 3283 Initializer *i2 = v->init->syntaxCopy(); 3284 i2 = i2->semantic(v->scope, v->type); 3285 e = i2->toExpression(); 3286 v->scope = NULL; 3287 } 3279 3288 } 3280 3289 else 3281 3290 { e = v->type->defaultInit(); 3282 3291 e->loc = loc; 3283 3292 } 3284 3293 offset = v->offset + v->type->size(); 3285 3294 } 3286 3295 elements->push(e); 3287 3296 } 3288 3297 3289 3298 type = sd->type; 3290 3299 return this; 3291 3300 } 3292 3301 3293 3302 /************************************** 3294 3303 * Gets expression at offset of type. 3295 3304 * Returns NULL if not found. 3296 3305 */ 3297 3306 3298 3307 Expression *StructLiteralExp::getField(Type *type, unsigned offset) trunk/src/mars.c
r214 r230 151 151 { 152 152 if (!global.gag) 153 153 { 154 154 char *p = loc.toChars(); 155 155 156 156 if (*p) 157 157 fprintf(stdmsg, "%s: ", p); 158 158 mem.free(p); 159 159 160 160 fprintf(stdmsg, "Error: "); 161 161 #if _MSC_VER 162 162 // MS doesn't recognize %zu format 163 163 OutBuffer tmp; 164 164 tmp.vprintf(format, ap); 165 165 fprintf(stdmsg, "%s", tmp.toChars()); 166 166 #else 167 167 vfprintf(stdmsg, format, ap); 168 168 #endif 169 169 fprintf(stdmsg, "\n"); 170 170 fflush(stdmsg); 171 //halt();171 halt(); 172 172 } 173 173 global.errors++; 174 174 } 175 175 176 176 /*************************************** 177 177 * Call this after printing out fatal error messages to clean up and exit 178 178 * the compiler. 179 179 */ 180 180 181 181 void fatal() 182 182 { 183 183 #if 0 184 184 halt(); 185 185 #endif 186 186 exit(EXIT_FAILURE); 187 187 } 188 188 189 189 /************************************** 190 190 * Try to stop forgetting to remove the breakpoints from 191 191 * release builds.
