souffle  2.0.2-371-g6315b36
Public Member Functions | Protected Member Functions | Protected Attributes | Friends
souffle::ast::Program Class Reference

The program class consists of relations, clauses and types. More...

#include <Program.h>

Inheritance diagram for souffle::ast::Program:
Inheritance graph
Collaboration diagram for souffle::ast::Program:
Collaboration graph

Public Member Functions

void addClause (Own< Clause > clause)
 Add a clause. More...
 
void addDirective (Own< Directive > directive)
 Add relation directive. More...
 
void addRelation (Own< Relation > relation)
 
void addType (Own< Type > type)
 Add a type declaration. More...
 
void apply (const NodeMapper &map) override
 Apply the mapper to all child nodes. More...
 
void clearComponents ()
 Remove components and components' instantiations. More...
 
Programclone () const override
 Create a clone (i.e. More...
 
std::vector< const Node * > getChildNodes () const override
 Obtain a list of all embedded AST child nodes. More...
 
std::vector< Clause * > getClauses () const
 Return clauses. More...
 
std::vector< ComponentInit * > getComponentInstantiations () const
 Return component instantiation. More...
 
std::vector< Component * > getComponents () const
 Return components. More...
 
std::vector< Directive * > getDirectives () const
 Return relation directives. More...
 
std::vector< FunctorDeclaration * > getFunctorDeclarations () const
 Return functor declarations. More...
 
const VecOwn< Pragma > & getPragmaDirectives () const
 Return pragma directives. More...
 
std::vector< Relation * > getRelations () const
 Return relations. More...
 
std::vector< Type * > getTypes () const
 Return types. More...
 
bool removeClause (const Clause *clause)
 Remove a clause. More...
 
bool removeDirective (const Directive *directive)
 Remove a directive. More...
 
bool removeRelationDecl (const QualifiedName &name)
 Remove relation. More...
 
void setClauses (VecOwn< Clause > newClauses)
 Set clauses. More...
 
- Public Member Functions inherited from souffle::ast::Node
std::string extloc () const
 Return source location of the syntactic element. More...
 
const SrcLocationgetSrcLoc () const
 Return source location of the Node. More...
 
 Node (SrcLocation loc={})
 
bool operator!= (const Node &other) const
 Inequality check for two AST nodes. More...
 
bool operator== (const Node &other) const
 Equivalence check for two AST nodes. More...
 
void setSrcLoc (SrcLocation l)
 Set source location for the Node. More...
 
virtual ~Node ()=default
 

Protected Member Functions

void addComponent (Own< Component > component)
 Add component. More...
 
void addFunctorDeclaration (Own< FunctorDeclaration > functor)
 
void addInstantiation (Own< ComponentInit > instantiation)
 Add component instantiation. More...
 
void addPragma (Own< Pragma > pragma)
 
bool equal (const Node &node) const override
 Abstract equality check for two AST nodes. More...
 
void print (std::ostream &os) const override
 Output to a given output stream. More...
 

Protected Attributes

VecOwn< Clauseclauses
 Program clauses. More...
 
VecOwn< Componentcomponents
 Component definitions. More...
 
VecOwn< Directivedirectives
 Directives. More...
 
VecOwn< FunctorDeclarationfunctors
 External Functors. More...
 
VecOwn< ComponentInitinstantiations
 Component instantiations. More...
 
VecOwn< Pragmapragmas
 Pragmas. More...
 
VecOwn< Relationrelations
 Program relations. More...
 
VecOwn< Typetypes
 Program types
More...
 

Friends

class souffle::ParserDriver
 

Detailed Description

The program class consists of relations, clauses and types.

Definition at line 52 of file Program.h.

Member Function Documentation

◆ addClause()

void souffle::ast::Program::addClause ( Own< Clause clause)

Add a clause.

Definition at line 62 of file Program.cpp.

62  {
63  clauses.erase(it);
64  return true;
65  }
66  }

References clauses.

Referenced by souffle::ParserDriver::addClause().

◆ addComponent()

void souffle::ast::Program::addComponent ( Own< Component component)
inlineprotected

Add component.

Definition at line 248 of file Program.h.

248  {
249  assert(component && "NULL component");
250  components.push_back(std::move(component));
251  }

References components.

Referenced by souffle::ParserDriver::addComponent().

◆ addDirective()

void souffle::ast::Program::addDirective ( Own< Directive directive)
inline

Add relation directive.

Definition at line 80 of file Program.h.

80  {
81  assert(directive && "NULL directive");
82  directives.push_back(std::move(directive));
83  }

References directives.

Referenced by souffle::ParserDriver::addDirective().

◆ addFunctorDeclaration()

void souffle::ast::Program::addFunctorDeclaration ( Own< FunctorDeclaration functor)
protected

Definition at line 100 of file Program.cpp.

Referenced by souffle::ParserDriver::addFunctorDeclaration().

◆ addInstantiation()

void souffle::ast::Program::addInstantiation ( Own< ComponentInit instantiation)
inlineprotected

Add component instantiation.

Definition at line 254 of file Program.h.

254  {
255  assert(instantiation && "NULL instantiation");
256  instantiations.push_back(std::move(instantiation));
257  }

References instantiations.

Referenced by souffle::ParserDriver::addInstantiation().

◆ addPragma()

void souffle::ast::Program::addPragma ( Own< Pragma pragma)
protected

Definition at line 95 of file Program.cpp.

Referenced by souffle::ParserDriver::addPragma().

◆ addRelation()

void souffle::ast::Program::addRelation ( Own< Relation relation)

Definition at line 43 of file Program.cpp.

43  {
44  for (auto it = relations.begin(); it != relations.end(); it++) {
45  const auto& rel = *it;
46  if (rel->getQualifiedName() == name) {
47  relations.erase(it);
48  return true;
49  }

References rel(), and relations.

Referenced by souffle::ParserDriver::addRelation().

Here is the call graph for this function:

◆ addType()

void souffle::ast::Program::addType ( Own< Type type)

Add a type declaration.

Definition at line 88 of file Program.cpp.

92  {
93  auto* existingFunctorDecl = getIf(getFunctorDeclarations(),

Referenced by souffle::ParserDriver::addType().

◆ apply()

void souffle::ast::Program::apply ( const NodeMapper )
inlineoverridevirtual

Apply the mapper to all child nodes.

Reimplemented from souffle::ast::Node.

Definition at line 139 of file Program.h.

139  {
140  for (auto& cur : pragmas) {
141  cur = map(std::move(cur));
142  }
143  for (auto& cur : components) {
144  cur = map(std::move(cur));
145  }
146  for (auto& cur : instantiations) {
147  cur = map(std::move(cur));
148  }
149  for (auto& cur : functors) {
150  cur = map(std::move(cur));
151  }
152  for (auto& cur : types) {
153  cur = map(std::move(cur));
154  }
155  for (auto& cur : relations) {
156  cur = map(std::move(cur));
157  }
158  for (auto& cur : clauses) {
159  cur = map(std::move(cur));
160  }
161  for (auto& cur : directives) {
162  cur = map(std::move(cur));
163  }
164  }

References clauses, components, directives, functors, instantiations, souffle::map(), pragmas, relations, and types.

Here is the call graph for this function:

◆ clearComponents()

void souffle::ast::Program::clearComponents ( )

Remove components and components' instantiations.

Definition at line 107 of file Program.cpp.

◆ clone()

Program* souffle::ast::Program::clone ( ) const
inlineoverridevirtual

Create a clone (i.e.

deep copy) of this node

Implements souffle::ast::Node.

Definition at line 126 of file Program.h.

126  {
127  auto res = new Program();
128  res->pragmas = souffle::clone(pragmas);
129  res->components = souffle::clone(components);
130  res->instantiations = souffle::clone(instantiations);
131  res->types = souffle::clone(types);
132  res->functors = souffle::clone(functors);
133  res->relations = souffle::clone(relations);
134  res->clauses = souffle::clone(clauses);
135  res->directives = souffle::clone(directives);
136  return res;
137  }

References clauses, souffle::clone(), components, directives, functors, instantiations, pragmas, relations, and types.

Here is the call graph for this function:

◆ equal()

bool souffle::ast::Program::equal ( const Node ) const
inlineoverrideprotectedvirtual

Abstract equality check for two AST nodes.

Reimplemented from souffle::ast::Node.

Definition at line 211 of file Program.h.

211  {
212  const auto& other = static_cast<const Program&>(node);
213  if (!equal_targets(pragmas, other.pragmas)) {
214  return false;
215  }
216  if (!equal_targets(components, other.components)) {
217  return false;
218  }
219  if (!equal_targets(instantiations, other.instantiations)) {
220  return false;
221  }
222  if (!equal_targets(functors, other.functors)) {
223  return false;
224  }
225  if (!equal_targets(types, other.types)) {
226  return false;
227  }
228  if (!equal_targets(relations, other.relations)) {
229  return false;
230  }
231  if (!equal_targets(clauses, other.clauses)) {
232  return false;
233  }
234  if (!equal_targets(directives, other.directives)) {
235  return false;
236  }
237  return true;
238  }

References clauses, components, directives, souffle::equal_targets(), functors, instantiations, pragmas, relations, and types.

Here is the call graph for this function:

◆ getChildNodes()

std::vector<const Node*> souffle::ast::Program::getChildNodes ( ) const
inlineoverridevirtual

Obtain a list of all embedded AST child nodes.

Reimplemented from souffle::ast::Node.

Definition at line 166 of file Program.h.

166  {
167  std::vector<const Node*> res;
168  for (const auto& cur : pragmas) {
169  res.push_back(cur.get());
170  }
171  for (const auto& cur : components) {
172  res.push_back(cur.get());
173  }
174  for (const auto& cur : instantiations) {
175  res.push_back(cur.get());
176  }
177  for (const auto& cur : functors) {
178  res.push_back(cur.get());
179  }
180  for (const auto& cur : types) {
181  res.push_back(cur.get());
182  }
183  for (const auto& cur : relations) {
184  res.push_back(cur.get());
185  }
186  for (const auto& cur : clauses) {
187  res.push_back(cur.get());
188  }
189  for (const auto& cur : directives) {
190  res.push_back(cur.get());
191  }
192  return res;
193  }

References clauses, components, directives, functors, instantiations, pragmas, relations, and types.

◆ getClauses()

std::vector<Clause*> souffle::ast::Program::getClauses ( ) const
inline

Return clauses.

Definition at line 65 of file Program.h.

65  {
66  return toPtrVector(clauses);
67  }

References clauses, and souffle::toPtrVector().

Referenced by souffle::ast::getRecords().

Here is the call graph for this function:

◆ getComponentInstantiations()

std::vector<ComponentInit*> souffle::ast::Program::getComponentInstantiations ( ) const
inline

Return component instantiation.

Definition at line 119 of file Program.h.

119  {
120  return toPtrVector(instantiations);
121  }

References instantiations, and souffle::toPtrVector().

Here is the call graph for this function:

◆ getComponents()

std::vector<Component*> souffle::ast::Program::getComponents ( ) const
inline

Return components.

Definition at line 114 of file Program.h.

114  {
115  return toPtrVector(components);
116  }

References components, and souffle::toPtrVector().

Here is the call graph for this function:

◆ getDirectives()

std::vector<Directive*> souffle::ast::Program::getDirectives ( ) const
inline

Return relation directives.

Definition at line 75 of file Program.h.

75  {
76  return toPtrVector(directives);
77  }

References directives, and souffle::toPtrVector().

Referenced by souffle::ParserDriver::addDirective(), and souffle::ast::transform::IODefaultsTransformer::transform().

Here is the call graph for this function:

◆ getFunctorDeclarations()

std::vector<FunctorDeclaration*> souffle::ast::Program::getFunctorDeclarations ( ) const
inline

Return functor declarations.

Definition at line 70 of file Program.h.

70  {
71  return toPtrVector(functors);
72  }

References functors, and souffle::toPtrVector().

Referenced by souffle::ParserDriver::addFunctorDeclaration().

Here is the call graph for this function:

◆ getPragmaDirectives()

const VecOwn<Pragma>& souffle::ast::Program::getPragmaDirectives ( ) const
inline

Return pragma directives.

Definition at line 86 of file Program.h.

86  {
87  return pragmas;
88  }

References pragmas.

◆ getRelations()

std::vector<Relation*> souffle::ast::Program::getRelations ( ) const
inline

Return relations.

Definition at line 60 of file Program.h.

60  {
61  return toPtrVector(relations);
62  }

References relations, and souffle::toPtrVector().

Referenced by souffle::ast::transform::SemanticCheckerImpl::SemanticCheckerImpl(), and souffle::ast::transform::test::TEST().

Here is the call graph for this function:

◆ getTypes()

std::vector<Type*> souffle::ast::Program::getTypes ( ) const
inline

Return types.

Definition at line 55 of file Program.h.

55  {
56  return toPtrVector(types);
57  }

References souffle::toPtrVector(), and types.

Referenced by souffle::ParserDriver::addType().

Here is the call graph for this function:

◆ print()

void souffle::ast::Program::print ( std::ostream &  os) const
inlineoverrideprotectedvirtual

Output to a given output stream.

Implements souffle::ast::Node.

Definition at line 196 of file Program.h.

196  {
197  auto show = [&](auto&& xs, char const* sep = "\n") {
198  if (!xs.empty()) os << join(xs, sep) << "\n";
199  };
200 
201  show(pragmas, "\n\n");
202  show(components);
203  show(instantiations);
204  show(types);
205  show(functors);
206  show(relations);
207  show(clauses, "\n\n");
208  show(directives, "\n\n");
209  }

References clauses, components, directives, functors, instantiations, souffle::join(), pragmas, relations, and types.

Here is the call graph for this function:

◆ removeClause()

bool souffle::ast::Program::removeClause ( const Clause clause)

Remove a clause.

Definition at line 68 of file Program.cpp.

70  {
71  for (auto it = directives.begin(); it != directives.end(); it++) {
72  if (**it == *directive) {
73  directives.erase(it);
74  return true;
75  }
76  }

◆ removeDirective()

bool souffle::ast::Program::removeDirective ( const Directive directive)

Remove a directive.

Definition at line 78 of file Program.cpp.

80  {
81  auto* existingType = getIf(getTypes(),
82  [&](const Type* current) { return current->getQualifiedName() == type->getQualifiedName(); });
83  assert(existingType == nullptr && "Redefinition of type!");
84  types.push_back(std::move(type));
85 }
86 

◆ removeRelationDecl()

bool souffle::ast::Program::removeRelationDecl ( const QualifiedName name)

Remove relation.

Definition at line 51 of file Program.cpp.

54  {
55  assert(clause != nullptr && "Undefined clause");
56  assert(clause->getHead() != nullptr && "Undefined head of the clause");
57  clauses.push_back(std::move(clause));
58 }
59 
60 bool Program::removeClause(const Clause* clause) {

◆ setClauses()

void souffle::ast::Program::setClauses ( VecOwn< Clause newClauses)
inline

Set clauses.

Definition at line 97 of file Program.h.

97  {
98  clauses = std::move(newClauses);
99  }

References clauses.

Friends And Related Function Documentation

◆ souffle::ParserDriver

friend class souffle::ParserDriver
friend

Definition at line 241 of file Program.h.

Field Documentation

◆ clauses

VecOwn<Clause> souffle::ast::Program::clauses
protected

Program clauses.

Definition at line 269 of file Program.h.

Referenced by addClause(), apply(), clone(), equal(), getChildNodes(), getClauses(), print(), and setClauses().

◆ components

VecOwn<Component> souffle::ast::Program::components
protected

Component definitions.

Definition at line 275 of file Program.h.

Referenced by addComponent(), apply(), clone(), equal(), getChildNodes(), getComponents(), and print().

◆ directives

VecOwn<Directive> souffle::ast::Program::directives
protected

Directives.

Definition at line 272 of file Program.h.

Referenced by addDirective(), apply(), clone(), equal(), getChildNodes(), getDirectives(), and print().

◆ functors

VecOwn<FunctorDeclaration> souffle::ast::Program::functors
protected

External Functors.

Definition at line 266 of file Program.h.

Referenced by apply(), clone(), equal(), getChildNodes(), getFunctorDeclarations(), and print().

◆ instantiations

VecOwn<ComponentInit> souffle::ast::Program::instantiations
protected

Component instantiations.

Definition at line 278 of file Program.h.

Referenced by addInstantiation(), apply(), clone(), equal(), getChildNodes(), getComponentInstantiations(), and print().

◆ pragmas

VecOwn<Pragma> souffle::ast::Program::pragmas
protected

Pragmas.

Definition at line 281 of file Program.h.

Referenced by apply(), clone(), equal(), getChildNodes(), getPragmaDirectives(), and print().

◆ relations

VecOwn<Relation> souffle::ast::Program::relations
protected

Program relations.

Definition at line 263 of file Program.h.

Referenced by addRelation(), apply(), clone(), equal(), getChildNodes(), getRelations(), and print().

◆ types

VecOwn<Type> souffle::ast::Program::types
protected

Program types

Definition at line 260 of file Program.h.

Referenced by apply(), clone(), equal(), getChildNodes(), getTypes(), and print().


The documentation for this class was generated from the following files:
souffle::ast::Program::getFunctorDeclarations
std::vector< FunctorDeclaration * > getFunctorDeclarations() const
Return functor declarations.
Definition: Program.h:70
souffle::ast::Program::pragmas
VecOwn< Pragma > pragmas
Pragmas.
Definition: Program.h:281
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
souffle::ast::Program::directives
VecOwn< Directive > directives
Directives.
Definition: Program.h:272
souffle::ast::Program::relations
VecOwn< Relation > relations
Program relations.
Definition: Program.h:263
souffle::ast::Program::clauses
VecOwn< Clause > clauses
Program clauses.
Definition: Program.h:269
souffle::clone
auto clone(const std::vector< A * > &xs)
Definition: ContainerUtil.h:172
souffle::join
detail::joined_sequence< Iter, Printer > join(const Iter &a, const Iter &b, const std::string &sep, const Printer &p)
Creates an object to be forwarded to some output stream for printing sequences of elements interspers...
Definition: StreamUtil.h:175
souffle::equal_targets
bool equal_targets(const Container &a, const Container &b, const Comparator &comp)
A function testing whether two containers are equal with the given Comparator.
Definition: ContainerUtil.h:433
souffle::ast::Program::functors
VecOwn< FunctorDeclaration > functors
External Functors.
Definition: Program.h:266
souffle::ast::Program::getTypes
std::vector< Type * > getTypes() const
Return types.
Definition: Program.h:55
souffle::getIf
C::value_type getIf(const C &container, std::function< bool(const typename C::value_type)> pred)
Returns the first element in a container that satisfies a given predicate, nullptr otherwise.
Definition: ContainerUtil.h:101
souffle::ast::Program::components
VecOwn< Component > components
Component definitions.
Definition: Program.h:275
souffle::ast::Program::types
VecOwn< Type > types
Program types
Definition: Program.h:260
rel
void rel(size_t limit, bool showLimit=true)
Definition: Tui.h:1086
souffle::ast::Program::removeClause
bool removeClause(const Clause *clause)
Remove a clause.
Definition: Program.cpp:68
souffle::toPtrVector
std::vector< T * > toPtrVector(const std::vector< std::unique_ptr< T >> &v)
A utility function enabling the creation of a vector of pointers.
Definition: ContainerUtil.h:146
std::type
ElementType type
Definition: span.h:640
souffle::ast::Program::instantiations
VecOwn< ComponentInit > instantiations
Component instantiations.
Definition: Program.h:278