예제 #1
0
    void replace(StatementPtr& in, StatementPtr st, StatementPtr with) {
        assert(in);
        assert(st);
        assert(with);

        if (in == st) {
            in = with;
            return;
        }

        StatementList& children = in->getChildren();
        for (size_t i = 0; i < children.size(); ++i) {
            replace(children[i], st, with);
        }       
    }
예제 #2
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();        
    }
예제 #3
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);
        }
    }
예제 #4
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);
        }       
    }
예제 #5
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();        
    }
예제 #6
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();
    }