Represent predicate parameters explicitly
This adds a vector of Parameter structs to PredicateDeclaration. In this way, the domain of each parameter can be tracked individually.
This commit is contained in:
parent
541cb3fb47
commit
43d2c153c7
@ -243,9 +243,14 @@ struct PredicateDeclaration
|
||||
Hidden
|
||||
};
|
||||
|
||||
struct Parameter
|
||||
{
|
||||
Domain domain{Domain::Unknown};
|
||||
};
|
||||
|
||||
explicit PredicateDeclaration(std::string &&name, size_t arity)
|
||||
: name{std::move(name)},
|
||||
arity{arity}
|
||||
parameters{std::vector<Parameter>(arity)}
|
||||
{
|
||||
}
|
||||
|
||||
@ -254,8 +259,13 @@ struct PredicateDeclaration
|
||||
PredicateDeclaration(PredicateDeclaration &&other) noexcept = default;
|
||||
PredicateDeclaration &operator=(PredicateDeclaration &&other) noexcept = default;
|
||||
|
||||
size_t arity() const noexcept
|
||||
{
|
||||
return parameters.size();
|
||||
}
|
||||
|
||||
std::string name;
|
||||
size_t arity;
|
||||
std::vector<Parameter> parameters;
|
||||
bool isUsed{false};
|
||||
bool isExternal{false};
|
||||
Visibility visibility{Visibility::Default};
|
||||
|
@ -38,7 +38,7 @@ struct Context
|
||||
const auto matchesExistingPredicateDeclaration =
|
||||
[&](const auto &predicateDeclaration)
|
||||
{
|
||||
return (predicateDeclaration->arity == arity
|
||||
return (predicateDeclaration->arity() == arity
|
||||
&& strcmp(predicateDeclaration->name.c_str(), name) == 0);
|
||||
};
|
||||
|
||||
|
@ -261,7 +261,7 @@ inline output::ColorStream &print(output::ColorStream &stream, const Predicate &
|
||||
|
||||
inline output::ColorStream &print(output::ColorStream &stream, const PredicateDeclaration &predicateDeclaration, PrintContext &, bool)
|
||||
{
|
||||
return (stream << predicateDeclaration.name << "/" << predicateDeclaration.arity);
|
||||
return (stream << predicateDeclaration.name << "/" << predicateDeclaration.arity());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -104,12 +104,12 @@ ast::Formula completePredicate(ast::PredicateDeclaration &predicateDeclaration,
|
||||
{
|
||||
// Create new set of parameters for the completed definition for the predicate
|
||||
ast::VariableDeclarationPointers parameters;
|
||||
parameters.reserve(predicateDeclaration.arity);
|
||||
parameters.reserve(predicateDeclaration.arity());
|
||||
|
||||
std::vector<ast::Term> arguments;
|
||||
arguments.reserve(predicateDeclaration.arity);
|
||||
arguments.reserve(predicateDeclaration.arity());
|
||||
|
||||
for (size_t i = 0; i < predicateDeclaration.arity; i++)
|
||||
for (size_t i = 0; i < predicateDeclaration.arity(); i++)
|
||||
{
|
||||
parameters.emplace_back(std::make_unique<ast::VariableDeclaration>(ast::VariableDeclaration::Type::Head));
|
||||
arguments.emplace_back(ast::Term::make<ast::Variable>(parameters.back().get()));
|
||||
@ -169,7 +169,7 @@ std::vector<ast::Formula> complete(std::vector<ast::ScopedFormula> &&scopedFormu
|
||||
if (order != 0)
|
||||
return (order < 0);
|
||||
|
||||
return lhs->arity < rhs->arity;
|
||||
return lhs->arity() < rhs->arity();
|
||||
});
|
||||
|
||||
std::vector<ast::Formula> completedFormulas;
|
||||
|
@ -181,7 +181,7 @@ PredicateReplacement findReplacement(const ast::PredicateDeclaration &predicateD
|
||||
else if (completedPredicateDefinition.is<ast::Not>())
|
||||
return findReplacement(predicateDeclaration, completedPredicateDefinition.get<ast::Not>());
|
||||
|
||||
throw CompletionException("unsupported completed definition for predicate “" + predicateDeclaration.name + "/" + std::to_string(predicateDeclaration.arity) + "” for hiding predicates");
|
||||
throw CompletionException("unsupported completed definition for predicate “" + predicateDeclaration.name + "/" + std::to_string(predicateDeclaration.arity()) + "” for hiding predicates");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -217,7 +217,7 @@ void eliminateHiddenPredicates(std::vector<ast::Formula> &completedFormulas, Con
|
||||
if (isPredicateVisible)
|
||||
continue;
|
||||
|
||||
context.logger.log(output::Priority::Debug) << "eliminating “" << predicateDeclaration->name << "/" << predicateDeclaration->arity << "”";
|
||||
context.logger.log(output::Priority::Debug) << "eliminating “" << predicateDeclaration->name << "/" << predicateDeclaration->arity() << "”";
|
||||
|
||||
const auto &completedPredicateDefinition = completedFormulas[i];
|
||||
auto replacement = findReplacement(*predicateDeclaration, completedPredicateDefinition);
|
||||
@ -227,7 +227,7 @@ void eliminateHiddenPredicates(std::vector<ast::Formula> &completedFormulas, Con
|
||||
|
||||
if (hasCircularDependency)
|
||||
{
|
||||
context.logger.log(output::Priority::Warning) << "cannot hide predicate “" << predicateDeclaration->name << "/" << predicateDeclaration->arity << "” due to circular dependency";
|
||||
context.logger.log(output::Priority::Warning) << "cannot hide predicate “" << predicateDeclaration->name << "/" << predicateDeclaration->arity() << "” due to circular dependency";
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -96,7 +96,7 @@ void translate(const char *fileName, std::istream &stream, Context &context)
|
||||
<< "#show declaration of “"
|
||||
<< predicateDeclaration->name
|
||||
<< "/"
|
||||
<< predicateDeclaration->arity
|
||||
<< predicateDeclaration->arity()
|
||||
<< "” does not match any declared predicate";
|
||||
|
||||
// Check for #external statements with undeclared predicates
|
||||
@ -105,7 +105,7 @@ void translate(const char *fileName, std::istream &stream, Context &context)
|
||||
<< "#external declaration of “"
|
||||
<< predicateDeclaration->name
|
||||
<< "/"
|
||||
<< predicateDeclaration->arity
|
||||
<< predicateDeclaration->arity()
|
||||
<< "” does not match any declared predicate";
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user