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

Changeset 235

Show
Ignore:
Timestamp:
11/04/09 07:24:58 (15 years ago)
Author:
walter
Message:

bugzilla 3367

Files:

Legend:

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

    r233 r235  
    10741074                    /* Before calling the constructor, initialize 
    10751075                     * variable with a bit copy of the default 
    10761076                     * initializer 
    10771077                     */ 
    10781078                    Expression *e = new AssignExp(loc, new VarExp(loc, this), t->defaultInit(loc)); 
    10791079                    e->op = TOKblit; 
    10801080                    e->type = t; 
    10811081                    ei->exp = new CommaExp(loc, e, ei->exp); 
    10821082 
    10831083                    /* Replace __ctmp being constructed with e1 
    10841084                     */ 
    10851085                    dve->e1 = e1; 
    10861086                    return; 
    10871087                } 
    10881088                } 
    10891089            } 
    10901090            } 
    10911091#endif 
    10921092            if (!ei->exp->implicitConvTo(type)) 
    10931093            { 
     1094            Type *ti = ei->exp->type->toBasetype(); 
     1095            // Look for constructor first 
     1096            if (sd->ctor && 
     1097                /* Initializing with the same type is done differently 
     1098                 */ 
     1099                !(ti->ty == Tstruct && t->toDsymbol(sc) == ti->toDsymbol(sc))) 
     1100            { 
     1101               // Rewrite as e1.ctor(arguments) 
     1102                Expression *ector = new DotIdExp(loc, e1, Id::ctor); 
     1103                ei->exp = new CallExp(loc, ector, ei->exp); 
     1104            }  
     1105            else 
    10941106            /* Look for opCall 
    10951107             * See bugzilla 2702 for more discussion 
    10961108             */ 
    1097             Type *ti = ei->exp->type->toBasetype(); 
    10981109            // Don't cast away invariant or mutability in initializer 
    10991110            if (search_function(sd, Id::call) && 
    11001111                /* Initializing with the same type is done differently 
    11011112                 */ 
    11021113                !(ti->ty == Tstruct && t->toDsymbol(sc) == ti->toDsymbol(sc))) 
    11031114            {   // Rewrite as e1.call(arguments) 
    11041115                Expression * eCall = new DotIdExp(loc, e1, Id::call); 
    11051116                ei->exp = new CallExp(loc, eCall, ei->exp); 
    11061117            } 
    11071118            } 
    11081119        } 
    11091120        ei->exp = new AssignExp(loc, e1, ei->exp); 
    11101121        ei->exp->op = op; 
    11111122        canassign++; 
    11121123        ei->exp = ei->exp->semantic(sc); 
    11131124        canassign--; 
    11141125        ei->exp->optimize(WANTvalue); 
    11151126        } 
    11161127        else 
    11171128        { 
  • trunk/src/expression.c

    r233 r235  
    321321    return fd; 
    322322 
    323323Lno: 
    324324    return NULL;        // don't have 'this' available 
    325325} 
    326326 
    327327 
    328328/*************************************** 
    329329 * Pull out any properties. 
    330330 */ 
    331331 
    332332Expression *resolveProperties(Scope *sc, Expression *e) 
    333333{ 
    334334    //printf("resolveProperties(%s)\n", e->toChars()); 
    335335    if (e->type) 
    336336    { 
    337337    Type *t = e->type->toBasetype(); 
    338338 
    339339    if (t->ty == Tfunction || e->op == TOKoverloadset) 
    340340    { 
     341#if 0 
     342        if (t->ty == Tfunction && !((TypeFunction *)t)->isproperty) 
     343        error(e->loc, "not a property %s\n", e->toChars()); 
     344#endif 
    341345        e = new CallExp(e->loc, e); 
    342346        e = e->semantic(sc); 
    343347    } 
    344348 
    345349    /* Look for e being a lazy parameter; rewrite as delegate call 
    346350     */ 
    347351    else if (e->op == TOKvar) 
    348352    {   VarExp *ve = (VarExp *)e; 
    349353 
    350354        if (ve->var->storage_class & STClazy) 
    351355        { 
    352356        e = new CallExp(e->loc, e); 
    353357        e = e->semantic(sc); 
    354358        } 
    355359    } 
    356360 
    357361    else if (e->op == TOKdotexp) 
    358362    { 
    359363        e->error("expression has no value"); 
    360364    } 
  • trunk/src/func.c

    r219 r235  
    29342934    Statement *s = new DeclarationStatement(0, v); 
    29352935    sa->push(s); 
    29362936    Expression *e = new IdentifierExp(0, id); 
    29372937    e = new AddAssignExp(0, e, new IntegerExp(1)); 
    29382938    e = new EqualExp(TOKnotequal, 0, e, new IntegerExp(1)); 
    29392939    s = new IfStatement(0, NULL, e, new ReturnStatement(0, NULL), NULL); 
    29402940    sa->push(s); 
    29412941    if (fbody) 
    29422942        sa->push(fbody); 
    29432943    fbody = new CompoundStatement(0, sa); 
    29442944    } 
    29452945 
    29462946    FuncDeclaration::semantic(sc); 
    29472947 
    29482948    // We're going to need ModuleInfo 
    29492949    Module *m = getModule(); 
    29502950    if (!m) 
    29512951    m = sc->module; 
    29522952    if (m) 
    29532953    {   m->needmoduleinfo = 1; 
     2954    //printf("module1 %s needs moduleinfo\n", m->toChars()); 
    29542955#ifdef IN_GCC 
    29552956    m->strictlyneedmoduleinfo = 1; 
    29562957#endif 
    29572958    } 
    29582959} 
    29592960 
    29602961AggregateDeclaration *StaticCtorDeclaration::isThis() 
    29612962{ 
    29622963    return NULL; 
    29632964} 
    29642965 
    29652966int StaticCtorDeclaration::isStaticConstructor() 
    29662967{ 
    29672968    return TRUE; 
    29682969} 
    29692970 
    29702971int StaticCtorDeclaration::isVirtual() 
    29712972{ 
    29722973    return FALSE; 
    29732974} 
     
    30433044    sa->push(s); 
    30443045    Expression *e = new IdentifierExp(0, id); 
    30453046    e = new AddAssignExp(0, e, new IntegerExp(-1)); 
    30463047    e = new EqualExp(TOKnotequal, 0, e, new IntegerExp(0)); 
    30473048    s = new IfStatement(0, NULL, e, new ReturnStatement(0, NULL), NULL); 
    30483049    sa->push(s); 
    30493050    if (fbody) 
    30503051        sa->push(fbody); 
    30513052    fbody = new CompoundStatement(0, sa); 
    30523053    vgate = v; 
    30533054    } 
    30543055 
    30553056    FuncDeclaration::semantic(sc); 
    30563057 
    30573058    // We're going to need ModuleInfo 
    30583059    Module *m = getModule(); 
    30593060    if (!m) 
    30603061    m = sc->module; 
    30613062    if (m) 
    30623063    {   m->needmoduleinfo = 1; 
     3064    //printf("module2 %s needs moduleinfo\n", m->toChars()); 
    30633065#ifdef IN_GCC 
    30643066    m->strictlyneedmoduleinfo = 1; 
    30653067#endif 
    30663068    } 
    30673069} 
    30683070 
    30693071AggregateDeclaration *StaticDtorDeclaration::isThis() 
    30703072{ 
    30713073    return NULL; 
    30723074} 
    30733075 
    30743076int StaticDtorDeclaration::isStaticDestructor() 
    30753077{ 
    30763078    return TRUE; 
    30773079} 
    30783080 
    30793081int StaticDtorDeclaration::isVirtual() 
    30803082{ 
    30813083    return FALSE; 
    30823084} 
     
    31953197    assert(!s); 
    31963198    utd = new UnitTestDeclaration(loc, endloc); 
    31973199    return FuncDeclaration::syntaxCopy(utd); 
    31983200} 
    31993201 
    32003202 
    32013203void UnitTestDeclaration::semantic(Scope *sc) 
    32023204{ 
    32033205    if (global.params.useUnitTests) 
    32043206    { 
    32053207    type = new TypeFunction(NULL, Type::tvoid, FALSE, LINKd); 
    32063208    Scope *sc2 = sc->push(); 
    32073209    sc2->linkage = LINKd; 
    32083210    FuncDeclaration::semantic(sc2); 
    32093211    sc2->pop(); 
    32103212    } 
    32113213 
    32123214    // We're going to need ModuleInfo even if the unit tests are not 
    32133215    // compiled in, because other modules may import this module and refer 
    32143216    // to this ModuleInfo. 
     3217    // (This doesn't make sense to me?) 
    32153218    Module *m = getModule(); 
    32163219    if (!m) 
    32173220    m = sc->module; 
    32183221    if (m) 
     3222    { 
     3223    //printf("module3 %s needs moduleinfo\n", m->toChars()); 
    32193224    m->needmoduleinfo = 1; 
     3225    } 
    32203226} 
    32213227 
    32223228AggregateDeclaration *UnitTestDeclaration::isThis() 
    32233229{ 
    32243230    return NULL; 
    32253231} 
    32263232 
    32273233int UnitTestDeclaration::isVirtual() 
    32283234{ 
    32293235    return FALSE; 
    32303236} 
    32313237 
    32323238int UnitTestDeclaration::addPreInvariant() 
    32333239{ 
    32343240    return FALSE; 
    32353241} 
    32363242 
    32373243int UnitTestDeclaration::addPostInvariant() 
    32383244{ 
    32393245    return FALSE; 
  • trunk/src/module.c

    r205 r235  
    851851    for (int i = 0; i < members->dim; i++) 
    852852    {   Dsymbol *s = (Dsymbol *)members->data[i]; 
    853853 
    854854    s->toCBuffer(&buf, &hgs); 
    855855    } 
    856856 
    857857    // Transfer image to file 
    858858    symfile->setbuffer(buf.data, buf.offset); 
    859859    buf.data = NULL; 
    860860 
    861861    symfile->writev(); 
    862862} 
    863863 
    864864/********************************** 
    865865 * Determine if we need to generate an instance of ModuleInfo 
    866866 * for this Module. 
    867867 */ 
    868868 
    869869int Module::needModuleInfo() 
    870870{ 
     871    //printf("needModuleInfo() %s, %d, %d\n", toChars(), needmoduleinfo, global.params.cov); 
    871872    return needmoduleinfo || global.params.cov; 
    872873} 
    873874 
    874875Dsymbol *Module::search(Loc loc, Identifier *ident, int flags) 
    875876{ 
    876877    /* Since modules can be circularly referenced, 
    877878     * need to stop infinite recursive searches. 
    878879     * This is done with the cache. 
    879880     */ 
    880881 
    881882    //printf("%s Module::search('%s', flags = %d) insearch = %d\n", toChars(), ident->toChars(), flags, insearch); 
    882883    Dsymbol *s; 
    883884    if (insearch) 
    884885    s = NULL; 
    885886    else if (searchCacheIdent == ident && searchCacheFlags == flags) 
    886887    { 
    887888    s = searchCacheSymbol; 
    888889    //printf("%s Module::search('%s', flags = %d) insearch = %d searchCacheSymbol = %s\n", toChars(), ident->toChars(), flags, insearch, searchCacheSymbol ? searchCacheSymbol->toChars() : "null"); 
    889890    } 
    890891    else 
  • trunk/src/mtype.c

    r233 r235  
    51055105        break; 
    51065106        } 
    51075107        sd = s->isStructDeclaration(); 
    51085108        if (sd) 
    51095109        { 
    51105110        if (exp->op == TOKsuper) 
    51115111        { 
    51125112            error(loc, "struct %s has no 'super'", sd->toChars()); 
    51135113            goto Lerr; 
    51145114        } 
    51155115        t = sd->type->pointerTo(); 
    51165116        break; 
    51175117        } 
    51185118    } 
    51195119    } 
    51205120    else 
    51215121#endif 
    51225122    { 
    51235123    sc->intypeof++; 
    51245124    exp = exp->semantic(sc); 
    5125     //exp = resolveProperties(sc, exp); 
     5125    if (exp->type && exp->type->ty == Tfunction && 
     5126        ((TypeFunction *)exp->type)->isproperty) 
     5127        exp = resolveProperties(sc, exp); 
    51265128    sc->intypeof--; 
    51275129    if (exp->op == TOKtype) 
    51285130    { 
    51295131        error(loc, "argument %s to typeof is not an expression", exp->toChars()); 
    51305132    } 
    51315133    t = exp->type; 
    51325134    if (!t) 
    51335135    { 
    51345136        error(loc, "expression (%s) has no type", exp->toChars()); 
    51355137        goto Lerr; 
    51365138    } 
    51375139    if (t->ty == Ttypeof) 
    51385140        error(loc, "forward reference to %s", toChars()); 
    51395141 
    51405142    /* typeof should reflect the true type, 
    51415143     * not what 'auto' would have gotten us. 
    51425144     */ 
    51435145    //t = t->toHeadMutable(); 
    51445146    } 
    51455147    if (idents.dim)