souffle  2.0.2-371-g6315b36
RelationDetailCache.cpp
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 RelationDetailCache.cpp
12  *
13  * Implements method of precedence graph to build the precedence graph,
14  * compute strongly connected components of the precedence graph, and
15  * build the strongly connected component graph.
16  *
17  ***********************************************************************/
18 
20 #include "ast/Atom.h"
21 #include "ast/Clause.h"
22 #include "ast/Node.h"
23 #include "ast/Program.h"
24 #include "ast/QualifiedName.h"
25 #include "ast/Relation.h"
26 #include "ast/TranslationUnit.h"
27 #include <set>
28 #include <utility>
29 #include <vector>
30 
31 namespace souffle::ast::analysis {
32 
33 void RelationDetailCacheAnalysis::run(const TranslationUnit& translationUnit) {
34  const auto& program = translationUnit.getProgram();
35  for (auto* rel : program.getRelations()) {
36  nameToRelation[rel->getQualifiedName()] = rel;
37  nameToClauses[rel->getQualifiedName()] = std::set<Clause*>();
38  }
39  for (auto* clause : program.getClauses()) {
40  const auto& relationName = clause->getHead()->getQualifiedName();
41  if (nameToClauses.find(relationName) == nameToClauses.end()) {
42  nameToClauses[relationName] = std::set<Clause*>();
43  }
44  nameToClauses.at(relationName).insert(clause);
45  }
46 }
47 
48 void RelationDetailCacheAnalysis::print(std::ostream& os) const {
49  for (const auto& pair : nameToClauses) {
50  os << "--" << pair.first << "--";
51  os << std::endl;
52  for (const auto* clause : pair.second) {
53  os << *clause << std::endl;
54  }
55  os << std::endl;
56  }
57 }
58 
59 } // namespace souffle::ast::analysis
TranslationUnit.h
RelationDetailCache.h
souffle::ast::analysis::RelationDetailCacheAnalysis::nameToClauses
std::map< QualifiedName, std::set< Clause * > > nameToClauses
Definition: RelationDetailCache.h:78
Relation.h
Atom.h
souffle::ast::analysis::RelationDetailCacheAnalysis::nameToRelation
std::map< QualifiedName, Relation * > nameToRelation
Definition: RelationDetailCache.h:77
Node.h
souffle::ast::analysis::RelationDetailCacheAnalysis::run
void run(const TranslationUnit &translationUnit) override
run analysis for a Ast translation unit
Definition: RelationDetailCache.cpp:41
QualifiedName.h
Program.h
Clause.h
souffle::ast::analysis
Definition: Aggregate.cpp:39
souffle::ast::analysis::RelationDetailCacheAnalysis::print
void print(std::ostream &os) const override
print the analysis result in HTML format
Definition: RelationDetailCache.cpp:56
rel
void rel(size_t limit, bool showLimit=true)
Definition: Tui.h:1086