Exemplo n.º 1
0
ConditionSet SimpleQueryLinker::get_indirect_links(
        const std::string& qvar1, const std::string& qvar2,
        const ConditionPtr& condition1, 
        std::set<std::string> visited_qvars)
{
    if(has_link(qvar1, qvar2)) {
        return get_linked_conditions(qvar1, qvar2, condition1);
    } else {
        ConditionSet result;

        for(std::set<std::string>::iterator qit = _qvar_link_table[qvar1].begin();
            qit != _qvar_link_table[qvar1].end(); ++qit)
        {
            std::string mid_qvar = *qit;

            if(visited_qvars.count(mid_qvar) == 0) {
                visited_qvars.insert(mid_qvar);

                ConditionSet direct_links = get_linked_conditions(
                        qvar1, mid_qvar, condition1);
                for(ConditionSet::iterator cit = direct_links.begin();
                    cit != direct_links.end(); ++cit)
                {
                    result.union_with(get_indirect_links(mid_qvar, qvar2,
                                *cit, visited_qvars));
                }
            }
        }
        return result;
    }
}
Exemplo n.º 2
0
ConditionSet FollowSolver::solve_left<StatementAst>(StatementAst *ast) {
    ConditionSet result;

    if(ast->prev()) {
        result.insert(new SimpleStatementCondition(ast->prev()));
    }
    return result;
}
Exemplo n.º 3
0
ConditionSet ParentSolver::solve_left<StatementAst>(StatementAst *ast) {
    ConditionSet result;

    if(ast->get_parent()) {
        result.insert(new SimpleStatementCondition(ast->get_parent()));
    }
    return result;
}
Exemplo n.º 4
0
ConditionSet ParentSolver::solve_right<WhileAst>(WhileAst *loop) {
    ConditionSet result;
    StatementAst *body = loop->get_body();

    while(body != NULL) {
        result.insert(new SimpleStatementCondition(body));
        body = body->next();
    }

    return result;
}
Exemplo n.º 5
0
void SimpleQueryMatcher::solve_both_same_qvar(const ConditionSet& values,
     /* output */   ConditionSet& new_values,
                    std::vector<ConditionPair>& result_pairs)
{
    for(ConditionSet::iterator it = values.begin();
            it != values.end(); ++it)
    {
        if(_solver->validate(it->get(), it->get())) {
            new_values.insert(*it);
            result_pairs.push_back(ConditionPair(*it, *it));
        }
    }
}
Exemplo n.º 6
0
void SimpleQueryLinker::update_results(const std::string& qvar, 
        const ConditionSet& new_set)
{
    if(!is_initialized(qvar)) {
        _qvar_table[qvar] = new_set;
    } else {
        ConditionSet difference = _qvar_table[qvar].difference_with(new_set);
        if(!difference.is_empty()) {
            for(ConditionSet::iterator it = difference.begin(); 
                    it != difference.end(); ++it )
            {
                remove_condition(qvar, *it);
            }
        }
    }
}
Exemplo n.º 7
0
ConditionSet ParentSolver::solve_right<ConditionalAst>(ConditionalAst *condition) {
    ConditionSet result;
    StatementAst *then_branch = condition->get_then_branch();
    StatementAst *else_branch = condition->get_else_branch();

    while(then_branch != NULL) {
        result.insert(new SimpleStatementCondition(then_branch));
        then_branch = then_branch->next();
    }

    while(else_branch != NULL) {
        result.insert(new SimpleStatementCondition(else_branch));
        else_branch = else_branch->next();
    }

    return result;
}
Exemplo n.º 8
0
void ConditionSet::intersect_with(const ConditionSet& other) {
    if(other.is_empty()) {
        // we are intersecting with empty set, and so
        // the result is also an empty set.
        _set.clear();
        return; 
    }

    std::set<ConditionPtr>::iterator it = _set.begin();
    while(it != _set.end()) {
        if(!other.has_element(*it)) {
            std::set<ConditionPtr>::iterator old_it = it++;
            _set.erase(old_it);
        } else {
            ++it;
        }
    }
}
Exemplo n.º 9
0
void SimpleQueryMatcher::solve_both_diff_qvar(
                    const ConditionSet& left, const ConditionSet& right,
    /* output */    ConditionSet& new_left, ConditionSet& new_right,
                    std::vector<ConditionPair>& result_pairs) 
{
    for(ConditionSet::iterator left_it = left.begin(); 
            left_it != left.end(); ++left_it)
    {
        for(ConditionSet::iterator right_it = right.begin();
              right_it != right.end(); ++right_it)
        {
            if(_solver->validate(left_it->get(), right_it->get())) {
                new_left.insert(*left_it);
                new_right.insert(*right_it);
                result_pairs.push_back(ConditionPair(*left_it, *right_it));
            }
        }
    }
}