Пример #1
0
void ppCond::HandleDef(std::string &line, bool Else, bool negate, int lineno)
{
    Tokenizer tk(line, NULL);
    const Token *t = tk.Next();
    if (!t->IsIdentifier())
    {
        Errors::Error("Identifier expected");
        if (Else)
            HandleElif(false,""); // FIXME 1st arg is bool!
         else
            HandleIf(false,"", lineno);// FIXME 1st arg is bool!
    }
    else
    {
        int v = !!define->Lookup(t->GetId());
        if (asmpp && !v)
        {
            std::string one = UTF8::ToUpper(t->GetId());
            Symbol *t = define->Lookup(one);
            if (t)
            {
                ppDefine::Definition *p = static_cast<ppDefine::Definition *>(t);
                v = p->IsCaseInsensitive();
            }
        }
        if (negate)
            v = !v;
        if (Else)
            HandleElif(v,tk.GetString());
        else
            HandleIf(v, tk.GetString(), lineno);
    }
}
Пример #2
0
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool Peephole::ProcessBranching(Instruction* instr) {
    switch(instr->GetOpcode()) {
        case Instr_If:     { 
            return HandleIf(instr->As<IfInstr>()); 
        }
        case Instr_Switch: { 
            return HandleSwitch(instr->As<SwitchInstr>());
        }
    }

    return false;
}
Пример #3
0
void ppCond::HandleStr(std::string &line, bool Else, bool negate, int lineno)
{
    define->Process(line);
    Tokenizer tk(line, NULL);
    const Token *t = tk.Next();
    int v = t->IsString();
    if (negate)
        v = !v;
    if (Else)
        HandleElif(v, tk.GetString());
    else
        HandleIf(v, tk.GetString(), lineno);
}
Пример #4
0
void ppCond::HandleCtx(std::string &line, bool Else, bool negate, int lineno)
{
    define->Process(line);
    Tokenizer tk(line, NULL);
    const Token *t = tk.Next();
    int v = false; // FIXME
    if (t->IsIdentifier())
    {
        v = ctx.Matches(t->GetId());
        if (negate)
            v = !v;
    }
    else
    {
        Errors::Error("Identifier expected");
    }
    if (Else)
        HandleElif(v, tk.GetString());
    else
        HandleIf(v, tk.GetString(), lineno);
}
Пример #5
0
bool ppCond::Check(int token, const std::string &line, int lineno)
{
    std::string line1 = line;
    switch(token)
    {
        case ELSE:
            HandleElse(line1);
            break;
        case ENDIF:
            HandleEndIf(line1);
            break;
        case IF:
            define->replaceDefined(line1);
            define->Process(line1);
            HandleIf(expr.Eval(line1), line1, lineno);
            break;
        case ELIF:
            define->replaceDefined(line1);
            define->Process(line1);
            HandleElif(expr.Eval(line1), line1);
            break;
        case IFDEF:
            HandleDef(line1, false, false, lineno);
            break;
        case IFNDEF:
            HandleDef(line1, false, true, lineno);
            break;
        case ELIFDEF:
            HandleDef(line1, true, false, lineno);
            break;
        case ELIFNDEF:
            HandleDef(line1, true, true, lineno);
            break;
        case IFIDN:
            HandleIdn(line1, false, false, true, lineno);
            break;
        case ELIFIDN:
            HandleIdn(line1, true, false, true, lineno);
            break;
        case IFNIDN:
            HandleIdn(line1, false, true, true, lineno);
            break;
        case ELIFNIDN:
            HandleIdn(line1, true, true, true, lineno);
            break;
        case IFIDNI:
            HandleIdn(line1, false, false, false, lineno);
            break;
        case ELIFIDNI:
            HandleIdn(line1, true, false, false, lineno);
            break;
        case IFNIDNI:
            HandleIdn(line1, false, true, false, lineno);
            break;
        case ELIFNIDNI:
            HandleIdn(line1, true, true, false, lineno);
            break;
        case IFID:
            HandleId(line1, false, false, lineno);
            break;
        case ELIFID:
            HandleId(line1, true, false, lineno);
            break;
        case IFNID:
            HandleId(line1, false, true, lineno);
            break;
        case ELIFNID:
            HandleId(line1, true, true, lineno);
            break;
        case IFNUM:
            HandleNum(line1, false, false, lineno);
            break;
        case ELIFNUM:
            HandleNum(line1, true, false, lineno);
            break;
        case IFNNUM:
            HandleNum(line1, false, true, lineno);
            break;
        case ELIFNNUM:
            HandleNum(line1, true, true, lineno);
            break;
        case IFSTR:
            HandleStr(line1, false, false, lineno);
            break;
        case ELIFSTR:
            HandleStr(line1, true, false, lineno);
            break;
        case IFNSTR:
            HandleStr(line1, false, true, lineno);
            break;
        case ELIFNSTR:
            HandleStr(line1, true, true, lineno);
            break;
        case IFCTX:
            HandleCtx(line1, false, false, lineno);
            break;
        case ELIFCTX:
            HandleCtx(line1, true, false, lineno);
            break;
        case IFNCTX:
            HandleCtx(line1, false, true, lineno);
            break;
        case ELIFNCTX:
            HandleCtx(line1, true, true, lineno);
            break;
        default:
            return current && current->skipping;
    }
    return true;
}
Пример #6
0
void ppCond::HandleIdn(std::string &line, bool Else, bool negate, bool caseSensitive, int lineno)
{
    define->Process(line);
    size_t n = line.find_first_of(',');
    if (n == std::string::npos)
    {
        Errors::Error("Syntax error in string comparison directive");
        if (Else)
            HandleElif(false, ""); // FIXME 1st arg is bool!
        else
            HandleIf(false,"", lineno);// FIXME 1st arg is bool!
    }
    else
    {
        std::string line1 = line.substr(0, n);
        line.erase(0, n+1);
        n = line.find_first_not_of(" \t\v\n");
        if (n && n != std::string::npos)
            line.erase(0, n);
        n = line.find_last_not_of(" \t\v\n");
        if (n != std::string::npos && n != line.size()-1)
            line.erase(n+1, line.size()-n-1);
        n = line1.find_first_not_of(" \t\v\n");
        if (n && n != std::string::npos)
            line1.erase(0, n);
        n = line1.find_last_not_of(" \t\v\n");
        if (n != std::string::npos && n != line1.size()-1)
            line1.erase(n+1, line1.size()-n-1);
        int pos=0, pos1 = 0;
        int z = 0;
        if (!caseSensitive)
        {
            line = UTF8::ToUpper(line);
            line1 = UTF8::ToUpper(line);
        }
        while (true)
        {
            if (line[pos] == ' ' || line[pos] == '\t' || line[pos] == '\v' || line[pos] == '\n')
            {
                z ^= 1;
                pos = line.find_first_not_of(" \t\v\n", pos);
                if (pos == std::string::npos)
                    pos = line.size();
            }
            if (line1[pos1] == ' ' || line1[pos1] == '\t' || line1[pos1] == '\v' || line1[pos1] == '\n')
            {
                z ^= 1;
                pos1 = line1.find_first_not_of(" \t\v\n", pos);
                if (pos1 == std::string::npos)
                    pos1 = line1.size();
            }
            if (z || pos == line.size() || pos1 == line1.size())
                break;
            if (line[pos] != line1[pos1])
                break;
            pos++, pos1++;
            if (pos == line.size() || pos1 == line1.size())
                break;
        }
        int v = !z && pos == line.size() && pos1 == line1.size();
        if (negate)
            v = !v;
        if (Else)
            HandleElif(v,"");
        else
            HandleIf(v, "", lineno);
    }
}