souffle  2.0.2-371-g6315b36
Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes
souffle::ast::analysis::RecursiveClausesAnalysis Class Reference

Analysis pass identifying clauses which are recursive. More...

#include <RecursiveClauses.h>

Inheritance diagram for souffle::ast::analysis::RecursiveClausesAnalysis:
Inheritance graph
Collaboration diagram for souffle::ast::analysis::RecursiveClausesAnalysis:
Collaboration graph

Public Member Functions

void print (std::ostream &os) const override
 print the analysis result in HTML format More...
 
bool recursive (const Clause *clause) const
 
 RecursiveClausesAnalysis ()
 
void run (const TranslationUnit &translationUnit) override
 run analysis for a Ast translation unit More...
 
- Public Member Functions inherited from souffle::ast::analysis::Analysis
 Analysis (std::string identifier)
 
virtual const std::string & getName () const
 get name of the analysis More...
 
virtual ~Analysis ()=default
 

Static Public Attributes

static constexpr const char * name = "recursive-clauses"
 

Private Member Functions

bool computeIsRecursive (const Clause &clause, const TranslationUnit &translationUnit) const
 Determines whether the given clause is recursive within the given program. More...
 

Private Attributes

std::set< const Clause * > recursiveClauses
 

Additional Inherited Members

- Protected Attributes inherited from souffle::ast::analysis::Analysis
const std::string identifier
 

Detailed Description

Analysis pass identifying clauses which are recursive.

Definition at line 44 of file RecursiveClauses.h.

Constructor & Destructor Documentation

◆ RecursiveClausesAnalysis()

souffle::ast::analysis::RecursiveClausesAnalysis::RecursiveClausesAnalysis ( )
inline

Definition at line 48 of file RecursiveClauses.h.

50 :
51  std::set<const Clause*> recursiveClauses;

Member Function Documentation

◆ computeIsRecursive()

bool souffle::ast::analysis::RecursiveClausesAnalysis::computeIsRecursive ( const Clause clause,
const TranslationUnit translationUnit 
) const
private

Determines whether the given clause is recursive within the given program.

Definition at line 58 of file RecursiveClauses.cpp.

62  : getBodyLiterals<Atom>(clause)) {
63  auto rel = relationDetail.getRelation(cur->getQualifiedName());
64  if (rel == trg) {
65  return true;
66  }
67  worklist.push_back(rel);
68  }
69 
70  // process remaining elements
71  while (!worklist.empty()) {
72  // get next to process
73  const Relation* cur = worklist.back();
74  worklist.pop_back();
75 
76  // skip null pointers (errors in the input code)
77  if (cur == nullptr) {
78  continue;
79  }
80 
81  // check whether this one has been checked before
82  if (!reached.insert(cur).second) {
83  continue;
84  }
85 
86  // check all atoms in the relations
87  for (const Clause* cl : relationDetail.getClauses(cur)) {
88  for (const Atom* at : getBodyLiterals<Atom>(*cl)) {
89  auto rel = relationDetail.getRelation(at->getQualifiedName());
90  if (rel == trg) {
91  return true;
92  }
93  worklist.push_back(rel);
94  }
95  }
96  }
97 
98  // no cycles found
99  return false;
100 }
101 
102 } // namespace souffle::ast::analysis

References rel().

Here is the call graph for this function:

◆ print()

void souffle::ast::analysis::RecursiveClausesAnalysis::print ( std::ostream &  ) const
overridevirtual

print the analysis result in HTML format

Reimplemented from souffle::ast::analysis::Analysis.

Definition at line 54 of file RecursiveClauses.cpp.

◆ recursive()

bool souffle::ast::analysis::RecursiveClausesAnalysis::recursive ( const Clause clause) const
inline

Definition at line 54 of file RecursiveClauses.h.

◆ run()

void souffle::ast::analysis::RecursiveClausesAnalysis::run ( const TranslationUnit )
overridevirtual

run analysis for a Ast translation unit

Implements souffle::ast::analysis::Analysis.

Definition at line 45 of file RecursiveClauses.cpp.

46  {
47  os << recursiveClauses << std::endl;
48 }
49 
51  const Clause& clause, const TranslationUnit& translationUnit) const {
52  const auto& relationDetail = *translationUnit.getAnalysis<RelationDetailCacheAnalysis>();

References recursiveClauses.

Field Documentation

◆ name

constexpr const char* souffle::ast::analysis::RecursiveClausesAnalysis::name = "recursive-clauses"
staticconstexpr

Definition at line 46 of file RecursiveClauses.h.

◆ recursiveClauses

std::set<const Clause*> souffle::ast::analysis::RecursiveClausesAnalysis::recursiveClauses
private

Definition at line 59 of file RecursiveClauses.h.

Referenced by run().


The documentation for this class was generated from the following files:
souffle::ast::analysis::RecursiveClausesAnalysis::computeIsRecursive
bool computeIsRecursive(const Clause &clause, const TranslationUnit &translationUnit) const
Determines whether the given clause is recursive within the given program.
Definition: RecursiveClauses.cpp:58
souffle::ast::analysis::RecursiveClausesAnalysis::recursiveClauses
std::set< const Clause * > recursiveClauses
Definition: RecursiveClauses.h:59
rel
void rel(size_t limit, bool showLimit=true)
Definition: Tui.h:1086