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); } }
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(); }
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); } }
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); } }
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(); }
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(); }