souffle  2.0.2-371-g6315b36
ProvenanceClauseTranslator.cpp
Go to the documentation of this file.
1 /*
2  * Souffle - A Datalog Compiler
3  * Copyright (c) 2018 The Souffle Developers. All rights reserved
4  * Licensed under the Universal Permissive License v 1.0 as shown at:
5  * - https://opensource.org/licenses/UPL
6  * - <souffle root>/licenses/SOUFFLE-UPL.txt
7  */
8 
9 /************************************************************************
10  *
11  * @file ProvenanceClauseTranslator.cpp
12  *
13  * Clause translator when provenance is used
14  *
15  ***********************************************************************/
16 
18 #include "ast/Atom.h"
19 #include "ast/BinaryConstraint.h"
20 #include "ast/Clause.h"
21 #include "ast/ProvenanceNegation.h"
23 #include "ast2ram/ValueIndex.h"
24 #include "ram/Condition.h"
25 #include "ram/Relation.h"
26 #include "ram/SignedConstant.h"
27 #include "ram/SubroutineReturn.h"
28 
29 namespace souffle::ast2ram {
30 
31 Own<ram::Condition> ProvenanceClauseTranslator::createCondition(const ast::Clause& /* originalClause */) {
32  return nullptr;
33 }
34 
35 Own<ram::Operation> ProvenanceClauseTranslator::createOperation(const ast::Clause& clause) {
36  VecOwn<ram::Expression> values;
37 
38  // get all values in the body
39  for (ast::Literal* lit : clause.getBodyLiterals()) {
40  if (auto atom = dynamic_cast<ast::Atom*>(lit)) {
41  for (ast::Argument* arg : atom->getArguments()) {
42  values.push_back(translator.translateValue(arg, *valueIndex));
43  }
44  } else if (auto neg = dynamic_cast<ast::ProvenanceNegation*>(lit)) {
45  size_t auxiliaryArity = translator.getEvaluationArity(neg->getAtom());
46  for (size_t i = 0; i < neg->getAtom()->getArguments().size() - auxiliaryArity; ++i) {
47  auto arg = neg->getAtom()->getArguments()[i];
48  values.push_back(translator.translateValue(arg, *valueIndex));
49  }
50  for (size_t i = 0; i < auxiliaryArity; ++i) {
51  values.push_back(mk<ram::SignedConstant>(-1));
52  }
53  } else if (auto neg = dynamic_cast<ast::Negation*>(lit)) {
54  for (ast::Argument* arg : neg->getAtom()->getArguments()) {
55  values.push_back(translator.translateValue(arg, *valueIndex));
56  }
57  } else if (auto con = dynamic_cast<ast::BinaryConstraint*>(lit)) {
58  values.push_back(translator.translateValue(con->getLHS(), *valueIndex));
59  values.push_back(translator.translateValue(con->getRHS(), *valueIndex));
60  }
61  }
62 
63  return mk<ram::SubroutineReturn>(std::move(values));
64 }
65 
66 } // namespace souffle::ast2ram
TCB_SPAN_NAMESPACE_NAME::detail::size
constexpr auto size(const C &c) -> decltype(c.size())
Definition: span.h:198
ProvenanceNegation.h
AstToRamTranslator.h
souffle::ast2ram::ClauseTranslator::translator
AstToRamTranslator & translator
Definition: ClauseTranslator.h:49
souffle::ast2ram::ProvenanceClauseTranslator::createCondition
Own< ram::Condition > createCondition(const ast::Clause &originalClause) override
Definition: ProvenanceClauseTranslator.cpp:37
souffle::ast::Atom
An atom class.
Definition: Atom.h:51
ProvenanceClauseTranslator.h
souffle::ast::Argument
An abstract class for arguments.
Definition: Argument.h:33
souffle::ast2ram::AstToRamTranslator::getEvaluationArity
size_t getEvaluationArity(const ast::Atom *atom) const
determine the auxiliary for relations
Definition: AstToRamTranslator.cpp:154
souffle::ast2ram::ProvenanceClauseTranslator::createOperation
Own< ram::Operation > createOperation(const ast::Clause &clause) override
Definition: ProvenanceClauseTranslator.cpp:41
i
size_t i
Definition: json11.h:663
souffle::ast::ProvenanceNegation
Subclass of Literal that represents a negated atom, * e.g., !parent(x,y).
Definition: ProvenanceNegation.h:40
Relation.h
Atom.h
Condition.h
souffle::ast::Literal
Defines an abstract class for literals in a horn clause.
Definition: Literal.h:36
ValueIndex.h
souffle::ast2ram::AstToRamTranslator::translateValue
Own< ram::Expression > translateValue(const ast::Argument *arg, const ValueIndex &index)
translate an AST argument to a RAM value
Definition: AstToRamTranslator.cpp:236
souffle::ast2ram
Definition: AstToRamTranslator.cpp:132
SignedConstant.h
Clause.h
souffle::ast2ram::ClauseTranslator::valueIndex
Own< ValueIndex > valueIndex
Definition: ClauseTranslator.h:52
SubroutineReturn.h
BinaryConstraint.h