Started implementing support for #show statements.

This commit is contained in:
Patrick Lühne 2017-06-01 04:05:11 +02:00
parent 663c59c470
commit 2bc60d3eea
Signed by: patrick
GPG Key ID: 05F3611E97A70ABF
4 changed files with 54 additions and 2 deletions

View File

@ -201,7 +201,6 @@ struct Interval
////////////////////////////////////////////////////////////////////////////////////////////////////
// TODO: implement declaration/signature
struct Predicate
{
explicit Predicate(std::string &&name)
@ -231,6 +230,26 @@ struct Predicate
////////////////////////////////////////////////////////////////////////////////////////////////////
// TODO: make more use of this class
struct PredicateSignature
{
explicit PredicateSignature(std::string &&name, size_t arity)
: name{std::move(name)},
arity{arity}
{
}
PredicateSignature(const PredicateSignature &other) = delete;
PredicateSignature &operator=(const PredicateSignature &other) = delete;
PredicateSignature(PredicateSignature &&other) noexcept = default;
PredicateSignature &operator=(PredicateSignature &&other) noexcept = default;
std::string name;
size_t arity;
};
////////////////////////////////////////////////////////////////////////////////////////////////////
struct SpecialInteger
{
enum class Type

View File

@ -1,6 +1,9 @@
#ifndef __ANTHEM__CONTEXT_H
#define __ANTHEM__CONTEXT_H
#include <experimental/optional>
#include <anthem/AST.h>
#include <anthem/output/Logger.h>
namespace anthem
@ -25,6 +28,8 @@ struct Context
bool simplify = false;
bool complete = false;
std::experimental::optional<std::vector<ast::PredicateSignature>> visiblePredicateSignatures;
};
////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -150,10 +150,36 @@ struct StatementVisitor
}
}
void visit(const Clingo::AST::ShowSignature &showSignature, const Clingo::AST::Statement &statement, std::vector<ast::ScopedFormula> &, Context &context)
{
if (showSignature.csp)
throw LogicException(statement.location, "CSP #show statements are not supported");
auto &signature = showSignature.signature;
if (signature.negative())
throw LogicException(statement.location, "negative #show atom signatures are currently unsupported");
if (!context.visiblePredicateSignatures)
context.visiblePredicateSignatures.emplace();
if (std::strlen(signature.name()) == 0)
return;
context.logger.log(output::Priority::Debug) << "showing “" << signature.name() << "/" << signature.arity() << "";
context.visiblePredicateSignatures.value().emplace_back(std::string(signature.name()), signature.arity());
}
void visit(const Clingo::AST::ShowTerm &, const Clingo::AST::Statement &statement, std::vector<ast::ScopedFormula> &, Context &)
{
throw LogicException(statement.location, "only #show statements for atoms (not terms) are supported currently");
}
template<class T>
void visit(const T &, const Clingo::AST::Statement &statement, std::vector<ast::ScopedFormula> &, Context &)
{
throw LogicException(statement.location, "statement currently unsupported, expected rule");
throw LogicException(statement.location, "statement currently unsupported");
}
};

View File

@ -64,6 +64,8 @@ void translate(const char *fileName, std::istream &stream, Context &context)
ast::PrintContext printContext;
// TODO: respect predicate visibility in output
if (!context.complete)
{
for (const auto &scopedFormula : scopedFormulas)