Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

Changeset 222

Show
Ignore:
Timestamp:
10/28/09 18:27:01 (15 years ago)
Author:
walter
Message:

bugzilla 3035

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/attrib.c

    r203 r222  
    877877            sc->module->members->push(pragma); 
    878878        } 
    879879    } 
    880880#endif // TARGET_NET 
    881881} 
    882882 
    883883void PragmaDeclaration::semantic(Scope *sc) 
    884884{   // Should be merged with PragmaStatement 
    885885 
    886886    //printf("\tPragmaDeclaration::semantic '%s'\n",toChars()); 
    887887    if (ident == Id::msg) 
    888888    { 
    889889    if (args) 
    890890    { 
    891891        for (size_t i = 0; i < args->dim; i++) 
    892892        { 
    893893        Expression *e = (Expression *)args->data[i]; 
    894894 
    895895        e = e->semantic(sc); 
    896896        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()); 
    904898        } 
    905899        fprintf(stdmsg, "\n"); 
    906900    } 
    907901    goto Lnodecl; 
    908902    } 
    909903    else if (ident == Id::lib) 
    910904    { 
    911905    if (!args || args->dim != 1) 
    912906        error("string expected for library name"); 
    913907    else 
    914908    { 
    915909        Expression *e = (Expression *)args->data[0]; 
    916910 
    917911        e = e->semantic(sc); 
    918912        e = e->optimize(WANTvalue | WANTinterpret); 
    919913        args->data[0] = (void *)e; 
    920914        if (e->op != TOKstring) 
    921915        error("string expected for library name, not '%s'", e->toChars()); 
    922916        else if (global.params.verbose) 
    923917        { 
  • trunk/src/expression.c

    r220 r222  
    11951195{ 
    11961196    // Default is 'yes' - do nothing 
    11971197 
    11981198#ifdef DEBUG 
    11991199    if (!type) 
    12001200    dump(0); 
    12011201#endif 
    12021202 
    12031203    if (!type->checkBoolean()) 
    12041204    { 
    12051205    error("expression %s of type %s does not have a boolean value", toChars(), type->toChars()); 
    12061206    } 
    12071207    return this; 
    12081208} 
    12091209 
    12101210/**************************** 
    12111211 */ 
    12121212 
    12131213Expression *Expression::checkToPointer() 
    12141214{ 
    1215     Type *tb; 
    1216  
    12171215    //printf("Expression::checkToPointer()\n"); 
    12181216    Expression *e = this; 
    12191217 
    12201218#if !SARRAYVALUE 
    12211219    // If C static array, convert to pointer 
    12221220    Type *tb = type->toBasetype(); 
    12231221    if (tb->ty == Tsarray) 
    12241222    {   TypeSArray *ts = (TypeSArray *)tb; 
    12251223    if (ts->size(loc) == 0) 
    12261224        e = new NullExp(loc); 
    12271225    else 
    12281226        e = new AddrExp(loc, this); 
    12291227    e->type = ts->next->pointerTo(); 
    12301228    } 
    12311229#endif 
    12321230    return e; 
    12331231} 
    12341232 
    12351233/****************************** 
    12361234 * Take address of expression. 
     
    28032801        assert(0); 
    28042802    } 
    28052803    } 
    28062804    return len1 - len2; 
    28072805} 
    28082806 
    28092807int StringExp::isBool(int result) 
    28102808{ 
    28112809    return result ? TRUE : FALSE; 
    28122810} 
    28132811 
    28142812#if DMDV2 
    28152813int StringExp::isLvalue() 
    28162814{ 
    28172815    return 1; 
    28182816} 
    28192817#endif 
    28202818 
    28212819Expression *StringExp::toLvalue(Scope *sc, Expression *e) 
    28222820{ 
     2821    //printf("StringExp::toLvalue(%s)\n", toChars()); 
    28232822    return this; 
    28242823} 
    28252824 
    28262825unsigned StringExp::charAt(size_t i) 
    28272826{   unsigned value; 
    28282827 
    28292828    switch (sz) 
    28302829    { 
    28312830    case 1: 
    28322831        value = ((unsigned char *)string)[i]; 
    28332832        break; 
    28342833 
    28352834    case 2: 
    28362835        value = ((unsigned short *)string)[i]; 
    28372836        break; 
    28382837 
    28392838    case 4: 
    28402839        value = ((unsigned int *)string)[i]; 
    28412840        break; 
    28422841 
  • trunk/src/mtype.c

    r221 r222  
    41544154    {   Argument *arg = Argument::getNth(tf->parameters, i); 
    41554155 
    41564156        tf->inuse++; 
    41574157        arg->type = arg->type->semantic(loc, argsc); 
    41584158        if (tf->inuse == 1) tf->inuse--; 
    41594159 
    41604160        arg->type = arg->type->addStorageClass(arg->storageClass); 
    41614161 
    41624162        if (arg->storageClass & (STCauto | STCalias | STCstatic)) 
    41634163        { 
    41644164        if (!arg->type) 
    41654165            continue; 
    41664166        } 
    41674167 
    41684168        Type *t = arg->type->toBasetype(); 
    41694169 
    41704170        if (arg->storageClass & (STCout | STCref | STClazy)) 
    41714171        { 
    41724172        //if (t->ty == Tsarray) 
    41734173            //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/invariant out 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()); 
    41764176        } 
    41774177        if (!(arg->storageClass & STClazy) && t->ty == Tvoid) 
    41784178        error(loc, "cannot have parameter of type %s", arg->type->toChars()); 
    41794179 
    41804180        if (arg->defaultArg) 
    41814181        { 
    41824182        arg->defaultArg = arg->defaultArg->semantic(argsc); 
    41834183        arg->defaultArg = resolveProperties(argsc, arg->defaultArg); 
    41844184        arg->defaultArg = arg->defaultArg->implicitCastTo(argsc, arg->type); 
    41854185        } 
    41864186 
    41874187        /* If arg turns out to be a tuple, the number of parameters may 
    41884188         * change. 
    41894189         */ 
    41904190        if (t->ty == Ttuple) 
    41914191        {   dim = Argument::dim(tf->parameters); 
    41924192        i--; 
    41934193        } 
    41944194    } 
    41954195    argsc->pop(); 
  • trunk/src/statement.c

    r221 r222  
    24782478    b = body->syntaxCopy(); 
    24792479    PragmaStatement *s = new PragmaStatement(loc, 
    24802480        ident, Expression::arraySyntaxCopy(args), b); 
    24812481    return s; 
    24822482} 
    24832483 
    24842484Statement *PragmaStatement::semantic(Scope *sc) 
    24852485{   // Should be merged with PragmaDeclaration 
    24862486    //printf("PragmaStatement::semantic() %s\n", toChars()); 
    24872487    //printf("body = %p\n", body); 
    24882488    if (ident == Id::msg) 
    24892489    { 
    24902490        if (args) 
    24912491        { 
    24922492            for (size_t i = 0; i < args->dim; i++) 
    24932493            { 
    24942494                Expression *e = (Expression *)args->data[i]; 
    24952495 
    24962496                e = e->semantic(sc); 
    24972497        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()); 
    25052499            } 
    25062500            fprintf(stdmsg, "\n"); 
    25072501        } 
    25082502    } 
    25092503    else if (ident == Id::lib) 
    25102504    { 
    25112505#if 1 
    25122506    /* Should this be allowed? 
    25132507     */ 
    25142508    error("pragma(lib) not allowed as statement"); 
    25152509#else 
    25162510    if (!args || args->dim != 1) 
    25172511        error("string expected for library name"); 
    25182512    else 
    25192513    { 
    25202514        Expression *e = (Expression *)args->data[0]; 
    25212515 
    25222516        e = e->semantic(sc); 
    25232517        e = e->optimize(WANTvalue | WANTinterpret); 
    25242518        args->data[0] = (void *)e; 
  • trunk/src/traits.c

    r189 r222  
    323323 
    324324    for (size_t i = 0; i < dim; i++) 
    325325    {   Object *o = (Object *)args->data[i]; 
    326326        Expression *e; 
    327327 
    328328        unsigned errors = global.errors; 
    329329        global.gag++; 
    330330 
    331331        Type *t = isType(o); 
    332332        if (t) 
    333333        {   Dsymbol *s; 
    334334        t->resolve(loc, sc, &e, &t, &s); 
    335335        if (t) 
    336336            t->semantic(loc, sc); 
    337337        else if (e) 
    338338            e->semantic(sc); 
    339339        } 
    340340        else 
    341341        {   e = isExpression(o); 
    342342        if (e) 
    343             e->semantic(sc); 
     343        {   e->semantic(sc); 
     344        } 
    344345        } 
    345346 
    346347        global.gag--; 
    347348        if (errors != global.errors) 
    348349        {   if (global.gag == 0) 
    349350            global.errors = errors; 
    350351        goto Lfalse; 
    351352        } 
    352353    } 
    353354    goto Ltrue; 
    354355    } 
    355356    else if (ident == Id::isSame) 
    356357    {   /* Determine if two symbols are the same 
    357358     */ 
    358359    if (dim != 2) 
    359360        goto Ldimerror; 
    360361    TemplateInstance::semanticTiargs(loc, sc, args, 0); 
    361362    Object *o1 = (Object *)args->data[0]; 
    362363    Object *o2 = (Object *)args->data[1]; 
    363364    Dsymbol *s1 = getDsymbol(o1); 
    364365    Dsymbol *s2 = getDsymbol(o2); 
    365366 
     367    //printf("isSame: %s, %s\n", o1->toChars(), o2->toChars()); 
    366368#if 0 
    367369    printf("o1: %p\n", o1); 
    368370    printf("o2: %p\n", o2); 
    369371    if (!s1) 
    370372    {   Expression *ea = isExpression(o1); 
    371373        if (ea) 
    372374        printf("%s\n", ea->toChars()); 
    373375        Type *ta = isType(o1); 
    374376        if (ta) 
    375377        printf("%s\n", ta->toChars()); 
    376378        goto Lfalse; 
    377379    } 
    378380    else 
    379381        printf("%s %s\n", s1->kind(), s1->toChars()); 
    380382#endif 
    381383    if (!s1 && !s2) 
    382384    {   Expression *ea1 = isExpression(o1); 
    383385        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        } 
    386391    } 
    387392 
    388393    if (!s1 || !s2) 
    389394        goto Lfalse; 
    390395 
    391396    s1 = s1->toAlias(); 
    392397    s2 = s2->toAlias(); 
    393398 
    394399    if (s1 == s2) 
    395400        goto Ltrue; 
    396401    else 
    397402        goto Lfalse; 
    398403    } 
    399404    else 
    400405    {   error("unrecognized trait %s", ident->toChars()); 
    401406    goto Lfalse; 
    402407    } 
    403408 
    404409    return NULL; 
    405410