// @brief Returns true if the PredicateEnry matches with other PredicateEntry // @return bool bool PredicateEntry::matches(shared_ptr<SymbolTableEntry> other, SubstitutionList & substitution_list) const { if (!other->is_predicate()) { return false; } shared_ptr<PredicateEntry> otherp = dynamic_pointer_cast<PredicateEntry>(other); if (_name != otherp->_name || _symbols.size() != otherp->_symbols.size()) { return false; } for (unsigned int i = 0; i < _symbols.size(); ++i) { shared_ptr<SymbolTableEntry> ci_value = substitution_list.find_value(_symbols[i]); shared_ptr<SymbolTableEntry> oi_value = substitution_list.find_value(otherp->_symbols[i]); shared_ptr<SymbolTableEntry> ci = substitution_list.find_non_null(_symbols[i]); shared_ptr<SymbolTableEntry> oi = substitution_list.find_non_null(otherp->_symbols[i]); if (!ci_value || !oi_value) { //semantic error return false; } if (!(*ci_value == *oi_value)) { if (ci_value->is_constant() && oi_value->is_constant()) { return false; } if (!ci_value->is_constant()) { substitution_list.add(ci, oi); } else { //!oi->is_constant() substitution_list.add(oi, ci); } } } return true; }
shared_ptr<Predicate> PredicateEntry::substitute(SubstitutionList & substitution_list) const { vector<shared_ptr<SymbolTableEntry>> symbols; for (auto i = _symbols.begin(); i != _symbols.end(); ++i) { symbols.push_back(substitution_list.find_value(*i)); } PredicateEntry p(string(_name), symbols); ostringstream s; s << "(" << p.text() << ")"; Parser parser(s.str()); return parser.parse_predicate(); }