Changeset 460

Show
Ignore:
Timestamp:
04/12/07 18:54:52 (1 year ago)
Author:
Gregor
Message:

MERGE: DMD 1.012

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/dmdfe/arraytypes.h

    r458 r460  
    2424struct TemplateParameter; 
    2525struct FuncDeclaration; 
     26struct Identifier; 
     27struct Initializer; 
    2628 
    2729struct TemplateParameters : Array { }; 
     
    4345struct Arguments : Array { }; 
    4446 
     47struct Identifiers : Array { }; 
     48 
     49struct Initializers : Array { }; 
     50 
    4551#endif 
  • branches/dmdfe/declaration.c

    r458 r460  
    692692    storage_class = (storage_class & ~STCconst) | STCctorinit; 
    693693 
    694     if (isConst() || isFinal()
     694    if (isConst()
    695695    { 
    696696    } 
  • branches/dmdfe/delegatize.c

    r458 r460  
    178178 
    179179 
     180void AssocArrayLiteralExp::scanForNestedRef(Scope *sc) 
     181{ 
     182    arrayExpressionScanForNestedRef(sc, keys); 
     183    arrayExpressionScanForNestedRef(sc, values); 
     184} 
     185 
     186 
    180187void TupleExp::scanForNestedRef(Scope *sc) 
    181188{ 
  • branches/dmdfe/expression.c

    r458 r460  
    25122512    {   Expression *e = (Expression *)elements->data[i]; 
    25132513    e->toMangleBuffer(buf); 
     2514    } 
     2515} 
     2516 
     2517/************************ AssocArrayLiteralExp ************************************/ 
     2518 
     2519// [ key0 : value0, key1 : value1, ... ] 
     2520 
     2521AssocArrayLiteralExp::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 
     2530Expression *AssocArrayLiteralExp::syntaxCopy() 
     2531{ 
     2532    return new AssocArrayLiteralExp(loc, 
     2533    arraySyntaxCopy(keys), arraySyntaxCopy(values)); 
     2534} 
     2535 
     2536Expression *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 
     2597int 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 
     2612int AssocArrayLiteralExp::isBool(int result) 
     2613{ 
     2614    size_t dim = keys->dim; 
     2615    return result ? (dim != 0) : (dim == 0); 
     2616} 
     2617 
     2618void 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 
     2634void 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); 
    25142644    } 
    25152645} 
     
    32083338 
    32093339    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()))) 
    32113342    error("cannot modify final variable '%s'", var->toChars()); 
    32123343 
  • branches/dmdfe/expression.h

    r458 r460  
    351351}; 
    352352 
     353struct 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 
    353376struct TypeDotIdExp : Expression 
    354377{ 
  • branches/dmdfe/init.c

    r458 r460  
    4646} 
    4747 
    48 Array *Initializer::arraySyntaxCopy(Array *ai) 
    49 {   Array *a = NULL; 
     48Initializers *Initializer::arraySyntaxCopy(Initializers *ai) 
     49{   Initializers *a = NULL; 
    5050 
    5151    if (ai) 
    5252    { 
    53     a = new Array(); 
     53    a = new Initializers(); 
    5454    a->setDim(ai->dim); 
    5555    for (int i = 0; i < a->dim; i++) 
  • branches/dmdfe/init.h

    r458 r460  
    11 
    22// Compiler implementation of the D programming language 
    3 // Copyright (c) 1999-2006 by Digital Mars 
     3// Copyright (c) 1999-2007 by Digital Mars 
    44// All Rights Reserved 
    55// written by Walter Bright 
     
    1515 
    1616#include "mars.h" 
     17#include "arraytypes.h" 
    1718 
    1819struct Identifier; 
     
    4041    char *toChars(); 
    4142 
    42     static Array *arraySyntaxCopy(Array *ai); 
     43    static Initializers *arraySyntaxCopy(Initializers *ai); 
    4344 
    4445    virtual VoidInitializer *isVoidInitializer() { return NULL; } 
     
    6162struct StructInitializer : Initializer 
    6263{ 
    63     Array field;  // of Identifier *'s 
    64     Array value;  // parallel array of Initializer *'s 
     64    Identifiers field;    // of Identifier *'s 
     65    Initializers value;   // parallel array of Initializer *'s 
    6566 
    6667    Array vars;     // parallel array of VarDeclaration *'s 
     
    7778struct ArrayInitializer : Initializer 
    7879{ 
    79     Array index;   // of Expression *'
    80     Array value;  // of Initializer *'s 
     80    Expressions index; // indice
     81    Initializers value;   // of Initializer *'s 
    8182    unsigned dim;   // length of array being initialized 
    8283    Type *type;     // type that array will be used to initialize 
  • branches/dmdfe/inline.c

    r458 r460  
    182182{ 
    183183    return 1 + arrayInlineCost(ics, elements); 
     184} 
     185 
     186int AssocArrayLiteralExp::inlineCost(InlineCostState *ics) 
     187{ 
     188    return 1 + arrayInlineCost(ics, keys) + arrayInlineCost(ics, values); 
    184189} 
    185190 
     
    700705 
    701706 
     707Expression *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 
    702718Expression *ArrayExp::doInline(InlineDoState *ids) 
    703719{ 
     
    10891105    //printf("ArrayLiteralExp::inlineScan()\n"); 
    10901106    arrayInlineScan(iss, elements); 
     1107 
     1108    return e; 
     1109} 
     1110 
     1111 
     1112Expression *AssocArrayLiteralExp::inlineScan(InlineScanState *iss) 
     1113{   Expression *e = this; 
     1114 
     1115    //printf("AssocArrayLiteralExp::inlineScan()\n"); 
     1116    arrayInlineScan(iss, keys); 
     1117    arrayInlineScan(iss, values); 
    10911118 
    10921119    return e; 
  • branches/dmdfe/interpret.c

    r458 r460  
    985985    } 
    986986    ArrayLiteralExp *ae = new ArrayLiteralExp(loc, expsx); 
     987    ae->type = type; 
     988    return ae; 
     989    } 
     990    return this; 
     991} 
     992 
     993Expression *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); 
    9871063    ae->type = type; 
    9881064    return ae; 
  • branches/dmdfe/lexer.c

    r458 r460  
    27302730    Token::tochars[TOKarraylength]  = "arraylength"; 
    27312731    Token::tochars[TOKarrayliteral] = "arrayliteral"; 
     2732    Token::tochars[TOKassocarrayliteral] = "assocarrayliteral"; 
    27322733    Token::tochars[TOKstring]       = "string"; 
    27332734    Token::tochars[TOKdsymbol]      = "symbol"; 
  • branches/dmdfe/lexer.h

    r458 r460  
    11 
    22// Compiler implementation of the D programming language 
    3 // Copyright (c) 1999-2006 by Digital Mars 
     3// Copyright (c) 1999-2007 by Digital Mars 
    44// All Rights Reserved 
    55// written by Walter Bright 
     
    6767    TOKremove, 
    6868    TOKnewanonclass, TOKcomment, 
    69     TOKarrayliteral, 
     69    TOKarrayliteral, TOKassocarrayliteral, 
    7070 
    7171    // Operators 
  • branches/dmdfe/mangle.c

    r458 r460  
    11 
    22// Compiler implementation of the D programming language 
    3 // Copyright (c) 1999-2006 by Digital Mars 
     3// Copyright (c) 1999-2007 by Digital Mars 
    44// All Rights Reserved 
    55// written by Walter Bright 
     
    126126    p = buf.toChars(); 
    127127    buf.data = NULL; 
     128    //printf("Declaration::mangle(this = %p, '%s', parent = '%s', linkage = %d) = %s\n", this, toChars(), parent ? parent->toChars() : "null", linkage, p); 
    128129    return p; 
    129130    } 
     
    193194char *TemplateInstance::mangle() 
    194195{ 
    195     //printf("TemplateInstance::mangle() '%s'\n", toChars()); 
    196     return Dsymbol::mangle(); 
    197 } 
    198  
    199  
    200  
    201 char *Dsymbol::mangle() 
    202 { 
    203196    OutBuffer buf; 
    204197    char *id; 
    205198 
    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 
     222char *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 
    207233    id = ident ? ident->toChars() : toChars(); 
    208234    if (parent) 
    209235    { 
    210     //printf("  parent = '%s', kind = '%s'\n", parent->mangle(), parent->kind()); 
    211236    char *p = parent->mangle(); 
    212237    if (p[0] == '_' && p[1] == 'D') 
     
    214239    buf.writestring(p); 
    215240    } 
    216     buf.printf(ZU "%s", strlen(id), id); 
     241    buf.printf("%zu%s", strlen(id), id); 
    217242    id = buf.toChars(); 
    218243    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  
    5656    copyright = "Copyright (c) 1999-2007 by Digital Mars"; 
    5757    written = "written by Walter Bright"; 
    58     version = "v1.011"; 
     58    version = "v1.012"; 
    5959    global.structalign = 8; 
    6060 
     
    217217    } 
    218218 
    219     // Initialization 
    220     Type::init(); 
    221     Id::initialize(); 
    222     Module::init(); 
    223     initPrecedence(); 
    224  
    225     //backend_init(); 
    226  
    227219#if __DMC__ // DMC unique support for response files 
    228220    if (response_expand(&argc,&argv))   // expand response files 
     
    564556    VersionCondition::addPredefinedGlobalIdent("D_Coverage"); 
    565557 
     558    // Initialization 
     559    Type::init(); 
     560    Id::initialize(); 
     561    Module::init(); 
     562    initPrecedence(); 
     563 
     564    //backend_init(); 
    566565 
    567566    //printf("%d source files\n",files.dim); 
  • branches/dmdfe/optimize.c

    r458 r460  
    8484        elements->data[i] = (void *)e; 
    8585    } 
     86    } 
     87    return this; 
     88} 
     89 
     90Expression *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; 
    86102    } 
    87103    return this; 
  • branches/dmdfe/template.c

    r458 r460  
    24072407    this->nest = 0; 
    24082408    this->havetempdecl = 0; 
    2409     this->isnested = 0
     2409    this->isnested = NULL
    24102410    this->errors = 0; 
    24112411} 
     
    24292429    this->nest = 0; 
    24302430    this->havetempdecl = 1; 
    2431     this->isnested = 0
     2431    this->isnested = NULL
    24322432    this->errors = 0; 
    24332433 
     
    25402540    if (isnested != ti->isnested) 
    25412541        continue; 
     2542#if 0 
    25422543    if (isnested && sc->parent != ti->parent) 
    25432544        continue; 
    2544  
     2545#endif 
    25452546    for (size_t j = 0; j < tdtypes.dim; j++) 
    25462547    {   Object *o1 = (Object *)tdtypes.data[j]; 
     
    25762577    ident = genIdent();     // need an identifier for name mangling purposes. 
    25772578 
     2579#if 1 
    25782580    if (isnested) 
    2579     parent = sc->parent; 
     2581    parent = isnested; 
     2582#endif 
    25802583    //printf("parent = '%s'\n", parent->kind()); 
    25812584 
     
    30713074 
    30723075int TemplateInstance::isNested(Objects *args) 
    3073 { 
     3076{   int nested = 0; 
    30743077    //printf("TemplateInstance::isNested('%s')\n", tempdecl->ident->toChars()); 
    30753078 
     
    31053108        // if module level template 
    31063109        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; 
    31093115        } 
    31103116        else 
     
    31143120    else if (va) 
    31153121    { 
    3116         if (isNested(&va->objects)) 
    3117         return 1; 
    3118     } 
    3119     } 
    3120     return 0; 
     3122        nested |= isNested(&va->objects); 
     3123    } 
     3124    } 
     3125    return nested; 
    31213126} 
    31223127 
  • branches/dmdfe/template.h

    r458 r460  
    250250    int nest;       // for recursion detection 
    251251    int havetempdecl;   // 1 if used second constructor 
    252     int isnested;  // if referencing local symbols 
     252    Dsymbol *isnested; // if referencing local symbols, this is the context 
    253253    int errors;     // 1 if compiled with errors 
    254254#ifdef IN_GCC