Minor restructuring.

This commit is contained in:
Patrick Lühne 2017-03-06 15:42:38 +01:00
parent 70cb79b233
commit 71e6e4107a
Signed by: patrick
GPG Key ID: 05F3611E97A70ABF

View File

@ -36,40 +36,32 @@ struct StatementVisitor
rule.head.data.accept(HeadLiteralCollectFunctionTermsVisitor(), rule.head, context); rule.head.data.accept(HeadLiteralCollectFunctionTermsVisitor(), rule.head, context);
// Print auxiliary variables replacing the head atoms arguments // Print auxiliary variables replacing the head atoms arguments
if (!context.headTerms.empty()) for (auto i = context.headTerms.cbegin(); i != context.headTerms.cend(); i++)
{ {
for (auto i = context.headTerms.cbegin(); i != context.headTerms.cend(); i++) const auto &headTerm = **i;
{
const auto &headTerm = **i;
if (i != context.headTerms.cbegin()) if (i != context.headTerms.cbegin())
outputStream << " " << Clingo::AST::BinaryOperator::And << " "; outputStream << " " << Clingo::AST::BinaryOperator::And << " ";
const auto variableName = std::string(AuxiliaryHeadVariablePrefix) + std::to_string(i - context.headTerms.cbegin() + 1); const auto variableName = std::string(AuxiliaryHeadVariablePrefix) + std::to_string(i - context.headTerms.cbegin() + 1);
outputStream outputStream
<< output::Variable(variableName.c_str()) << output::Variable(variableName.c_str())
<< " " << output::Keyword("in") << " " << headTerm; << " " << output::Keyword("in") << " " << headTerm;
}
} }
if (rule.body.empty() && context.headTerms.empty() && !context.isChoiceRule) // Print translated body literals
outputStream << Clingo::AST::Boolean({true}); for (auto i = rule.body.cbegin(); i != rule.body.cend(); i++)
else
{ {
// Print translated body literals const auto &bodyLiteral = *i;
for (auto i = rule.body.cbegin(); i != rule.body.cend(); i++)
{
const auto &bodyLiteral = *i;
if (!context.headTerms.empty() || i != rule.body.cbegin()) if (!context.headTerms.empty() || i != rule.body.cbegin())
outputStream << " " << Clingo::AST::BinaryOperator::And << " "; outputStream << " " << Clingo::AST::BinaryOperator::And << " ";
if (bodyLiteral.sign != Clingo::AST::Sign::None) if (bodyLiteral.sign != Clingo::AST::Sign::None)
throwErrorAtLocation(bodyLiteral.location, "only positive literals currently supported", context); throwErrorAtLocation(bodyLiteral.location, "only positive literals currently supported", context);
bodyLiteral.data.accept(BodyLiteralPrintVisitor(), bodyLiteral, context); bodyLiteral.data.accept(BodyLiteralPrintVisitor(), bodyLiteral, context);
}
} }
// Handle choice rules // Handle choice rules
@ -89,6 +81,10 @@ struct StatementVisitor
outputStream << ")"; outputStream << ")";
} }
// Print “true” on the left side of the formula in case there is nothing else
if (rule.body.empty() && context.headTerms.empty() && !context.isChoiceRule)
outputStream << Clingo::AST::Boolean({true});
outputStream << " " << output::Operator("->") << " "; outputStream << " " << output::Operator("->") << " ";
// Print consequent of the implication // Print consequent of the implication