souffle  2.0.2-371-g6315b36
Negation.h
Go to the documentation of this file.
1 /*
2  * Souffle - A Datalog Compiler
3  * Copyright (c) 2013, Oracle and/or its affiliates. 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 Negation.h
12  *
13  * Define the negated atom class
14  *
15  ***********************************************************************/
16 
17 #pragma once
18 
19 #include "ast/Atom.h"
20 #include "ast/Literal.h"
21 #include "ast/Node.h"
22 #include "ast/utility/NodeMapper.h"
23 #include "parser/SrcLocation.h"
26 #include <cassert>
27 #include <iostream>
28 #include <memory>
29 #include <string>
30 #include <utility>
31 #include <vector>
32 
33 namespace souffle::ast {
34 
35 /**
36  * @class Negation
37  * @brief Negation of an atom negated atom
38  *
39  * Example:
40  * !parent(x,y).
41  *
42  * A negated atom can only occur in the body of a clause.
43  */
44 class Negation : public Literal {
45 public:
46  Negation(Own<Atom> atom, SrcLocation loc = {}) : Literal(std::move(loc)), atom(std::move(atom)) {}
47 
48  /** Get negated atom */
49  Atom* getAtom() const {
50  return atom.get();
51  }
52 
53  Negation* clone() const override {
54  return new Negation(souffle::clone(atom), getSrcLoc());
55  }
56 
57  void apply(const NodeMapper& map) override {
58  atom = map(std::move(atom));
59  }
60 
61  std::vector<const Node*> getChildNodes() const override {
62  return {atom.get()};
63  }
64 
65 protected:
66  void print(std::ostream& os) const override {
67  os << "!" << *atom;
68  }
69 
70  bool equal(const Node& node) const override {
71  assert(isA<Negation>(&node));
72  const auto& other = static_cast<const Negation&>(node);
73  return equal_ptr(atom, other.atom);
74  }
75 
76  /** Negated atom */
78 };
79 
80 } // namespace souffle::ast
souffle::ast::Negation::getChildNodes
std::vector< const Node * > getChildNodes() const override
Obtain a list of all embedded AST child nodes.
Definition: Negation.h:67
SrcLocation.h
souffle::ast::NodeMapper
An abstract class for manipulating AST Nodes by substitution.
Definition: NodeMapper.h:36
souffle::Own
std::unique_ptr< A > Own
Definition: ContainerUtil.h:42
souffle::map
auto map(const std::vector< A > &xs, F &&f)
Applies a function to each element of a vector and returns the results.
Definition: ContainerUtil.h:158
MiscUtil.h
souffle::ast::Negation::print
void print(std::ostream &os) const override
Output to a given output stream.
Definition: Negation.h:72
souffle::ast::Negation::apply
void apply(const NodeMapper &map) override
Apply the mapper to all child nodes.
Definition: Negation.h:63
NodeMapper.h
souffle::ast::Negation::atom
Own< Atom > atom
Negated atom.
Definition: Negation.h:83
souffle::clone
auto clone(const std::vector< A * > &xs)
Definition: ContainerUtil.h:172
ContainerUtil.h
souffle::ast::Negation
Negation of an atom negated atom.
Definition: Negation.h:50
Atom.h
Literal.h
souffle::equal_ptr
bool equal_ptr(const T *a, const T *b)
Compares two values referenced by a pointer where the case where both pointers are null is also consi...
Definition: MiscUtil.h:130
souffle::ast::Negation::clone
Negation * clone() const override
Create a clone (i.e.
Definition: Negation.h:59
Node.h
souffle::ast::Node
Abstract class for syntactic elements in an input program.
Definition: Node.h:40
souffle::ast::Negation::Negation
Negation(Own< Atom > atom, SrcLocation loc={})
Definition: Negation.h:52
souffle::ast::Negation::getAtom
Atom * getAtom() const
Get negated atom.
Definition: Negation.h:55
souffle::ast::Node::getSrcLoc
const SrcLocation & getSrcLoc() const
Return source location of the Node.
Definition: Node.h:46
souffle::ast
Definition: Aggregator.h:35
souffle::ast::Negation::equal
bool equal(const Node &node) const override
Abstract equality check for two AST nodes.
Definition: Negation.h:76