Exemplo n.º 1
0
/**
 * Collects all unit test functions from the given array of symbols.
 *
 * This is a helper function used by the implementation of __traits(getUnitTests).
 *
 * Input:
 *      symbols             array of symbols to collect the functions from
 *      uniqueUnitTests     an associative array (should actually be a set) to
 *                          keep track of already collected functions. We're
 *                          using an AA here to avoid doing a linear search of unitTests
 *
 * Output:
 *      unitTests           array of DsymbolExp's of the collected unit test functions
 *      uniqueUnitTests     updated with symbols from unitTests[ ]
 */
static void collectUnitTests(Dsymbols *symbols, AA *uniqueUnitTests, Expressions *unitTests)
{
    if (!symbols)
        return;
    for (size_t i = 0; i < symbols->dim; i++)
    {
        Dsymbol *symbol = (*symbols)[i];
        UnitTestDeclaration *unitTest = symbol->isUnitTestDeclaration();
        if (unitTest)
        {
            if (!_aaGetRvalue(uniqueUnitTests, unitTest))
            {
                FuncAliasDeclaration* alias = new FuncAliasDeclaration(unitTest, 0);
                alias->protection = unitTest->protection;
                Expression* e = new DsymbolExp(Loc(), alias);
                unitTests->push(e);
                bool* value = (bool*) _aaGet(&uniqueUnitTests, unitTest);
                *value = true;
            }
        }
        else
        {
            AttribDeclaration *attrDecl = symbol->isAttribDeclaration();

            if (attrDecl)
            {
                Dsymbols *decl = attrDecl->include(NULL, NULL);
                collectUnitTests(decl, uniqueUnitTests, unitTests);
            }
        }
    }
}
Exemplo n.º 2
0
void ConditionalDeclaration::parsepragmas(Module *m)
{
    // we only know how to disclude the right version
    bool doinclude = true;
    
    if (dynamic_cast<VersionCondition*>(condition)) {
        VersionCondition *vc = (VersionCondition *) condition;
        
        if (!(vc->include(NULL, NULL))) {
            doinclude = false;
        }
    } else if (dynamic_cast<DebugCondition*>(condition)) {
        DebugCondition *dc = (DebugCondition *) condition;
        
        if (!(dc->include(NULL, NULL))) {
            doinclude = false;
        }
    }
    
    if (doinclude) {
        AttribDeclaration::parsepragmas(m);
        
    } else if (elsedecl) {
        for (int i = 0; i < elsedecl->dim; i++) {
            Dsymbol *ds = (Dsymbol *) elsedecl->data[i];
            
            if (ds->isAttribDeclaration()) {
                AttribDeclaration *ad = (AttribDeclaration *) ds;
                ad->parsepragmas(m);
                
            } else if (ds->isImport()) {
                Import *im = (Import *) ds;
                im->load(m, NULL);
                im->mod->parsepragmas();
                
            } else if (dynamic_cast<VersionSymbol*>(ds)) {
                VersionSymbol *vs = (VersionSymbol *) ds;
                vs->addMember(NULL, m, 0);
                
            }
        }
    }
}
Exemplo n.º 3
0
static unsigned setMangleOverride(Dsymbol *s, char *sym)
{
    AttribDeclaration *ad = s->isAttribDeclaration();

    if (ad)
    {
        Dsymbols *decls = ad->include(NULL, NULL);
        unsigned nestedCount = 0;

        if (decls && decls->dim)
            for (size_t i = 0; i < decls->dim; ++i)
                nestedCount += setMangleOverride((*decls)[i], sym);

        return nestedCount;
    }
    else if (s->isFuncDeclaration() || s->isVarDeclaration())
    {
        s->isDeclaration()->mangleOverride = sym;
        return 1;
    }
    else
        return 0;
}
Exemplo n.º 4
0
void AttribDeclaration::parsepragmas(Module *m)
{
    if (decl) {
        for (int i = 0; i < decl->dim; i++) {
            Dsymbol *ds = (Dsymbol *) decl->data[i];
            
            if (ds->isAttribDeclaration()) {
                AttribDeclaration *ad = (AttribDeclaration *) ds;
                ad->parsepragmas(m);
                
            } else if (ds->isImport()) {
                Import *im = (Import *) ds;
                im->load(m, NULL);
                im->mod->parsepragmas();
                
            } else if (dynamic_cast<VersionSymbol*>(ds)) {
                VersionSymbol *vs = (VersionSymbol *) ds;
                vs->addMember(NULL, m, 0);
                
            }
        }
    }
}
Exemplo n.º 5
0
int Dsymbol_canThrow(Dsymbol *s, bool mustNotThrow)
{
    AttribDeclaration *ad;
    VarDeclaration *vd;
    TemplateMixin *tm;
    TupleDeclaration *td;

    //printf("Dsymbol_toElem() %s\n", s->toChars());
    ad = s->isAttribDeclaration();
    if (ad)
    {
        Dsymbols *decl = ad->include(NULL, NULL);
        if (decl && decl->dim)
        {
            for (size_t i = 0; i < decl->dim; i++)
            {
                s = (*decl)[i];
                if (Dsymbol_canThrow(s, mustNotThrow))
                    return 1;
            }
        }
    }
    else if ((vd = s->isVarDeclaration()) != NULL)
    {
        s = s->toAlias();
        if (s != vd)
            return Dsymbol_canThrow(s, mustNotThrow);
        if (vd->storage_class & STCmanifest)
            ;
        else if (vd->isStatic() || vd->storage_class & (STCextern | STCtls | STCgshared))
            ;
        else
        {
            if (vd->init)
            {   ExpInitializer *ie = vd->init->isExpInitializer();
                if (ie && ie->exp->canThrow(mustNotThrow))
                    return 1;
            }
            if (vd->edtor && !vd->noscope)
                return vd->edtor->canThrow(mustNotThrow);
        }
    }
    else if ((tm = s->isTemplateMixin()) != NULL)
    {
        //printf("%s\n", tm->toChars());
        if (tm->members)
        {
            for (size_t i = 0; i < tm->members->dim; i++)
            {
                Dsymbol *sm = (*tm->members)[i];
                if (Dsymbol_canThrow(sm, mustNotThrow))
                    return 1;
            }
        }
    }
    else if ((td = s->isTupleDeclaration()) != NULL)
    {
        for (size_t i = 0; i < td->objects->dim; i++)
        {   RootObject *o = (*td->objects)[i];
            if (o->dyncast() == DYNCAST_EXPRESSION)
            {   Expression *eo = (Expression *)o;
                if (eo->op == TOKdsymbol)
                {   DsymbolExp *se = (DsymbolExp *)eo;
                    if (Dsymbol_canThrow(se->s, mustNotThrow))
                        return 1;
                }
            }
        }
    }
    return 0;
}