Changeset 658
- Timestamp:
- 07/02/07 18:16:27 (1 year ago)
- Files:
-
- branches/dmdfe/expression.c (modified) (7 diffs)
- branches/dmdfe/expression.h (modified) (2 diffs)
- branches/dmdfe/hdrgen.h (modified) (1 diff)
- branches/dmdfe/idgen.c (modified) (3 diffs)
- branches/dmdfe/inline.c (modified) (3 diffs)
- branches/dmdfe/interpret.c (modified) (12 diffs)
- branches/dmdfe/lexer.c (modified) (2 diffs)
- branches/dmdfe/mars.c (modified) (2 diffs)
- branches/dmdfe/mtype.c (modified) (4 diffs)
- branches/dmdfe/mtype.h (modified) (1 diff)
- branches/dmdfe/statement.c (modified) (1 diff)
- branches/dmdfe/statement.h (modified) (3 diffs)
- branches/dmdfe/staticassert.c (modified) (2 diffs)
- branches/dmdfe/template.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/dmdfe/expression.c
r657 r658 2351 2351 case '"': 2352 2352 case '\\': 2353 buf->writeByte('\\'); 2353 if (!hgs->console) 2354 buf->writeByte('\\'); 2354 2355 default: 2355 2356 if (c <= 0xFF) 2356 { if (c <= 0x7F && isprint(c))2357 { if (c <= 0x7F && (isprint(c) || hgs->console)) 2357 2358 buf->writeByte(c); 2358 2359 else … … 2710 2711 error("overlapping initialization for %s", v->toChars()); 2711 2712 offset = v->offset + v->type->size(); 2712 e = e->implicitCastTo(sc, v->type); 2713 2714 Type *telem = v->type; 2715 while (!e->implicitConvTo(telem) && telem->toBasetype()->ty == Tsarray) 2716 { /* Static array initialization, as in: 2717 * T[3][5] = e; 2718 */ 2719 telem = telem->toBasetype()->nextOf(); 2720 } 2721 2722 e = e->implicitCastTo(sc, telem); 2723 2713 2724 elements->data[i] = (void *)e; 2714 2725 } … … 2733 2744 } 2734 2745 else 2735 e = v->type->defaultInit(); 2746 { e = v->type->defaultInit(); 2747 e->loc = loc; 2748 } 2736 2749 offset = v->offset + v->type->size(); 2737 2750 } … … 2791 2804 } 2792 2805 2806 2807 Expression *StructLiteralExp::toLvalue(Scope *sc, Expression *e) 2808 { 2809 return this; 2810 } 2793 2811 2794 2812 … … 3396 3414 { 3397 3415 if (!v->isDataseg()) 3398 error("escaping reference to local %s", v->toChars());3416 error("escaping reference to local variable %s", v->toChars()); 3399 3417 } 3400 3418 } … … 6144 6162 if (v) 6145 6163 { 6146 if (!v->isDataseg() )6164 if (!v->isDataseg() && !v->isParameter()) 6147 6165 error("escaping reference to local %s", v->toChars()); 6148 6166 } … … 6770 6788 : BinExp(loc, TOKassign, sizeof(AssignExp), e1, e2) 6771 6789 { 6790 ismemset = 0; 6772 6791 } 6773 6792 branches/dmdfe/expression.h
r656 r658 402 402 Expression *interpret(InterState *istate); 403 403 dt_t **toDt(dt_t **pdt); 404 Expression *toLvalue(Scope *sc, Expression *e); 404 405 405 406 int inlineCost(InlineCostState *ics); … … 982 983 983 984 struct AssignExp : BinExp 984 { 985 { int ismemset; // !=0 if setting the contents of an array 986 985 987 AssignExp(Loc loc, Expression *e1, Expression *e2); 986 988 Expression *semantic(Scope *sc); branches/dmdfe/hdrgen.h
r458 r658 14 14 int hdrgen; // 1 if generating header file 15 15 int ddoc; // 1 if generating Ddoc file 16 int console; // 1 if writing to console 16 17 int tpltMember; 17 18 int inCallExp; branches/dmdfe/idgen.c
r656 r658 83 83 { "TypeInfo_Delegate" }, 84 84 { "TypeInfo_Tuple" }, 85 { "TypeInfo_Const" }, 86 { "TypeInfo_Invariant" }, 85 87 { "elements" }, 86 88 { "_arguments_typeinfo" }, … … 94 96 { "TIME", "__TIME__" }, 95 97 { "TIMESTAMP", "__TIMESTAMP__" }, 98 { "VENDOR", "__VENDOR__" }, 99 { "VERSIONX", "__VERSION__" }, 96 100 97 101 { "nan" }, … … 123 127 { "reverse" }, 124 128 { "dup" }, 129 { "idup" }, 125 130 126 131 // For inline assembler branches/dmdfe/inline.c
r656 r658 1 1 2 // Copyright (c) 1999-200 6by Digital Mars2 // Copyright (c) 1999-2007 by Digital Mars 3 3 // All Rights Reserved 4 4 // written by Walter Bright … … 347 347 if (s->isReturnStatement()) 348 348 break; 349 350 /* Check for: 351 * if (condition) 352 * return exp1; 353 * else 354 * return exp2; 355 */ 356 IfStatement *ifs = s->isIfStatement(); 357 if (ifs && ifs->elsebody && ifs->ifbody && 358 ifs->ifbody->isReturnStatement() && 359 ifs->elsebody->isReturnStatement() 360 ) 361 break; 362 349 363 } 350 364 } … … 1237 1251 * no return expression. 1238 1252 */ 1239 if (t ype->next && type->next->ty != Tvoid &&1253 if (tf->next && tf->next->ty != Tvoid && 1240 1254 !(hasReturnExp & 1) && 1241 1255 !hdrscan) branches/dmdfe/interpret.c
r657 r658 859 859 } 860 860 861 Expression *getVarExp( InterState *istate, Declaration *d)861 Expression *getVarExp(Loc loc, InterState *istate, Declaration *d) 862 862 { 863 863 Expression *e = EXP_CANT_INTERPRET; … … 874 874 { e = v->value; 875 875 if (!e) 876 error( "variable %s is used before initialization", v->toChars());876 error(loc, "variable %s is used before initialization", v->toChars()); 877 877 else if (e != EXP_CANT_INTERPRET) 878 878 e = e->interpret(istate); … … 897 897 printf("VarExp::interpret() %s\n", toChars()); 898 898 #endif 899 return getVarExp( istate, var);899 return getVarExp(loc, istate, var); 900 900 } 901 901 … … 932 932 { 933 933 #if LOG 934 printf(" VarExp::interpret() %s\n", toChars());934 printf("TupleExp::interpret() %s\n", toChars()); 935 935 #endif 936 936 Expressions *expsx = NULL; … … 1415 1415 if (!v || v->isDataseg()) 1416 1416 return EXP_CANT_INTERPRET; 1417 if (fp && !v->value) 1418 { error("variable %s is used before initialization", v->toChars()); 1419 return e; 1417 if (!v->value) 1418 { 1419 if (fp) 1420 { error("variable %s is used before initialization", v->toChars()); 1421 return e; 1422 } 1423 1424 Type *t = v->type->toBasetype(); 1425 if (t->ty == Tsarray) 1426 { 1427 /* This array was void initialized. Create a 1428 * default initializer for it. 1429 * What we should do is fill the array literal with 1430 * NULL data, so use-before-initialized can be detected. 1431 * But we're too lazy at the moment to do it, as that 1432 * involves redoing Index() and whoever calls it. 1433 */ 1434 Expression *ev = v->type->defaultInit(); 1435 size_t dim = ((TypeSArray *)t)->dim->toInteger(); 1436 Expressions *elements = new Expressions(); 1437 elements->setDim(dim); 1438 for (size_t i = 0; i < dim; i++) 1439 elements->data[i] = (void *)ev; 1440 ArrayLiteralExp *ae = new ArrayLiteralExp(0, elements); 1441 ae->type = v->type; 1442 v->value = ae; 1443 } 1444 else 1445 return EXP_CANT_INTERPRET; 1420 1446 } 1421 1447 … … 1616 1642 } 1617 1643 } 1644 Expression *eold = v->value; 1618 1645 v->value = e; 1619 e = Cast(type, type, e 2);1646 e = Cast(type, type, eold); 1620 1647 } 1621 1648 } … … 1709 1736 if (eresult) 1710 1737 e = eresult; 1711 else if (fd->type->toBasetype()->next ->ty == Tvoid)1738 else if (fd->type->toBasetype()->nextOf()->ty == Tvoid) 1712 1739 e = EXP_VOID_INTERPRET; 1713 1740 else … … 1855 1882 e1 = this->e1->interpret(istate); 1856 1883 if (e1 == EXP_CANT_INTERPRET) 1857 goto Lcant; 1884 { 1885 goto Lcant; 1886 } 1858 1887 e2 = this->e2->interpret(istate); 1859 1888 if (e2 == EXP_CANT_INTERPRET) … … 1862 1891 1863 1892 Lcant: 1893 #if LOG 1894 printf("CatExp::interpret() %s CANT\n", toChars()); 1895 #endif 1864 1896 return EXP_CANT_INTERPRET; 1865 1897 } … … 1879 1911 1880 1912 Lcant: 1913 #if LOG 1914 printf("CastExp::interpret() %s CANT\n", toChars()); 1915 #endif 1881 1916 return EXP_CANT_INTERPRET; 1882 1917 } … … 1932 1967 VarDeclaration *v = soe->var->isVarDeclaration(); 1933 1968 if (v) 1934 { Expression *ev = getVarExp( istate, v);1969 { Expression *ev = getVarExp(loc, istate, v); 1935 1970 if (ev != EXP_CANT_INTERPRET && ev->op == TOKstructliteral) 1936 1971 { StructLiteralExp *se = (StructLiteralExp *)ev; … … 1967 2002 Expression *interpret_aaKeys(InterState *istate, Expressions *arguments) 1968 2003 { 1969 printf("interpret_aaKeys()\n");2004 //printf("interpret_aaKeys()\n"); 1970 2005 if (!arguments || arguments->dim != 2) 1971 2006 return NULL; branches/dmdfe/lexer.c
r656 r658 630 630 if (mod && id == Id::FILE) 631 631 { 632 t->value = TOKstring;633 632 t->ustring = (unsigned char *)(loc.filename ? loc.filename : mod->ident->toChars()); 634 goto L len;633 goto Lstring; 635 634 } 636 635 else if (mod && id == Id::LINE) … … 641 640 else if (id == Id::DATE) 642 641 { 643 t->value = TOKstring;644 642 t->ustring = (unsigned char *)date; 645 goto L len;643 goto Lstring; 646 644 } 647 645 else if (id == Id::TIME) 648 646 { 649 t->value = TOKstring;650 647 t->ustring = (unsigned char *)time; 651 goto Llen; 648 goto Lstring; 649 } 650 else if (id == Id::VENDOR) 651 { 652 t->ustring = (unsigned char *)"Digital Mars D"; 653 goto Lstring; 652 654 } 653 655 else if (id == Id::TIMESTAMP) 654 656 { 657 t->ustring = (unsigned char *)timestamp; 658 Lstring: 655 659 t->value = TOKstring; 656 t->ustring = (unsigned char *)timestamp;657 660 Llen: 658 661 t->postfix = 0; 659 662 t->len = strlen((char *)t->ustring); 663 } 664 else if (id == Id::VERSIONX) 665 { unsigned major = 0; 666 unsigned minor = 0; 667 668 for (char *p = global.version + 1; 1; p++) 669 { 670 char c = *p; 671 if (isdigit(c)) 672 minor = minor * 10 + c - '0'; 673 else if (c == '.') 674 { major = minor; 675 minor = 0; 676 } 677 else 678 break; 679 } 680 t->value = TOKint64v; 681 t->uns64value = major * 1000 + minor; 660 682 } 661 683 } branches/dmdfe/mars.c
r657 r658 56 56 copyright = "Copyright (c) 1999-2007 by Digital Mars"; 57 57 written = "written by Walter Bright"; 58 version = "v1.01 5";58 version = "v1.017"; 59 59 global.structalign = 8; 60 60 … … 146 146 global.version, global.copyright, global.written); 147 147 printf("\ 148 Documentation: http://www.digitalmars.com/d/ index.html\n\148 Documentation: http://www.digitalmars.com/d/1.0/index.html\n\ 149 149 Usage:\n\ 150 150 dmd files.d ... { -switch }\n\ branches/dmdfe/mtype.c
r656 r658 593 593 else if (ident == Id::init) 594 594 { 595 #if 0 595 596 if (v->init) 596 597 { … … 616 617 return e; 617 618 } 619 #endif 620 return defaultInit(); 618 621 } 619 622 } … … 2721 2724 t = arg->type->toBasetype(); 2722 2725 2723 /* If arg turns out to be a tuple, the number of parameters may2724 * change.2725 */2726 if (t->ty == Ttuple)2727 dim = Argument::dim(parameters);2728 2729 2726 if (arg->storageClass & (STCout | STCref | STClazy)) 2730 2727 { … … 2740 2737 arg->defaultArg = resolveProperties(sc, arg->defaultArg); 2741 2738 arg->defaultArg = arg->defaultArg->implicitCastTo(sc, arg->type); 2739 } 2740 2741 /* If arg turns out to be a tuple, the number of parameters may 2742 * change. 2743 */ 2744 if (t->ty == Ttuple) 2745 { dim = Argument::dim(parameters); 2746 i--; 2742 2747 } 2743 2748 } branches/dmdfe/mtype.h
r458 r658 239 239 virtual Expression *toExpression(); 240 240 virtual int hasPointers(); 241 Type *nextOf() { return next; } 241 242 242 243 static void error(Loc loc, const char *format, ...); branches/dmdfe/statement.c
r657 r658 2911 2911 sym = es->sds; 2912 2912 } 2913 else if (exp->op == TOKtype) 2914 { TypeExp *es = (TypeExp *)exp; 2915 2916 sym = es->type->toDsymbol(sc)->isScopeDsymbol(); 2917 if (!sym) 2918 { error("%s has no members", es->toChars()); 2919 body = body->semantic(sc); 2920 return this; 2921 } 2922 } 2913 2923 else 2914 2924 { Type *t = exp->type; branches/dmdfe/statement.h
r458 r658 27 27 struct LabelDsymbol; 28 28 struct Identifier; 29 struct IfStatement; 29 30 struct DeclarationStatement; 30 31 struct DefaultStatement; … … 99 100 virtual CompoundStatement *isCompoundStatement() { return NULL; } 100 101 virtual ReturnStatement *isReturnStatement() { return NULL; } 102 virtual IfStatement *isIfStatement() { return NULL; } 101 103 }; 102 104 … … 311 313 int usesEH(); 312 314 int fallOffEnd(); 315 IfStatement *isIfStatement() { return this; } 313 316 314 317 int inlineCost(InlineCostState *ics); branches/dmdfe/staticassert.c
r458 r658 16 16 #include "expression.h" 17 17 #include "id.h" 18 #include "hdrgen.h" 18 19 19 20 /********************************* AttribDeclaration ****************************/ … … 54 55 { 55 56 if (msg) 56 { 57 { HdrGenState hgs; 58 OutBuffer buf; 59 57 60 msg = msg->semantic(sc); 58 61 msg = msg->optimize(WANTvalue | WANTinterpret); 59 char *p = msg->toChars(); 60 p = strdup(p); 61 error("%s", p); 62 free(p); 62 hgs.console = 1; 63 msg->toCBuffer(&buf, &hgs); 64 error("%s", buf.toChars()); 63 65 } 64 66 else branches/dmdfe/template.c
r656 r658 564 564 for (i = 0; i < fargs->dim; i++) 565 565 { Expression *e = (Expression *)fargs->data[i]; 566 printf("\tfarg[%d] = %s\n", i,e->toChars());566 printf("\tfarg[%d] is %s, type is %s\n", i, e->toChars(), e->type->toChars()); 567 567 } 568 568 #endif … … 695 695 { farg = (Expression *)fargs->data[i]; 696 696 #if 0 697 printf(" farg->type = %s\n", farg->type->toChars());698 printf(" fparam->type = %s\n", fparam->type->toChars());697 printf("\tfarg->type = %s\n", farg->type->toChars()); 698 printf("\tfparam->type = %s\n", fparam->type->toChars()); 699 699 #endif 700 700 … … 1099 1099 goto Lnomatch; 1100 1100 1101 Lagain:1102 1101 if (this == tparam) 1103 1102 goto Lexact; … … 1116 1115 tparam = tparam->semantic(0, sc); 1117 1116 assert(tparam->ty != Tident); 1118 goto Lagain;1117 return deduceType(sc, tparam, parameters, dedtypes); 1119 1118 } 1120 1119
