Changeset 222
- Timestamp:
- 10/28/09 18:27:01 (15 years ago)
- Files:
-
- trunk/src/attrib.c (modified) (1 diff)
- trunk/src/expression.c (modified) (2 diffs)
- trunk/src/mtype.c (modified) (1 diff)
- trunk/src/statement.c (modified) (1 diff)
- trunk/src/traits.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/attrib.c
r203 r222 877 877 sc->module->members->push(pragma); 878 878 } 879 879 } 880 880 #endif // TARGET_NET 881 881 } 882 882 883 883 void PragmaDeclaration::semantic(Scope *sc) 884 884 { // Should be merged with PragmaStatement 885 885 886 886 //printf("\tPragmaDeclaration::semantic '%s'\n",toChars()); 887 887 if (ident == Id::msg) 888 888 { 889 889 if (args) 890 890 { 891 891 for (size_t i = 0; i < args->dim; i++) 892 892 { 893 893 Expression *e = (Expression *)args->data[i]; 894 894 895 895 e = e->semantic(sc); 896 896 e = e->optimize(WANTvalue | WANTinterpret); 897 if (e->op == TOKstring) 898 { 899 StringExp *se = (StringExp *)e; 900 fprintf(stdmsg, "%.*s", (int)se->len, (char *)se->string); 901 } 902 else 903 error("string expected for message, not '%s'", e->toChars()); 897 fprintf(stdmsg, e->toChars()); 904 898 } 905 899 fprintf(stdmsg, "\n"); 906 900 } 907 901 goto Lnodecl; 908 902 } 909 903 else if (ident == Id::lib) 910 904 { 911 905 if (!args || args->dim != 1) 912 906 error("string expected for library name"); 913 907 else 914 908 { 915 909 Expression *e = (Expression *)args->data[0]; 916 910 917 911 e = e->semantic(sc); 918 912 e = e->optimize(WANTvalue | WANTinterpret); 919 913 args->data[0] = (void *)e; 920 914 if (e->op != TOKstring) 921 915 error("string expected for library name, not '%s'", e->toChars()); 922 916 else if (global.params.verbose) 923 917 { trunk/src/expression.c
r220 r222 1195 1195 { 1196 1196 // Default is 'yes' - do nothing 1197 1197 1198 1198 #ifdef DEBUG 1199 1199 if (!type) 1200 1200 dump(0); 1201 1201 #endif 1202 1202 1203 1203 if (!type->checkBoolean()) 1204 1204 { 1205 1205 error("expression %s of type %s does not have a boolean value", toChars(), type->toChars()); 1206 1206 } 1207 1207 return this; 1208 1208 } 1209 1209 1210 1210 /**************************** 1211 1211 */ 1212 1212 1213 1213 Expression *Expression::checkToPointer() 1214 1214 { 1215 Type *tb;1216 1217 1215 //printf("Expression::checkToPointer()\n"); 1218 1216 Expression *e = this; 1219 1217 1220 1218 #if !SARRAYVALUE 1221 1219 // If C static array, convert to pointer 1222 1220 Type *tb = type->toBasetype(); 1223 1221 if (tb->ty == Tsarray) 1224 1222 { TypeSArray *ts = (TypeSArray *)tb; 1225 1223 if (ts->size(loc) == 0) 1226 1224 e = new NullExp(loc); 1227 1225 else 1228 1226 e = new AddrExp(loc, this); 1229 1227 e->type = ts->next->pointerTo(); 1230 1228 } 1231 1229 #endif 1232 1230 return e; 1233 1231 } 1234 1232 1235 1233 /****************************** 1236 1234 * Take address of expression. … … 2803 2801 assert(0); 2804 2802 } 2805 2803 } 2806 2804 return len1 - len2; 2807 2805 } 2808 2806 2809 2807 int StringExp::isBool(int result) 2810 2808 { 2811 2809 return result ? TRUE : FALSE; 2812 2810 } 2813 2811 2814 2812 #if DMDV2 2815 2813 int StringExp::isLvalue() 2816 2814 { 2817 2815 return 1; 2818 2816 } 2819 2817 #endif 2820 2818 2821 2819 Expression *StringExp::toLvalue(Scope *sc, Expression *e) 2822 2820 { 2821 //printf("StringExp::toLvalue(%s)\n", toChars()); 2823 2822 return this; 2824 2823 } 2825 2824 2826 2825 unsigned StringExp::charAt(size_t i) 2827 2826 { unsigned value; 2828 2827 2829 2828 switch (sz) 2830 2829 { 2831 2830 case 1: 2832 2831 value = ((unsigned char *)string)[i]; 2833 2832 break; 2834 2833 2835 2834 case 2: 2836 2835 value = ((unsigned short *)string)[i]; 2837 2836 break; 2838 2837 2839 2838 case 4: 2840 2839 value = ((unsigned int *)string)[i]; 2841 2840 break; 2842 2841 trunk/src/mtype.c
r221 r222 4154 4154 { Argument *arg = Argument::getNth(tf->parameters, i); 4155 4155 4156 4156 tf->inuse++; 4157 4157 arg->type = arg->type->semantic(loc, argsc); 4158 4158 if (tf->inuse == 1) tf->inuse--; 4159 4159 4160 4160 arg->type = arg->type->addStorageClass(arg->storageClass); 4161 4161 4162 4162 if (arg->storageClass & (STCauto | STCalias | STCstatic)) 4163 4163 { 4164 4164 if (!arg->type) 4165 4165 continue; 4166 4166 } 4167 4167 4168 4168 Type *t = arg->type->toBasetype(); 4169 4169 4170 4170 if (arg->storageClass & (STCout | STCref | STClazy)) 4171 4171 { 4172 4172 //if (t->ty == Tsarray) 4173 4173 //error(loc, "cannot have out or ref parameter of type %s", t->toChars()); 4174 if (arg->storageClass & STCout && arg->type->mod )4175 error(loc, "cannot have const /invariantout parameter of type %s", t->toChars());4174 if (arg->storageClass & STCout && arg->type->mod & (STCconst | STCimmutable)) 4175 error(loc, "cannot have const or immutable out parameter of type %s", t->toChars()); 4176 4176 } 4177 4177 if (!(arg->storageClass & STClazy) && t->ty == Tvoid) 4178 4178 error(loc, "cannot have parameter of type %s", arg->type->toChars()); 4179 4179 4180 4180 if (arg->defaultArg) 4181 4181 { 4182 4182 arg->defaultArg = arg->defaultArg->semantic(argsc); 4183 4183 arg->defaultArg = resolveProperties(argsc, arg->defaultArg); 4184 4184 arg->defaultArg = arg->defaultArg->implicitCastTo(argsc, arg->type); 4185 4185 } 4186 4186 4187 4187 /* If arg turns out to be a tuple, the number of parameters may 4188 4188 * change. 4189 4189 */ 4190 4190 if (t->ty == Ttuple) 4191 4191 { dim = Argument::dim(tf->parameters); 4192 4192 i--; 4193 4193 } 4194 4194 } 4195 4195 argsc->pop(); trunk/src/statement.c
r221 r222 2478 2478 b = body->syntaxCopy(); 2479 2479 PragmaStatement *s = new PragmaStatement(loc, 2480 2480 ident, Expression::arraySyntaxCopy(args), b); 2481 2481 return s; 2482 2482 } 2483 2483 2484 2484 Statement *PragmaStatement::semantic(Scope *sc) 2485 2485 { // Should be merged with PragmaDeclaration 2486 2486 //printf("PragmaStatement::semantic() %s\n", toChars()); 2487 2487 //printf("body = %p\n", body); 2488 2488 if (ident == Id::msg) 2489 2489 { 2490 2490 if (args) 2491 2491 { 2492 2492 for (size_t i = 0; i < args->dim; i++) 2493 2493 { 2494 2494 Expression *e = (Expression *)args->data[i]; 2495 2495 2496 2496 e = e->semantic(sc); 2497 2497 e = e->optimize(WANTvalue | WANTinterpret); 2498 if (e->op == TOKstring) 2499 { 2500 StringExp *se = (StringExp *)e; 2501 fprintf(stdmsg, "%.*s", (int)se->len, (char*)se->string); 2502 } 2503 else 2504 error("string expected for message, not '%s'", e->toChars()); 2498 fprintf(stdmsg, e->toChars()); 2505 2499 } 2506 2500 fprintf(stdmsg, "\n"); 2507 2501 } 2508 2502 } 2509 2503 else if (ident == Id::lib) 2510 2504 { 2511 2505 #if 1 2512 2506 /* Should this be allowed? 2513 2507 */ 2514 2508 error("pragma(lib) not allowed as statement"); 2515 2509 #else 2516 2510 if (!args || args->dim != 1) 2517 2511 error("string expected for library name"); 2518 2512 else 2519 2513 { 2520 2514 Expression *e = (Expression *)args->data[0]; 2521 2515 2522 2516 e = e->semantic(sc); 2523 2517 e = e->optimize(WANTvalue | WANTinterpret); 2524 2518 args->data[0] = (void *)e; trunk/src/traits.c
r189 r222 323 323 324 324 for (size_t i = 0; i < dim; i++) 325 325 { Object *o = (Object *)args->data[i]; 326 326 Expression *e; 327 327 328 328 unsigned errors = global.errors; 329 329 global.gag++; 330 330 331 331 Type *t = isType(o); 332 332 if (t) 333 333 { Dsymbol *s; 334 334 t->resolve(loc, sc, &e, &t, &s); 335 335 if (t) 336 336 t->semantic(loc, sc); 337 337 else if (e) 338 338 e->semantic(sc); 339 339 } 340 340 else 341 341 { e = isExpression(o); 342 342 if (e) 343 e->semantic(sc); 343 { e->semantic(sc); 344 } 344 345 } 345 346 346 347 global.gag--; 347 348 if (errors != global.errors) 348 349 { if (global.gag == 0) 349 350 global.errors = errors; 350 351 goto Lfalse; 351 352 } 352 353 } 353 354 goto Ltrue; 354 355 } 355 356 else if (ident == Id::isSame) 356 357 { /* Determine if two symbols are the same 357 358 */ 358 359 if (dim != 2) 359 360 goto Ldimerror; 360 361 TemplateInstance::semanticTiargs(loc, sc, args, 0); 361 362 Object *o1 = (Object *)args->data[0]; 362 363 Object *o2 = (Object *)args->data[1]; 363 364 Dsymbol *s1 = getDsymbol(o1); 364 365 Dsymbol *s2 = getDsymbol(o2); 365 366 367 //printf("isSame: %s, %s\n", o1->toChars(), o2->toChars()); 366 368 #if 0 367 369 printf("o1: %p\n", o1); 368 370 printf("o2: %p\n", o2); 369 371 if (!s1) 370 372 { Expression *ea = isExpression(o1); 371 373 if (ea) 372 374 printf("%s\n", ea->toChars()); 373 375 Type *ta = isType(o1); 374 376 if (ta) 375 377 printf("%s\n", ta->toChars()); 376 378 goto Lfalse; 377 379 } 378 380 else 379 381 printf("%s %s\n", s1->kind(), s1->toChars()); 380 382 #endif 381 383 if (!s1 && !s2) 382 384 { Expression *ea1 = isExpression(o1); 383 385 Expression *ea2 = isExpression(o2); 384 if (ea1 && ea2 && ea1->equals(ea2)) 385 goto Ltrue; 386 if (ea1 && ea2) 387 { 388 if (ea1->equals(ea2)) 389 goto Ltrue; 390 } 386 391 } 387 392 388 393 if (!s1 || !s2) 389 394 goto Lfalse; 390 395 391 396 s1 = s1->toAlias(); 392 397 s2 = s2->toAlias(); 393 398 394 399 if (s1 == s2) 395 400 goto Ltrue; 396 401 else 397 402 goto Lfalse; 398 403 } 399 404 else 400 405 { error("unrecognized trait %s", ident->toChars()); 401 406 goto Lfalse; 402 407 } 403 408 404 409 return NULL; 405 410
