Changeset 315
- Timestamp:
- 12/29/09 01:22:33 (15 years ago)
- Files:
-
- branches/dmd-1.x/src/constfold.c (modified) (1 diff)
- branches/dmd-1.x/src/declaration.c (modified) (1 diff)
- branches/dmd-1.x/src/interpret.c (modified) (1 diff)
- branches/dmd-1.x/src/mars.h (modified) (1 diff)
- branches/dmd-1.x/src/mtype.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/dmd-1.x/src/constfold.c
r314 r315 1030 1030 } 1031 1031 e = new IntegerExp(loc, n, type); 1032 1032 return e; 1033 1033 } 1034 1034 1035 1035 /* Also returns EXP_CANT_INTERPRET if cannot be computed. 1036 1036 * to: type to cast to 1037 1037 * type: type to paint the result 1038 1038 */ 1039 1039 1040 1040 Expression *Cast(Type *type, Type *to, Expression *e1) 1041 1041 { Expression *e = EXP_CANT_INTERPRET; 1042 1042 Loc loc = e1->loc; 1043 1043 1044 1044 //printf("Cast(type = %s, to = %s, e1 = %s)\n", type->toChars(), to->toChars(), e1->toChars()); 1045 1045 //printf("e1->type = %s\n", e1->type->toChars()); 1046 1046 if (type->equals(e1->type) && to->equals(type)) 1047 1047 return e1; 1048 1048 1049 1049 Type *tb = to->toBasetype(); 1050 Type *typeb = type->toBasetype(); 1050 1051 1051 1052 /* Allow casting from one string type to another 1052 1053 */ 1053 1054 if (e1->op == TOKstring) 1054 1055 { 1055 Type *typeb = type->toBasetype();1056 1056 if (tb->ty == Tarray && typeb->ty == Tarray && 1057 1057 tb->nextOf()->size() == typeb->nextOf()->size()) 1058 1058 { 1059 1059 return expType(to, e1); 1060 1060 } 1061 1061 } 1062 1062 1063 if (e1->op == TOKarrayliteral && e1->type->toBasetype() == tb) 1063 if (e1->op == TOKarrayliteral && typeb == tb) 1064 { 1064 1065 return e1; 1066 } 1065 1067 1066 1068 if (e1->isConst() != 1) 1069 { 1067 1070 return EXP_CANT_INTERPRET; 1071 } 1068 1072 1069 1073 if (tb->ty == Tbool) 1070 1074 e = new IntegerExp(loc, e1->toInteger() != 0, type); 1071 1075 else if (type->isintegral()) 1072 1076 { 1073 1077 if (e1->type->isfloating()) 1074 1078 { dinteger_t result; 1075 1079 real_t r = e1->toReal(); 1076 1080 1077 1081 switch (type->toBasetype()->ty) 1078 1082 { 1079 1083 case Tint8: result = (d_int8)r; break; 1080 1084 case Tchar: 1081 1085 case Tuns8: result = (d_uns8)r; break; 1082 1086 case Tint16: result = (d_int16)r; break; 1083 1087 case Twchar: 1084 1088 case Tuns16: result = (d_uns16)r; break; 1085 1089 case Tint32: result = (d_int32)r; break; 1086 1090 case Tdchar: 1087 1091 case Tuns32: result = (d_uns32)r; break; branches/dmd-1.x/src/declaration.c
r314 r315 1294 1294 if (fdv && fdthis) 1295 1295 { 1296 1296 if (loc.filename) 1297 1297 fdthis->getLevel(loc, fdv); 1298 1298 nestedref = 1; 1299 1299 fdv->nestedFrameRef = 1; 1300 1300 //printf("var %s in function %s is nested ref\n", toChars(), fdv->toChars()); 1301 1301 } 1302 1302 } 1303 1303 } 1304 1304 1305 1305 /******************************* 1306 1306 * Does symbol go into data segment? 1307 1307 * Includes extern variables. 1308 1308 */ 1309 1309 1310 1310 int VarDeclaration::isDataseg() 1311 1311 { 1312 1312 #if 0 1313 1313 printf("VarDeclaration::isDataseg(%p, '%s')\n", this, toChars()); 1314 printf("% x, %p, %p\n", storage_class & (STCstatic | STCconst), parent->isModule(), parent->isTemplateInstance());1314 printf("%llx, %p, %p\n", storage_class & (STCstatic | STCconst), parent->isModule(), parent->isTemplateInstance()); 1315 1315 printf("parent = '%s'\n", parent->toChars()); 1316 1316 #endif 1317 1317 Dsymbol *parent = this->toParent(); 1318 1318 if (!parent && !(storage_class & (STCstatic | STCconst))) 1319 1319 { error("forward referenced"); 1320 1320 type = Type::terror; 1321 1321 return 0; 1322 1322 } 1323 1323 return (storage_class & (STCstatic | STCconst) || 1324 1324 parent->isModule() || 1325 1325 parent->isTemplateInstance()); 1326 1326 } 1327 1327 1328 1328 /************************************ 1329 1329 * Does symbol go into thread local storage? 1330 1330 */ 1331 1331 1332 1332 int VarDeclaration::isThreadlocal() 1333 1333 { 1334 1334 return 0; 1335 1335 } 1336 1336 1337 1337 /******************************************** 1338 1338 * Can variable be read and written by CTFE? 1339 1339 */ 1340 1340 1341 1341 int VarDeclaration::isCTFE() 1342 1342 { 1343 //printf("VarDeclaration::isCTFE(%p, '%s')\n", this, toChars()); 1344 //printf("%llx\n", storage_class); 1343 1345 return (storage_class & STCctfe) || !isDataseg(); 1344 1346 } 1345 1347 1346 1348 int VarDeclaration::hasPointers() 1347 1349 { 1348 1350 //printf("VarDeclaration::hasPointers() %s, ty = %d\n", toChars(), type->ty); 1349 1351 return (!isDataseg() && type->hasPointers()); 1350 1352 } 1351 1353 1352 1354 /****************************************** 1353 1355 * If a variable has an auto destructor call, return call for it. 1354 1356 * Otherwise, return NULL. 1355 1357 */ 1356 1358 1357 1359 Expression *VarDeclaration::callAutoDtor(Scope *sc) 1358 1360 { Expression *e = NULL; 1359 1361 1360 1362 //printf("VarDeclaration::callAutoDtor() %s\n", toChars()); 1361 1363 if (storage_class & (STCauto | STCscope) && !noauto) 1362 1364 { branches/dmd-1.x/src/interpret.c
r314 r315 1140 1140 te->type = new TypeTuple(te->exps); 1141 1141 return te; 1142 1142 } 1143 1143 return this; 1144 1144 } 1145 1145 1146 1146 Expression *ArrayLiteralExp::interpret(InterState *istate) 1147 1147 { Expressions *expsx = NULL; 1148 1148 1149 1149 #if LOG 1150 1150 printf("ArrayLiteralExp::interpret() %s\n", toChars()); 1151 1151 #endif 1152 1152 if (elements) 1153 1153 { 1154 1154 for (size_t i = 0; i < elements->dim; i++) 1155 1155 { Expression *e = (Expression *)elements->data[i]; 1156 1156 Expression *ex; 1157 1157 1158 1158 ex = e->interpret(istate); 1159 1159 if (ex == EXP_CANT_INTERPRET) 1160 { delete expsx; 1161 return EXP_CANT_INTERPRET; 1162 } 1160 goto Lerror; 1163 1161 1164 1162 /* If any changes, do Copy On Write 1165 1163 */ 1166 1164 if (ex != e) 1167 1165 { 1168 1166 if (!expsx) 1169 1167 { expsx = new Expressions(); 1170 1168 expsx->setDim(elements->dim); 1171 1169 for (size_t j = 0; j < elements->dim; j++) 1172 1170 { 1173 1171 expsx->data[j] = elements->data[j]; 1174 1172 } 1175 1173 } 1176 1174 expsx->data[i] = (void *)ex; 1177 1175 } 1178 1176 } 1179 1177 } 1180 1178 if (elements && expsx) 1181 1179 { 1182 1180 expandTuples(expsx); 1183 1181 if (expsx->dim != elements->dim) 1184 { delete expsx; 1185 return EXP_CANT_INTERPRET; 1186 } 1182 goto Lerror; 1187 1183 ArrayLiteralExp *ae = new ArrayLiteralExp(loc, expsx); 1188 1184 ae->type = type; 1189 1185 return ae; 1190 1186 } 1191 1187 return this; 1188 1189 Lerror: 1190 if (expsx) 1191 delete expsx; 1192 error("cannot interpret array literal"); 1193 return EXP_CANT_INTERPRET; 1192 1194 } 1193 1195 1194 1196 Expression *AssocArrayLiteralExp::interpret(InterState *istate) 1195 1197 { Expressions *keysx = keys; 1196 1198 Expressions *valuesx = values; 1197 1199 1198 1200 #if LOG 1199 1201 printf("AssocArrayLiteralExp::interpret() %s\n", toChars()); 1200 1202 #endif 1201 1203 for (size_t i = 0; i < keys->dim; i++) 1202 1204 { Expression *ekey = (Expression *)keys->data[i]; 1203 1205 Expression *evalue = (Expression *)values->data[i]; 1204 1206 Expression *ex; 1205 1207 1206 1208 ex = ekey->interpret(istate); 1207 1209 if (ex == EXP_CANT_INTERPRET) 1208 1210 goto Lerr; 1209 1211 1210 1212 /* If any changes, do Copy On Write 1211 1213 */ branches/dmd-1.x/src/mars.h
r243 r315 347 347 enum DYNCAST 348 348 { 349 349 DYNCAST_OBJECT, 350 350 DYNCAST_EXPRESSION, 351 351 DYNCAST_DSYMBOL, 352 352 DYNCAST_TYPE, 353 353 DYNCAST_IDENTIFIER, 354 354 DYNCAST_TUPLE, 355 355 }; 356 356 357 357 enum MATCH 358 358 { 359 359 MATCHnomatch, // no match 360 360 MATCHconvert, // match with conversions 361 361 #if DMDV2 362 362 MATCHconst, // match with conversion to const 363 363 #endif 364 364 MATCHexact // exact match 365 365 }; 366 366 367 typedef u nsignedStorageClass;367 typedef uint64_t StorageClass; 368 368 369 369 370 370 void warning(Loc loc, const char *format, ...); 371 371 void error(Loc loc, const char *format, ...); 372 372 void verror(Loc loc, const char *format, va_list); 373 373 void fatal(); 374 374 void err_nomem(); 375 375 int runLINK(); 376 376 void deleteExeFile(); 377 377 int runProgram(); 378 378 void inifile(const char *argv0, const char *inifile); 379 379 void halt(); 380 380 void util_progress(); 381 381 382 382 /*** Where to send error messages ***/ 383 383 #if IN_GCC 384 384 #define stdmsg stderr 385 385 #else 386 386 #define stdmsg stderr 387 387 #endif branches/dmd-1.x/src/mtype.c
r304 r315 5207 5207 { 5208 5208 Ldefault: 5209 5209 Type::resolve(loc, sc, pe, pt, ps); 5210 5210 } 5211 5211 } 5212 5212 5213 5213 void TypeSlice::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod) 5214 5214 { 5215 5215 if (mod != this->mod) 5216 5216 { toCBuffer3(buf, hgs, mod); 5217 5217 return; 5218 5218 } 5219 5219 next->toCBuffer2(buf, hgs, this->mod); 5220 5220 5221 5221 buf->printf("[%s .. ", lwr->toChars()); 5222 5222 buf->printf("%s]", upr->toChars()); 5223 5223 } 5224 5224 5225 5225 /***************************** Parameter *****************************/ 5226 5226 5227 Parameter::Parameter( unsignedstorageClass, Type *type, Identifier *ident, Expression *defaultArg)5227 Parameter::Parameter(StorageClass storageClass, Type *type, Identifier *ident, Expression *defaultArg) 5228 5228 { 5229 5229 this->type = type; 5230 5230 this->ident = ident; 5231 5231 this->storageClass = storageClass; 5232 5232 this->defaultArg = defaultArg; 5233 5233 } 5234 5234 5235 5235 Parameter *Parameter::syntaxCopy() 5236 5236 { 5237 5237 Parameter *a = new Parameter(storageClass, 5238 5238 type ? type->syntaxCopy() : NULL, 5239 5239 ident, 5240 5240 defaultArg ? defaultArg->syntaxCopy() : NULL); 5241 5241 return a; 5242 5242 } 5243 5243 5244 5244 Parameters *Parameter::arraySyntaxCopy(Parameters *args) 5245 5245 { Parameters *a = NULL; 5246 5246 5247 5247 if (args)
