Exemple #1
0
// prints out the ast
void opNode::PrintTree(const opString& filename, int depth) {
    FileNode* file = GetFile();
    opString s = file->GetInputName();
    int line = GetLine();

    s += '(';

    if (line == -1)
        s += "UNKNOWN) : \t";
    else
        s += opString(line) + ") : \t";

    for (int i = 0; i < depth; i++) s += ". ";

    if (IsTerminal()) {
        Token t = GetId();

        // NOTE: this prints the value now (make optional?)
        if (t == T_NEWLINE || t == T_EOF || t == T_CONTINUELINE ||
            t == T_CCOMMENT) {
            Log(s + TokenFunctions::ToString(GetId()));
        } else
            Log(s + TokenFunctions::ToString(GetId()) + "     '" +
                GetTreeValue() + "'");
    } else {
        // If we're not in -fulltree mode, we want to limit
        // the kinds of nodes we print (mostly auto modifiers).
        if (!opParameters::Get().PrintFullTree && (id == G_AUTO_MODIFIERS)) {
            return;
        }

        opString value = GetTreeValue();

        if (!value.Size())
            Log(s + TokenFunctions::ToString(GetId()));
        else
            Log(s + TokenFunctions::ToString(GetId()) + "     '" + value + "'");

        iterator i = GetBegin();
        iterator end = GetEnd();

        while (i != end) {
            i->PrintTree(filename, depth + 1);

            ++i;
        }
    }
}
Exemple #2
0
opNode* OPObjectNode::GetStatementArgument(const opString& argumentname,
                                           StatementBase* statement,
                                           stackedgroup& tempmodifiers) {
    if (opNode* node = statement->FetchModifier(argumentname)) return node;

    if (argumentname == "source_line") {
        int linenumber = statement->GetLine();

        stacked<ExpandableArgumentNode> node = NEWNODE(ExpandableArgumentNode);
        node->CopyBasics(this);
        node->SetValue("source_line");

        node->AppendTerminalNode(linenumber, T_NUMBER);

        opNode* SourceLineArgument = *node;

        tempmodifiers.Push(node);

        return SourceLineArgument;
    } else if (argumentname == "source_file") {
        FileNode* file = statement->GetFile();
        opString filename = file->GetInputName();

        stacked<ExpandableArgumentNode> node = NEWNODE(ExpandableArgumentNode);
        node->CopyBasics(this);
        node->SetValue("source_file");

        node->AppendTerminalNode(filename, T_ID);

        opNode* SourceFileArgument = *node;

        tempmodifiers.Push(node);

        return SourceFileArgument;
    }

    return NULL;
}