Changeset 460
- Timestamp:
- 04/12/07 18:54:52 (1 year ago)
- Files:
-
- branches/dmdfe/arraytypes.h (modified) (2 diffs)
- branches/dmdfe/declaration.c (modified) (1 diff)
- branches/dmdfe/delegatize.c (modified) (1 diff)
- branches/dmdfe/expression.c (modified) (2 diffs)
- branches/dmdfe/expression.h (modified) (1 diff)
- branches/dmdfe/init.c (modified) (1 diff)
- branches/dmdfe/init.h (modified) (5 diffs)
- branches/dmdfe/inline.c (modified) (3 diffs)
- branches/dmdfe/interpret.c (modified) (1 diff)
- branches/dmdfe/lexer.c (modified) (1 diff)
- branches/dmdfe/lexer.h (modified) (2 diffs)
- branches/dmdfe/mangle.c (modified) (4 diffs)
- branches/dmdfe/mars.c (modified) (3 diffs)
- branches/dmdfe/optimize.c (modified) (1 diff)
- branches/dmdfe/template.c (modified) (7 diffs)
- branches/dmdfe/template.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/dmdfe/arraytypes.h
r458 r460 24 24 struct TemplateParameter; 25 25 struct FuncDeclaration; 26 struct Identifier; 27 struct Initializer; 26 28 27 29 struct TemplateParameters : Array { }; … … 43 45 struct Arguments : Array { }; 44 46 47 struct Identifiers : Array { }; 48 49 struct Initializers : Array { }; 50 45 51 #endif branches/dmdfe/declaration.c
r458 r460 692 692 storage_class = (storage_class & ~STCconst) | STCctorinit; 693 693 694 if (isConst() || isFinal())694 if (isConst()) 695 695 { 696 696 } branches/dmdfe/delegatize.c
r458 r460 178 178 179 179 180 void AssocArrayLiteralExp::scanForNestedRef(Scope *sc) 181 { 182 arrayExpressionScanForNestedRef(sc, keys); 183 arrayExpressionScanForNestedRef(sc, values); 184 } 185 186 180 187 void TupleExp::scanForNestedRef(Scope *sc) 181 188 { branches/dmdfe/expression.c
r458 r460 2512 2512 { Expression *e = (Expression *)elements->data[i]; 2513 2513 e->toMangleBuffer(buf); 2514 } 2515 } 2516 2517 /************************ AssocArrayLiteralExp ************************************/ 2518 2519 // [ key0 : value0, key1 : value1, ... ] 2520 2521 AssocArrayLiteralExp::AssocArrayLiteralExp(Loc loc, 2522 Expressions *keys, Expressions *values) 2523 : Expression(loc, TOKassocarrayliteral, sizeof(AssocArrayLiteralExp)) 2524 { 2525 assert(keys->dim == values->dim); 2526 this->keys = keys; 2527 this->values = values; 2528 } 2529 2530 Expression *AssocArrayLiteralExp::syntaxCopy() 2531 { 2532 return new AssocArrayLiteralExp(loc, 2533 arraySyntaxCopy(keys), arraySyntaxCopy(values)); 2534 } 2535 2536 Expression *AssocArrayLiteralExp::semantic(Scope *sc) 2537 { Expression *e; 2538 Type *tkey = NULL; 2539 Type *tvalue = NULL; 2540 2541 #if LOGSEMANTIC 2542 printf("AssocArrayLiteralExp::semantic('%s')\n", toChars()); 2543 #endif 2544 2545 // Run semantic() on each element 2546 for (size_t i = 0; i < keys->dim; i++) 2547 { Expression *key = (Expression *)keys->data[i]; 2548 Expression *value = (Expression *)values->data[i]; 2549 2550 key = key->semantic(sc); 2551 value = value->semantic(sc); 2552 2553 keys->data[i] = (void *)key; 2554 values->data[i] = (void *)value; 2555 } 2556 expandTuples(keys); 2557 expandTuples(values); 2558 if (keys->dim != values->dim) 2559 { 2560 error("number of keys is %u, must match number of values %u", keys->dim, values->dim); 2561 keys->setDim(0); 2562 values->setDim(0); 2563 } 2564 for (size_t i = 0; i < keys->dim; i++) 2565 { Expression *key = (Expression *)keys->data[i]; 2566 Expression *value = (Expression *)values->data[i]; 2567 2568 if (!key->type) 2569 error("%s has no value", key->toChars()); 2570 if (!value->type) 2571 error("%s has no value", value->toChars()); 2572 key = resolveProperties(sc, key); 2573 value = resolveProperties(sc, value); 2574 2575 if (!tkey) 2576 tkey = key->type; 2577 else 2578 key = key->implicitCastTo(sc, tkey); 2579 keys->data[i] = (void *)key; 2580 2581 if (!tvalue) 2582 tvalue = value->type; 2583 else 2584 value = value->implicitCastTo(sc, tvalue); 2585 values->data[i] = (void *)value; 2586 } 2587 2588 if (!tkey) 2589 tkey = Type::tvoid; 2590 if (!tvalue) 2591 tvalue = Type::tvoid; 2592 type = new TypeAArray(tvalue, tkey); 2593 type = type->semantic(loc, sc); 2594 return this; 2595 } 2596 2597 int AssocArrayLiteralExp::checkSideEffect(int flag) 2598 { int f = 0; 2599 2600 for (size_t i = 0; i < keys->dim; i++) 2601 { Expression *key = (Expression *)keys->data[i]; 2602 Expression *value = (Expression *)values->data[i]; 2603 2604 f |= key->checkSideEffect(2); 2605 f |= value->checkSideEffect(2); 2606 } 2607 if (flag == 0 && f == 0) 2608 Expression::checkSideEffect(0); 2609 return f; 2610 } 2611 2612 int AssocArrayLiteralExp::isBool(int result) 2613 { 2614 size_t dim = keys->dim; 2615 return result ? (dim != 0) : (dim == 0); 2616 } 2617 2618 void AssocArrayLiteralExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs) 2619 { 2620 buf->writeByte('['); 2621 for (size_t i = 0; i < keys->dim; i++) 2622 { Expression *key = (Expression *)keys->data[i]; 2623 Expression *value = (Expression *)values->data[i]; 2624 2625 if (i) 2626 buf->writeByte(','); 2627 expToCBuffer(buf, hgs, key, PREC_assign); 2628 buf->writeByte(':'); 2629 expToCBuffer(buf, hgs, value, PREC_assign); 2630 } 2631 buf->writeByte(']'); 2632 } 2633 2634 void AssocArrayLiteralExp::toMangleBuffer(OutBuffer *buf) 2635 { 2636 size_t dim = keys->dim; 2637 buf->printf("A%u", dim); 2638 for (size_t i = 0; i < dim; i++) 2639 { Expression *key = (Expression *)keys->data[i]; 2640 Expression *value = (Expression *)values->data[i]; 2641 2642 key->toMangleBuffer(buf); 2643 value->toMangleBuffer(buf); 2514 2644 } 2515 2645 } … … 3208 3338 3209 3339 VarDeclaration *v = var->isVarDeclaration(); 3210 if (v && v->canassign == 0 && (var->isConst() || var->isFinal())) 3340 if (v && v->canassign == 0 && 3341 (var->isConst() || (global.params.Dversion > 1 && var->isFinal()))) 3211 3342 error("cannot modify final variable '%s'", var->toChars()); 3212 3343 branches/dmdfe/expression.h
r458 r460 351 351 }; 352 352 353 struct AssocArrayLiteralExp : Expression 354 { 355 Expressions *keys; 356 Expressions *values; 357 358 AssocArrayLiteralExp(Loc loc, Expressions *keys, Expressions *values); 359 360 Expression *syntaxCopy(); 361 Expression *semantic(Scope *sc); 362 int isBool(int result); 363 elem *toElem(IRState *irs); 364 int checkSideEffect(int flag); 365 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 366 void toMangleBuffer(OutBuffer *buf); 367 void scanForNestedRef(Scope *sc); 368 Expression *optimize(int result); 369 Expression *interpret(InterState *istate); 370 371 int inlineCost(InlineCostState *ics); 372 Expression *doInline(InlineDoState *ids); 373 Expression *inlineScan(InlineScanState *iss); 374 }; 375 353 376 struct TypeDotIdExp : Expression 354 377 { branches/dmdfe/init.c
r458 r460 46 46 } 47 47 48 Array *Initializer::arraySyntaxCopy(Array*ai)49 { Array*a = NULL;48 Initializers *Initializer::arraySyntaxCopy(Initializers *ai) 49 { Initializers *a = NULL; 50 50 51 51 if (ai) 52 52 { 53 a = new Array();53 a = new Initializers(); 54 54 a->setDim(ai->dim); 55 55 for (int i = 0; i < a->dim; i++) branches/dmdfe/init.h
r458 r460 1 1 2 2 // Compiler implementation of the D programming language 3 // Copyright (c) 1999-200 6by Digital Mars3 // Copyright (c) 1999-2007 by Digital Mars 4 4 // All Rights Reserved 5 5 // written by Walter Bright … … 15 15 16 16 #include "mars.h" 17 #include "arraytypes.h" 17 18 18 19 struct Identifier; … … 40 41 char *toChars(); 41 42 42 static Array *arraySyntaxCopy(Array*ai);43 static Initializers *arraySyntaxCopy(Initializers *ai); 43 44 44 45 virtual VoidInitializer *isVoidInitializer() { return NULL; } … … 61 62 struct StructInitializer : Initializer 62 63 { 63 Arrayfield; // of Identifier *'s64 Arrayvalue; // parallel array of Initializer *'s64 Identifiers field; // of Identifier *'s 65 Initializers value; // parallel array of Initializer *'s 65 66 66 67 Array vars; // parallel array of VarDeclaration *'s … … 77 78 struct ArrayInitializer : Initializer 78 79 { 79 Array index; // of Expression *'s80 Arrayvalue; // of Initializer *'s80 Expressions index; // indices 81 Initializers value; // of Initializer *'s 81 82 unsigned dim; // length of array being initialized 82 83 Type *type; // type that array will be used to initialize branches/dmdfe/inline.c
r458 r460 182 182 { 183 183 return 1 + arrayInlineCost(ics, elements); 184 } 185 186 int AssocArrayLiteralExp::inlineCost(InlineCostState *ics) 187 { 188 return 1 + arrayInlineCost(ics, keys) + arrayInlineCost(ics, values); 184 189 } 185 190 … … 700 705 701 706 707 Expression *AssocArrayLiteralExp::doInline(InlineDoState *ids) 708 { 709 AssocArrayLiteralExp *ce; 710 711 ce = (AssocArrayLiteralExp *)copy(); 712 ce->keys = arrayExpressiondoInline(keys, ids); 713 ce->values = arrayExpressiondoInline(values, ids); 714 return ce; 715 } 716 717 702 718 Expression *ArrayExp::doInline(InlineDoState *ids) 703 719 { … … 1089 1105 //printf("ArrayLiteralExp::inlineScan()\n"); 1090 1106 arrayInlineScan(iss, elements); 1107 1108 return e; 1109 } 1110 1111 1112 Expression *AssocArrayLiteralExp::inlineScan(InlineScanState *iss) 1113 { Expression *e = this; 1114 1115 //printf("AssocArrayLiteralExp::inlineScan()\n"); 1116 arrayInlineScan(iss, keys); 1117 arrayInlineScan(iss, values); 1091 1118 1092 1119 return e; branches/dmdfe/interpret.c
r458 r460 985 985 } 986 986 ArrayLiteralExp *ae = new ArrayLiteralExp(loc, expsx); 987 ae->type = type; 988 return ae; 989 } 990 return this; 991 } 992 993 Expression *AssocArrayLiteralExp::interpret(InterState *istate) 994 { Expressions *keysx = NULL; 995 Expressions *valuesx = NULL; 996 997 #if LOG 998 printf("AssocArrayLiteralExp::interpret() %s\n", toChars()); 999 #endif 1000 for (size_t i = 0; i < keys->dim; i++) 1001 { Expression *ekey = (Expression *)keys->data[i]; 1002 Expression *evalue = (Expression *)values->data[i]; 1003 Expression *ex; 1004 1005 ex = ekey->interpret(istate); 1006 if (ex == EXP_CANT_INTERPRET) 1007 { delete keysx; 1008 delete valuesx; 1009 return EXP_CANT_INTERPRET; 1010 } 1011 1012 /* If any changes, do Copy On Write 1013 */ 1014 if (ex != ekey) 1015 { 1016 if (!keysx) 1017 { keysx = new Expressions(); 1018 keysx->setDim(keys->dim); 1019 for (size_t j = 0; j < i; j++) 1020 { 1021 keysx->data[j] = keys->data[j]; 1022 } 1023 } 1024 keysx->data[i] = (void *)ex; 1025 } 1026 1027 ex = evalue->interpret(istate); 1028 if (ex == EXP_CANT_INTERPRET) 1029 { delete keysx; 1030 delete valuesx; 1031 return EXP_CANT_INTERPRET; 1032 } 1033 1034 /* If any changes, do Copy On Write 1035 */ 1036 if (ex != evalue) 1037 { 1038 if (!valuesx) 1039 { valuesx = new Expressions(); 1040 valuesx->setDim(values->dim); 1041 for (size_t j = 0; j < i; j++) 1042 { 1043 valuesx->data[j] = values->data[j]; 1044 } 1045 } 1046 valuesx->data[i] = (void *)ex; 1047 } 1048 } 1049 if (keysx || valuesx) 1050 { 1051 if (keysx) 1052 expandTuples(keysx); 1053 if (valuesx) 1054 expandTuples(valuesx); 1055 if ((keysx && keysx->dim != keys->dim) || 1056 (valuesx && valuesx->dim != values->dim)) 1057 { delete keysx; 1058 delete valuesx; 1059 return EXP_CANT_INTERPRET; 1060 } 1061 AssocArrayLiteralExp *ae = new AssocArrayLiteralExp(loc, 1062 keysx ? keysx : keys, valuesx ? valuesx : values); 987 1063 ae->type = type; 988 1064 return ae; branches/dmdfe/lexer.c
r458 r460 2730 2730 Token::tochars[TOKarraylength] = "arraylength"; 2731 2731 Token::tochars[TOKarrayliteral] = "arrayliteral"; 2732 Token::tochars[TOKassocarrayliteral] = "assocarrayliteral"; 2732 2733 Token::tochars[TOKstring] = "string"; 2733 2734 Token::tochars[TOKdsymbol] = "symbol"; branches/dmdfe/lexer.h
r458 r460 1 1 2 2 // Compiler implementation of the D programming language 3 // Copyright (c) 1999-200 6by Digital Mars3 // Copyright (c) 1999-2007 by Digital Mars 4 4 // All Rights Reserved 5 5 // written by Walter Bright … … 67 67 TOKremove, 68 68 TOKnewanonclass, TOKcomment, 69 TOKarrayliteral, 69 TOKarrayliteral, TOKassocarrayliteral, 70 70 71 71 // Operators branches/dmdfe/mangle.c
r458 r460 1 1 2 2 // Compiler implementation of the D programming language 3 // Copyright (c) 1999-200 6by Digital Mars3 // Copyright (c) 1999-2007 by Digital Mars 4 4 // All Rights Reserved 5 5 // written by Walter Bright … … 126 126 p = buf.toChars(); 127 127 buf.data = NULL; 128 //printf("Declaration::mangle(this = %p, '%s', parent = '%s', linkage = %d) = %s\n", this, toChars(), parent ? parent->toChars() : "null", linkage, p); 128 129 return p; 129 130 } … … 193 194 char *TemplateInstance::mangle() 194 195 { 195 //printf("TemplateInstance::mangle() '%s'\n", toChars());196 return Dsymbol::mangle();197 }198 199 200 201 char *Dsymbol::mangle()202 {203 196 OutBuffer buf; 204 197 char *id; 205 198 206 //printf("Dsymbol::mangle() '%s'\n", toChars()); 199 #if 0 200 printf("TemplateInstance::mangle() %s", toChars()); 201 if (parent) 202 printf(" parent = %s %s", parent->kind(), parent->toChars()); 203 printf("\n"); 204 #endif 205 id = ident ? ident->toChars() : toChars(); 206 if (tempdecl->parent) 207 { 208 char *p = tempdecl->parent->mangle(); 209 if (p[0] == '_' && p[1] == 'D') 210 p += 2; 211 buf.writestring(p); 212 } 213 buf.printf(ZU "%s", strlen(id), id); 214 id = buf.toChars(); 215 buf.data = NULL; 216 //printf("TemplateInstance::mangle() %s = %s\n", toChars(), id); 217 return id; 218 } 219 220 221 222 char *Dsymbol::mangle() 223 { 224 OutBuffer buf; 225 char *id; 226 227 #if 0 228 printf("Dsymbol::mangle() '%s'", toChars()); 229 if (parent) 230 printf(" parent = %s %s", parent->kind(), parent->toChars()); 231 printf("\n"); 232 #endif 207 233 id = ident ? ident->toChars() : toChars(); 208 234 if (parent) 209 235 { 210 //printf(" parent = '%s', kind = '%s'\n", parent->mangle(), parent->kind());211 236 char *p = parent->mangle(); 212 237 if (p[0] == '_' && p[1] == 'D') … … 214 239 buf.writestring(p); 215 240 } 216 buf.printf( ZU "%s", strlen(id), id);241 buf.printf("%zu%s", strlen(id), id); 217 242 id = buf.toChars(); 218 243 buf.data = NULL; 219 return id; 220 } 221 222 244 //printf("Dsymbol::mangle() %s = %s\n", toChars(), id); 245 return id; 246 } 247 248 branches/dmdfe/mars.c
r458 r460 56 56 copyright = "Copyright (c) 1999-2007 by Digital Mars"; 57 57 written = "written by Walter Bright"; 58 version = "v1.01 1";58 version = "v1.012"; 59 59 global.structalign = 8; 60 60 … … 217 217 } 218 218 219 // Initialization220 Type::init();221 Id::initialize();222 Module::init();223 initPrecedence();224 225 //backend_init();226 227 219 #if __DMC__ // DMC unique support for response files 228 220 if (response_expand(&argc,&argv)) // expand response files … … 564 556 VersionCondition::addPredefinedGlobalIdent("D_Coverage"); 565 557 558 // Initialization 559 Type::init(); 560 Id::initialize(); 561 Module::init(); 562 initPrecedence(); 563 564 //backend_init(); 566 565 567 566 //printf("%d source files\n",files.dim); branches/dmdfe/optimize.c
r458 r460 84 84 elements->data[i] = (void *)e; 85 85 } 86 } 87 return this; 88 } 89 90 Expression *AssocArrayLiteralExp::optimize(int result) 91 { 92 assert(keys->dim == values->dim); 93 for (size_t i = 0; i < keys->dim; i++) 94 { Expression *e = (Expression *)keys->data[i]; 95 96 e = e->optimize(WANTvalue | (result & WANTinterpret)); 97 keys->data[i] = (void *)e; 98 99 e = (Expression *)values->data[i]; 100 e = e->optimize(WANTvalue | (result & WANTinterpret)); 101 values->data[i] = (void *)e; 86 102 } 87 103 return this; branches/dmdfe/template.c
r458 r460 2407 2407 this->nest = 0; 2408 2408 this->havetempdecl = 0; 2409 this->isnested = 0;2409 this->isnested = NULL; 2410 2410 this->errors = 0; 2411 2411 } … … 2429 2429 this->nest = 0; 2430 2430 this->havetempdecl = 1; 2431 this->isnested = 0;2431 this->isnested = NULL; 2432 2432 this->errors = 0; 2433 2433 … … 2540 2540 if (isnested != ti->isnested) 2541 2541 continue; 2542 #if 0 2542 2543 if (isnested && sc->parent != ti->parent) 2543 2544 continue; 2544 2545 #endif 2545 2546 for (size_t j = 0; j < tdtypes.dim; j++) 2546 2547 { Object *o1 = (Object *)tdtypes.data[j]; … … 2576 2577 ident = genIdent(); // need an identifier for name mangling purposes. 2577 2578 2579 #if 1 2578 2580 if (isnested) 2579 parent = sc->parent; 2581 parent = isnested; 2582 #endif 2580 2583 //printf("parent = '%s'\n", parent->kind()); 2581 2584 … … 3071 3074 3072 3075 int TemplateInstance::isNested(Objects *args) 3073 { 3076 { int nested = 0; 3074 3077 //printf("TemplateInstance::isNested('%s')\n", tempdecl->ident->toChars()); 3075 3078 … … 3105 3108 // if module level template 3106 3109 if (tempdecl->toParent()->isModule()) 3107 { isnested = 1; 3108 return 1; 3110 { 3111 if (isnested && isnested != d->toParent()) 3112 error("inconsistent nesting levels %s and %s", isnested->toChars(), d->toParent()->toChars()); 3113 isnested = d->toParent(); 3114 nested |= 1; 3109 3115 } 3110 3116 else … … 3114 3120 else if (va) 3115 3121 { 3116 if (isNested(&va->objects)) 3117 return 1; 3118 } 3119 } 3120 return 0; 3122 nested |= isNested(&va->objects); 3123 } 3124 } 3125 return nested; 3121 3126 } 3122 3127 branches/dmdfe/template.h
r458 r460 250 250 int nest; // for recursion detection 251 251 int havetempdecl; // 1 if used second constructor 252 int isnested; // if referencing local symbols252 Dsymbol *isnested; // if referencing local symbols, this is the context 253 253 int errors; // 1 if compiled with errors 254 254 #ifdef IN_GCC
