Wiki Roadmap Timeline Tickets New Ticket Source Search Help / Guide About Trac Login

Changeset 1630:44b145be2ef5

Show
Ignore:
Timestamp:
02/06/10 10:53:52 (2 years ago)
Author:
Robert Clipsham <robert@octarineparrot.com>
branch:
default
Message:

Merge dmd 1.056.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • dmd/access.c

    r1406 r1630  
    393393    if (!e) 
    394394    { 
    395     if (d->getModule() != sc->module) 
    396         if (d->prot() == PROTprivate || 
    397         d->prot() == PROTpackage && !hasPackageAccess(sc, d)) 
    398  
    399         error(loc, "%s %s.%s is not accessible from %s", 
    400             d->kind(), d->getModule()->toChars(), d->toChars(), sc->module->toChars()); 
     395    if (d->prot() == PROTprivate && d->getModule() != sc->module || 
     396        d->prot() == PROTpackage && !hasPackageAccess(sc, d)) 
     397 
     398        error(loc, "%s %s.%s is not accessible from %s", 
     399        d->kind(), d->getModule()->toChars(), d->toChars(), sc->module->toChars()); 
    401400    } 
    402401    else if (e->type->ty == Tclass) 
  • dmd/aggregate.h

    r1624 r1630  
    2020#include "dsymbol.h" 
    2121 
     22#if IN_LLVM 
    2223#include <vector> 
    2324#include <set> 
    2425#include <map> 
     26#endif 
    2527 
    2628struct Identifier; 
     
    3941struct dt_t; 
    4042 
     43#if IN_LLVM 
    4144namespace llvm 
    4245{ 
     
    4750    class GlobalVariable; 
    4851} 
     52#endif 
    4953 
    5054struct AggregateDeclaration : ScopeDsymbol 
  • dmd/arrayop.c

    r1607 r1630  
    2525#include "init.h" 
    2626 
     27#if IN_DMD 
     28extern int binary(const char *p , const char **tab, int high); 
     29 
     30/************************************** 
     31 * Hash table of array op functions already generated or known about. 
     32 */ 
     33 
     34StringTable arrayfuncs; 
     35#endif 
    2736 
    2837/*********************************** 
  • dmd/attrib.c

    r1602 r1630  
    393393    if (stc & (STCgshared | STCshared | STCtls)) 
    394394        scstc &= ~(STCgshared | STCshared | STCtls); 
     395    if (stc & (STCsafe | STCtrusted | STCsystem)) 
     396        scstc &= ~(STCsafe | STCtrusted | STCsystem); 
    395397    scstc |= stc; 
    396398 
     
    416418    if (stc & (STCgshared | STCshared | STCtls)) 
    417419        scstc &= ~(STCgshared | STCshared | STCtls); 
     420    if (stc & (STCsafe | STCtrusted | STCsystem)) 
     421        scstc &= ~(STCsafe | STCtrusted | STCsystem); 
    418422    scstc |= stc; 
    419423 
     
    454458    { STCtls,          TOKtls }, 
    455459    { STCgshared,      TOKgshared }, 
     460    { STCproperty,     TOKat }, 
     461    { STCsafe,         TOKat }, 
     462    { STCtrusted,      TOKat }, 
     463    { STCdisable,       TOKat }, 
    456464#endif 
    457465    }; 
     
    715723    } 
    716724 
     725    unsigned dprogress_save = Module::dprogress; 
     726 
    717727    assert(sc->parent); 
    718728 
     
    744754    sc = sc->push(); 
    745755    sc->anonAgg = &aad; 
    746     sc->stc &= ~(STCauto | STCscope | STCstatic | STCtls); 
     756    sc->stc &= ~(STCauto | STCscope | STCstatic | STCtls | STCgshared); 
    747757    sc->inunion = isunion; 
    748758    sc->offset = 0; 
     
    776786        scope->module->addDeferredSemantic(this); 
    777787        } 
     788        Module::dprogress = dprogress_save; 
    778789        //printf("\tforward reference %p\n", this); 
    779790        return; 
     
    806817        VarDeclaration *v = (VarDeclaration *)aad.fields.data[i]; 
    807818 
    808         // LDC 
     819#if IN_LLVM 
    809820        v->offset2 = sc->offset; 
    810  
     821#endif 
    811822        v->offset += sc->offset; 
    812823 
    813         // LDC 
     824#if IN_LLVM 
    814825        if (!v->anonDecl) 
    815826            v->anonDecl = this; 
    816  
     827#endif 
    817828        ad->fields.push(v); 
    818829    } 
     
    13701381    memcpy(name, se->string, se->len); 
    13711382    name[se->len] = 0; 
     1383#if OMFOBJ 
     1384    /* The OMF format allows library names to be inserted 
     1385     * into the object file. The linker will then automatically 
     1386     * search that library, too. 
     1387     */ 
    13721388    obj_includelib(name); 
     1389#elif ELFOBJ || MACHOBJ 
     1390    /* The format does not allow embedded library names, 
     1391     * so instead append the library name to the list to be passed 
     1392     * to the linker. 
     1393     */ 
     1394    global.params.libfiles->push((void *) name); 
     1395#else 
     1396    error("pragma lib not supported"); 
     1397#endif 
    13731398    } 
    13741399#if DMDV2 
  • dmd/class.c

    r1628 r1630  
    265265    scope = NULL; 
    266266    } 
     267    unsigned dprogress_save = Module::dprogress; 
    267268#ifdef IN_GCC 
    268269    methods.setDim(0); 
     
    629630    scope->module->addDeferredSemantic(this); 
    630631 
     632    Module::dprogress = dprogress_save; 
     633 
    631634    //printf("\tsemantic('%s') failed due to forward references\n", toChars()); 
    632635    return; 
  • dmd/cond.c

    r1387 r1630  
    143143    "none", 
    144144 
    145     // LDC 
     145#if IN_LLVM 
    146146    "LLVM", "LDC", "LLVM64", 
    147147    "PPC", "PPC64", 
    148148    "darwin","solaris","freebsd" 
     149#endif 
    149150    }; 
    150151 
  • dmd/declaration.c

    r1621 r1630  
    836836        v->semantic(sc); 
    837837             
    838 /* 
     838#if !IN_LLVM 
    839839// removed for LDC since TupleDeclaration::toObj already creates the fields; 
    840840// adding them to the scope again leads to duplicates 
     
    844844            sc->scopesym->members->push(v); 
    845845        } 
    846 */ 
     846#endif 
     847 
    847848        Expression *e = new DsymbolExp(loc, v); 
    848849        exps->data[i] = e; 
     
    14911492{ 
    14921493    assert(linkage == LINKc); 
    1493     // LDC 
     1494#if IN_LLVM 
    14941495    if (!global.params.useAvailableExternally) 
    14951496        availableExternally = false; 
     1497#endif 
    14961498} 
    14971499 
  • dmd/declaration.h

    r1621 r1630  
    1616#endif /* __DMC__ */ 
    1717 
     18#if IN_LLVM 
    1819#include <set> 
    1920#include <map> 
    2021#include <string> 
     22#endif 
    2123 
    2224#include "dsymbol.h" 
  • dmd/dsymbol.c

    r1607 r1630  
    3030#include "template.h" 
    3131#include "attrib.h" 
     32#if IN_LLVM 
    3233#include "../gen/enums.h" 
     34#endif 
    3335 
    3436/****************************** Dsymbol ******************************/ 
  • dmd/dsymbol.h

    r1587 r1630  
    2222#include "arraytypes.h" 
    2323 
    24 // llvm 
     24#if IN_LLVM 
    2525#include "../ir/irdsymbol.h" 
     26#endif 
    2627 
    2728struct Identifier; 
     
    5253struct VarDeclaration; 
    5354struct AttribDeclaration; 
     55#if IN_DMD 
     56struct Symbol; 
     57#endif 
    5458struct Package; 
    5559struct Module; 
     
    7781struct PragmaScope; 
    7882#endif 
    79 #if IN_DMD 
    80 struct Symbol; 
    81 #endif 
    8283#if IN_GCC 
    8384union tree_node; 
     
    110111}; 
    111112 
     113/* State of symbol in winding its way through the passes of the compiler 
     114 */ 
     115enum PASS 
     116{ 
     117    PASSinit,       // initial state 
     118    PASSsemantic,   // semantic() started 
     119    PASSsemanticdone,   // semantic() done 
     120    PASSsemantic2,  // semantic2() run 
     121    PASSsemantic3,  // semantic3() started 
     122    PASSsemantic3done,  // semantic3() done 
     123    PASSobj,        // toObjFile() run 
     124}; 
    112125 
    113126struct Dsymbol : Object 
  • dmd/enum.c

    r1628 r1630  
    11 
    2 // Copyright (c) 1999-2009 by Digital Mars 
     2// Copyright (c) 1999-2010 by Digital Mars 
    33// All Rights Reserved 
    44// written by Walter Bright 
     
    1515#include "mtype.h" 
    1616#include "scope.h" 
     17#include "module.h" 
    1718#include "declaration.h" 
    1819 
     
    7576    } 
    7677 
     78    unsigned dprogress_save = Module::dprogress; 
     79 
    7780    if (sc->stc & STCdeprecated) 
    7881    isdeprecated = 1; 
     
    98101 
    99102    isdone = 1; 
     103    Module::dprogress++; 
    100104 
    101105    t = isAnonymous() ? memtype : type; 
  • dmd/expression.c

    r1629 r1630  
    11 
    22// Compiler implementation of the D programming language 
    3 // Copyright (c) 1999-2009 by Digital Mars 
     3// Copyright (c) 1999-2010 by Digital Mars 
    44// All Rights Reserved 
    55// written by Walter Bright 
     
    37113711            } 
    37123712        } 
    3713          
    37143713        } 
    37153714    } 
     
    87788777    e1->checkIntegral(); 
    87798778    e2 = e2->checkIntegral(); 
    8780     //e2 = e2->castTo(sc, Type::tshiftcnt); 
    8781     e2 = e2->castTo(sc, e1->type); // LDC 
     8779#if !IN_LLVM 
     8780    e2 = e2->castTo(sc, Type::tshiftcnt); 
     8781#else 
     8782    e2 = e2->castTo(sc, e1->type); 
     8783#endif 
    87828784    return this; 
    87838785} 
     
    88078809    e1->checkIntegral(); 
    88088810    e2 = e2->checkIntegral(); 
    8809     //e2 = e2->castTo(sc, Type::tshiftcnt); 
    8810     e2 = e2->castTo(sc, e1->type); // LDC 
     8811#if !IN_LLVM 
     8812    e2 = e2->castTo(sc, Type::tshiftcnt); 
     8813#else 
     8814    e2 = e2->castTo(sc, e1->type); 
     8815#endif 
    88118816    return this; 
    88128817} 
     
    88368841    e1->checkIntegral(); 
    88378842    e2 = e2->checkIntegral(); 
    8838     //e2 = e2->castTo(sc, Type::tshiftcnt); 
    8839     e2 = e2->castTo(sc, e1->type); // LDC 
     8843#if !IN_LLVM 
     8844    e2 = e2->castTo(sc, Type::tshiftcnt); 
     8845#else 
     8846    e2 = e2->castTo(sc, e1->type); 
     8847#endif 
    88408848    return this; 
    88418849} 
     
    93249332    e2 = e2->checkIntegral(); 
    93259333    e1 = e1->integralPromotions(sc); 
    9326     //e2 = e2->castTo(sc, Type::tshiftcnt); 
    9327     e2 = e2->castTo(sc, e1->type); // LDC 
     9334#if !IN_LLVM 
     9335    e2 = e2->castTo(sc, Type::tshiftcnt); 
     9336#else 
     9337    e2 = e2->castTo(sc, e1->type); 
     9338#endif 
    93289339    type = e1->type; 
    93299340    } 
     
    93499360    e2 = e2->checkIntegral(); 
    93509361    e1 = e1->integralPromotions(sc); 
    9351     //e2 = e2->castTo(sc, Type::tshiftcnt); 
    9352     e2 = e2->castTo(sc, e1->type); // LDC 
     9362#if !IN_LLVM 
     9363    e2 = e2->castTo(sc, Type::tshiftcnt); 
     9364#else 
     9365    e2 = e2->castTo(sc, e1->type); 
     9366#endif 
    93539367    type = e1->type; 
    93549368    } 
     
    93749388    e2 = e2->checkIntegral(); 
    93759389    e1 = e1->integralPromotions(sc); 
    9376     //e2 = e2->castTo(sc, Type::tshiftcnt); 
    9377     e2 = e2->castTo(sc, e1->type); // LDC 
     9390#if !IN_LLVM 
     9391    e2 = e2->castTo(sc, Type::tshiftcnt); 
     9392#else 
     9393    e2 = e2->castTo(sc, e1->type); 
     9394#endif 
    93789395    type = e1->type; 
    93799396    } 
  • dmd/expression.h

    r1626 r1630  
    11 
    22// Compiler implementation of the D programming language 
    3 // Copyright (c) 1999-2009 by Digital Mars 
     3// Copyright (c) 1999-2010 by Digital Mars 
    44// All Rights Reserved 
    55// written by Walter Bright 
     
    646646    SymOffExp(Loc loc, Declaration *var, unsigned offset); 
    647647    Expression *semantic(Scope *sc); 
     648    Expression *interpret(InterState *istate); 
    648649    void checkEscape(); 
    649650    void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 
     
    723724    Expression *syntaxCopy(); 
    724725    Expression *semantic(Scope *sc); 
     726    Expression *interpret(InterState *istate); 
    725727    void scanForNestedRef(Scope *sc); 
    726728    char *toChars(); 
     
    986988    DelegateExp(Loc loc, Expression *e, FuncDeclaration *func); 
    987989    Expression *semantic(Scope *sc); 
     990    Expression *interpret(InterState *istate); 
    988991    MATCH implicitConvTo(Type *t); 
    989992    Expression *castTo(Scope *sc, Type *t); 
  • dmd/func.c

    r1617 r1630  
    11// Compiler implementation of the D programming language 
    2 // Copyright (c) 1999-2009 by Digital Mars 
     2// Copyright (c) 1999-2010 by Digital Mars 
    33// All Rights Reserved 
    44// written by Walter Bright 
     
    6666    inlineAsm = 0; 
    6767    cantInterpret = 0; 
    68     semanticRun = 0
     68    semanticRun = PASSinit
    6969#if DMDV1 
    7070    nestedFrameRef = 0; 
     
    132132    assert(!fthrows); // deprecated 
    133133 
    134     // LDC 
     134#if IN_LLVM 
    135135    f->intrinsicName = intrinsicName; 
     136#endif 
    136137 
    137138    return f; 
     
    156157#endif 
    157158 
    158     if (semanticRun && isFuncLiteralDeclaration()) 
     159    if (semanticRun != PASSinit && isFuncLiteralDeclaration()) 
    159160    { 
    160161    /* Member functions that have return types that are 
     
    165166    return; 
    166167    } 
    167     assert(semanticRun <= 1); 
    168     semanticRun = 1; 
     168    parent = sc->parent; 
     169    Dsymbol *parent = toParent(); 
     170 
     171    if (semanticRun == PASSsemanticdone) 
     172    { 
     173    if (!parent->isClassDeclaration()) 
     174        return; 
     175    // need to re-run semantic() in order to set the class's vtbl[] 
     176    } 
     177    else 
     178    { 
     179    assert(semanticRun <= PASSsemantic); 
     180    semanticRun = PASSsemantic; 
     181    } 
     182 
     183    unsigned dprogress_save = Module::dprogress; 
     184 
     185    foverrides.setDim(0);   // reset in case semantic() is being retried for this function 
    169186 
    170187    if (!type->deco) 
     
    182199 
    183200    linkage = sc->linkage; 
    184 //    if (!parent) 
    185     { 
    186     //parent = sc->scopesym; 
    187     parent = sc->parent; 
    188     } 
    189201    protection = sc->protection; 
    190202    storage_class |= sc->stc; 
    191203    //printf("function storage_class = x%x\n", storage_class); 
    192     Dsymbol *parent = toParent(); 
    193204 
    194205    if (ident == Id::ctor && !isCtorDeclaration()) 
     
    268279        isUnitTestDeclaration() || isNewDeclaration() || isDelete()) 
    269280        error("special function not allowed in interface %s", id->toChars()); 
    270     if (fbody
     281    if (fbody && isVirtual()
    271282        error("function body is not abstract in interface %s", id->toChars()); 
    272283    } 
     
    338349    } 
    339350 
    340     // Find index of existing function in vtbl[] to override 
    341     vi = findVtblIndex(&cd->vtbl, cd->baseClass ? cd->baseClass->vtbl.dim : 0); 
     351    /* Find index of existing function in base class's vtbl[] to override 
     352     * (the index will be the same as in cd's current vtbl[]) 
     353     */ 
     354    vi = cd->baseClass ? findVtblIndex(&cd->baseClass->vtbl, cd->baseClass->vtbl.dim) 
     355               : -1; 
     356 
    342357    switch (vi) 
    343358    { 
     
    379394        case -2:    // can't determine because of fwd refs 
    380395        cd->sizeok = 2; // can't finish due to forward reference 
     396        Module::dprogress = dprogress_save; 
    381397        return; 
    382398 
    383399        default: 
    384         {   FuncDeclaration *fdv = (FuncDeclaration *)cd->vtbl.data[vi]; 
     400        {   FuncDeclaration *fdv = (FuncDeclaration *)cd->baseClass->vtbl.data[vi]; 
    385401        // This function is covariant with fdv 
    386402        if (fdv->isFinal()) 
     
    456472        case -2: 
    457473            cd->sizeok = 2; // can't finish due to forward reference 
     474            Module::dprogress = dprogress_save; 
    458475            return; 
    459476 
     
    473490             * offsets differ 
    474491             */ 
     492            unsigned errors = global.errors; 
     493            global.gag++;            // suppress printing of error messages 
    475494            int offset; 
    476             if (fdv->type->nextOf()->isBaseOf(type->nextOf(), &offset)) 
     495            int baseOf = fdv->type->nextOf()->isBaseOf(type->nextOf(), &offset); 
     496            global.gag--;            // suppress printing of error messages 
     497            if (errors != global.errors) 
     498            { 
     499                // any error in isBaseOf() is a forward reference error, so we bail out 
     500                global.errors = errors; 
     501                cd->sizeok = 2;    // can't finish due to forward reference 
     502                Module::dprogress = dprogress_save; 
     503                return; 
     504            } 
     505            if (baseOf) 
    477506            { 
    478507                ti = fdv->type; 
    479 #if 0 
    480                 if (offset) 
    481                 ti = fdv->type; 
    482                 else if (type->nextOf()->ty == Tclass) 
    483                 {   ClassDeclaration *cdn = ((TypeClass *)type->nextOf())->sym; 
    484                 if (cdn && cdn->sizeok != 1) 
    485                     ti = fdv->type; 
    486                 } 
    487 #endif 
    488508            } 
    489509            } 
     
    597617    } 
    598618 
    599     if (isVirtual()
     619    if (isVirtual() && semanticRun != PASSsemanticdone
    600620    { 
    601621    /* Rewrite contracts as nested functions, then call them. 
     
    653673 
    654674Ldone: 
     675    Module::dprogress++; 
     676    semanticRun = PASSsemanticdone; 
     677 
    655678    /* Save scope for possible later use (if we need the 
    656679     * function internals) 
     
    689712 
    690713    //printf(" sc->incontract = %d\n", sc->incontract); 
    691     if (semanticRun >= 3) 
     714    if (semanticRun >= PASSsemantic3) 
    692715    return; 
    693     semanticRun = 3; 
    694  
    695     // LDC 
     716    semanticRun = PASSsemantic3; 
     717 
     718#if IN_LLVM 
    696719    if (!global.params.useAvailableExternally) 
    697720        availableExternally = false; 
    698  
     721#endif 
    699722    if (!type || type->ty != Tfunction) 
    700723    return; 
     
    14671490    sc2->pop(); 
    14681491    } 
    1469     semanticRun = 4
     1492    semanticRun = PASSsemantic3done
    14701493} 
    14711494 
     
    16391662 * Find index of function in vtbl[0..dim] that 
    16401663 * this function overrides. 
     1664 * Prefer an exact match to a covariant one. 
    16411665 * Returns: 
    16421666 *  -1  didn't find one 
     
    16461670int FuncDeclaration::findVtblIndex(Array *vtbl, int dim) 
    16471671{ 
     1672    FuncDeclaration *mismatch = NULL; 
     1673    int bestvi = -1; 
    16481674    for (int vi = 0; vi < dim; vi++) 
    16491675    { 
     
    16511677    if (fdv && fdv->ident == ident) 
    16521678    { 
     1679        if (type->equals(fdv->type))    // if exact match 
     1680            return vi;          // no need to look further 
     1681 
    16531682        int cov = type->covariant(fdv->type); 
    16541683        //printf("\tbaseclass cov = %d\n", cov); 
     
    16591688 
    16601689        case 1: 
    1661             return vi; 
     1690                bestvi = vi;    // covariant, but not identical 
     1691                break;      // keep looking for an exact match 
    16621692 
    16631693        case 2: 
    1664             //type->print(); 
    1665             //fdv->type->print(); 
    1666             //printf("%s %s\n", type->deco, fdv->type->deco); 
    1667             error("of type %s overrides but is not covariant with %s of type %s", 
    1668             type->toChars(), fdv->toPrettyChars(), fdv->type->toChars()); 
    1669             break; 
     1694            mismatch = fdv; // overrides, but is not covariant 
     1695            break;      // keep looking for an exact match 
    16701696 
    16711697        case 3: 
     
    16771703    } 
    16781704    } 
    1679     return -1; 
     1705    if (bestvi == -1 && mismatch) 
     1706    { 
     1707    //type->print(); 
     1708    //mismatch->type->print(); 
     1709    //printf("%s %s\n", type->deco, mismatch->type->deco); 
     1710    error("of type %s overrides but is not covariant with %s of type %s", 
     1711        type->toChars(), mismatch->toPrettyChars(), mismatch->type->toChars()); 
     1712    } 
     1713    return bestvi; 
    16801714} 
    16811715 
     
    25552589    else 
    25562590    id = "__funcliteral"; 
    2557     this->ident = Identifier::generateId(id); 
     2591    this->ident = Lexer::uniqueId(id); 
    25582592    this->tok = tok; 
    25592593    this->fes = fes; 
     
    25692603    f = (FuncLiteralDeclaration *)s; 
    25702604    else 
    2571     f = new FuncLiteralDeclaration(loc, endloc, type->syntaxCopy(), tok, fes); 
     2605    {   f = new FuncLiteralDeclaration(loc, endloc, type->syntaxCopy(), tok, fes); 
     2606    f->ident = ident;       // keep old identifier 
     2607    } 
    25722608    FuncDeclaration::syntaxCopy(f); 
    25732609    return f; 
     
    26352671void CtorDeclaration::semantic(Scope *sc) 
    26362672{ 
    2637     ClassDeclaration *cd; 
    2638     Type *tret; 
    2639  
    2640     //printf("CtorDeclaration::semantic()\n"); 
    2641     if (type) 
    2642     return; 
    2643  
     2673    //printf("CtorDeclaration::semantic() %s\n", toChars()); 
    26442674    sc = sc->push(); 
    26452675    sc->stc &= ~STCstatic;      // not a static constructor 
     
    26472677    parent = sc->parent; 
    26482678    Dsymbol *parent = toParent(); 
    2649     cd = parent->isClassDeclaration(); 
     2679    Type *tret; 
     2680    ClassDeclaration *cd = parent->isClassDeclaration(); 
    26502681    if (!cd) 
    26512682    { 
     
    26562687    else 
    26572688    tret = cd->type; //->referenceTo(); 
    2658     type = new TypeFunction(arguments, tret, varargs, LINKd); 
     2689    if (!type) 
     2690    type = new TypeFunction(arguments, tret, varargs, LINKd); 
    26592691#if STRUCTTHISREF 
    26602692    if (ad && ad->isStructDeclaration()) 
     
    26712703    //  return this; 
    26722704    // to the function body 
    2673     if (fbody
     2705    if (fbody && semanticRun < PASSsemantic
    26742706    { 
    26752707    Expression *e = new ThisExp(loc); 
     
    27452777    //printf("PostBlitDeclaration::semantic() %s\n", toChars()); 
    27462778    //printf("ident: %s, %s, %p, %p\n", ident->toChars(), Id::dtor->toChars(), ident, Id::dtor); 
     2779    //printf("stc = x%llx\n", sc->stc); 
    27472780    parent = sc->parent; 
    27482781    Dsymbol *parent = toParent(); 
     
    27522785    error("post blits are only for struct/union definitions, not %s %s", parent->kind(), parent->toChars()); 
    27532786    } 
    2754     else if (ident == Id::_postblit
     2787    else if (ident == Id::_postblit && semanticRun < PASSsemantic
    27552788    ad->postblits.push(this); 
    2756     type = new TypeFunction(NULL, Type::tvoid, FALSE, LINKd); 
     2789 
     2790    if (!type) 
     2791    type = new TypeFunction(NULL, Type::tvoid, FALSE, LINKd); 
    27572792 
    27582793    sc = sc->push(); 
     
    27872822void PostBlitDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) 
    27882823{ 
    2789     if (hgs->hdrgen) 
    2790     return; 
    2791     buf->writestring("=this()"); 
     2824    buf->writestring("this(this)"); 
    27922825    bodyToCBuffer(buf, hgs); 
    27932826} 
     
    28262859    fatal(); 
    28272860    } 
    2828     else 
     2861    else if (semanticRun < PASSsemantic) 
    28292862    cd->dtors.push(this); 
    2830     type = new TypeFunction(NULL, Type::tvoid, FALSE, LINKd); 
     2863 
     2864    if (!type) 
     2865    type = new TypeFunction(NULL, Type::tvoid, FALSE, LINKd); 
    28312866 
    28322867    sc = sc->push(); 
     
    28942929Dsymbol *StaticCtorDeclaration::syntaxCopy(Dsymbol *s) 
    28952930{ 
    2896     StaticCtorDeclaration *scd; 
    2897  
    28982931    assert(!s); 
    2899     scd = new StaticCtorDeclaration(loc, endloc); 
     2932    StaticCtorDeclaration *scd = new StaticCtorDeclaration(loc, endloc); 
    29002933    return FuncDeclaration::syntaxCopy(scd); 
    29012934} 
     
    29062939    //printf("StaticCtorDeclaration::semantic()\n"); 
    29072940 
    2908     type = new TypeFunction(NULL, Type::tvoid, FALSE, LINKd); 
     2941    if (!type) 
     2942    type = new TypeFunction(NULL, Type::tvoid, FALSE, LINKd); 
    29092943 
    29102944    /* If the static ctor appears within a template instantiation, 
     
    29122946     * for different modules. Thus, protect it with a gate. 
    29132947     */ 
    2914     if (inTemplateInstance()
     2948    if (inTemplateInstance() && semanticRun < PASSsemantic
    29152949    { 
    29162950    /* Add this prefix to the function: 
     
    29442978    if (m) 
    29452979    {   m->needmoduleinfo = 1; 
     2980    //printf("module1 %s needs moduleinfo\n", m->toChars()); 
    29462981#ifdef IN_GCC 
    29472982    m->strictlyneedmoduleinfo = 1; 
     
    30063041void StaticDtorDeclaration::semantic(Scope *sc) 
    30073042{ 
    3008     ClassDeclaration *cd; 
    3009     Type *tret; 
    3010  
    3011     cd = sc->scopesym->isClassDeclaration(); 
    3012     if (!cd) 
    3013     { 
    3014     } 
    3015     type = new TypeFunction(NULL, Type::tvoid, FALSE, LINKd); 
     3043    ClassDeclaration *cd = sc->scopesym->isClassDeclaration(); 
     3044 
     3045    if (!type) 
     3046    type = new TypeFunction(NULL, Type::tvoid, FALSE, LINKd); 
    30163047 
    30173048    /* If the static ctor appears within a template instantiation, 
     
    30193050     * for different modules. Thus, protect it with a gate. 
    30203051     */ 
    3021     if (inTemplateInstance()
     3052    if (inTemplateInstance() && semanticRun < PASSsemantic
    30223053    { 
    30233054    /* Add this prefix to the function: 
     
    31133144void InvariantDeclaration::semantic(Scope *sc) 
    31143145{ 
    3115     AggregateDeclaration *ad; 
    3116     Type *tret; 
    3117  
    31183146    parent = sc->parent; 
    31193147    Dsymbol *parent = toParent(); 
    3120     ad = parent->isAggregateDeclaration(); 
     3148    AggregateDeclaration *ad = parent->isAggregateDeclaration(); 
    31213149    if (!ad) 
    31223150    { 
     
    31243152    return; 
    31253153    } 
    3126     else if (ad->inv && ad->inv != this
     3154    else if (ad->inv && ad->inv != this && semanticRun < PASSsemantic
    31273155    { 
    31283156    error("more than one invariant for %s", ad->toChars()); 
    31293157    } 
    31303158    ad->inv = this; 
    3131     type = new TypeFunction(NULL, Type::tvoid, FALSE, LINKd); 
     3159    if (!type) 
     3160    type = new TypeFunction(NULL, Type::tvoid, FALSE, LINKd); 
    31323161 
    31333162    sc = sc->push(); 
     
    31963225    if (global.params.useUnitTests) 
    31973226    { 
    3198     type = new TypeFunction(NULL, Type::tvoid, FALSE, LINKd); 
     3227    if (!type) 
     3228        type = new TypeFunction(NULL, Type::tvoid, FALSE, LINKd); 
    31993229    Scope *sc2 = sc->push(); 
    32003230    sc2->linkage = LINKd; 
     
    32723302void NewDeclaration::semantic(Scope *sc) 
    32733303{ 
    3274     ClassDeclaration *cd; 
    3275     Type *tret; 
    3276  
    32773304    //printf("NewDeclaration::semantic()\n"); 
    32783305 
    32793306    parent = sc->parent; 
    32803307    Dsymbol *parent = toParent(); 
    3281     cd = parent->isClassDeclaration(); 
     3308    ClassDeclaration *cd = parent->isClassDeclaration(); 
    32823309    if (!cd && !parent->isStructDeclaration()) 
    32833310    { 
    32843311    error("new allocators only are for class or struct definitions"); 
    32853312    } 
    3286     tret = Type::tvoid->pointerTo(); 
    3287     type = new TypeFunction(arguments, tret, varargs, LINKd); 
     3313    Type *tret = Type::tvoid->pointerTo(); 
     3314    if (!type) 
     3315    type = new TypeFunction(arguments, tret, varargs, LINKd); 
    32883316 
    32893317    type = type->semantic(loc, sc); 
     
    33583386void DeleteDeclaration::semantic(Scope *sc) 
    33593387{ 
    3360     ClassDeclaration *cd; 
    3361  
    33623388    //printf("DeleteDeclaration::semantic()\n"); 
    33633389 
    33643390    parent = sc->parent; 
    33653391    Dsymbol *parent = toParent(); 
    3366     cd = parent->isClassDeclaration(); 
     3392    ClassDeclaration *cd = parent->isClassDeclaration(); 
    33673393    if (!cd && !parent->isStructDeclaration()) 
    33683394    { 
    33693395    error("new allocators only are for class or struct definitions"); 
    33703396    } 
    3371     type = new TypeFunction(arguments, Type::tvoid, 0, LINKd); 
     3397    if (!type) 
     3398    type = new TypeFunction(arguments, Type::tvoid, 0, LINKd); 
    33723399 
    33733400    type = type->semantic(loc, sc); 
  • dmd/identifier.h

    r1195 r1630  
    1717 
    1818#include "root.h" 
    19  
     19#if IN_LLVM 
    2020namespace llvm 
    2121{ 
    2222    class Value; 
    2323} 
     24#endif 
    2425 
    2526struct Identifier : Object 
  • dmd/inline.c

    r1587 r1630  
    12821282    return 0; 
    12831283 
    1284     if (inlineNest || (semanticRun < 3 && !hdrscan)) 
     1284    if (inlineNest || (semanticRun < PASSsemantic3 && !hdrscan)) 
    12851285    { 
    12861286#if CANINLINE_LOG 
  • dmd/interpret.c

    r1627 r1630  
    11 
    22// Compiler implementation of the D programming language 
    3 // Copyright (c) 1999-2009 by Digital Mars 
     3// Copyright (c) 1999-2010 by Digital Mars 
    44// All Rights Reserved 
    55// written by Walter Bright 
     
    5353Expression *interpret_values(InterState *istate, Expression *earg, FuncDeclaration *fd); 
    5454 
     55ArrayLiteralExp *createBlockDuplicatedArrayLiteral(Type *type, Expression *elem, size_t dim); 
     56 
    5557/************************************* 
    5658 * Attempt to interpret a function given the arguments. 
     
    9395#endif 
    9496 
    95     if (cantInterpret || semanticRun == 3) 
     97    if (cantInterpret || semanticRun == PASSsemantic3) 
    9698    return NULL; 
    9799 
     
    101103    } 
    102104 
    103     if (semanticRun < 3 && scope) 
     105    if (semanticRun < PASSsemantic3 && scope) 
    104106    { 
    105107    semantic3(scope); 
     
    107109        return NULL; 
    108110    } 
    109     if (semanticRun < 4
     111    if (semanticRun < PASSsemantic3done
    110112    return NULL; 
    111113 
     
    161163        Parameter *arg = Parameter::getNth(tf->parameters, i); 
    162164 
    163         if (arg->storageClass & (STCout | STCref)) 
     165        if (arg->storageClass & (STCout | STCref | STClazy)) 
    164166        { 
    165167        } 
     
    10061008} 
    10071009 
     1010Expression *FuncExp::interpret(InterState *istate) 
     1011{ 
     1012#if LOG 
     1013    printf("FuncExp::interpret() %s\n", toChars()); 
     1014#endif 
     1015    return this; 
     1016} 
     1017 
     1018Expression *SymOffExp::interpret(InterState *istate) 
     1019{ 
     1020#if LOG 
     1021    printf("SymOffExp::interpret() %s\n", toChars()); 
     1022#endif 
     1023    if (var->isFuncDeclaration() && offset == 0) 
     1024    { 
     1025    return this; 
     1026    } 
     1027    error("Cannot interpret %s at compile time", toChars()); 
     1028    return EXP_CANT_INTERPRET; 
     1029} 
     1030 
     1031Expression *DelegateExp::interpret(InterState *istate) 
     1032{ 
     1033#if LOG 
     1034    printf("DelegateExp::interpret() %s\n", toChars()); 
     1035#endif 
     1036    return this; 
     1037} 
     1038 
    10081039Expression *getVarExp(Loc loc, InterState *istate, Declaration *d) 
    10091040{ 
     
    10141045    { 
    10151046#if DMDV2 
     1047    /* Magic variable __ctfe always returns true when interpreting 
     1048     */ 
     1049    if (v->ident == Id::ctfe) 
     1050        return new IntegerExp(loc, 1, Type::tbool); 
     1051 
    10161052    if ((v->isConst() || v->isImmutable() || v->storage_class & STCmanifest) && v->init && !v->value) 
    10171053#else 
     
    10211057        if (e && !e->type) 
    10221058        e->type = v->type; 
     1059    } 
     1060    else if (v->isCTFE() && !v->value) 
     1061    { 
     1062        if (v->init) 
     1063        { 
     1064        e = v->init->toExpression(); 
     1065        e = e->interpret(istate); 
     1066        } 
     1067        else // This should never happen 
     1068        e = v->type->defaultInitLiteral(); 
    10231069    } 
    10241070    else 
     
    14831529 
    14841530/*************************************** 
    1485  * Returns oldelems[0..insertpoint] ~ newelems ~ oldelems[insertpoint..$] 
     1531 * Returns oldelems[0..insertpoint] ~ newelems ~ oldelems[insertpoint+newelems.length..$] 
    14861532 */ 
    14871533Expressions *spliceElements(Expressions *oldelems, 
     
    14981544    } 
    14991545    return expsx; 
     1546} 
     1547 
     1548/*************************************** 
     1549 * Returns oldstr[0..insertpoint] ~ newstr ~ oldstr[insertpoint+newlen..$] 
     1550 */ 
     1551StringExp *spliceStringExp(StringExp *oldstr, StringExp *newstr, size_t insertpoint) 
     1552{ 
     1553    assert(oldstr->sz==newstr->sz); 
     1554    unsigned char *s; 
     1555    size_t oldlen = oldstr->len; 
     1556    size_t newlen = newstr->len; 
     1557    size_t sz = oldstr->sz; 
     1558    s = (unsigned char *)mem.calloc(oldlen + 1, sz); 
     1559    memcpy(s, oldstr->string, oldlen * sz); 
     1560    memcpy(s + insertpoint * sz, newstr->string, newlen * sz); 
     1561    StringExp *se2 = new StringExp(oldstr->loc, s, oldlen); 
     1562    se2->committed = oldstr->committed; 
     1563    se2->postfix = oldstr->postfix; 
     1564    se2->type = oldstr->type; 
     1565    return se2; 
    15001566} 
    15011567 
     
    15151581} 
    15161582 
     1583/****************************** 
     1584 * Create a string literal consisting of 'value' duplicated 'dim' times. 
     1585 */ 
     1586StringExp *createBlockDuplicatedStringLiteral(Type *type, 
     1587    unsigned value, size_t dim, int sz) 
     1588{ 
     1589    unsigned char *s; 
     1590    s = (unsigned char *)mem.calloc(dim + 1, sz); 
     1591    for (int elemi=0; elemi<dim; ++elemi) 
     1592    { 
     1593        switch (sz) 
     1594    { 
     1595        case 1: s[elemi] = value; break; 
     1596        case 2: ((unsigned short *)s)[elemi] = value; break; 
     1597        case 4: ((unsigned *)s)[elemi] = value; break; 
     1598        default:    assert(0); 
     1599    } 
     1600    } 
     1601    StringExp *se = new StringExp(0, s, dim); 
     1602    se->type = type; 
     1603    return se; 
     1604} 
    15171605 
    15181606/******************************** 
     
    15831671    // extract the aggregate now. 
    15841672    Expression *aggregate; 
    1585     if (e1->op == TOKdotvar) { 
     1673    if (e1->op == TOKdotvar) 
     1674    { 
    15861675        aggregate = ((DotVarExp *)e1)->e1; 
    15871676    // Get rid of 'this'. 
    15881677        if (aggregate->op == TOKthis && istate->localThis) 
    1589             aggregate = istate->localThis;   
    1590     } 
    1591      
     1678            aggregate = istate->localThis; 
     1679    } 
     1680    if (e1->op == TOKthis && istate->localThis) 
     1681    e1 = istate->localThis; 
     1682 
    15921683    /* Assignment to variable of the form: 
    15931684     *  v = e2 
     
    16241715        return e2; 
    16251716 
    1626         addVarToInterstate(istate, v); 
     1717        if (istate) 
     1718        addVarToInterstate(istate, v); 
    16271719        v->value = e2; 
    16281720        e = Cast(type, type, post ? ev : e2); 
     
    16691761         * That's probably a good enhancement idea. 
    16701762         */ 
    1671         v->value = v->type->defaultInit(); 
     1763        v->value = v->type->defaultInitLiteral(); 
    16721764    } 
    16731765    Expression *vie = v->value; 
     1766    assert(vie != EXP_CANT_INTERPRET); 
     1767 
    16741768    if (vie->op == TOKvar) 
    16751769    { 
     
    16781772    } 
    16791773    if (vie->op != TOKstructliteral) 
     1774    { 
     1775        error("Cannot assign %s=%s in CTFE", v->toChars(), vie->toChars()); 
    16801776        return EXP_CANT_INTERPRET; 
     1777    } 
    16811778    StructLiteralExp *se = (StructLiteralExp *)vie; 
    16821779    VarDeclaration *vf = ((DotVarExp *)e1)->var->isVarDeclaration(); 
     
    20162113        return EXP_CANT_INTERPRET; 
    20172114    } 
    2018        // Chase down rebinding of out and ref 
    2019        if (v->value && v->value->op == TOKvar) 
    2020        { 
    2021        VarExp *ve2 = (VarExp *)v->value; 
    2022        if (ve2->var->isStaticStructInitDeclaration()) 
    2023        {  // This can happen if v is a struct initialized to 
    2024            // 0 using an __initZ SymbolDeclaration from 
    2025            // TypeStruct::defaultInit() 
    2026        
    2027        else 
    2028             v = ve2->var->isVarDeclaration(); 
    2029        assert(v); 
    2030        
     2115       // Chase down rebinding of out and ref 
     2116        if (v->value && v->value->op == TOKvar) 
     2117        { 
     2118        VarExp *ve2 = (VarExp *)v->value; 
     2119        if (ve2->var->isStaticStructInitDeclaration()) 
     2120        { // This can happen if v is a struct initialized to 
     2121        // 0 using an __initZ SymbolDeclaration from 
     2122        // TypeStruct::defaultInit() 
     2123       
     2124        else 
     2125        v = ve2->var->isVarDeclaration(); 
     2126        assert(v); 
     2127   
    20312128    /* Set the $ variable 
    20322129     */ 
     
    20632160        dim = ((ArrayLiteralExp *)v->value)->elements->dim; 
    20642161        else if (v->value->op ==TOKstring) 
    2065         { 
    2066         error("String slice assignment is not yet supported in CTFE"); 
    2067         return EXP_CANT_INTERPRET; 
    2068         } 
     2162           dim = ((StringExp *)v->value)->len; 
    20692163    } 
    20702164    else 
     
    20762170    int lowerbound = lower ? lower->toInteger() : 0; 
    20772171 
    2078     ArrayLiteralExp *existing; 
    20792172    if (((int)lowerbound < 0) || (upperbound > dim)) 
    20802173    { 
    2081         error("Array bounds [0..%d] exceeded in slice [%d..%d]", dim, lowerbound, upperbound); 
     2174        error("Array bounds [0..%d] exceeded in slice [%d..%d]", 
     2175        dim, lowerbound, upperbound); 
    20822176        return EXP_CANT_INTERPRET; 
    20832177    } 
    2084     if (upperbound-lowerbound != dim) 
    2085     { 
    2086         // Only modifying part of the array. Must create a new array literal. 
    2087         // If the existing array is uninitialized (this can only happen 
    2088         // with static arrays), create it. 
    2089         if (v->value && v->value->op == TOKarrayliteral) 
    2090             existing = (ArrayLiteralExp *)v->value; 
    2091         else 
    2092         { 
    2093         // this can only happen with static arrays 
    2094         existing = createBlockDuplicatedArrayLiteral(v->type, v->type->defaultInit(), dim); 
    2095         } 
    2096     } 
    2097  
     2178    // Could either be slice assignment (v[] = e[]),  
     2179    // or block assignment (v[] = val).  
     2180    // For the former, we check that the lengths match. 
     2181    bool isSliceAssignment = (e2->op == TOKarrayliteral) 
     2182        || (e2->op == TOKstring); 
     2183    size_t srclen = 0; 
     2184    if (e2->op == TOKarrayliteral) 
     2185        srclen = ((ArrayLiteralExp *)e2)->elements->dim; 
     2186    else if (e2->op == TOKstring) 
     2187        srclen = ((StringExp *)e2)->len; 
     2188    if (isSliceAssignment && srclen != (upperbound - lowerbound)) 
     2189    { 
     2190        error("Array length mismatch assigning [0..%d] to [%d..%d]", srclen, lowerbound, upperbound); 
     2191        return e; 
     2192    } 
    20982193    if (e2->op == TOKarrayliteral) 
    20992194    { 
    21002195        // Static array assignment from literal 
    21012196        ArrayLiteralExp *ae = (ArrayLiteralExp *)e2;                 
    2102         if (ae->elements->dim != (upperbound - lowerbound)) 
    2103         { 
    2104         error("Array length mismatch assigning [0..%d] to [%d..%d]", ae->elements->dim, lowerbound, upperbound); 
    2105         return e; 
    2106         } 
    21072197        if (upperbound - lowerbound == dim) 
    21082198        v->value = ae; 
    21092199        else 
    21102200        { 
     2201        ArrayLiteralExp *existing; 
     2202        // Only modifying part of the array. Must create a new array literal. 
     2203        // If the existing array is uninitialized (this can only happen 
     2204        // with static arrays), create it. 
     2205        if (v->value && v->value->op == TOKarrayliteral) 
     2206            existing = (ArrayLiteralExp *)v->value; 
     2207        else // this can only happen with static arrays 
     2208            existing = createBlockDuplicatedArrayLiteral(v->type, v->type->defaultInit(), dim); 
    21112209        // value[] = value[0..lower] ~ ae ~ value[upper..$] 
    21122210        existing->elements = spliceElements(existing->elements, ae->elements, lowerbound); 
     
    21152213        return e2; 
    21162214    } 
     2215    else if (e2->op == TOKstring) 
     2216    { 
     2217        StringExp *se = (StringExp *)e2; 
     2218        if (upperbound-lowerbound == dim) 
     2219            v->value = e2;       
     2220        else 
     2221        { 
     2222        if (!v->value) 
     2223            v->value = createBlockDuplicatedStringLiteral(se->type, 
     2224            se->type->defaultInit()->toInteger(), dim, se->sz); 
     2225        if (v->value->op==TOKstring) 
     2226                v->value = spliceStringExp((StringExp *)v->value, se, lowerbound); 
     2227        else 
     2228                error("String slice assignment is not yet supported in CTFE"); 
     2229        } 
     2230        return e2; 
     2231    } 
    21172232    else if (t->nextOf()->ty == e2->type->ty) 
    21182233    { 
    2119         // Static array block assignment 
    2120         if (upperbound-lowerbound ==dim) 
     2234        // Static array block assignment 
     2235        if (upperbound - lowerbound == dim) 
    21212236        v->value = createBlockDuplicatedArrayLiteral(v->type, e2, dim); 
    21222237        else 
    21232238        { 
     2239        ArrayLiteralExp *existing; 
     2240        // Only modifying part of the array. Must create a new array literal. 
     2241        // If the existing array is uninitialized (this can only happen 
     2242        // with static arrays), create it. 
     2243        if (v->value && v->value->op == TOKarrayliteral) 
     2244            existing = (ArrayLiteralExp *)v->value; 
     2245        else // this can only happen with static arrays 
     2246            existing = createBlockDuplicatedArrayLiteral(v->type, v->type->defaultInit(), dim); 
    21242247        // value[] = value[0..lower] ~ ae ~ value[upper..$] 
    2125         existing->elements = spliceElements(existing->elements, createBlockDuplicatedArrayLiteral(v->type, e2, upperbound-lowerbound)->elements, lowerbound); 
     2248        existing->elements = spliceElements(existing->elements, 
     2249            createBlockDuplicatedArrayLiteral(v->type, e2, upperbound-lowerbound)->elements, 
     2250            lowerbound); 
    21262251        v->value = existing; 
    21272252        }                
    2128         return e2; 
    2129     } 
    2130     else if (e2->op == TOKstring) 
    2131     { 
    2132         StringExp *se = (StringExp *)e2; 
    2133         // This is problematic. char[8] should be storing 
    2134         // values as a string literal, not 
    2135         // as an array literal. Then, for static arrays, we 
    2136         // could do modifications 
    2137         // in-place, with a dramatic memory and speed improvement. 
    2138         error("String slice assignment is not yet supported in CTFE"); 
    21392253        return e2; 
    21402254    } 
     
    22612375    printf("CallExp::interpret() %s\n", toChars()); 
    22622376#endif 
    2263     if (e1->op == TOKdotvar) 
    2264     { 
    2265         Expression * pthis = ((DotVarExp*)e1)->e1; 
    2266     FuncDeclaration *fd = ((DotVarExp*)e1)->var->isFuncDeclaration(); 
    2267     TypeFunction *tf = fd ? (TypeFunction *)(fd->type) : NULL; 
    2268     if (tf) 
    2269     {   // Member function call 
    2270         if(pthis->op == TOKthis) 
    2271         pthis = istate->localThis;       
    2272         Expression *eresult = fd->interpret(istate, arguments, pthis); 
     2377 
     2378    Expression * pthis = NULL;  
     2379    FuncDeclaration *fd = NULL; 
     2380    Expression *ecall = e1; 
     2381    if (ecall->op == TOKindex) 
     2382        ecall = e1->interpret(istate); 
     2383    if (ecall->op == TOKdotvar && !((DotVarExp*)ecall)->var->isFuncDeclaration()) 
     2384        ecall = e1->interpret(istate); 
     2385    
     2386    if (ecall->op == TOKdotvar) 
     2387    {   // Calling a member function     
     2388        pthis = ((DotVarExp*)e1)->e1; 
     2389    fd = ((DotVarExp*)e1)->var->isFuncDeclaration(); 
     2390    } 
     2391    else if (ecall->op == TOKvar) 
     2392    { 
     2393        VarDeclaration *vd = ((VarExp *)ecall)->var->isVarDeclaration(); 
     2394    if (vd && vd->value)  
     2395        ecall = vd->value; 
     2396    else // Calling a function 
     2397        fd = ((VarExp *)e1)->var->isFuncDeclaration(); 
     2398    }     
     2399    if (ecall->op == TOKdelegate) 
     2400    {   // Calling a delegate 
     2401    fd = ((DelegateExp *)ecall)->func; 
     2402    pthis = ((DelegateExp *)ecall)->e1; 
     2403    } 
     2404    else if (ecall->op == TOKfunction) 
     2405    {   // Calling a delegate literal 
     2406        fd = ((FuncExp*)ecall)->fd; 
     2407    } 
     2408    else if (ecall->op == TOKstar && ((PtrExp*)ecall)->e1->op==TOKfunction) 
     2409    {   // Calling a function literal 
     2410        fd = ((FuncExp*)((PtrExp*)ecall)->e1)->fd; 
     2411    }    
     2412    else if (ecall->op == TOKstar && ((PtrExp*)ecall)->e1->op==TOKvar) 
     2413    {   // Calling a function pointer 
     2414        VarDeclaration *vd = ((VarExp *)((PtrExp*)ecall)->e1)->var->isVarDeclaration(); 
     2415    if (vd && vd->value && vd->value->op==TOKsymoff)  
     2416        fd = ((SymOffExp *)vd->value)->var->isFuncDeclaration(); 
     2417    } 
     2418     
     2419    TypeFunction *tf = fd ? (TypeFunction *)(fd->type) : NULL; 
     2420    if (!tf) 
     2421    {   // DAC: I'm not sure if this ever happens 
     2422    //printf("ecall=%s %d %d\n", ecall->toChars(), ecall->op, TOKcall); 
     2423    error("cannot evaluate %s at compile time", toChars()); 
     2424    return EXP_CANT_INTERPRET; 
     2425    } 
     2426    if (pthis && fd) 
     2427    {   // Member function call 
     2428    if (pthis->op == TOKthis) 
     2429        pthis = istate->localThis; 
     2430    else if (pthis->op == TOKcomma) 
     2431        pthis = pthis->interpret(istate); 
     2432    Expression *eresult = fd->interpret(istate, arguments, pthis); 
     2433    if (eresult) 
     2434        e = eresult; 
     2435    else if (fd->type->toBasetype()->nextOf()->ty == Tvoid && !global.errors) 
     2436        e = EXP_VOID_INTERPRET; 
     2437    else 
     2438        error("cannot evaluate %s at compile time", toChars()); 
     2439    return e; 
     2440    } 
     2441    else if (fd) 
     2442    {    // function call 
     2443#if DMDV2 
     2444    enum BUILTIN b = fd->isBuiltin(); 
     2445    if (b) 
     2446    {   Expressions args; 
     2447        args.setDim(arguments->dim); 
     2448        for (size_t i = 0; i < args.dim; i++) 
     2449        { 
     2450        Expression *earg = (Expression *)arguments->data[i]; 
     2451        earg = earg->interpret(istate); 
     2452        if (earg == EXP_CANT_INTERPRET) 
     2453            return earg; 
     2454        args.data[i] = (void *)earg; 
     2455        } 
     2456        e = eval_builtin(b, &args); 
     2457        if (!e) 
     2458        e = EXP_CANT_INTERPRET; 
     2459    } 
     2460    else 
     2461#endif 
     2462    // Inline .dup 
     2463    if (fd->ident == Id::adDup && arguments && arguments->dim == 2) 
     2464    { 
     2465        e = (Expression *)arguments->data[1]; 
     2466        e = e->interpret(istate); 
     2467        if (e != EXP_CANT_INTERPRET) 
     2468        { 
     2469        e = expType(type, e); 
     2470        } 
     2471    } 
     2472    else 
     2473    { 
     2474        Expression *eresult = fd->interpret(istate, arguments); 
    22732475        if (eresult) 
    22742476        e = eresult; 
     
    22772479        else 
    22782480        error("cannot evaluate %s at compile time", toChars()); 
    2279         return e; 
    2280     }  
     2481    } 
     2482    } 
     2483    else 
     2484    { 
    22812485    error("cannot evaluate %s at compile time", toChars()); 
    22822486        return EXP_CANT_INTERPRET; 
    22832487    } 
    2284     if (e1->op == TOKvar) 
    2285     { 
    2286     FuncDeclaration *fd = ((VarExp *)e1)->var->isFuncDeclaration(); 
    2287     if (fd) 
    2288     { 
    2289 #if DMDV2 
    2290         enum BUILTIN b = fd->isBuiltin(); 
    2291         if (b) 
    2292         {   Expressions args; 
    2293         args.setDim(arguments->dim); 
    2294         for (size_t i = 0; i < args.dim; i++) 
    2295         { 
    2296             Expression *earg = (Expression *)arguments->data[i]; 
    2297             earg = earg->interpret(istate); 
    2298             if (earg == EXP_CANT_INTERPRET) 
    2299             return earg; 
    2300             args.data[i] = (void *)earg; 
    2301         } 
    2302         e = eval_builtin(b, &args); 
    2303         if (!e) 
    2304             e = EXP_CANT_INTERPRET; 
    2305         } 
    2306         else 
    2307 #endif 
    2308         // Inline .dup 
    2309         if (fd->ident == Id::adDup && arguments && arguments->dim == 2) 
    2310         { 
    2311         e = (Expression *)arguments->data[1]; 
    2312         e = e->interpret(istate); 
    2313         if (e != EXP_CANT_INTERPRET) 
    2314         { 
    2315             e = expType(type, e); 
    2316         } 
    2317         } 
    2318         else 
    2319         { 
    2320         Expression *eresult = fd->interpret(istate, arguments); 
    2321         if (eresult) 
    2322             e = eresult; 
    2323         else if (fd->type->toBasetype()->nextOf()->ty == Tvoid && !global.errors) 
    2324             e = EXP_VOID_INTERPRET; 
    2325         else 
    2326             error("cannot evaluate %s at compile time", toChars()); 
    2327         } 
    2328     } 
    2329     } 
    2330     return e; 
     2488    return e;  
    23312489} 
    23322490 
     
    23362494    printf("CommaExp::interpret() %s\n", toChars()); 
    23372495#endif 
     2496    // If the comma returns a temporary variable, it needs to be an lvalue 
     2497    // (this is particularly important for struct constructors) 
     2498    if (e1->op == TOKdeclaration && e2->op == TOKvar  
     2499       && ((DeclarationExp *)e1)->declaration == ((VarExp*)e2)->var) 
     2500    { 
     2501    VarExp* ve = (VarExp *)e2; 
     2502    VarDeclaration *v = ve->var->isVarDeclaration(); 
     2503    if (!v->init && !v->value) 
     2504        v->value = v->type->defaultInitLiteral(); 
     2505    if (!v->value) 
     2506        v->value = v->init->toExpression(); 
     2507    v->value = v->value->interpret(istate);  
     2508    return e2; 
     2509    } 
     2510 
    23382511    Expression *e = e1->interpret(istate); 
    23392512    if (e != EXP_CANT_INTERPRET) 
     
    25172690    {   // Special case: deal with compiler-inserted assert(&this, "null this")  
    25182691    AddrExp *ade = (AddrExp *)this->e1; 
    2519     if(ade->e1->op == TOKthis && istate->localThis)      
    2520     return istate->localThis->interpret(istate); 
    2521     } 
    2522 if (this->e1->op == TOKthis) 
    2523 
    2524     if(istate->localThis)        
    2525     return istate->localThis->interpret(istate); 
    2526 }     
     2692    if (ade->e1->op == TOKthis && istate->localThis) 
     2693        if (ade->e1->op == TOKdotvar 
     2694            && ((DotVarExp *)(istate->localThis))->e1->op == TOKthis) 
     2695            return getVarExp(loc, istate, ((DotVarExp*)(istate->localThis))->var); 
     2696        else 
     2697            return istate->localThis->interpret(istate); 
     2698    } 
     2699    if (this->e1->op == TOKthis) 
     2700    { 
     2701    if (istate->localThis) 
     2702        return istate->localThis->interpret(istate); 
     2703    } 
    25272704    e1 = this->e1->interpret(istate); 
    25282705    if (e1 == EXP_CANT_INTERPRET) 
  • dmd/mangle.c

    r1587 r1630  
    114114            break; 
    115115 
    116         // LDC 
     116#if IN_LLVM 
    117117        case LINKintrinsic: 
    118  
     118#endif 
    119119        case LINKc: 
    120120        case LINKwindows: 
  • dmd/mars.c

    r1628 r1630  
    11 
    22// Compiler implementation of the D programming language 
    3 // Copyright (c) 1999-2009 by Digital Mars 
     3// Copyright (c) 1999-2010 by Digital Mars 
    44// All Rights Reserved 
    55// written by Walter Bright 
     
    1414#include <assert.h> 
    1515#include <limits.h> 
     16#if IN_LLVM 
    1617#include <string> 
    1718#include <cstdarg> 
     19#endif 
    1820 
    1921#if POSIX 
     
    3537#include "json.h" 
    3638 
     39#if IN_LLVM 
    3740#include "gen/revisions.h" 
     41#endif 
    3842 
    3943Global global; 
     
    4751    ddoc_ext = "ddoc"; 
    4852    json_ext = "json"; 
     53    map_ext  = "map"; 
    4954 
    5055// LDC 
     
    5964    copyright = "Copyright (c) 1999-2009 by Digital Mars and Tomas Lindquist Olsen"; 
    6065    written = "written by Walter Bright and Tomas Lindquist Olsen"; 
    61     version = "v1.055"; 
     66    version = "v1.056"; 
    6267    ldc_version = LDC_REV; 
    6368    llvm_version = LLVM_REV_STR; 
  • dmd/mars.h

    r1621 r1630  
    11 
    22// Compiler implementation of the D programming language 
    3 // Copyright (c) 1999-2009 by Digital Mars 
     3// Copyright (c) 1999-2010 by Digital Mars 
    44// All Rights Reserved 
    55// written by Walter Bright 
     
    236236    char *resfile; 
    237237    char *exefile; 
    238  
     238    char *mapfile; 
     239 
     240#if IN_LLVM 
    239241    // LDC stuff 
    240242    OUTPUTFLAG output_ll; 
     
    251253    const char *targetTriple; 
    252254    const char *dataLayout; 
     255#endif 
    253256}; 
    254257 
     
    269272    const char *hdr_ext;    // for D 'header' import files 
    270273    const char *json_ext;   // for JSON files 
     274    const char *map_ext;    // for .map files 
    271275    const char *copyright; 
    272276    const char *written; 
     
    394398    LINKpascal, 
    395399 
    396     // LDC 
     400#if IN_LLVM 
    397401    LINKintrinsic, 
     402#endif 
    398403}; 
    399404 
  • dmd/module.c

    r1587 r1630  
    11 
    22// Compiler implementation of the D programming language 
    3 // Copyright (c) 1999-2009 by Digital Mars 
     3// Copyright (c) 1999-2010 by Digital Mars 
    44// All Rights Reserved 
    55// written by Walter Bright 
     
    4545#endif 
    4646 
    47  
     47#if IN_LLVM 
    4848#include "llvm/Support/CommandLine.h" 
    4949#include <map> 
     
    5656    llvm::cl::desc("Write object files with fully qualified names"), 
    5757    llvm::cl::ZeroOrMore); 
    58  
    59  
     58#endif 
    6059 
    6160ClassDeclaration *Module::moduleinfo; 
     
    972971void Module::runDeferredSemantic() 
    973972{ 
    974     size_t len; 
     973    if (dprogress == 0) 
     974    return; 
    975975 
    976976    static int nested; 
     
    980980    nested++; 
    981981 
     982    size_t len; 
    982983    do 
    983984    { 
  • dmd/module.h

    r1587 r1630  
    154154    void deleteObjFile(); 
    155155    void addDeferredSemantic(Dsymbol *s); 
    156     void runDeferredSemantic(); 
     156    static void runDeferredSemantic(); 
    157157    int imports(Module *m); 
    158158 
  • dmd/mtype.c

    r1627 r1630  
    40624062{ 
    40634063    if (sym->scope) 
    4064     { 
    4065     sym->semantic(NULL);    // attempt to resolve forward reference 
     4064    {   // Enum is forward referenced. We don't need to resolve the whole thing, 
     4065    // just the base type 
     4066    if (sym->memtype) 
     4067    {   sym->memtype = sym->memtype->semantic(sym->loc, sym->scope); 
     4068    } 
     4069    else 
     4070    {   if (!sym->isAnonymous()) 
     4071        sym->memtype = Type::tint32; 
     4072    } 
    40664073    } 
    40674074    if (!sym->memtype) 
  • dmd/optimize.c

    r1622 r1630  
    11 
    22// Compiler implementation of the D programming language 
    3 // Copyright (c) 1999-2009 by Digital Mars 
     3// Copyright (c) 1999-2010 by Digital Mars 
    44// All Rights Reserved 
    55// written by Walter Bright 
     
    345345 
    346346Expression *CallExp::optimize(int result) 
    347 {   Expression *e = this; 
     347
     348    //printf("CallExp::optimize(result = %d) %s\n", result, toChars()); 
     349    Expression *e = this; 
    348350 
    349351    // Optimize parameters 
     
    359361 
    360362    e1 = e1->optimize(result); 
    361     if (e1->op == TOKvar && result & WANTinterpret) 
    362     { 
    363     FuncDeclaration *fd = ((VarExp *)e1)->var->isFuncDeclaration(); 
    364     if (fd) 
    365     { 
    366         Expression *eresult = fd->interpret(NULL, arguments); 
    367         if (eresult && eresult != EXP_VOID_INTERPRET) 
    368         e = eresult; 
    369         else if (result & WANTinterpret) 
    370         error("cannot evaluate %s at compile time", toChars()); 
    371     } 
     363    if (result & WANTinterpret) 
     364    { 
     365        Expression *eresult = interpret(NULL); 
     366    if (eresult == EXP_CANT_INTERPRET) 
     367        return e; 
     368    if (eresult && eresult != EXP_VOID_INTERPRET) 
     369        e = eresult; 
     370    else 
     371        error("cannot evaluate %s at compile time", toChars()); 
    372372    } 
    373373    return e; 
     
    625625 
    626626    //printf("CommaExp::optimize(result = %d) %s\n", result, toChars()); 
     627    // Comma needs special treatment, because it may 
     628    // contain compiler-generated declarations. We can interpret them, but 
     629    // otherwise we must NOT attempt to constant-fold them. 
     630    // In particular, if the comma returns a temporary variable, it needs 
     631    // to be an lvalue (this is particularly important for struct constructors) 
     632 
     633    if (result & WANTinterpret) 
     634    {   // Interpreting comma needs special treatment, because it may 
     635        // contain compiler-generated declarations. 
     636    e = interpret(NULL); 
     637    return (e == EXP_CANT_INTERPRET) ?  this : e; 
     638    } 
     639    // Don't constant fold if it is a compiler-generated temporary. 
     640    if (e1->op == TOKdeclaration) 
     641       return this; 
     642 
    627643    e1 = e1->optimize(result & WANTinterpret); 
    628644    e2 = e2->optimize(result); 
     
    710726    {   // Convert slice of string literal into dynamic array 
    711727        Type *t = e1->type->toBasetype(); 
    712         if (t->next
    713         e = e1->castTo(NULL, t->next->arrayOf()); 
     728        if (t->nextOf()
     729        e = e1->castTo(NULL, t->nextOf()->arrayOf()); 
    714730    } 
    715731    return e; 
  • dmd/statement.c

    r1607 r1630  
    24842484 
    24852485                e = e->semantic(sc); 
     2486#if 1 
    24862487        e = e->optimize(WANTvalue | WANTinterpret); 
     2488#else 
     2489            e = e->interpret(NULL); 
     2490        if (e == EXP_CANT_INTERPRET) 
     2491            fprintf(stdmsg, ((Expression *)args->data[i])->toChars()); 
     2492                else 
     2493#endif 
    24872494                if (e->op == TOKstring) 
    24882495                { 
  • dmd/statement.h

    r1607 r1630  
    5555 
    5656enum TOK; 
    57  
     57#if IN_LLVM 
    5858namespace llvm 
    5959{ 
     
    6262    class ConstantInt; 
    6363} 
     64#endif 
    6465 
    6566// Back end 
     
    142143    virtual CaseStatement* isCaseStatement() { return NULL; } 
    143144 
    144     // LDC 
     145#if IN_LLVM 
    145146    virtual void toNakedIR(IRState *irs); 
    146147    virtual AsmBlockStatement* endsWithAsm(); 
     148#endif 
    147149}; 
    148150 
     
    173175    void toIR(IRState *irs); 
    174176 
    175     // LDC 
     177#if IN_LLVM 
    176178    void toNakedIR(IRState *irs); 
     179#endif 
    177180}; 
    178181 
  • dmd/struct.c

    r1628 r1630  
    2020#include "id.h" 
    2121#include "statement.h" 
     22#include "template.h" 
    2223 
    2324/********************************* AggregateDeclaration ****************************/ 
     
    269270        scope = NULL; 
    270271    } 
     272 
     273    unsigned dprogress_save = Module::dprogress; 
    271274 
    272275    parent = sc->parent; 
     
    418421    scope->setNoFree(); 
    419422    scope->module->addDeferredSemantic(this); 
     423 
     424    Module::dprogress = dprogress_save; 
    420425    //printf("\tdeferring %s\n", toChars()); 
    421426    return; 
  • dmd/template.c

    r1618 r1630  
    11 
    22// Compiler implementation of the D programming language 
    3 // Copyright (c) 1999-2009 by Digital Mars 
     3// Copyright (c) 1999-2010 by Digital Mars 
    44// All Rights Reserved 
    55// written by Walter Bright 
     
    35403540    if (tinst) 
    35413541    {   tinst->printInstantiationTrace(); 
    3542         fatal(); 
     3542        if (!global.gag) 
     3543        fatal(); 
    35433544    } 
    35443545    errors = 1; 
Copyright © 2008, LDC Development Team.