Пример #1
0
    CodeNodePtr findInterpolatable(StatementPtr stmt) {
        if (CodeNodePtr e = stmt->getExpression()) {
            if (CodeNodePtr f = findInterpolatable(e)) {
                return f;
            }
        }

        StatementList children = stmt->getChildren();
        for (size_t i = 0; i < children.size(); ++i) {
            if (CodeNodePtr f = findInterpolatable(children[i])) {
                return f;
            }
        }

        return CodeNodePtr();        
    }
Пример #2
0
    static void doCountReferences(
        StatementPtr statement,
        ReferenceMap& refs,
        ReferencePath path
    ) {
        assert(statement);
        path.push_back(statement);

        if (CodeNodePtr e = statement->getExpression()) {
            countReferences(e, refs, path);
        }
        
        StatementList children = statement->getChildren();
        for (size_t i = 0; i < children.size(); ++i) {
            doCountReferences(children[i], refs, path);
        }
    }
Пример #3
0
    void replace(StatementPtr st, CodeNodePtr node, CodeNodePtr with) {
        assert(st);
        assert(node);
        assert(with);

        if (CodeNodePtr e = st->getExpression()) {
            if (e == node) {
                st->setExpression(with);
            } else {
                replace(e, node, with);
            }
        }

        StatementList children = st->getChildren();
        for (size_t i = 0; i < children.size(); ++i) {
            replace(children[i], node, with);
        }       
    }
Пример #4
0
    IfCodeNodePtr findBranch(StatementPtr stmt, StatementPtr& ref) {
        assert(stmt);

        if (CodeNodePtr e = stmt->getExpression()) {
            if (IfCodeNodePtr f = findBranch(e)) {
                ref = stmt;
                return f;
            }
        }

        StatementList children = stmt->getChildren();
        for (size_t i = 0; i < children.size(); ++i) {
            if (IfCodeNodePtr f = findBranch(children[i], ref)) {
                return f;
            }
        }

        return IfCodeNodePtr();        
    }
Пример #5
0
    CodeNodePtr findMultiplyReferenced(
        StatementPtr stmt,
        const ReferenceMap& refs
    ) {
        assert(stmt);

        if (CodeNodePtr e = stmt->getExpression()) {
            if (CodeNodePtr f = findMultiplyReferenced(e, refs)) {
                return f;
            }
        }

        StatementList children = stmt->getChildren();
        for (size_t i = 0; i < children.size(); ++i) {
            if (CodeNodePtr f = findMultiplyReferenced(children[i], refs)) {
                return f;
            }
        }

        return CodeNodePtr();
    }