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

Changeset 1526:54b3c1394d62

Show
Ignore:
Timestamp:
07/06/09 21:26:11 (3 years ago)
Author:
Robert Clipsham <robert@octarineparrot.com>
branch:
default
Message:

Merged dmdfe 2.031.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • dmd2/arrayop.c

    r1452 r1526  
    11 
    2 // Copyright (c) 1999-2008 by Digital Mars 
     2// Copyright (c) 1999-2009 by Digital Mars 
    33// All Rights Reserved 
    44// written by Walter Bright 
     
    436436     */ 
    437437    Expression *ex2 = e2->buildArrayLoop(fparams); 
     438    /* Need the cast because: 
     439     *   b = c + p[i]; 
     440     * where b is a byte fails because (c + p[i]) is an int 
     441     * which cannot be implicitly cast to byte. 
     442     */ 
     443    ex2 = new CastExp(0, ex2, e1->type->nextOf()); 
    438444    Expression *ex1 = e1->buildArrayLoop(fparams); 
    439445    Argument *param = (Argument *)fparams->data[0]; 
  • dmd2/attrib.c

    r1452 r1526  
    2727#include "parse.h" 
    2828#include "template.h" 
     29#if TARGET_NET 
     30 #include "frontend.net/pragma.h" 
     31#endif 
    2932 
    3033#if IN_LLVM 
     
    7376    } 
    7477    return m; 
     78} 
     79 
     80void AttribDeclaration::semanticNewSc(Scope *sc, 
     81    unsigned stc, enum LINK linkage, enum PROT protection, int explicitProtection, 
     82    unsigned structalign) 
     83{ 
     84    if (decl) 
     85    { 
     86    Scope *newsc = sc; 
     87    if (stc != sc->stc || 
     88        linkage != sc->linkage || 
     89        protection != sc->protection || 
     90        explicitProtection != sc->explicitProtection || 
     91        structalign != sc->structalign) 
     92    { 
     93        // create new one for changes 
     94        newsc = new Scope(*sc); 
     95        newsc->flags &= ~SCOPEfree; 
     96        newsc->stc = stc; 
     97        newsc->linkage = linkage; 
     98        newsc->protection = protection; 
     99        newsc->explicitProtection = explicitProtection; 
     100        newsc->structalign = structalign; 
     101    } 
     102    for (unsigned i = 0; i < decl->dim; i++) 
     103    {   Dsymbol *s = (Dsymbol *)decl->data[i]; 
     104 
     105        s->semantic(newsc); 
     106    } 
     107    if (newsc != sc) 
     108    { 
     109        sc->offset = newsc->offset; 
     110        newsc->pop(); 
     111    } 
     112    } 
    75113} 
    76114 
     
    306344{ 
    307345    if (decl) 
    308     {   unsigned stc_save = sc->stc; 
    309  
    310     if (stc & (STCauto | STCscope | STCstatic | STCextern)) 
    311         sc->stc &= ~(STCauto | STCscope | STCstatic | STCextern); 
     346    { 
     347#if 1 
     348    unsigned scstc = sc->stc; 
     349 
     350    /* These sets of storage classes are mutually exclusive, 
     351     * so choose the innermost or most recent one. 
     352     */ 
     353    if (stc & (STCauto | STCscope | STCstatic | STCextern | STCmanifest)) 
     354        scstc &= ~(STCauto | STCscope | STCstatic | STCextern | STCmanifest); 
     355    if (stc & (STCauto | STCscope | STCstatic | STCtls | STCmanifest | STCgshared)) 
     356        scstc &= ~(STCauto | STCscope | STCstatic | STCtls | STCmanifest | STCgshared); 
     357    if (stc & (STCconst | STCimmutable | STCmanifest)) 
     358        scstc &= ~(STCconst | STCimmutable | STCmanifest); 
     359    if (stc & (STCgshared | STCshared | STCtls)) 
     360        scstc &= ~(STCgshared | STCshared | STCtls); 
     361    scstc |= stc; 
     362 
     363    semanticNewSc(sc, scstc, sc->linkage, sc->protection, sc->explicitProtection, sc->structalign); 
     364#else 
     365    unsigned stc_save = sc->stc; 
     366 
     367    /* These sets of storage classes are mutually exclusive, 
     368     * so choose the innermost or most recent one. 
     369     */ 
     370    if (stc & (STCauto | STCscope | STCstatic | STCextern | STCmanifest)) 
     371        sc->stc &= ~(STCauto | STCscope | STCstatic | STCextern | STCmanifest); 
     372    if (stc & (STCauto | STCscope | STCstatic | STCtls | STCmanifest | STCgshared)) 
     373        sc->stc &= ~(STCauto | STCscope | STCstatic | STCtls | STCmanifest | STCgshared); 
     374    if (stc & (STCconst | STCimmutable | STCmanifest)) 
     375        sc->stc &= ~(STCconst | STCimmutable | STCmanifest); 
     376    if (stc & (STCgshared | STCshared | STCtls)) 
     377        sc->stc &= ~(STCgshared | STCshared | STCtls); 
    312378    sc->stc |= stc; 
    313379    for (unsigned i = 0; i < decl->dim; i++) 
     
    318384    } 
    319385    sc->stc = stc_save; 
    320     } 
    321     else 
    322     sc->stc = stc; 
     386#endif 
     387    } 
    323388} 
    324389 
     
    394459    //printf("LinkDeclaration::semantic(linkage = %d, decl = %p)\n", linkage, decl); 
    395460    if (decl) 
    396     {   enum LINK linkage_save = sc->linkage; 
     461    { 
     462#if 1 
     463    semanticNewSc(sc, sc->stc, linkage, sc->protection, sc->explicitProtection, sc->structalign); 
     464#else 
     465    enum LINK linkage_save = sc->linkage; 
    397466 
    398467    sc->linkage = linkage; 
     
    404473    } 
    405474    sc->linkage = linkage_save; 
    406     } 
    407     else 
    408     { 
    409     sc->linkage = linkage; 
     475#endif 
    410476    } 
    411477} 
     
    482548{ 
    483549    if (decl) 
    484     {   enum PROT protection_save = sc->protection; 
     550    { 
     551#if 1 
     552    semanticNewSc(sc, sc->stc, sc->linkage, protection, 1, sc->structalign); 
     553#else 
     554    enum PROT protection_save = sc->protection; 
    485555    int explicitProtection_save = sc->explicitProtection; 
    486556 
     
    495565    sc->protection = protection_save; 
    496566    sc->explicitProtection = explicitProtection_save; 
    497     } 
    498     else 
    499     {   sc->protection = protection; 
    500     sc->explicitProtection = 1; 
    501     } 
    502 
    503  
    504 void ProtDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) 
    505 {   const char *p; 
     567#endif 
     568    } 
     569
     570 
     571void ProtDeclaration::protectionToCBuffer(OutBuffer *buf, enum PROT protection) 
     572
     573    const char *p; 
    506574 
    507575    switch (protection) 
     
    517585    } 
    518586    buf->writestring(p); 
     587    buf->writeByte(' '); 
     588} 
     589 
     590void ProtDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) 
     591{ 
     592    protectionToCBuffer(buf, protection); 
    519593    AttribDeclaration::toCBuffer(buf, hgs); 
    520594} 
     
    546620    //printf("\tAlignDeclaration::semantic '%s'\n",toChars()); 
    547621    if (decl) 
    548     {   unsigned salign_save = sc->structalign; 
     622    { 
     623#if 1 
     624    semanticNewSc(sc, sc->stc, sc->linkage, sc->protection, sc->explicitProtection, salign); 
     625#else 
     626    unsigned salign_save = sc->structalign; 
     627 
    549628#if IN_DMD 
    550629    sc->structalign = salign; 
     
    554633        Dsymbol *s = (Dsymbol *)decl->data[i]; 
    555634 
     635#if IN_LLVM 
    556636        if (s->isStructDeclaration() && salign == 1) 
    557637        { 
     
    562642        else 
    563643        { 
     644#endif 
    564645            s->semantic(sc); 
    565         } 
     646#if IN_LLVM 
     647        } 
     648#endif 
    566649    } 
    567650    sc->structalign = salign_save; 
     651#endif 
    568652    } 
    569653    else 
     
    585669    this->loc = loc; 
    586670    this->isunion = isunion; 
    587     this->scope = NULL; 
    588671    this->sem = 0; 
    589672} 
     
    896979    goto Lnodecl; 
    897980    } 
    898  
     981#if TARGET_NET 
     982    else if (ident == Lexer::idPool("assembly")) 
     983    { 
     984        if (!args || args->dim != 1) 
     985            error("pragma has invalid number of arguments"); 
     986        else 
     987        { 
     988            Expression *e = (Expression *)args->data[0]; 
     989            e = e->semantic(sc); 
     990            e = e->optimize(WANTvalue | WANTinterpret); 
     991            args->data[0] = (void *)e; 
     992            if (e->op != TOKstring) 
     993            { 
     994                error("string expected, not '%s'", e->toChars()); 
     995            } 
     996            PragmaScope* pragma = new PragmaScope(this, sc->parent, static_cast<StringExp*>(e)); 
     997            decl = new Array; 
     998            decl->push(pragma); 
     999        } 
     1000    } 
     1001#endif // TARGET_NET 
    8991002// LDC 
    9001003#if IN_LLVM 
  • dmd2/attrib.h

    r1452 r1526  
    11 
    22// Compiler implementation of the D programming language 
    3 // Copyright (c) 1999-2007 by Digital Mars 
     3// Copyright (c) 1999-2009 by Digital Mars 
    44// All Rights Reserved 
    55// written by Walter Bright 
     
    3737    virtual Array *include(Scope *sc, ScopeDsymbol *s); 
    3838    int addMember(Scope *sc, ScopeDsymbol *s, int memnum); 
     39    void semanticNewSc(Scope *sc, 
     40    unsigned newstc, enum LINK linkage, enum PROT protection, int explictProtection, 
     41    unsigned structalign); 
    3942    void semantic(Scope *sc); 
    4043    void semantic2(Scope *sc); 
     
    9396    void semantic(Scope *sc); 
    9497    void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 
     98 
     99    static void protectionToCBuffer(OutBuffer *buf, enum PROT protection); 
    95100}; 
    96101 
     
    108113{ 
    109114    int isunion; 
    110     Scope *scope;       // !=NULL means context to use 
    111115    int sem;            // 1 if successful semantic() 
    112116 
  • dmd2/cast.c

    r1452 r1526  
    3434    {   TY tyfrom = type->toBasetype()->ty; 
    3535    TY tyto = t->toBasetype()->ty; 
     36#if DMDV1 
    3637    if (global.params.warnings && 
    3738        Type::impcnvWarn[tyfrom][tyto] && 
     
    4243        if (e->op == TOKint64) 
    4344        return e->implicitCastTo(sc, t); 
    44  
    4545        if (tyfrom == Tint32 && 
    4646        (op == TOKadd || op == TOKmin || 
     
    6262        } 
    6363    } 
     64#endif 
    6465#if DMDV2 
    6566    if (match == MATCHconst && t == type->constOf()) 
     
    145146    if (match != MATCHnomatch) 
    146147    return match; 
     148 
     149    /* See if we can do integral narrowing conversions 
     150     */ 
     151    if (type->isintegral() && t->isintegral() && 
     152    type->isTypeBasic() && t->isTypeBasic()) 
     153    {   IntRange ir = getIntRange(); 
     154    if (ir.imax <= t->sizemask()) 
     155        return MATCHconvert; 
     156    } 
     157 
    147158#if 0 
    148159    Type *tb = t->toBasetype(); 
     
    677688} 
    678689 
     690MATCH OrExp::implicitConvTo(Type *t) 
     691{ 
     692    MATCH result = Expression::implicitConvTo(t); 
     693 
     694    if (result == MATCHnomatch) 
     695    { 
     696    MATCH m1 = e1->implicitConvTo(t); 
     697    MATCH m2 = e2->implicitConvTo(t); 
     698 
     699    // Pick the worst match 
     700    result = (m1 < m2) ? m1 : m2; 
     701    } 
     702    return result; 
     703} 
     704 
     705MATCH XorExp::implicitConvTo(Type *t) 
     706{ 
     707    MATCH result = Expression::implicitConvTo(t); 
     708 
     709    if (result == MATCHnomatch) 
     710    { 
     711    MATCH m1 = e1->implicitConvTo(t); 
     712    MATCH m2 = e2->implicitConvTo(t); 
     713 
     714    // Pick the worst match 
     715    result = (m1 < m2) ? m1 : m2; 
     716    } 
     717    return result; 
     718} 
     719 
    679720MATCH CondExp::implicitConvTo(Type *t) 
    680721{ 
    681     MATCH m1; 
    682     MATCH m2; 
    683  
    684     m1 = e1->implicitConvTo(t); 
    685     m2 = e2->implicitConvTo(t); 
     722    MATCH m1 = e1->implicitConvTo(t); 
     723    MATCH m2 = e2->implicitConvTo(t); 
     724    //printf("CondExp: m1 %d m2 %d\n", m1, m2); 
    686725 
    687726    // Pick the worst match 
     
    689728} 
    690729 
     730MATCH CommaExp::implicitConvTo(Type *t) 
     731{ 
     732    return e2->implicitConvTo(t); 
     733} 
     734 
     735MATCH CastExp::implicitConvTo(Type *t) 
     736{ 
     737#if 0 
     738    printf("CastExp::implicitConvTo(this=%s, type=%s, t=%s)\n", 
     739    toChars(), type->toChars(), t->toChars()); 
     740#endif 
     741    MATCH result; 
     742 
     743    result = type->implicitConvTo(t); 
     744 
     745    if (result == MATCHnomatch) 
     746    { 
     747    if (t->isintegral() && 
     748        e1->type->isintegral() && 
     749        e1->implicitConvTo(t) != MATCHnomatch) 
     750        result = MATCHconvert; 
     751    else 
     752        result = Expression::implicitConvTo(t); 
     753    } 
     754    return result; 
     755} 
    691756 
    692757/* ==================== castTo ====================== */ 
     
    12591324        if (f) 
    12601325        { 
    1261             if (tb->ty == Tdelegate && f->needThis() && hasThis(sc)
     1326            if (tb->ty == Tdelegate
    12621327            { 
    1263             e = new DelegateExp(loc, new ThisExp(loc), f); 
    1264             e = e->semantic(sc); 
    1265             } 
    1266             else if (tb->ty == Tdelegate && f->isNested()) 
    1267             { 
    1268             e = new DelegateExp(loc, new IntegerExp(0), f); 
    1269             e = e->semantic(sc); 
     1328            if (f->needThis() && hasThis(sc)) 
     1329            { 
     1330                e = new DelegateExp(loc, new ThisExp(loc), f); 
     1331                e = e->semantic(sc); 
     1332            } 
     1333            else if (f->isNested()) 
     1334            { 
     1335                e = new DelegateExp(loc, new IntegerExp(0), f); 
     1336                e = e->semantic(sc); 
     1337            } 
     1338            else if (f->needThis()) 
     1339            {   error("no 'this' to create delegate for %s", f->toChars()); 
     1340                e = new ErrorExp(); 
     1341            } 
     1342            else 
     1343            {   error("cannot cast from function pointer to delegate"); 
     1344                e = new ErrorExp(); 
     1345            } 
    12701346            } 
    12711347            else 
     
    12741350            e->type = t; 
    12751351            } 
     1352#if DMDV2 
    12761353            f->tookAddressOf++; 
     1354#endif 
    12771355            return e; 
    12781356        } 
     
    13541432} 
    13551433 
     1434Expression *CommaExp::castTo(Scope *sc, Type *t) 
     1435{ 
     1436    Expression *e2c = e2->castTo(sc, t); 
     1437    Expression *e; 
     1438 
     1439    if (e2c != e2) 
     1440    { 
     1441    e = new CommaExp(loc, e1, e2c); 
     1442    e->type = e2c->type; 
     1443    } 
     1444    else 
     1445    {   e = this; 
     1446    e->type = e2->type; 
     1447    } 
     1448    return e; 
     1449} 
     1450 
    13561451/* ==================== ====================== */ 
    13571452 
     
    17781873    return 0; 
    17791874} 
     1875 
     1876/******************************************************************/ 
     1877 
     1878/* Determine the integral ranges of an expression. 
     1879 * This is used to determine if implicit narrowing conversions will 
     1880 * be allowed. 
     1881 */ 
     1882 
     1883uinteger_t getMask(uinteger_t v) 
     1884{ 
     1885    uinteger_t u = 0; 
     1886    if (v >= 0x80) 
     1887    u = 0xFF; 
     1888    while (u < v) 
     1889    u = (u << 1) | 1; 
     1890    return u; 
     1891} 
     1892 
     1893IntRange Expression::getIntRange() 
     1894{ 
     1895    IntRange ir; 
     1896    ir.imin = 0; 
     1897    ir.imax = type->sizemask(); 
     1898    return ir; 
     1899} 
     1900 
     1901IntRange IntegerExp::getIntRange() 
     1902{ 
     1903    IntRange ir; 
     1904    ir.imin = value & type->sizemask(); 
     1905    ir.imax = ir.imin; 
     1906    return ir; 
     1907} 
     1908 
     1909IntRange CastExp::getIntRange() 
     1910{ 
     1911    IntRange ir; 
     1912    ir = e1->getIntRange(); 
     1913    // Do sign extension 
     1914    switch (e1->type->toBasetype()->ty) 
     1915    { 
     1916    case Tint8: 
     1917        if (ir.imax & 0x80) 
     1918        ir.imax |= 0xFFFFFFFFFFFFFF00ULL; 
     1919        break; 
     1920    case Tint16: 
     1921        if (ir.imax & 0x8000) 
     1922        ir.imax |= 0xFFFFFFFFFFFF0000ULL; 
     1923        break; 
     1924    case Tint32: 
     1925        if (ir.imax & 0x80000000) 
     1926        ir.imax |= 0xFFFFFFFF00000000ULL; 
     1927        break; 
     1928    } 
     1929    ir.imin &= type->sizemask(); 
     1930    ir.imax &= type->sizemask(); 
     1931//printf("CastExp: imin = x%llx, imax = x%llx\n", ir.imin, ir.imax); 
     1932    return ir; 
     1933} 
     1934 
     1935IntRange DivExp::getIntRange() 
     1936{ 
     1937    if (!e1->type->isunsigned() && !e2->type->isunsigned()) 
     1938    return Expression::getIntRange(); 
     1939 
     1940    IntRange ir; 
     1941    IntRange ir1 = e1->getIntRange(); 
     1942    IntRange ir2 = e2->getIntRange(); 
     1943 
     1944    ir.imin = ir1.imin / ir2.imax; 
     1945    ir.imax = ir1.imax / ir2.imin; 
     1946 
     1947    ir.imin &= type->sizemask(); 
     1948    ir.imax &= type->sizemask(); 
     1949 
     1950//printf("DivExp: imin = x%llx, imax = x%llx\n", ir.imin, ir.imax); 
     1951//e1->dump(0); 
     1952 
     1953    return ir; 
     1954} 
     1955 
     1956IntRange AndExp::getIntRange() 
     1957{ 
     1958    IntRange ir; 
     1959    IntRange ir1 = e1->getIntRange(); 
     1960    IntRange ir2 = e2->getIntRange(); 
     1961 
     1962    ir.imin = ir1.imin; 
     1963    if (ir2.imin < ir.imin) 
     1964    ir.imin = ir2.imin; 
     1965 
     1966    ir.imax = ir1.imax; 
     1967    if (ir2.imax > ir.imax) 
     1968    ir.imax = ir2.imax; 
     1969 
     1970    uinteger_t u; 
     1971 
     1972    u = getMask(ir1.imax); 
     1973    ir.imin &= u; 
     1974    ir.imax &= u; 
     1975 
     1976    u = getMask(ir2.imax); 
     1977    ir.imin &= u; 
     1978    ir.imax &= u; 
     1979 
     1980    ir.imin &= type->sizemask(); 
     1981    ir.imax &= type->sizemask(); 
     1982 
     1983//printf("AndExp: imin = x%llx, imax = x%llx\n", ir.imin, ir.imax); 
     1984//e1->dump(0); 
     1985 
     1986    return ir; 
     1987} 
     1988 
     1989IntRange OrExp::getIntRange() 
     1990{ 
     1991    IntRange ir; 
     1992    IntRange ir1 = e1->getIntRange(); 
     1993    IntRange ir2 = e2->getIntRange(); 
     1994 
     1995    ir.imin = ir1.imin; 
     1996    if (ir2.imin < ir.imin) 
     1997    ir.imin = ir2.imin; 
     1998 
     1999    ir.imax = ir1.imax; 
     2000    if (ir2.imax > ir.imax) 
     2001    ir.imax = ir2.imax; 
     2002 
     2003    ir.imin &= type->sizemask(); 
     2004    ir.imax &= type->sizemask(); 
     2005 
     2006//printf("OrExp: imin = x%llx, imax = x%llx\n", ir.imin, ir.imax); 
     2007//e1->dump(0); 
     2008 
     2009    return ir; 
     2010} 
     2011 
     2012IntRange XorExp::getIntRange() 
     2013{ 
     2014    IntRange ir; 
     2015    IntRange ir1 = e1->getIntRange(); 
     2016    IntRange ir2 = e2->getIntRange(); 
     2017 
     2018    ir.imin = ir1.imin; 
     2019    if (ir2.imin < ir.imin) 
     2020    ir.imin = ir2.imin; 
     2021 
     2022    ir.imax = ir1.imax; 
     2023    if (ir2.imax > ir.imax) 
     2024    ir.imax = ir2.imax; 
     2025 
     2026    ir.imin &= type->sizemask(); 
     2027    ir.imax &= type->sizemask(); 
     2028 
     2029//printf("XorExp: imin = x%llx, imax = x%llx\n", ir.imin, ir.imax); 
     2030//e1->dump(0); 
     2031 
     2032    return ir; 
     2033} 
     2034 
     2035IntRange ShlExp::getIntRange() 
     2036{ 
     2037    IntRange ir; 
     2038    IntRange ir1 = e1->getIntRange(); 
     2039    IntRange ir2 = e2->getIntRange(); 
     2040 
     2041    ir.imin = getMask(ir1.imin) << ir2.imin; 
     2042    ir.imax = getMask(ir1.imax) << ir2.imax; 
     2043 
     2044    ir.imin &= type->sizemask(); 
     2045    ir.imax &= type->sizemask(); 
     2046 
     2047//printf("ShlExp: imin = x%llx, imax = x%llx\n", ir.imin, ir.imax); 
     2048//e1->dump(0); 
     2049 
     2050    return ir; 
     2051} 
     2052 
     2053IntRange ShrExp::getIntRange() 
     2054{ 
     2055    if (!e1->type->isunsigned()) 
     2056    return Expression::getIntRange(); 
     2057 
     2058    IntRange ir; 
     2059    IntRange ir1 = e1->getIntRange(); 
     2060    IntRange ir2 = e2->getIntRange(); 
     2061 
     2062    ir.imin = ir1.imin >> ir2.imax; 
     2063    ir.imax = ir1.imax >> ir2.imin; 
     2064 
     2065    ir.imin &= type->sizemask(); 
     2066    ir.imax &= type->sizemask(); 
     2067 
     2068//printf("ShrExp: imin = x%llx, imax = x%llx\n", ir.imin, ir.imax); 
     2069//e1->dump(0); 
     2070 
     2071    return ir; 
     2072} 
     2073 
     2074IntRange UshrExp::getIntRange() 
     2075{ 
     2076    IntRange ir; 
     2077    IntRange ir1 = e1->getIntRange(); 
     2078    IntRange ir2 = e2->getIntRange(); 
     2079 
     2080    ir.imin = ir1.imin >> ir2.imax; 
     2081    ir.imax = ir1.imax >> ir2.imin; 
     2082 
     2083    ir.imin &= type->sizemask(); 
     2084    ir.imax &= type->sizemask(); 
     2085 
     2086//printf("UshrExp: imin = x%llx, imax = x%llx\n", ir.imin, ir.imax); 
     2087//e1->dump(0); 
     2088 
     2089    return ir; 
     2090} 
     2091 
     2092IntRange CommaExp::getIntRange() 
     2093{ 
     2094    return e2->getIntRange(); 
     2095} 
     2096 
     2097 
  • dmd2/class.c

    r1452 r1526  
    11 
    22// Compiler implementation of the D programming language 
    3 // Copyright (c) 1999-2008 by Digital Mars 
     3// Copyright (c) 1999-2009 by Digital Mars 
    44// All Rights Reserved 
    55// written by Walter Bright 
     
    234234    } 
    235235 
    236     if (!scope
    237     { 
    238    if (!parent && sc->parent && !sc->parent->isModule()) 
    239         parent = sc->parent; 
    240  
    241    type = type->semantic(loc, sc); 
    242    handle = handle->semantic(loc, sc)
    243     } 
     236    if (!sc
     237    sc = scope; 
     238    if (!parent && sc->parent && !sc->parent->isModule()) 
     239    parent = sc->parent; 
     240 
     241    type = type->semantic(loc, sc); 
     242    handle = type
     243 
    244244    if (!members)           // if forward reference 
    245245    {   //printf("\tclass '%s' is forward referenced\n", toChars()); 
     
    276276    for (i = 0; i < baseclasses.dim; ) 
    277277    {   BaseClass *b = (BaseClass *)baseclasses.data[i]; 
     278//printf("test1 %s %s\n", toChars(), b->type->toChars()); 
    278279    b->type = b->type->semantic(loc, sc); 
     280//printf("test2\n"); 
    279281    Type *tb = b->type->toBasetype(); 
    280282 
     
    335337            } 
    336338        } 
     339        if (!tc->sym->symtab || tc->sym->sizeok == 0) 
     340        {   // Try to resolve forward reference 
     341            if (sc->mustsemantic && tc->sym->scope) 
     342            tc->sym->semantic(NULL); 
     343        } 
    337344        if (!tc->sym->symtab || tc->sym->scope || tc->sym->sizeok == 0) 
    338345        { 
     346            //printf("%s: forward reference of base class %s\n", toChars(), tc->sym->toChars()); 
    339347            //error("forward reference of base class %s", baseClass->toChars()); 
    340348            // Forward reference of base class, try again later 
     
    794802    //printf("%s.ClassDeclaration::search('%s')\n", toChars(), ident->toChars()); 
    795803    if (scope) 
    796     semantic(scope); 
     804    {   Scope *sc = scope; 
     805    sc->mustsemantic++; 
     806    semantic(sc); 
     807    sc->mustsemantic--; 
     808    } 
    797809 
    798810    if (!members || !symtab || scope) 
    799     {   error("is forward referenced when looking for '%s'", ident->toChars()); 
     811    { 
     812    error("is forward referenced when looking for '%s'", ident->toChars()); 
    800813    //*(char*)0=0; 
    801814    return NULL; 
     
    10381051    if (inuse) 
    10391052    return; 
    1040     if (!scope) 
    1041     {   type = type->semantic(loc, sc); 
    1042     handle = handle->semantic(loc, sc); 
    1043     } 
     1053 
     1054    if (!sc) 
     1055    sc = scope; 
     1056    if (!parent && sc->parent && !sc->parent->isModule()) 
     1057    parent = sc->parent; 
     1058 
     1059    type = type->semantic(loc, sc); 
     1060    handle = type; 
     1061 
    10441062    if (!members)           // if forward reference 
    10451063    {   //printf("\tinterface '%s' is forward referenced\n", toChars()); 
  • dmd2/cond.c

    r1452 r1526  
    144144    "none", 
    145145 
    146     // LDC 
     146#if IN_LLVM 
    147147    "LLVM", "LDC", "LLVM64", 
    148148    "PPC", "PPC64", 
    149149    "darwin","solaris","freebsd" 
     150#endif 
    150151    }; 
    151152 
  • dmd2/constfold.c

    r1452 r1526  
    854854    int cmp; 
    855855 
    856     if (e1->op == TOKnull && e2->op == TOKnull) 
    857     { 
    858     cmp = 1; 
     856    if (e1->op == TOKnull) 
     857    { 
     858    cmp = (e2->op == TOKnull); 
     859    } 
     860    else if (e2->op == TOKnull) 
     861    { 
     862    cmp = 0; 
    859863    } 
    860864    else if (e1->op == TOKsymoff && e2->op == TOKsymoff) 
  • dmd2/declaration.c

    r1487 r1526  
    464464    goto L2;            // it's a symbolic alias 
    465465 
     466#if DMDV2 
    466467    if (storage_class & STCref) 
    467468    {   // For 'ref' to be attached to function types, and picked 
     
    473474    } 
    474475    else 
     476#endif 
    475477    type->resolve(loc, sc, &e, &t, &s); 
    476478    if (s) 
     
    489491    } 
    490492    else if (t) 
     493    { 
    491494    type = t; 
     495    } 
    492496    if (overnext) 
    493497    ScopeDsymbol::multiplyDefined(0, this, overnext); 
     
    512516        { 
    513517        FuncAliasDeclaration *fa = new FuncAliasDeclaration(f); 
     518#if IN_LLVM 
    514519        fa->importprot = importprot; 
     520#endif 
    515521        if (!fa->overloadInsert(overnext)) 
    516522            ScopeDsymbol::multiplyDefined(0, f, overnext); 
     
    528534    } 
    529535    } 
     536    //printf("setting aliassym %p to %p\n", this, s); 
    530537    aliassym = s; 
    531538    this->inSemantic = 0; 
     
    625632    offset = 0; 
    626633    noauto = 0; 
     634#if DMDV1 
     635    nestedref = 0; 
     636#endif 
    627637    ctorinit = 0; 
    628638    aliassym = NULL; 
     
    630640    canassign = 0; 
    631641    value = NULL; 
    632     scope = NULL; 
    633642#if IN_LLVM 
    634643    aggrIndex = 0; 
     
    731740    //printf("storage_class = x%x\n", storage_class); 
    732741 
     742#if DMDV2 
    733743    if (storage_class & STCgshared && global.params.safe && !sc->module->safe) 
    734744    { 
    735745    error("__gshared not allowed in safe mode; use shared"); 
    736746    } 
     747#endif 
    737748 
    738749    Dsymbol *parent = toParent(); 
     
    852863        aad = parent->isAggregateDeclaration(); 
    853864    if (aad) 
    854     {   assert(!(storage_class & (STCextern | STCstatic | STCtls | STCgshared))); 
     865    { 
     866#if DMDV2 
     867        assert(!(storage_class & (STCextern | STCstatic | STCtls | STCgshared))); 
    855868 
    856869        if (storage_class & (STCconst | STCimmutable) && init) 
     
    860873        } 
    861874        else 
     875#endif 
    862876        aad->addField(sc, this); 
    863877    } 
     
    892906    } 
    893907 
     908#if DMDV2 
    894909    if ((storage_class & (STCref | STCparameter | STCforeach)) == STCref && 
    895910    ident != Id::This) 
     
    897912    error("only parameters or foreach declarations can be ref"); 
    898913    } 
     914#endif 
    899915 
    900916    if (type->isauto() && !noauto) 
     
    941957        e1 = new VarExp(loc, this); 
    942958        e = new AssignExp(loc, e1, e); 
     959#if DMDV2 
    943960        e->op = TOKconstruct; 
     961#endif 
    944962        e->type = e1->type;     // don't type check this, it would fail 
    945963        init = new ExpInitializer(loc, e); 
     
    962980        init = getExpInitializer(); 
    963981    } 
     982#if DMDV2 
    964983    // Default initializer is always a blit 
    965984    op = TOKblit; 
     985#endif 
    966986    } 
    967987 
     
    10411061        { 
    10421062            ei->exp = ei->exp->semantic(sc); 
    1043  
     1063#if DMDV2 
    10441064            /* Look to see if initializer is a call to the constructor 
    10451065             */ 
     
    10791099            } 
    10801100            } 
    1081  
     1101#endif 
    10821102            if (!ei->exp->implicitConvTo(type)) 
    10831103            {   Type *ti = ei->exp->type->toBasetype(); 
     
    11331153            if (global.gag == 0) 
    11341154            global.errors = errors; // act as if nothing happened 
    1135  
     1155#if DMDV2 
    11361156            /* Save scope for later use, to try again 
    11371157             */ 
    11381158            scope = new Scope(*sc); 
    11391159            scope->setNoFree(); 
     1160#endif 
    11401161        } 
    11411162        else if (ei) 
     
    11511172            ei->exp = e;        // no errors, keep result 
    11521173            } 
     1174#if DMDV2 
    11531175            else 
    11541176            { 
     
    11581180            scope->setNoFree(); 
    11591181            } 
     1182#endif 
    11601183        } 
    11611184        else 
     
    12211244    if (init) 
    12221245    {   buf->writestring(" = "); 
     1246#if DMDV2 
    12231247    ExpInitializer *ie = init->isExpInitializer(); 
    12241248    if (ie && (ie->exp->op == TOKconstruct || ie->exp->op == TOKblit)) 
    12251249        ((AssignExp *)ie->exp)->e2->toCBuffer(buf, hgs); 
    12261250    else 
     1251#endif 
    12271252        init->toCBuffer(buf, hgs); 
    12281253    } 
     
    15891614{ 
    15901615    assert(linkage == LINKc); 
    1591     // LDC 
     1616#if IN_LLVM 
    15921617    if (!global.params.useAvailableExternally) 
    15931618        availableExternally = false; 
     1619#endif 
    15941620} 
    15951621 
  • dmd2/declaration.h

    r1487 r1526  
    11 
    22// Compiler implementation of the D programming language 
    3 // Copyright (c) 1999-2008 by Digital Mars 
     3// Copyright (c) 1999-2009 by Digital Mars 
    44// All Rights Reserved 
    55// written by Walter Bright 
     
    270270    Expression *value;      // when interpreting, this is the value 
    271271                // (NULL if value not determinable) 
    272     Scope *scope;       // !=NULL means context to use 
    273272 
    274273    VarDeclaration(Loc loc, Type *t, Identifier *id, Initializer *init); 
     
    669668                    // this one is overriding 
    670669    int inferRetType;           // !=0 if return type is to be inferred 
    671     Scope *scope;           // !=NULL means context to use 
    672670 
    673671    // Things that should really go into Scope 
  • dmd2/dsymbol.c

    r1452 r1526  
    11 
    22// Compiler implementation of the D programming language 
    3 // Copyright (c) 1999-2008 by Digital Mars 
     3// Copyright (c) 1999-2009 by Digital Mars 
    44// All Rights Reserved 
    55// written by Walter Bright 
     
    4949    this->loc = 0; 
    5050    this->comment = NULL; 
     51    this->scope = NULL; 
    5152 
    5253#if IN_LLVM 
     
    6869    this->loc = 0; 
    6970    this->comment = NULL; 
     71    this->scope = NULL; 
    7072 
    7173#if IN_LLVM 
     
    194196        break; 
    195197    q--; 
     198#if TARGET_NET 
     199    if (AggregateDeclaration* ad = p->isAggregateDeclaration()) 
     200    { 
     201        if (ad->isNested() && p->parent && p->parent->isAggregateDeclaration()) 
     202        { 
     203            *q = '/'; 
     204            continue; 
     205        } 
     206    } 
     207#endif 
    196208    *q = '.'; 
    197209    } 
     
    270282} 
    271283 
     284/************************************* 
     285 * Set scope for future semantic analysis so we can 
     286 * deal better with forward references. 
     287 */ 
     288 
     289void Dsymbol::setScope(Scope *sc) 
     290{ 
     291    //printf("Dsymbol::setScope() %p %s\n", this, toChars()); 
     292    if (!sc->nofree) 
     293    sc->setNoFree();        // may need it even after semantic() finishes 
     294    scope = sc; 
     295} 
     296 
     297/************************************* 
     298 * Does semantic analysis on the public face of declarations. 
     299 */ 
     300 
    272301void Dsymbol::semantic(Scope *sc) 
    273302{ 
     
    275304} 
    276305 
     306/************************************* 
     307 * Does semantic analysis on initializers and members of aggregates. 
     308 */ 
     309 
    277310void Dsymbol::semantic2(Scope *sc) 
    278311{ 
     
    280313} 
    281314 
     315/************************************* 
     316 * Does semantic analysis on function bodies. 
     317 */ 
     318 
    282319void Dsymbol::semantic3(Scope *sc) 
    283320{ 
     
    285322} 
    286323 
     324/************************************* 
     325 * Look for function inlining possibilities. 
     326 */ 
     327 
    287328void Dsymbol::inlineScan() 
    288329{ 
    289     // Most Dsymbols have no further semantic analysis needed 
     330    // Most Dsymbols aren't functions 
    290331} 
    291332 
     
    345386        } 
    346387        ti->tempdecl = td; 
    347         if (!ti->semanticdone
     388        if (!ti->semanticRun
    348389        ti->semantic(sc); 
    349390        sm = ti->toAlias(); 
  • dmd2/dsymbol.h

    r1452 r1526  
    11 
    22// Compiler implementation of the D programming language 
    3 // Copyright (c) 1999-2008 by Digital Mars 
     3// Copyright (c) 1999-2009 by Digital Mars 
    44// All Rights Reserved 
    55// written by Walter Bright 
     
    7575struct HdrGenState; 
    7676struct OverloadSet; 
     77#if TARGET_NET 
     78struct PragmaScope; 
     79#endif 
    7780#if IN_LLVM 
    7881struct TypeInfoDeclaration; 
    7982struct ClassInfoDeclaration; 
    80 #endif 
    81  
    82 #if IN_DMD 
    83 struct Symbol; 
    8483#endif 
    8584 
     
    127126    unsigned char *comment; // documentation comment for this Dsymbol 
    128127    Loc loc;            // where defined 
     128    Scope *scope;       // !=NULL means context to use for semantic() 
    129129 
    130130    Dsymbol(); 
     
    152152    virtual Dsymbol *toAlias();         // resolve real symbol 
    153153    virtual int addMember(Scope *sc, ScopeDsymbol *s, int memnum); 
     154    virtual void setScope(Scope *sc); 
    154155    virtual void semantic(Scope *sc); 
    155156    virtual void semantic2(Scope *sc); 
     
    246247    virtual TypeInfoDeclaration* isTypeInfoDeclaration() { return NULL; } 
    247248    virtual ClassInfoDeclaration* isClassInfoDeclaration() { return NULL; } 
    248  
     249#if TARGET_NET 
     250    virtual PragmaScope* isPragmaScope() { return NULL; } 
     251#endif 
    249252#if IN_LLVM 
    250253    /// Codegen traversal 
  • dmd2/enum.c

    r1452 r1526  
    3434    sinit = NULL; 
    3535#endif 
    36     scope = NULL; 
    3736    isdeprecated = 0; 
    3837} 
  • dmd2/enum.h

    r1452 r1526  
    4141    Expression *minval; 
    4242    Expression *defaultval; // default initializer 
    43  
    44     Scope *scope;       // !=NULL means context to use 
    4543#endif 
    4644    int isdeprecated; 
  • dmd2/expression.c

    r1523 r1526  
    380380    } 
    381381 
     382    } 
     383    else if (e->op == TOKdottd) 
     384    { 
     385    e = new CallExp(e->loc, e); 
     386    e = e->semantic(sc); 
    382387    } 
    383388    return e; 
     
    10031008    halt(); 
    10041009#endif 
    1005     type = Type::tint32
     1010    type = Type::terror
    10061011    } 
    10071012} 
     
    10651070{ 
    10661071    error("expression %s is not a valid template value argument", toChars()); 
     1072#ifdef DEBUG 
     1073dump(0); 
     1074#endif 
    10671075} 
    10681076 
     
    11171125    if (!type->isscalar()) 
    11181126    error("'%s' is not a scalar, it is a %s", toChars(), type->toChars()); 
     1127    rvalue(); 
    11191128} 
    11201129 
     
    11311140    return new ErrorExp(); 
    11321141    } 
     1142    rvalue(); 
    11331143    return this; 
    11341144} 
     
    11401150    return new ErrorExp(); 
    11411151    } 
     1152    rvalue(); 
    11421153    return this; 
    11431154} 
     
    19972008    if (withsym) 
    19982009    { 
     2010#if DMDV2 
     2011        /* Disallow shadowing 
     2012         */ 
     2013        // First find the scope of the with 
     2014        Scope *scwith = sc; 
     2015        while (scwith->scopesym != scopesym) 
     2016        {   scwith = scwith->enclosing; 
     2017        assert(scwith); 
     2018        } 
     2019        // Look at enclosing scopes for symbols with the same name, 
     2020        // in the same function 
     2021        for (Scope *scx = scwith; scx && scx->func == scwith->func; scx = scx->enclosing) 
     2022        {   Dsymbol *s2; 
     2023 
     2024        if (scx->scopesym && scx->scopesym->symtab && 
     2025            (s2 = scx->scopesym->symtab->lookup(s->ident)) != NULL && 
     2026            s != s2) 
     2027        { 
     2028            error("with symbol %s is shadowing local symbol %s", s->toPrettyChars(), s2->toPrettyChars()); 
     2029        } 
     2030        } 
     2031#endif 
    19992032        s = s->toAlias(); 
    20002033 
     
    21612194    {   type = v->type; 
    21622195        if (!v->type) 
    2163         {   error("forward reference of %s", v->toChars()); 
     2196        {   error("forward reference of %s %s", v->kind(), v->toChars()); 
    21642197        type = Type::terror; 
    21652198        } 
     
    21792212    if (f) 
    21802213    {   //printf("'%s' is a function\n", f->toChars()); 
     2214 
     2215    if (!f->type->deco) 
     2216    { 
     2217        error("forward reference to %s", toChars()); 
     2218    } 
    21812219    return new VarExp(loc, f, hasOverloads); 
    21822220    } 
     
    22382276    TemplateInstance *ti = s->isTemplateInstance(); 
    22392277    if (ti && !global.errors) 
    2240     {   if (!ti->semanticdone
     2278    {   if (!ti->semanticRun
    22412279        ti->semantic(sc); 
    22422280    s = ti->inst->toAlias(); 
     
    29272965    {   e = (Expression *)elements->data[i]; 
    29282966    e = e->semantic(sc); 
     2967    assert(e->type); 
    29292968    elements->data[i] = (void *)e; 
    29302969    } 
     
    34063445} 
    34073446 
     3447void TypeExp::rvalue() 
     3448{ 
     3449    error("type %s has no value", toChars()); 
     3450} 
     3451 
    34083452void TypeExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs) 
    34093453{ 
     
    34413485    if (ti && !global.errors) 
    34423486    {   Dsymbol *s; 
    3443     if (!ti->semanticdone
     3487    if (!ti->semanticRun
    34443488        ti->semantic(sc); 
    34453489    s = ti->inst->toAlias(); 
     
    36563700#endif 
    36573701        } 
    3658         else if (fdn) // Possible problems here, no obvious solution when merging 
     3702#if 1 
     3703        else if (thisexp) 
     3704        error("e.new is only for allocating nested classes"); 
     3705        else if (fdn) 
     3706        { 
     3707        // make sure the parent context fdn of cd is reachable from sc 
     3708        for (Dsymbol *sp = sc->parent; 1; sp = sp->parent) 
     3709        { 
     3710            if (fdn == sp) 
     3711            break; 
     3712            FuncDeclaration *fsp = sp ? sp->isFuncDeclaration() : NULL; 
     3713            if (!sp || (fsp && fsp->isStatic())) 
     3714            { 
     3715            error("outer function context of %s is needed to 'new' nested class %s", fdn->toPrettyChars(), cd->toPrettyChars()); 
     3716            break; 
     3717            } 
     3718        } 
     3719        } 
     3720#else 
     3721        else if (fdn) 
    36593722        {   /* The nested class cd is nested inside a function, 
    36603723         * we'll let getEthis() look for errors. 
     
    36653728            error("e.new is only for allocating nested classes"); 
    36663729        } 
     3730#endif 
    36673731        else 
    36683732        assert(0); 
     
    40294093#endif 
    40304094    } 
     4095 
    40314096    /* Fix for 1161 doesn't work because it causes protection 
    40324097     * problems when instantiating imported templates passing private 
     
    41104175    } 
    41114176#endif 
     4177 
    41124178    return this; 
    41134179} 
     
    42964362    } 
    42974363    type = new TypeTuple(exps); 
     4364    type = type->semantic(loc, sc); 
    42984365    //printf("-TupleExp::semantic(%s)\n", toChars()); 
    42994366    return this; 
     
    61606227    {   ScopeExp *se = (ScopeExp *)e1; 
    61616228    TemplateInstance *ti = se->sds->isTemplateInstance(); 
    6162     if (ti && !ti->semanticdone
     6229    if (ti && !ti->semanticRun
    61636230    { 
    61646231        /* Attempt to instantiate ti. If that works, go with it. 
     
    61886255    {   DotTemplateInstanceExp *se = (DotTemplateInstanceExp *)e1; 
    61896256    TemplateInstance *ti = se->ti; 
    6190     if (!ti->semanticdone
     6257    if (!ti->semanticRun
    61916258    { 
    61926259        /* Attempt to instantiate ti. If that works, go with it. 
     
    67966863    : UnaExp(loc, TOKaddress, sizeof(AddrExp), e) 
    67976864{ 
     6865#if IN_LLVM 
    67986866    m = NULL; 
     6867#endif 
    67996868} 
    68006869 
     
    68066875    if (!type) 
    68076876    { 
     6877#if IN_LLVM 
    68086878    m = sc->module; 
     6879#endif 
    68096880    UnaExp::semantic(sc); 
    68106881    e1 = e1->toLvalue(sc, NULL); 
     
    68126883    { 
    68136884        error("cannot take address of %s", e1->toChars()); 
    6814         type = Type::tint32; 
    6815         return this; 
    6816     } 
     6885        return new ErrorExp(); 
     6886    } 
     6887    if (!e1->type->deco) 
     6888    { 
     6889        /* No deco means semantic() was not run on the type. 
     6890         * We have to run semantic() on the symbol to get the right type: 
     6891         *  auto x = &bar; 
     6892         *  pure: int bar() { return 1;} 
     6893         * otherwise the 'pure' is missing from the type assigned to x. 
     6894         */ 
     6895 
     6896        error("forward reference to %s", e1->toChars()); 
     6897        return new ErrorExp(); 
     6898    } 
     6899 
     6900//printf("test3 deco = %p\n", e1->type->deco); 
    68176901    type = e1->type->pointerTo(); 
    68186902 
     
    68796963    : UnaExp(loc, TOKstar, sizeof(PtrExp), e) 
    68806964{ 
    6881     if (e->type) 
    6882   type = ((TypePointer *)e->type)->next; 
     6965//    if (e->type) 
     6966//    type = ((TypePointer *)e->type)->next; 
    68836967} 
    68846968 
     
    68906974 
    68916975Expression *PtrExp::semantic(Scope *sc) 
    6892 {   Type *tb; 
    6893  
     6976
    68946977#if LOGSEMANTIC 
    68956978    printf("PtrExp::semantic('%s')\n", toChars()); 
     
    69046987    if (e) 
    69056988        return e; 
    6906     tb = e1->type->toBasetype(); 
     6989    Type *tb = e1->type->toBasetype(); 
    69076990    switch (tb->ty) 
    69086991    { 
     
    69197002        default: 
    69207003        error("can only * a pointer, not a '%s'", e1->type->toChars()); 
    6921         type = Type::tint32; 
    6922         break; 
     7004        return new ErrorExp(); 
    69237005    } 
    69247006    rvalue(); 
     
    97459827#endif 
    97469828    else 
     9829    {   e1->rvalue(); 
     9830    e2->rvalue(); 
    97479831    e = this; 
    9748     //printf("CmpExp: %s\n", e->toChars()); 
     9832    } 
     9833    //printf("CmpExp: %s, type = %s\n", e->toChars(), e->type->toChars()); 
    97499834    return e; 
    97509835} 
  • dmd2/expression.h

    r1452 r1526  
    8686int arrayExpressionCanThrow(Expressions *exps); 
    8787 
     88struct IntRange 
     89{   uinteger_t imin; 
     90    uinteger_t imax; 
     91}; 
     92 
    8893struct Expression : Object 
    8994{ 
     
    123128    virtual Expression *implicitCastTo(Scope *sc, Type *t); 
    124129    virtual MATCH implicitConvTo(Type *t); 
     130    virtual IntRange getIntRange(); 
    125131    virtual Expression *castTo(Scope *sc, Type *t); 
    126132    virtual void checkEscape(); 
     
    192198    char *toChars(); 
    193199    void dump(int indent); 
     200    IntRange getIntRange(); 
    194201    dinteger_t toInteger(); 
    195202    real_t toReal(); 
     
    559566    Expression *syntaxCopy(); 
    560567    Expression *semantic(Scope *sc); 
     568    void rvalue(); 
    561569    void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 
    562570    Expression *optimize(int result); 
     
    12311239    Expression *syntaxCopy(); 
    12321240    Expression *semantic(Scope *sc); 
     1241    MATCH implicitConvTo(Type *t); 
     1242    IntRange getIntRange(); 
    12331243    Expression *optimize(int result); 
    12341244    Expression *interpret(InterState *istate); 
     
    13351345    Expression *semantic(Scope *sc); 
    13361346    void checkEscape(); 
     1347    IntRange getIntRange(); 
    13371348    int isLvalue(); 
    13381349    Expression *toLvalue(Scope *sc, Expression *e); 
     
    13401351    int isBool(int result); 
    13411352    int checkSideEffect(int flag); 
     1353    MATCH implicitConvTo(Type *t); 
     1354    Expression *castTo(Scope *sc, Type *t); 
    13421355    Expression *optimize(int result); 
    13431356    Expression *interpret(InterState *istate); 
     
    15531566    void buildArrayIdent(OutBuffer *buf, Expressions *arguments); 
    15541567    Expression *buildArrayLoop(Arguments *fparams); 
     1568    IntRange getIntRange(); 
    15551569 
    15561570    // For operator overloading 
     
    15951609    Expression *optimize(int result); 
    15961610    Expression *interpret(InterState *istate); 
     1611    IntRange getIntRange(); 
    15971612 
    15981613    // For operator overloading 
     
    16151630    Expression *optimize(int result); 
    16161631    Expression *interpret(InterState *istate); 
     1632    IntRange getIntRange(); 
    16171633 
    16181634    // For operator overloading 
     
    16351651    Expression *optimize(int result); 
    16361652    Expression *interpret(InterState *istate); 
     1653    IntRange getIntRange(); 
    16371654 
    16381655    // For operator overloading 
     
    16571674    void buildArrayIdent(OutBuffer *buf, Expressions *arguments); 
    16581675    Expression *buildArrayLoop(Arguments *fparams); 
     1676    IntRange getIntRange(); 
    16591677 
    16601678    // For operator overloading 
     
    16801698    void buildArrayIdent(OutBuffer *buf, Expressions *arguments); 
    16811699    Expression *buildArrayLoop(Arguments *fparams); 
     1700    MATCH implicitConvTo(Type *t); 
     1701    IntRange getIntRange(); 
    16821702 
    16831703    // For operator overloading 
     
    17031723    void buildArrayIdent(OutBuffer *buf, Expressions *arguments); 
    17041724    Expression *buildArrayLoop(Arguments *fparams); 
     1725    MATCH implicitConvTo(Type *t); 
     1726    IntRange getIntRange(); 
    17051727 
    17061728    // For operator overloading 
  • dmd2/func.c

    r1487 r1526  
    11// Compiler implementation of the D programming language 
    2 // Copyright (c) 1999-2008 by Digital Mars 
     2// Copyright (c) 1999-2009 by Digital Mars 
    33// All Rights Reserved 
    44// written by Walter Bright 
     
    6565    cantInterpret = 0; 
    6666    semanticRun = 0; 
     67#if DMDV1 
     68    nestedFrameRef = 0; 
     69#endif 
    6770    fes = NULL; 
    6871    introducing = 0; 
     
    7275     */ 
    7376    inferRetType = (type && type->nextOf() == NULL); 
    74     scope = NULL; 
    7577    hasReturnExp = 0; 
    7678    nrvo_can = 1; 
     
    7981    shidden = NULL; 
    8082#endif 
    81  
     83#if DMDV2 
    8284    builtin = BUILTINunknown; 
    8385    tookAddressOf = 0; 
    84  
     86#endif 
    8587#if IN_LLVM 
    8688    // LDC 
     
    126128    assert(!fthrows); // deprecated 
    127129 
    128     // LDC 
     130#if IN_LLVM 
    129131    f->intrinsicName = intrinsicName; 
     132#endif 
    130133 
    131134    return f; 
     
    167170    if (!originalType) 
    168171    originalType = type; 
    169     if (!type->deco && type->nextOf()
     172    if (!type->deco
    170173    { 
    171174    /* Apply const and invariant storage class 
     
    305308 
    306309    if (isCtorDeclaration() || 
     310#if DMDV2 
    307311        isPostBlitDeclaration() || 
     312#endif 
    308313        isDtorDeclaration() || 
    309314        isInvariantDeclaration() || 
     
    879884        {   Argument *arg = (Argument *)f->parameters->data[i]; 
    880885 
     886        //printf("[%d] arg->type->ty = %d %s\n", i, arg->type->ty, arg->type->toChars()); 
    881887        if (arg->type->ty == Ttuple) 
    882888        {   TypeTuple *t = (TypeTuple *)arg->type; 
     
    10091015        v = new VarDeclaration(loc, type->nextOf(), outId, NULL); 
    10101016        v->noauto = 1; 
     1017#if DMDV2 
     1018        if (f->isref) 
     1019        { 
     1020            v->storage_class |= STCref | STCforeach; 
     1021        } 
     1022#endif 
    10111023        sc2->incontract--; 
    10121024        v->semantic(sc2); 
     
    11091121 
    11101122        fbody = fbody->semantic(sc2); 
     1123        if (!fbody) 
     1124        fbody = new CompoundStatement(0, new Statements()); 
    11111125 
    11121126        if (inferRetType) 
     
    11861200        else if (!inlineAsm) 
    11871201        { 
    1188         int blockexit = fbody ? fbody->blockExit() : 0
     1202        int blockexit = fbody ? fbody->blockExit() : BEfallthru
    11891203        if (f->isnothrow && blockexit & BEthrow) 
    11901204            error("'%s' is nothrow yet may throw", toChars()); 
     
    12051219            {   Expression *e; 
    12061220 
    1207             warning(loc, "no return at end of function"); 
     1221            //warning(loc, "no return exp; or assert(0); at end of function"); 
     1222            error("no return exp; or assert(0); at end of function"); 
    12081223 
    12091224            if (global.params.useAssert && 
     
    21702185 
    21712186void FuncDeclaration::appendState(Statement *s) 
    2172 {   CompoundStatement *cs; 
    2173  
     2187
    21742188    if (!fbody) 
    2175     {   Statements *a; 
    2176  
    2177     a = new Statements(); 
    2178     fbody = new CompoundStatement(0, a); 
    2179     } 
    2180     cs = fbody->isCompoundStatement(); 
    2181     cs->statements->push(s); 
     2189    fbody = s; 
     2190    else 
     2191    { 
     2192    CompoundStatement *cs = fbody->isCompoundStatement(); 
     2193    if (cs) 
     2194    { 
     2195        if (!cs->statements) 
     2196        fbody = s; 
     2197        else 
     2198        cs->statements->push(s); 
     2199    } 
     2200    else 
     2201        fbody = new CompoundStatement(0, fbody, s); 
     2202    } 
    21822203} 
    21832204 
     
    26362657/********************************* PostBlitDeclaration ****************************/ 
    26372658 
     2659#if DMDV2 
    26382660PostBlitDeclaration::PostBlitDeclaration(Loc loc, Loc endloc) 
    26392661    : FuncDeclaration(loc, endloc, Id::_postblit, STCundefined, NULL) 
     
    27052727    bodyToCBuffer(buf, hgs); 
    27062728} 
     2729#endif 
    27072730 
    27082731/********************************* DtorDeclaration ****************************/ 
  • dmd2/import.c

    r1452 r1526  
    2222#include "declaration.h" 
    2323#include "id.h" 
     24#include "attrib.h" 
    2425 
    2526/********************************* Import ****************************/ 
     
    101102    if (s) 
    102103    { 
     104#if TARGET_NET 
     105        mod = (Module *)s; 
     106#else 
    103107    if (s->isModule()) 
    104108        mod = (Module *)s; 
    105109    else 
    106110        error("package and module have the same name"); 
     111#endif 
    107112    } 
    108113 
     
    122127} 
    123128 
    124 #if IN_LLVM 
    125 char* escapePath(char* fname, char* buffer, int bufLen) { 
    126     char* res = buffer; 
    127     bufLen -= 2;    // for \0 and an occasional escape char 
    128     int dst = 0; 
    129     for (; dst < bufLen && *fname; ++dst, ++fname) { 
    130     switch (*fname) { 
     129void escapePath(OutBuffer *buf, const char *fname) 
     130
     131    while (1) 
     132    { 
     133    switch (*fname) 
     134    { 
     135        case 0: 
     136        return; 
    131137        case '(': 
    132138        case ')': 
    133139        case '\\': 
    134             buffer[dst++] = '\\'; 
    135             // fall through 
    136  
     140        buf->writebyte('\\'); 
    137141        default: 
    138             buffer[dst] = *fname; 
    139     } 
    140     } 
    141     buffer[dst] = '\0'; 
    142     return buffer; 
    143 
    144 #endif 
     142        buf->writebyte(*fname); 
     143        break; 
     144    } 
     145    fname++; 
     146    } 
     147
    145148 
    146149void Import::semantic(Scope *sc) 
     
    165168    //printf("%s imports %s\n", sc->module->toChars(), mod->toChars()); 
    166169    sc->module->aimports.push(mod); 
    167  
    168     mod->semantic(); 
    169170 
    170171    if (!isstatic && !aliasId && !names.dim) 
     
    178179    } 
    179180 
     181    mod->semantic(); 
     182 
    180183    if (mod->needmoduleinfo) 
    181184        sc->module->needmoduleinfo = 1; 
     
    194197    sc = sc->pop(); 
    195198    } 
    196     //printf("-Import::semantic('%s'), pkg = %p\n", toChars(), pkg); 
    197  
    198  
    199     if (global.params.moduleDeps != NULL) { 
    200     char fnameBuf[262];     // MAX_PATH+2 
    201  
    202     OutBuffer *const ob = global.params.moduleDeps; 
    203     ob->printf("%s (%s) : ", 
    204         sc->module->toPrettyChars(), 
    205         escapePath(sc->module->srcfile->toChars(), fnameBuf, sizeof(fnameBuf) / sizeof(*fnameBuf)) 
    206     ); 
    207  
    208     char* protStr = ""; 
    209     switch (sc->protection) { 
    210         case PROTpublic: protStr = "public"; break; 
    211         case PROTprivate: protStr = "private"; break; 
    212         case PROTpackage: protStr = "package"; break; 
    213         default: break; 
    214     } 
    215     ob->writestring(protStr); 
    216     if (isstatic) { 
    217         ob->writestring(" static"); 
    218     } 
    219     ob->writestring(" : "); 
    220  
    221     if (this->packages) { 
    222         for (size_t i = 0; i < this->packages->dim; i++) { 
    223         Identifier *pid = (Identifier *)this->packages->data[i]; 
     199 
     200    if (global.params.moduleDeps != NULL) 
     201    { 
     202    /* The grammar of the file is: 
     203     *  ImportDeclaration 
     204     *      ::= BasicImportDeclaration [ " : " ImportBindList ] [ " -> " 
     205     *  ModuleAliasIdentifier ] "\n" 
     206     * 
     207     *  BasicImportDeclaration 
     208     *      ::= ModuleFullyQualifiedName " (" FilePath ") : " Protection 
     209     *      " [ " static" ] : " ModuleFullyQualifiedName " (" FilePath ")" 
     210     * 
     211     *  FilePath 
     212     *      - any string with '(', ')' and '\' escaped with the '\' character 
     213     */ 
     214 
     215    OutBuffer *ob = global.params.moduleDeps; 
     216 
     217    ob->writestring(sc->module->toPrettyChars()); 
     218    ob->writestring(" ("); 
     219    escapePath(ob, sc->module->srcfile->toChars()); 
     220    ob->writestring(") : "); 
     221 
     222    ProtDeclaration::protectionToCBuffer(ob, sc->protection); 
     223    if (isstatic) 
     224        StorageClassDeclaration::stcToCBuffer(ob, STCstatic); 
     225    ob->writestring(": "); 
     226 
     227    if (packages) 
     228    { 
     229        for (size_t i = 0; i < packages->dim; i++) 
     230        { 
     231        Identifier *pid = (Identifier *)packages->data[i]; 
    224232        ob->printf("%s.", pid->toChars()); 
    225233        } 
    226234    } 
    227235 
    228     ob->printf("%s (%s)", 
    229         this->id->toChars(), 
    230         mod ? escapePath(mod->srcfile->toChars(), fnameBuf, sizeof(fnameBuf) / sizeof(*fnameBuf)) : "???" 
    231     ); 
    232  
    233     if (aliasId) { 
    234         ob->printf(" -> %s", aliasId->toChars()); 
    235     } else { 
    236         if (names.dim > 0) { 
    237         ob->writestring(" : "); 
    238         for (size_t i = 0; i < names.dim; i++) 
    239         { 
    240             if (i > 0) { 
    241             ob->writebyte(','); 
    242             } 
    243  
    244             Identifier *name = (Identifier *)names.data[i]; 
    245             Identifier *alias = (Identifier *)aliases.data[i]; 
    246  
    247             if (!alias) { 
    248             ob->printf("%s", name->toChars()); 
    249             alias = name; 
    250             } else { 
    251             ob->printf("%s=%s", alias->toChars(), name->toChars()); 
    252             } 
    253         } 
     236    ob->writestring(id->toChars()); 
     237    ob->writestring(" ("); 
     238    if (mod) 
     239        escapePath(ob, mod->srcfile->toChars()); 
     240    else 
     241        ob->writestring("???"); 
     242    ob->writebyte(')'); 
     243 
     244    for (size_t i = 0; i < names.dim; i++) 
     245    { 
     246        if (i == 0) 
     247        ob->writebyte(':'); 
     248        else 
     249        ob->writebyte(','); 
     250 
     251        Identifier *name = (Identifier *)names.data[i]; 
     252        Identifier *alias = (Identifier *)aliases.data[i]; 
     253 
     254        if (!alias) 
     255        { 
     256        ob->printf("%s", name->toChars()); 
     257        alias = name; 
    254258        } 
    255     } 
     259        else 
     260        ob->printf("%s=%s", alias->toChars(), name->toChars()); 
     261    } 
     262 
     263    if (aliasId) 
     264        ob->printf(" -> %s", aliasId->toChars()); 
    256265 
    257266    ob->writenl(); 
    258267    } 
     268 
     269   //printf("-Import::semantic('%s'), pkg = %p\n", toChars(), pkg); 
    259270} 
    260271 
     
    348359    } 
    349360    } 
    350     buf->printf("%s", id->toChars()); 
    351     if (names.dim > 0) { 
    352     buf->writebyte(':'); 
    353     for (size_t i = 0; i < names.dim; i++) 
    354     { 
    355         if (i > 0) { 
    356             buf->writebyte(','); 
    357         } 
    358  
    359         Identifier *name = (Identifier *)names.data[i]; 
    360         Identifier *alias = (Identifier *)aliases.data[i]; 
    361  
    362         if (!alias) { 
    363         buf->printf("%s", name->toChars()); 
    364         alias = name; 
    365         } else { 
    366         buf->printf("%s=%s", alias->toChars(), name->toChars()); 
    367         } 
    368     } 
    369     } 
    370     buf->writebyte(';'); 
     361    buf->printf("%s;", id->toChars()); 
    371362    buf->writenl(); 
    372363} 
  • dmd2/import.h

    r758 r1526  
    3535    Identifier *aliasId; 
    3636    int isstatic;       // !=0 if static import 
     37#if IN_LLVM 
    3738    enum PROT protection; 
     39#endif 
    3840 
    3941    // Pairs of alias=name to bind into current namespace 
     
    5153 
    5254    const char *kind(); 
     55#if IN_LLVM 
    5356    enum PROT prot(); 
     57#endif 
    5458    Dsymbol *syntaxCopy(Dsymbol *s);    // copy only syntax trees 
    5559    void load(Scope *sc); 
  • dmd2/inifile.c

    r1452 r1526  
    1515#include    <stdlib.h> 
    1616#include    <ctype.h> 
     17 
     18#if _WIN32 
     19#include <windows.h> 
     20#endif 
    1721 
    1822#if __APPLE__ 
     
    9296        if (!FileName::exists(filename)) 
    9397        { 
     98#if _WIN32 // This fix by Tim Matthews 
     99        char resolved_name[MAX_PATH + 1]; 
     100        if(GetModuleFileName(NULL, resolved_name, MAX_PATH + 1) && FileName::exists(resolved_name)) 
     101        { 
     102            filename = (char *)FileName::replaceName(resolved_name, inifile); 
     103            if(FileName::exists(filename)) 
     104                goto Ldone; 
     105        } 
     106#endif 
    94107        filename = (char *)FileName::replaceName(argv0, inifile); 
    95108        if (!FileName::exists(filename)) 
  • dmd2/init.c

    r1452 r1526  
    397397    Expression *e; 
    398398 
    399     //printf("ArrayInitializer::toExpression()\n"); 
     399    //printf("ArrayInitializer::toExpression(), dim = %d\n", dim); 
    400400    //static int i; if (++i == 2) halt(); 
     401 
     402    size_t edim; 
     403    Type *t = NULL; 
     404    if (type) 
     405    { 
     406    t = type->toBasetype(); 
     407    switch (t->ty) 
     408    { 
     409       case Tsarray: 
     410           edim = ((TypeSArray *)t)->dim->toInteger(); 
     411           break; 
     412 
     413       case Tpointer: 
     414       case Tarray: 
     415           edim = dim; 
     416           break; 
     417 
     418       default: 
     419           assert(0); 
     420    } 
     421    } 
     422    else 
     423    edim = value.dim; 
     424 
    401425    elements = new Expressions(); 
    402     for (size_t i = 0; i < value.dim; i++) 
     426    elements->setDim(edim); 
     427    for (size_t i = 0, j = 0; i < value.dim; i++, j++) 
    403428    { 
    404429    if (index.data[i]) 
    405         goto Lno; 
     430        j = ((Expression *)index.data[i])->toInteger(); 
     431    assert(j < edim); 
    406432    Initializer *iz = (Initializer *)value.data[i]; 
    407433    if (!iz) 
     
    409435    Expression *ex = iz->toExpression(); 
    410436    if (!ex) 
    411         goto Lno; 
    412     elements->push(ex); 
    413     } 
    414     e = new ArrayLiteralExp(loc, elements); 
     437    { 
     438        goto Lno; 
     439    } 
     440    elements->data[j] = ex; 
     441    } 
     442 
     443    /* Fill in any missing elements with the default initializer 
     444     */ 
     445    { 
     446    Expression *init = NULL; 
     447    for (size_t i = 0; i < edim; i++) 
     448    { 
     449    if (!elements->data[i]) 
     450    { 
     451        if (!type) 
     452        goto Lno; 
     453        if (!init) 
     454        init = ((TypeNext *)t)->next->defaultInit(); 
     455        elements->data[i] = init; 
     456    } 
     457    } 
     458 
     459    Expression *e = new ArrayLiteralExp(loc, elements); 
    415460    e->type = type; 
    416461    return e; 
     462    } 
    417463 
    418464Lno: 
     
    467513Type *ArrayInitializer::inferType(Scope *sc) 
    468514{ 
     515    //printf("ArrayInitializer::inferType() %s\n", toChars()); 
     516    type = Type::terror; 
    469517    for (size_t i = 0; i < value.dim; i++) 
    470518    { 
     
    472520        goto Lno; 
    473521    } 
    474     if (value.dim
    475     { 
    476     Initializer *iz = (Initializer *)value.data[0]; 
     522    for (size_t i = 0; i < value.dim; i++
     523    { 
     524    Initializer *iz = (Initializer *)value.data[i]; 
    477525    if (iz) 
    478526    {   Type *t = iz->inferType(sc); 
    479         t = new TypeSArray(t, new IntegerExp(value.dim)); 
    480         t = t->semantic(loc, sc); 
    481         return t; 
    482     } 
    483     } 
     527        if (i == 0) 
     528        {   t = new TypeSArray(t, new IntegerExp(value.dim)); 
     529        t = t->semantic(loc, sc); 
     530        type = t; 
     531        } 
     532    } 
     533    } 
     534    return type; 
    484535 
    485536Lno: 
  • dmd2/interpret.c

    r1452 r1526  
    22942294    AssocArrayLiteralExp *aae = (AssocArrayLiteralExp *)earg; 
    22952295    Expression *e = new ArrayLiteralExp(aae->loc, aae->keys); 
     2296    Type *elemType = ((TypeAArray *)aae->type)->index; 
     2297    e->type = new TypeSArray(elemType, new IntegerExp(arguments ? arguments->dim : 0)); 
    22962298    return e; 
    22972299} 
     
    23102312    AssocArrayLiteralExp *aae = (AssocArrayLiteralExp *)earg; 
    23112313    Expression *e = new ArrayLiteralExp(aae->loc, aae->values); 
     2314    Type *elemType = ((TypeAArray *)aae->type)->next; 
     2315    e->type = new TypeSArray(elemType, new IntegerExp(arguments ? arguments->dim : 0)); 
    23122316    //printf("result is %s\n", e->toChars()); 
    23132317    return e; 
  • dmd2/lexer.c

    r1460 r1526  
    12791279            } 
    12801280            if (ndigits != 2 && !utf_isValidDchar(v)) 
    1281             error("invalid UTF character \\U%08x", v); 
     1281            {   error("invalid UTF character \\U%08x", v); 
     1282            v = '?';    // recover with valid UTF character 
     1283            } 
    12821284            c = v; 
    12831285        } 
  • dmd2/mangle.c

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

    r1452 r1526  
    9999#endif 
    100100    ; 
    101     version = "v2.030"; 
     101    version = "v2.031"; 
    102102#if IN_LLVM 
    103103    ldc_version = LDC_REV; 
  • dmd2/mars.h

    r1487 r1526  
    210210 
    211211    const char *xmlname;    // filename for XML output 
    212      
    213     OutBuffer *moduleDeps; // buffer and filename for emitting module deps 
    214     char *moduleDepsFile; 
    215      
     212 
     213    char *moduleDepsFile;  // filename for deps output 
     214    OutBuffer *moduleDeps; // contents to be written to deps file 
     215   
    216216    // Hidden debug switches 
    217217    bool debuga; 
     
    444444#define stdmsg stderr 
    445445#else 
    446 #define stdmsg stdout 
     446#define stdmsg stderr 
    447447#endif 
    448448 
  • dmd2/module.c

    r1452 r1526  
    100100    searchCacheFlags = 0; 
    101101    semanticstarted = 0; 
    102     semanticdone = 0; 
     102    semanticRun = 0; 
    103103    decldefs = NULL; 
    104104    vmoduleinfo = NULL; 
     
    771771    symtab = new DsymbolTable(); 
    772772    for (i = 0; i < members->dim; i++) 
    773     {   Dsymbol *s; 
    774  
    775     s = (Dsymbol *)members->data[i]; 
     773    {   Dsymbol *s = (Dsymbol *)members->data[i]; 
    776774    s->addMember(NULL, sc->scopesym, 1); 
     775    } 
     776 
     777    /* Set scope for the symbols so that if we forward reference 
     778     * a symbol, it can possibly be resolved on the spot. 
     779     * If this works out well, it can be extended to all modules 
     780     * before any semantic() on any of them. 
     781     */ 
     782    for (i = 0; i < members->dim; i++) 
     783    {   Dsymbol *s = (Dsymbol *)members->data[i]; 
     784    s->setScope(sc); 
    777785    } 
    778786 
    779787    // Pass 1 semantic routines: do public side of the definition 
    780788    for (i = 0; i < members->dim; i++) 
    781     {   Dsymbol *s; 
    782  
    783     s = (Dsymbol *)members->data[i]; 
     789    {   Dsymbol *s = (Dsymbol *)members->data[i]; 
     790 
    784791    //printf("\tModule('%s'): '%s'.semantic()\n", toChars(), s->toChars()); 
    785792    s->semantic(sc); 
     
    788795 
    789796    sc = sc->pop(); 
    790     sc->pop(); 
    791     semanticdone = semanticstarted; 
     797    sc->pop();     // 2 pops because Scope::createGlobal() created 2 
     798    semanticRun = semanticstarted; 
    792799    //printf("-Module::semantic(this = %p, '%s'): parent = %p\n", this, toChars(), parent); 
    793800} 
     
    828835    sc = sc->pop(); 
    829836    sc->pop(); 
    830     semanticdone = semanticstarted; 
     837    semanticRun = semanticstarted; 
    831838    //printf("-Module::semantic2('%s'): parent = %p\n", toChars(), parent); 
    832839} 
     
    858865    sc = sc->pop(); 
    859866    sc->pop(); 
    860     semanticdone = semanticstarted; 
     867    semanticRun = semanticstarted; 
    861868} 
    862869 
     
    883890    s->inlineScan(); 
    884891    } 
    885     semanticdone = semanticstarted; 
     892    semanticRun = semanticstarted; 
    886893} 
    887894 
     
    11441151        { 
    11451152        assert(p->isPackage()); 
     1153#if TARGET_NET  //dot net needs modules and packages with same name 
     1154#else 
    11461155        if (p->isModule()) 
    11471156        {   p->error("module and package have the same name"); 
     
    11491158            break; 
    11501159        } 
     1160#endif 
    11511161        } 
    11521162        parent = p; 
  • dmd2/module.h

    r1452 r1526  
    9292 
    9393    int semanticstarted;    // has semantic() been started? 
    94     int semanticdone;     // has semantic() been done? 
     94    int semanticRun;      // has semantic() been done? 
    9595    int root;           // != 0 if this is a 'root' module, 
    9696                // i.e. a module that will be taken all the 
  • dmd2/mtype.c

    r1463 r1526  
    11721172    if (sv->ptrvalue) 
    11731173    {   t = (Type *) sv->ptrvalue; 
     1174#ifdef DEBUG 
     1175        if (!t->deco) 
     1176        printf("t = %s\n", t->toChars()); 
     1177#endif 
    11741178        assert(t->deco); 
    11751179        //printf("old value, deco = '%s' %p\n", t->deco, t->deco); 
     
    13251329 * to type 'to'. 
    13261330 * Returns: 
    1327  *  0   can't convert 
    1328  *  1   can convert using implicit conversions 
    1329  *  2   this and to are the same type 
     1331 *  MATCHnomatch, MATCHconvert, MATCHconst, MATCHexact 
    13301332 */ 
    13311333 
     
    13331335{ 
    13341336    //printf("Type::implicitConvTo(this=%p, to=%p)\n", this, to); 
     1337    //printf("from: %s\n", toChars()); 
     1338    //printf("to  : %s\n", to->toChars()); 
    13351339    if (this == to) 
    13361340    return MATCHexact; 
     
    15921596} 
    15931597 
     1598/**************************************** 
     1599 * Return the mask that an integral type will 
     1600 * fit into. 
     1601 */ 
     1602uinteger_t Type::sizemask() 
     1603{   uinteger_t m; 
     1604 
     1605    switch (toBasetype()->ty) 
     1606    { 
     1607    case Tbool: m = 1;              break; 
     1608    case Tchar: 
     1609    case Tint8: 
     1610    case Tuns8: m = 0xFF;           break; 
     1611    case Twchar: 
     1612    case Tint16: 
     1613    case Tuns16:    m = 0xFFFFUL;           break; 
     1614    case Tdchar: 
     1615    case Tint32: 
     1616    case Tuns32:    m = 0xFFFFFFFFUL;       break; 
     1617    case Tint64: 
     1618    case Tuns64:    m = 0xFFFFFFFFFFFFFFFFULL;  break; 
     1619    default: 
     1620        assert(0); 
     1621    } 
     1622    return m; 
     1623} 
     1624 
    15941625/* ============================= TypeNext =========================== */ 
    15951626 
     
    16111642{ 
    16121643    Type::checkDeprecated(loc, sc); 
    1613     next->checkDeprecated(loc, sc); 
     1644    if (next)   // next can be NULL if TypeFunction and auto return type 
     1645    next->checkDeprecated(loc, sc); 
    16141646} 
    16151647 
     
    16331665    }     
    16341666    TypeNext *t = (TypeNext *)Type::makeConst(); 
    1635     if (ty != Tfunction && ty != Tdelegate && next->deco && 
     1667    if (ty != Tfunction && ty != Tdelegate && 
     1668    (next->deco || next->ty == Tfunction) && 
    16361669        !next->isInvariant() && !next->isConst()) 
    16371670    {   if (next->isShared()) 
     
    16521685    } 
    16531686    TypeNext *t = (TypeNext *)Type::makeInvariant(); 
    1654     if (ty != Tfunction && ty != Tdelegate && next->deco && 
     1687    if (ty != Tfunction && ty != Tdelegate && 
     1688    (next->deco || next->ty == Tfunction) && 
    16551689    !next->isInvariant()) 
    16561690    {   t->next = next->invariantOf(); 
     
    16671701    }     
    16681702    TypeNext *t = (TypeNext *)Type::makeShared(); 
    1669     if (ty != Tfunction && ty != Tdelegate && next->deco && 
     1703    if (ty != Tfunction && ty != Tdelegate && 
     1704    (next->deco || next->ty == Tfunction) && 
    16701705        !next->isInvariant() && !next->isShared()) 
    16711706    { 
     
    16871722    }     
    16881723    TypeNext *t = (TypeNext *)Type::makeSharedConst(); 
    1689     if (ty != Tfunction && ty != Tdelegate && next->deco && 
     1724    if (ty != Tfunction && ty != Tdelegate && 
     1725    (next->deco || next->ty == Tfunction) && 
    16901726        !next->isInvariant() && !next->isSharedConst()) 
    16911727    { 
     
    23622398    return MATCHexact; 
    23632399 
     2400#if DMDV2 
    23642401    if (ty == to->ty) 
    23652402    { 
    23662403    return (mod == to->mod) ? MATCHexact : MATCHconst; 
    23672404    } 
     2405#endif 
    23682406 
    23692407    if (ty == Tvoid || to->ty == Tvoid) 
    23702408    return MATCHnomatch; 
    2371     if (1 || global.params.Dversion == 1) 
    2372     { 
    2373     if (to->ty == Tbool) 
    2374         return MATCHnomatch; 
    2375     } 
    2376     else 
    2377     { 
    2378     if (ty == Tbool || to->ty == Tbool) 
    2379         return MATCHnomatch; 
    2380     } 
     2409    if (to->ty == Tbool) 
     2410    return MATCHnomatch; 
    23812411    if (!to->isTypeBasic()) 
    23822412    return MATCHnomatch; 
     
    23892419        return MATCHnomatch; 
    23902420 
    2391     // If converting to integral 
    2392     if (0 && global.params.Dversion > 1 && tob->flags & TFLAGSintegral) 
     2421#if DMDV2 
     2422    // If converting from integral to integral 
     2423    if (1 && tob->flags & TFLAGSintegral) 
    23932424    {   d_uns64 sz = size(0); 
    23942425        d_uns64 tosz = tob->size(0); 
    23952426 
    2396         /* Can't convert to smaller size or, if same size, change sign 
     2427        /* Can't convert to smaller size 
    23972428         */ 
    23982429        if (sz > tosz) 
    23992430        return MATCHnomatch; 
    24002431 
     2432        /* Can't change sign if same size 
     2433         */ 
    24012434        /*if (sz == tosz && (flags ^ tob->flags) & TFLAGSunsigned) 
    24022435        return MATCHnomatch;*/ 
    24032436    } 
     2437#endif 
    24042438    } 
    24052439    else if (flags & TFLAGSfloating) 
     
    35533587{ 
    35543588    //printf("TypePointer::semantic()\n"); 
     3589    if (deco) 
     3590    return this; 
    35553591    Type *n = next->semantic(loc, sc); 
    35563592    switch (n->toBasetype()->ty) 
     
    35623598    } 
    35633599    if (n != next) 
     3600    { 
    35643601    deco = NULL; 
     3602    } 
    35653603    next = n; 
    35663604    transitive(); 
     
    38023840 
    38033841        if (!arg1->type->equals(arg2->type)) 
    3804         goto Ldistinct; 
     3842        { 
     3843#if 0 // turn on this for contravariant argument types, see bugzilla 3075 
     3844        // We can add const, but not subtract it 
     3845        if (arg2->type->implicitConvTo(arg1->type) < MATCHconst) 
     3846#endif 
     3847            goto Ldistinct; 
     3848        } 
    38053849        if ((arg1->storageClass & ~STCscope) != (arg2->storageClass & ~STCscope)) 
    38063850        inoutmismatch = 1; 
     
    40584102        buf->writestring(" const"); 
    40594103    if (mod & MODinvariant) 
    4060         buf->writestring(" invariant"); 
     4104        buf->writestring(" immutable"); 
    40614105    if (mod & MODshared) 
    40624106        buf->writestring(" shared"); 
     
    40824126    //printf("TypeFunction::semantic() %s, sc->stc = %x\n", toChars(), sc->stc); 
    40834127 
     4128    /* Copy in order to not mess up original. 
     4129     * This can produce redundant copies if inferring return type, 
     4130     * as semantic() will get called again on this. 
     4131     */ 
    40844132    TypeFunction *tf = (TypeFunction *)mem.malloc(sizeof(TypeFunction)); 
    40854133    memcpy(tf, this, sizeof(TypeFunction)); 
     
    41024150 
    41034151    tf->linkage = sc->linkage; 
    4104     if (!tf->next) 
    4105     { 
    4106     assert(global.errors); 
    4107     tf->next = tvoid; 
    4108     } 
    4109     tf->next = tf->next->semantic(loc,sc); 
    4110     if (tf->next->toBasetype()->ty == Tsarray) 
    4111     {   error(loc, "functions cannot return static array %s", tf->next->toChars()); 
    4112     tf->next = Type::terror; 
    4113     } 
    4114     if (tf->next->toBasetype()->ty == Tfunction) 
    4115     {   error(loc, "functions cannot return a function"); 
    4116     tf->next = Type::terror; 
    4117     } 
    4118     if (tf->next->toBasetype()->ty == Ttuple) 
    4119     {   error(loc, "functions cannot return a tuple"); 
    4120     tf->next = Type::terror; 
    4121     } 
    4122     if (tf->next->isauto() && !(sc->flags & SCOPEctor)) 
    4123     error(loc, "functions cannot return scope %s", tf->next->toChars()); 
     4152    if (tf->next) 
     4153    { 
     4154    tf->next = tf->next->semantic(loc,sc); 
     4155    if (tf->next->toBasetype()->ty == Tsarray) 
     4156    {   error(loc, "functions cannot return static array %s", tf->next->toChars()); 
     4157        tf->next = Type::terror; 
     4158    } 
     4159    if (tf->next->toBasetype()->ty == Tfunction) 
     4160    {   error(loc, "functions cannot return a function"); 
     4161        tf->next = Type::terror; 
     4162    } 
     4163    if (tf->next->toBasetype()->ty == Ttuple) 
     4164    {   error(loc, "functions cannot return a tuple"); 
     4165        tf->next = Type::terror; 
     4166    } 
     4167    if (tf->next->isauto() && !(sc->flags & SCOPEctor)) 
     4168        error(loc, "functions cannot return scope %s", tf->next->toChars()); 
     4169    } 
    41244170 
    41254171    if (tf->parameters) 
     
    41694215    } 
    41704216    } 
    4171     tf->deco = tf->merge()->deco; 
     4217    if (tf->next) 
     4218    tf->deco = tf->merge()->deco; 
    41724219 
    41734220    if (tf->inuse) 
     
    47714818 
    47724819void TypeIdentifier::resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymbol **ps) 
    4773 {   Dsymbol *s; 
     4820{ 
    47744821    Dsymbol *scopesym; 
    47754822 
    47764823    //printf("TypeIdentifier::resolve(sc = %p, idents = '%s')\n", sc, toChars()); 
    4777     s = sc->search(loc, ident, &scopesym); 
     4824    Dsymbol *s = sc->search(loc, ident, &scopesym); 
    47784825    resolveHelper(loc, sc, s, scopesym, pe, pt, ps); 
    47794826    if (*pt) 
     
    52425289{ 
    52435290    //printf("TypeEnum::semantic() %s\n", toChars()); 
    5244     sym->semantic(sc); 
     5291    //sym->semantic(sc); 
    52455292    return merge(); 
    52465293} 
     
    58965943    TemplateInstance *ti = s->isTemplateInstance(); 
    58975944    if (ti) 
    5898     {   if (!ti->semanticdone
     5945    {   if (!ti->semanticRun
    58995946        ti->semantic(sc); 
    59005947    s = ti->inst->toAlias(); 
     
    61356182{ 
    61366183    //printf("TypeClass::semantic(%s)\n", sym->toChars()); 
    6137     if (sym->scope) 
    6138     sym->semantic(sym->scope); 
     6184    if (deco) 
     6185    return this; 
     6186    //printf("\t%s\n", merge()->deco); 
    61396187    return merge(); 
    61406188} 
     
    64276475    TemplateInstance *ti = s->isTemplateInstance(); 
    64286476    if (ti) 
    6429     {   if (!ti->semanticdone
     6477    {   if (!ti->semanticRun
    64306478        ti->semantic(sc); 
    64316479    s = ti->inst->toAlias(); 
  • dmd2/mtype.h

    r1452 r1526  
    307307    //Type *next; 
    308308    virtual Type *nextOf(); 
     309    uinteger_t sizemask(); 
     310 
    309311 
    310312    static void error(Loc loc, const char *format, ...) IS_PRINTF(2); 
     
    715717 
    716718    TypeEnum(EnumDeclaration *sym); 
     719    Type *syntaxCopy(); 
    717720    d_uns64 size(Loc loc); 
    718721    unsigned alignsize(); 
    719722    char *toChars(); 
    720     Type *syntaxCopy(); 
    721723    Type *semantic(Loc loc, Scope *sc); 
    722724    Dsymbol *toDsymbol(Scope *sc); 
  • dmd2/opover.c

    r1452 r1526  
    199199    } 
    200200 
     201#if DMDV2 
    201202    // Didn't find it. Forward to aliasthis 
    202203    if (ad->aliasthis) 
     
    211212        return e; 
    212213    } 
     214#endif 
    213215    } 
    214216    return NULL; 
     
    442444    } 
    443445 
     446#if DMDV2 
    444447    // Try alias this on first operand 
    445448    if (ad1 && ad1->aliasthis) 
     
    467470    return e; 
    468471    } 
    469  
     472#endif 
    470473    return NULL; 
    471474} 
  • dmd2/optimize.c

    r1452 r1526  
    11 
    22// Compiler implementation of the D programming language 
    3 // Copyright (c) 1999-2007 by Digital Mars 
     3// Copyright (c) 1999-2009 by Digital Mars 
    44// All Rights Reserved 
    55// written by Walter Bright 
     
    806806    Expression *e1 = this->e1->optimize(WANTvalue | (result & WANTinterpret)); 
    807807    e1 = fromConstInitializer(result, e1); 
     808    if (this->e1->op == TOKvar) 
     809    {   VarExp *ve = (VarExp *)this->e1; 
     810    if (ve->var->storage_class & STCmanifest) 
     811    {   /* We generally don't want to have more than one copy of an 
     812         * array literal, but if it's an enum we have to because the 
     813         * enum isn't stored elsewhere. See Bugzilla 2559 
     814         */ 
     815        this->e1 = e1; 
     816    } 
     817    } 
    808818    e2 = e2->optimize(WANTvalue | (result & WANTinterpret)); 
    809819    e = Index(type, e1, e2); 
  • dmd2/parse.c

    r1452 r1526  
    31453145    Statement *ifbody; 
    31463146    Statement *elsebody; 
     3147    bool isfinal; 
    31473148    Loc loc = this->loc; 
    31483149 
     
    32463247    } 
    32473248 
     3249    case TOKfinal: 
     3250        if (peekNext() == TOKswitch) 
     3251        { 
     3252        nextToken(); 
     3253        isfinal = TRUE; 
     3254        goto Lswitch; 
     3255        } 
     3256        goto Ldeclaration; 
     3257 
    32483258    CASE_BASIC_TYPES: 
    32493259    case TOKtypedef: 
     
    32523262    case TOKauto: 
    32533263    case TOKextern: 
    3254     case TOKfinal: 
    32553264    case TOKinvariant: 
    32563265#if DMDV2 
     
    36523661 
    36533662    case TOKswitch: 
    3654     {   Expression *condition; 
    3655         Statement *body; 
    3656  
     3663        isfinal = FALSE; 
     3664        goto Lswitch; 
     3665 
     3666    Lswitch: 
     3667    { 
    36573668        nextToken(); 
    36583669        check(TOKlparen); 
    3659         condition = parseExpression(); 
     3670        Expression *condition = parseExpression(); 
    36603671        check(TOKrparen); 
    3661         body = parseStatement(PSscope); 
    3662         s = new SwitchStatement(loc, condition, body); 
     3672        Statement *body = parseStatement(PSscope); 
     3673        s = new SwitchStatement(loc, condition, body, isfinal); 
    36633674        break; 
    36643675    } 
     
    36683679        Statements *statements; 
    36693680        Array cases;    // array of Expression's 
     3681        Expression *last = NULL; 
    36703682 
    36713683        while (1) 
     
    36793691        check(TOKcolon); 
    36803692 
     3693#if DMDV2 
     3694        /* case exp: .. case last: 
     3695         */ 
     3696        if (token.value == TOKslice) 
     3697        { 
     3698        if (cases.dim > 1) 
     3699            error("only one case allowed for start of case range"); 
     3700        nextToken(); 
     3701        check(TOKcase); 
     3702        last = parseAssignExp(); 
     3703        check(TOKcolon); 
     3704        } 
     3705#endif 
     3706 
    36813707        statements = new Statements(); 
    36823708        while (token.value != TOKcase && 
     
    36893715        s = new ScopeStatement(loc, s); 
    36903716 
    3691         // Keep cases in order by building the case statements backwards 
    3692         for (int i = cases.dim; i; i--) 
    3693         { 
    3694         exp = (Expression *)cases.data[i - 1]; 
    3695         s = new CaseStatement(loc, exp, s); 
     3717#if DMDV2 
     3718        if (last) 
     3719        { 
     3720        s = new CaseRangeStatement(loc, exp, last, s); 
     3721        } 
     3722        else 
     3723#endif 
     3724        { 
     3725        // Keep cases in order by building the case statements backwards 
     3726        for (int i = cases.dim; i; i--) 
     3727        { 
     3728            exp = (Expression *)cases.data[i - 1]; 
     3729            s = new CaseStatement(loc, exp, s); 
     3730        } 
    36963731        } 
    36973732        break; 
     
    40254060 *      1   identifier optional 
    40264061 *      2   must have identifier 
     4062 * Output: 
     4063 *  if *pt is not NULL, it is set to the ending token, which would be endtok 
    40274064 */ 
    40284065 
     
    40634100 
    40644101Lis: 
    4065     //printf("\tis declaration\n"); 
     4102    //printf("\tis declaration, t = %s\n", t->toChars()); 
    40664103    return TRUE; 
    40674104 
     
    43584395{   // This code parallels parseParameters() 
    43594396    Token *t = *pt; 
    4360     int tmp; 
    43614397 
    43624398    //printf("isParameters()\n"); 
     
    43674403    for (;1; t = peek(t)) 
    43684404    { 
     4405     L1: 
    43694406    switch (t->value) 
    43704407    { 
     
    43814418        case TOKref: 
    43824419        case TOKlazy: 
     4420        case TOKfinal: 
     4421        continue; 
     4422 
    43834423        case TOKconst: 
    43844424        case TOKinvariant: 
    43854425        case TOKimmutable: 
    43864426        case TOKshared: 
    4387         case TOKfinal: 
    4388         continue; 
     4427        t = peek(t); 
     4428        if (t->value == TOKlparen) 
     4429        { 
     4430            t = peek(t); 
     4431            if (!isDeclaration(t, 0, TOKrparen, &t)) 
     4432            return FALSE; 
     4433            t = peek(t);    // skip past closing ')' 
     4434            goto L2; 
     4435        } 
     4436        goto L1; 
    43894437 
    43904438#if 0 
     
    44054453 
    44064454        default: 
    4407       if (!isBasicType(&t)) 
     4455        { if (!isBasicType(&t)) 
    44084456            return FALSE; 
    4409         tmp = FALSE; 
     4457        L2: 
     4458        int tmp = FALSE; 
    44104459        if (t->value != TOKdotdotdot && 
    44114460            !isDeclarator(&t, &tmp, TOKreserved)) 
     
    44214470            break; 
    44224471        } 
     4472        } 
    44234473        L3: 
    44244474        if (t->value == TOKcomma) 
  • dmd2/root/async.c

    r1452 r1526  
    6262void AsyncRead::start() 
    6363{ 
    64     unsigned threadaddr; 
    65     hThread = (HANDLE) _beginthreadex(NULL, 
    66     0, 
    67     &startthread, 
    68     this, 
    69     0, 
    70     (unsigned *)&threadaddr); 
     64    //printf("aw->filesdim = %p %d\n", this, filesdim); 
     65    if (filesdim) 
     66    { 
     67    unsigned threadaddr; 
     68    hThread = (HANDLE) _beginthreadex(NULL, 
     69        0, 
     70        &startthread, 
     71        this, 
     72        0, 
     73        (unsigned *)&threadaddr); 
    7174 
    72     if (hThread) 
    73     { 
    74     SetThreadPriority(hThread, THREAD_PRIORITY_HIGHEST); 
    75     } 
    76     else 
    77     { 
    78     assert(0); 
     75    if (hThread) 
     76    { 
     77        SetThreadPriority(hThread, THREAD_PRIORITY_HIGHEST); 
     78    } 
     79    else 
     80    { 
     81        assert(0); 
     82    } 
    7983    } 
    8084} 
     
    99103    AsyncRead *aw = (AsyncRead *)p; 
    100104 
     105    //printf("aw->filesdim = %p %d\n", aw, aw->filesdim); 
    101106    for (size_t i = 0; i < aw->filesdim; i++) 
    102107    {   FileData *f = &aw->files[i]; 
  • dmd2/scope.c

    r1452 r1526  
    7272    this->noctor = 0; 
    7373    this->noaccesscheck = 0; 
     74    this->mustsemantic = 0; 
    7475    this->intypeof = 0; 
    7576    this->parameterSpecialization = 0; 
     
    120121    this->noctor = enclosing->noctor; 
    121122    this->noaccesscheck = enclosing->noaccesscheck; 
     123    this->mustsemantic = enclosing->mustsemantic; 
    122124    this->intypeof = enclosing->intypeof; 
    123125    this->parameterSpecialization = enclosing->parameterSpecialization; 
  • dmd2/scope.h

    r1452 r1526  
    7272    int parameterSpecialization; // if in template parameter specialization 
    7373    int noaccesscheck;      // don't do access checks 
     74    int mustsemantic;       // cannot defer semantic() 
    7475 
    7576    unsigned callSuper;     // primitive flow analysis for constructors 
  • dmd2/statement.c

    r1452 r1526  
    142142{ 
    143143    //printf("Statement::comeFrom()\n"); 
     144    return FALSE; 
     145} 
     146 
     147// Return TRUE if statement has no code in it 
     148int Statement::isEmpty() 
     149{ 
     150    //printf("Statement::isEmpty()\n"); 
    144151    return FALSE; 
    145152} 
     
    581588} 
    582589 
     590int CompoundStatement::isEmpty() 
     591{ 
     592    for (int i = 0; i < statements->dim; i++) 
     593    {   Statement *s = (Statement *) statements->data[i]; 
     594    if (s && !s->isEmpty()) 
     595        return FALSE; 
     596    } 
     597    return TRUE; 
     598} 
     599 
    583600 
    584601/******************************** CompoundDeclarationStatement ***************************/ 
     
    857874} 
    858875 
     876int ScopeStatement::isEmpty() 
     877{ 
     878    //printf("ScopeStatement::isEmpty() %d\n", statement ? statement->isEmpty() : TRUE); 
     879    return statement ? statement->isEmpty() : TRUE; 
     880} 
     881 
    859882void ScopeStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs) 
    860883{ 
     
    15371560         */ 
    15381561        Identifier *id = Identifier::generateId("__r"); 
    1539         aggr = aggr->semantic(sc); 
    15401562        Expression *rinit = new SliceExp(loc, aggr, NULL, NULL); 
    15411563        rinit = rinit->trySemantic(sc); 
     
    18711893 
    18721894        s = new CompoundStatement(loc, a); 
    1873         s = new SwitchStatement(loc, e, s); 
     1895        s = new SwitchStatement(loc, e, s, FALSE); 
    18741896        s = s->semantic(sc); 
    18751897        } 
     
    25472569/******************************** SwitchStatement ***************************/ 
    25482570 
    2549 SwitchStatement::SwitchStatement(Loc loc, Expression *c, Statement *b
     2571SwitchStatement::SwitchStatement(Loc loc, Expression *c, Statement *b, bool isFinal
    25502572    : Statement(loc) 
    25512573{ 
    2552     condition = c; 
    2553     body = b; 
     2574    this->condition = c; 
     2575    this->body = b; 
     2576    this->isFinal = isFinal; 
    25542577    sdefault = NULL; 
    25552578    cases = NULL; 
    25562579    hasNoDefault = 0; 
    25572580    hasVars = 0; 
    2558     // LDC 
     2581#if IN_LLVM 
    25592582    enclosingScopeExit = NULL; 
     2583#endif 
    25602584} 
    25612585 
     
    25632587{ 
    25642588    SwitchStatement *s = new SwitchStatement(loc, 
    2565     condition->syntaxCopy(), body->syntaxCopy()); 
     2589    condition->syntaxCopy(), body->syntaxCopy(), isFinal); 
    25662590    return s; 
    25672591} 
     
    25722596    assert(!cases);     // ensure semantic() is only run once 
    25732597 
    2574     // LDC 
     2598#if IN_LLVM 
    25752599    enclosingScopeExit = sc->enclosingScopeExit; 
     2600#endif 
    25762601 
    25772602    condition = condition->semantic(sc); 
     
    26632688    body = cs; 
    26642689    } 
     2690 
     2691#if DMDV2 
     2692    if (isFinal) 
     2693    {   Type *t = condition->type; 
     2694    while (t->ty == Ttypedef) 
     2695    {   // Don't use toBasetype() because that will skip past enums 
     2696        t = ((TypeTypedef *)t)->sym->basetype; 
     2697    } 
     2698    if (condition->type->ty == Tenum) 
     2699    {   TypeEnum *te = (TypeEnum *)condition->type; 
     2700        EnumDeclaration *ed = te->toDsymbol(sc)->isEnumDeclaration(); 
     2701        assert(ed); 
     2702        size_t dim = ed->members->dim; 
     2703        for (size_t i = 0; i < dim; i++) 
     2704        { 
     2705        EnumMember *em = ((Dsymbol *)ed->members->data[i])->isEnumMember(); 
     2706        if (em) 
     2707        { 
     2708            for (size_t j = 0; j < cases->dim; j++) 
     2709            {   CaseStatement *cs = (CaseStatement *)cases->data[j]; 
     2710            if (cs->exp->equals(em->value)) 
     2711                goto L1; 
     2712            } 
     2713            error("enum member %s not represented in final switch", em->toChars()); 
     2714        } 
     2715          L1: 
     2716        ; 
     2717        } 
     2718    } 
     2719    } 
     2720#endif 
    26652721 
    26662722    sc->pop(); 
     
    27472803    if (sw) 
    27482804    { 
    2749     // LDC 
     2805#if IN_LLVM 
    27502806    enclosingScopeExit = sc->enclosingScopeExit; 
    27512807    if (enclosingScopeExit != sw->enclosingScopeExit) 
     
    27532809        error("case must be inside the same try, synchronized or volatile level as switch"); 
    27542810    } 
    2755  
     2811#endif 
    27562812    exp = exp->implicitCastTo(sc, sw->condition->type); 
    27572813    exp = exp->optimize(WANTvalue | WANTinterpret); 
     
    27682824         */ 
    27692825        sw->hasVars = 1; 
     2826        if (sw->isFinal) 
     2827            error("case variables not allowed in final switch statements"); 
    27702828        goto L1; 
    27712829        } 
     
    28462904    statement->toCBuffer(buf, hgs); 
    28472905} 
     2906 
     2907/******************************** CaseRangeStatement ***************************/ 
     2908 
     2909#if DMDV2 
     2910 
     2911CaseRangeStatement::CaseRangeStatement(Loc loc, Expression *first, 
     2912    Expression *last, Statement *s) 
     2913    : Statement(loc) 
     2914{ 
     2915    this->first = first; 
     2916    this->last = last; 
     2917    this->statement = s; 
     2918} 
     2919 
     2920Statement *CaseRangeStatement::syntaxCopy() 
     2921{ 
     2922    CaseRangeStatement *s = new CaseRangeStatement(loc, 
     2923    first->syntaxCopy(), last->syntaxCopy(), statement->syntaxCopy()); 
     2924    return s; 
     2925} 
     2926 
     2927Statement *CaseRangeStatement::semantic(Scope *sc) 
     2928{   SwitchStatement *sw = sc->sw; 
     2929 
     2930    //printf("CaseRangeStatement::semantic() %s\n", toChars()); 
     2931    if (sw->isFinal) 
     2932    error("case ranges not allowed in final switch"); 
     2933 
     2934    first = first->semantic(sc); 
     2935    first = first->implicitCastTo(sc, sw->condition->type); 
     2936    first = first->optimize(WANTvalue | WANTinterpret); 
     2937    dinteger_t fval = first->toInteger(); 
     2938 
     2939    last = last->semantic(sc); 
     2940    last = last->implicitCastTo(sc, sw->condition->type); 
     2941    last = last->optimize(WANTvalue | WANTinterpret); 
     2942    dinteger_t lval = last->toInteger(); 
     2943 
     2944    if (lval - fval > 256) 
     2945    {   error("more than 256 cases in case range"); 
     2946    lval = fval + 256; 
     2947    } 
     2948 
     2949    /* This works by replacing the CaseRange with an array of Case's. 
     2950     * 
     2951     * case a: .. case b: s; 
     2952     *    => 
     2953     * case a: 
     2954     *   [...] 
     2955     * case b: 
     2956     *   s; 
     2957     */ 
     2958 
     2959    Statements *statements = new Statements(); 
     2960    for (dinteger_t i = fval; i <= lval; i++) 
     2961    { 
     2962    Statement *s = statement; 
     2963    if (i != lval) 
     2964        s = new ExpStatement(loc, NULL); 
     2965    Expression *e = new IntegerExp(loc, i, first->type); 
     2966    Statement *cs = new CaseStatement(loc, e, s); 
     2967    statements->push(cs); 
     2968    } 
     2969    Statement *s = new CompoundStatement(loc, statements); 
     2970    s = s->semantic(sc); 
     2971    return s; 
     2972} 
     2973 
     2974void CaseRangeStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs) 
     2975{ 
     2976    buf->writestring("case "); 
     2977    first->toCBuffer(buf, hgs); 
     2978    buf->writestring(": .. case "); 
     2979    last->toCBuffer(buf, hgs); 
     2980    buf->writenl(); 
     2981    statement->toCBuffer(buf, hgs); 
     2982} 
     2983 
     2984#endif 
    28482985 
    28492986/******************************** DefaultStatement ***************************/ 
     
    28783015    sc->sw->sdefault = this; 
    28793016 
    2880     // LDC 
     3017#if IN_LLVM 
    28813018    enclosingScopeExit = sc->enclosingScopeExit; 
    28823019    if (enclosingScopeExit != sc->sw->enclosingScopeExit) 
     
    28843021        error("default must be inside the same try, synchronized or volatile level as switch"); 
    28853022    } 
     3023 
     3024    if (sc->sw->isFinal) 
     3025    { 
     3026        error("default statement not allowed in final switch statement"); 
     3027    } 
     3028#endif 
    28863029    } 
    28873030    else 
     
    32183361        // Construct: { vresult = exp; return cases.dim + 1; } 
    32193362        exp = new AssignExp(loc, new VarExp(0, fd->vresult), exp); 
     3363        exp->op = TOKconstruct; 
    32203364        exp = exp->semantic(sc); 
    32213365        Statement *s1 = new ExpStatement(loc, exp); 
     
    32343378 
    32353379        exp = new AssignExp(loc, v, exp); 
     3380        exp->op = TOKconstruct; 
    32363381        exp = exp->semantic(sc); 
    32373382    } 
     
    37583903    } 
    37593904 
    3760     if (!body) 
     3905    if (!body || body->isEmpty()) 
     3906    { 
    37613907    return NULL; 
    3762  
     3908    } 
    37633909    return this; 
    37643910} 
  • dmd2/statement.h

    r1452 r1526  
    129129    virtual int blockExit(); 
    130130    virtual int comeFrom(); 
     131    virtual int isEmpty(); 
    131132    virtual void scopeCode(Scope *sc, Statement **sentry, Statement **sexit, Statement **sfinally); 
    132133    virtual Statements *flatten(Scope *sc); 
     
    147148    virtual CaseStatement* isCaseStatement() { return NULL; } 
    148149 
    149     // LDC 
     150#if IN_LLVM 
    150151    virtual void toNakedIR(IRState *irs); 
    151152    virtual AsmBlockStatement* endsWithAsm(); 
     153#endif 
    152154}; 
    153155 
     
    169171    void toIR(IRState *irs); 
    170172 
    171     // LDC 
     173#if IN_LLVM 
    172174    void toNakedIR(IRState *irs); 
     175#endif 
    173176}; 
    174177 
     
    210213    int blockExit(); 
    211214    int comeFrom(); 
     215    int isEmpty(); 
    212216    virtual Statements *flatten(Scope *sc); 
    213217    ReturnStatement *isReturnStatement(); 
     
    220224    virtual void toIR(IRState *irs); 
    221225 
    222     // LDC 
     226#if IN_LLVM 
    223227    virtual void toNakedIR(IRState *irs); 
    224228    virtual AsmBlockStatement* endsWithAsm(); 
     229#endif 
    225230 
    226231    virtual CompoundStatement *isCompoundStatement() { return this; } 
     
    273278    int blockExit(); 
    274279    int comeFrom(); 
     280    int isEmpty(); 
    275281    Expression *interpret(InterState *istate); 
    276282 
     
    480486    Expression *condition; 
    481487    Statement *body; 
     488    bool isFinal; 
    482489 
    483490    DefaultStatement *sdefault; 
     
    488495    int hasVars;        // !=0 if has variable case values 
    489496 
    490     // LDC 
     497#if IN_LLVM 
    491498    Statement *enclosingScopeExit; 
    492  
    493     SwitchStatement(Loc loc, Expression *c, Statement *b); 
     499#endif 
     500 
     501    SwitchStatement(Loc loc, Expression *c, Statement *b, bool isFinal); 
    494502    Statement *syntaxCopy(); 
    495503    Statement *semantic(Scope *sc); 
     
    509517    Expression *exp; 
    510518    Statement *statement; 
     519 
    511520    int index;      // which case it is (since we sort this) 
    512521    block *cblock;  // back end: label for the block 
    513522 
    514     // LDC 
     523#if IN_LLVM 
    515524    Statement *enclosingScopeExit; 
     525#endif 
    516526 
    517527    CaseStatement(Loc loc, Expression *exp, Statement *s); 
     
    531541    CaseStatement* isCaseStatement() { return this; } 
    532542 
    533     // LDC 
     543#if IN_LLVM 
    534544    llvm::BasicBlock* bodyBB; 
    535545    llvm::ConstantInt* llvmIdx; 
    536 }; 
     546#endif 
     547}; 
     548 
     549#if DMDV2 
     550 
     551struct CaseRangeStatement : Statement 
     552
     553    Expression *first; 
     554    Expression *last; 
     555    Statement *statement; 
     556 
     557    CaseRangeStatement(Loc loc, Expression *first, Expression *last, Statement *s); 
     558    Statement *syntaxCopy(); 
     559    Statement *semantic(Scope *sc); 
     560    void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 
     561}; 
     562 
     563#endif 
    537564 
    538565struct DefaultStatement : Statement 
     
    543570#endif 
    544571 
    545     // LDC 
     572#if IN_LLVM 
    546573    Statement *enclosingScopeExit; 
     574#endif 
    547575 
    548576    DefaultStatement(Loc loc, Statement *s); 
     
    559587    void toIR(IRState *irs); 
    560588 
    561     // LDC 
     589#if IN_LLVM 
    562590    llvm::BasicBlock* bodyBB; 
     591#endif 
    563592}; 
    564593 
     
    635664    void toIR(IRState *irs); 
    636665 
     666#if IN_LLVM 
    637667    // LDC: only set if ident is set: label statement to jump to 
    638668    LabelStatement *target; 
     669#endif 
    639670}; 
    640671 
     
    652683    void toIR(IRState *irs); 
    653684 
     685#if IN_LLVM 
    654686    // LDC: only set if ident is set: label statement to jump to 
    655687    LabelStatement *target; 
     688#endif 
    656689}; 
    657690 
     
    676709    SynchronizedStatement(Loc loc, elem *esync, Statement *body); 
    677710    void toIR(IRState *irs); 
     711#if IN_LLVM 
    678712    llvm::Value* llsync; 
     713#endif 
    679714}; 
    680715 
     
    838873    void toIR(IRState *irs); 
    839874 
    840     // LDC 
     875#if IN_LLVM 
    841876    bool asmLabel;       // for labels inside inline assembler 
    842877    void toNakedIR(IRState *irs); 
     878#endif 
    843879}; 
    844880 
     
    874910    void toIR(IRState *irs); 
    875911 
    876     // LDC 
     912#if IN_LLVM 
    877913    // non-zero if this is a branch, contains the target labels identifier 
    878914    Identifier* isBranchToLabel; 
    879915 
    880916    void toNakedIR(IRState *irs); 
     917#endif 
    881918}; 
    882919 
  • dmd2/struct.c

    r1487 r1526  
    4747    sinit = NULL; 
    4848#endif 
    49     scope = NULL; 
    5049    isnested = 0; 
    5150    vthis = NULL; 
     
    7170{ 
    7271    //printf("AggregateDeclaration::semantic2(%s)\n", toChars()); 
    73     if (scope
     72    if (scope && members
    7473    {   error("has forward references"); 
    7574    return; 
     
    9089{   int i; 
    9190 
    92     // LDC 
     91#if IN_LLVM 
    9392    if (!global.params.useAvailableExternally) 
    9493        availableExternally = false; 
     94#endif 
    9595 
    9696    //printf("AggregateDeclaration::semantic3(%s)\n", toChars()); 
     
    289289 
    290290    parent = sc->parent; 
     291    type = type->semantic(loc, sc); 
    291292#if STRUCTTHISREF 
    292293    handle = type; 
  • dmd2/template.c

    r1452 r1526  
    309309    this->overnext = NULL; 
    310310    this->overroot = NULL; 
    311     this->scope = NULL
     311    this->semanticRun = 0
    312312    this->onemember = NULL; 
    313313    this->literal = 0; 
     
    338338 
    339339#if IN_LLVM 
    340     // LDC 
    341340    td->intrinsicName = intrinsicName; 
    342341#endif 
     
    350349    printf("TemplateDeclaration::semantic(this = %p, id = '%s')\n", this, ident->toChars()); 
    351350#endif 
    352     if (scope
     351    if (semanticRun
    353352    return;     // semantic() already run 
     353    semanticRun = 1; 
    354354 
    355355    if (sc->func) 
     
    879879    } 
    880880 
    881     nfparams = Argument::dim(fparameters); // number of function parameters 
    882     nfargs = fargs->dim;      // number of function arguments 
     881    nfparams = Argument::dim(fparameters); // number of function parameters 
     882    nfargs = fargs ? fargs->dim : 0;      // number of function arguments 
    883883 
    884884    /* Check for match of function arguments with variadic template 
     
    13301330    for (TemplateDeclaration *td = this; td; td = td->overnext) 
    13311331    { 
    1332     if (!td->scope
     1332    if (!td->semanticRun
    13331333    { 
    13341334        error("forward reference to template %s", td->toChars()); 
     
    32163216    this->argsym = NULL; 
    32173217    this->aliasdecl = NULL; 
    3218     this->semanticdone = 0; 
     3218    this->semanticRun = 0; 
    32193219    this->semantictiargsdone = 0; 
    32203220    this->withsym = NULL; 
     
    32503250    this->argsym = NULL; 
    32513251    this->aliasdecl = NULL; 
    3252     this->semanticdone = 0; 
     3252    this->semanticRun = 0; 
    32533253    this->semantictiargsdone = 1; 
    32543254    this->withsym = NULL; 
     
    33253325    tinst = sc->tinst; 
    33263326 
    3327     if (semanticdone != 0) 
     3327    if (semanticRun != 0) 
    33283328    { 
    33293329    error(loc, "recursive template expansion"); 
     
    33313331    return; 
    33323332    } 
    3333     semanticdone = 1; 
     3333    semanticRun = 1; 
    33343334#if IN_LLVM 
    33353335    // get the enclosing template instance from the scope tinst 
     
    34753475        //printf("\t2: adding to module %s instead of module %s\n", m->toChars(), sc->module->toChars()); 
    34763476        a = m->members; 
    3477         if (m->semanticdone >= 3) 
     3477        if (m->semanticRun >= 3) 
    34783478        dosemantic3 = 1; 
    34793479    } 
     
    34963496    // Create our own scope for the template parameters 
    34973497    Scope *scope = tempdecl->scope; 
    3498     if (!scope
    3499     { 
    3500     error("forward reference to template declaration %s\n", tempdecl->toChars()); 
     3498    if (!tempdecl->semanticRun
     3499    { 
     3500    error("template instantiation %s forward references template declaration %s\n", toChars(), tempdecl->toChars()); 
    35013501    return; 
    35023502    } 
     
    37183718        else if (ta) 
    37193719        { 
     3720          Ltype: 
    37203721        if (ta->ty == Ttuple) 
    37213722        {   // Expand tuple 
     
    37533754        tiargs->data[j] = ea; 
    37543755        if (ea->op == TOKtype) 
    3755         tiargs->data[j] = ea->type; 
     3756        {   ta = ea->type; 
     3757        goto Ltype; 
     3758        } 
     3759        if (ea->op == TOKtuple) 
     3760        {   // Expand tuple 
     3761        TupleExp *te = (TupleExp *)ea; 
     3762        size_t dim = te->exps->dim; 
     3763        tiargs->remove(j); 
     3764        if (dim) 
     3765        {   tiargs->reserve(dim); 
     3766            for (size_t i = 0; i < dim; i++) 
     3767            tiargs->insert(j + i, te->exps->data[i]); 
     3768        } 
     3769        j--; 
     3770        } 
    37563771    } 
    37573772    else if (sa) 
    37583773    { 
    37593774        TemplateDeclaration *td = sa->isTemplateDeclaration(); 
    3760         if (td && !td->scope && td->literal) 
     3775        if (td && !td->semanticRun && td->literal) 
    37613776        td->semantic(sc); 
    37623777    } 
     
    38993914    printf("TemplateInstance::findBestMatch()\n"); 
    39003915#endif 
     3916    // First look for forward references 
     3917    for (TemplateDeclaration *td = tempdecl; td; td = td->overnext) 
     3918    { 
     3919    if (!td->semanticRun) 
     3920    { 
     3921        if (td->scope) 
     3922        {   // Try to fix forward reference 
     3923        td->semantic(td->scope); 
     3924        } 
     3925        if (!td->semanticRun) 
     3926        { 
     3927        error("%s forward references template declaration %s\n", toChars(), td->toChars()); 
     3928        return NULL; 
     3929        } 
     3930    } 
     3931    } 
     3932 
    39013933    for (TemplateDeclaration *td = tempdecl; td; td = td->overnext) 
    39023934    { 
     
    39153947    dedtypes.setDim(td->parameters->dim); 
    39163948    dedtypes.zero(); 
    3917     if (!td->scope) 
    3918     { 
    3919         error("forward reference to template declaration %s", td->toChars()); 
    3920         return NULL; 
    3921     } 
     3949    assert(td->semanticRun); 
    39223950    m = td->matchWithInstance(this, &dedtypes, 0); 
    39233951    //printf("matchWithInstance = %d\n", m); 
     
    42134241 */ 
    42144242 
    4215 void TemplateInstance::declareParameters(Scope *scope
     4243void TemplateInstance::declareParameters(Scope *sc
    42164244{ 
    42174245    //printf("TemplateInstance::declareParameters()\n"); 
     
    42234251 
    42244252    //printf("\ttdtypes[%d] = %p\n", i, o); 
    4225     tempdecl->declareParameter(scope, tp, o); 
     4253    tempdecl->declareParameter(sc, tp, o); 
    42264254    } 
    42274255} 
     
    42314259{   int i; 
    42324260 
    4233     if (semanticdone >= 2) 
     4261    if (semanticRun >= 2) 
    42344262    return; 
    4235     semanticdone = 2; 
     4263    semanticRun = 2; 
    42364264#if LOG 
    42374265    printf("+TemplateInstance::semantic2('%s')\n", toChars()); 
     
    42634291{ 
    42644292#if LOG 
    4265     printf("TemplateInstance::semantic3('%s'), semanticdone = %d\n", toChars(), semanticdone); 
     4293    printf("TemplateInstance::semantic3('%s'), semanticRun = %d\n", toChars(), semanticRun); 
    42664294#endif 
    42674295//if (toChars()[0] == 'D') *(char*)0=0; 
    4268     if (semanticdone >= 3) 
     4296    if (semanticRun >= 3) 
    42694297    return; 
    4270     semanticdone = 3; 
     4298    semanticRun = 3; 
    42714299    if (!errors && members) 
    42724300    { 
     
    44584486    this->idents = idents; 
    44594487    this->tiargs = tiargs ? tiargs : new Objects(); 
    4460     this->scope = NULL; 
    44614488} 
    44624489 
     
    44924519    fflush(stdout); 
    44934520#endif 
    4494     if (semanticdone && 
     4521    if (semanticRun && 
    44954522    // This for when a class/struct contains mixin members, and 
    44964523    // is done over because of forward references 
     
    45024529    return; 
    45034530    } 
    4504     if (!semanticdone
    4505     semanticdone = 1; 
     4531    if (!semanticRun
     4532    semanticRun = 1; 
    45064533#if LOG 
    45074534    printf("\tdo semantic\n"); 
     
    45784605    for (TemplateDeclaration *td = tempdecl; td; td = td->overnext) 
    45794606    { 
    4580     if (!td->scope
     4607    if (!td->semanticRun
    45814608    { 
    45824609        /* Cannot handle forward references if mixin is a struct member, 
     
    45864613         * semantic. 
    45874614         */ 
    4588         semanticdone = 0; 
     4615        semanticRun = 0; 
    45894616        AggregateDeclaration *ad = toParent()->isAggregateDeclaration(); 
    45904617        if (ad) 
     
    46924719    argsym = new ScopeDsymbol(); 
    46934720    argsym->parent = scy->parent; 
    4694     Scope *scope = scy->push(argsym); 
     4721    Scope *argscope = scy->push(argsym); 
    46954722 
    46964723    unsigned errorsave = global.errors; 
    46974724 
    46984725    // Declare each template parameter as an alias for the argument type 
    4699     declareParameters(scope); 
     4726    declareParameters(argscope); 
    47004727 
    47014728    // Add members to enclosing scope, as well as this scope 
     
    47044731 
    47054732    s = (Dsymbol *)members->data[i]; 
    4706     s->addMember(scope, this, i); 
     4733    s->addMember(argscope, this, i); 
    47074734    //sc->insert(s); 
    47084735    //printf("sc->parent = %p, sc->scopesym = %p\n", sc->parent, sc->scopesym); 
     
    47154742#endif 
    47164743    Scope *sc2; 
    4717     sc2 = scope->push(this); 
     4744    sc2 = argscope->push(this); 
    47184745    sc2->offset = sc->offset; 
    47194746 
     
    47584785    sc2->pop(); 
    47594786 
    4760     scope->pop(); 
     4787    argscope->pop(); 
    47614788 
    47624789//    if (!isAnonymous()) 
     
    47724799{   int i; 
    47734800 
    4774     if (semanticdone >= 2) 
     4801    if (semanticRun >= 2) 
    47754802    return; 
    4776     semanticdone = 2; 
     4803    semanticRun = 2; 
    47774804#if LOG 
    47784805    printf("+TemplateMixin::semantic2('%s')\n", toChars()); 
     
    48024829{   int i; 
    48034830 
    4804     if (semanticdone >= 3) 
     4831    if (semanticRun >= 3) 
    48054832    return; 
    4806     semanticdone = 3; 
     4833    semanticRun = 3; 
    48074834#if LOG 
    48084835    printf("TemplateMixin::semantic3('%s')\n", toChars()); 
  • dmd2/template.h

    r1452 r1526  
    6262    TemplateDeclaration *overroot;  // first in overnext list 
    6363 
    64     Scope *scope; 
     64    int semanticRun;            // 1 semantic() run 
     65 
    6566    Dsymbol *onemember;     // if !=NULL then one member of this template 
    6667 
     
    285286                    // sole member 
    286287    WithScopeSymbol *withsym;       // if a member of a with statement 
    287     int semanticdone; // has semantic() been done? 
     288    int semanticRun;  // has semantic() been done? 
    288289    int semantictiargsdone; // has semanticTiargs() been done? 
    289290    int nest;       // for recursion detection 
     
    343344    Array *idents; 
    344345    Type *tqual; 
    345  
    346     Scope *scope;       // for forward referencing 
    347346 
    348347    TemplateMixin(Loc loc, Identifier *ident, Type *tqual, Array *idents, Objects *tiargs); 
Copyright © 2008, LDC Development Team.