souffle  2.0.2-371-g6315b36
RelationDetailCache.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 RelationDetailCache.h
12  *
13  * Defines the class 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 
19 #pragma once
20 
21 #include "ast/QualifiedName.h"
22 #include "ast/Relation.h"
23 #include "ast/analysis/Analysis.h"
24 #include <cassert>
25 #include <map>
26 #include <set>
27 #include <string>
28 
29 namespace souffle::ast {
30 
31 class Clause;
32 class TranslationUnit;
33 
34 namespace analysis {
35 
36 /**
37  * Analysis pass mapping identifiers with relations and clauses.
38  */
39 class RelationDetailCacheAnalysis : public Analysis {
40 public:
41  static constexpr const char* name = "relation-detail";
42 
44 
45  void run(const TranslationUnit& translationUnit) override;
46 
47  void print(std::ostream& os) const override;
48 
50  if (nameToRelation.find(name) != nameToRelation.end()) {
51  return nameToRelation.at(name);
52  }
53  return nullptr;
54  }
55 
56  std::set<Clause*> getClauses(const Relation* rel) const {
57  assert(rel != nullptr && "invalid relation");
58  return getClauses(rel->getQualifiedName());
59  }
60 
61  std::set<Clause*> getClauses(const QualifiedName& name) const {
62  if (nameToClauses.find(name) != nameToClauses.end()) {
63  return nameToClauses.at(name);
64  }
65  return std::set<Clause*>();
66  }
67 
68 private:
69  std::map<QualifiedName, Relation*> nameToRelation;
70  std::map<QualifiedName, std::set<Clause*>> nameToClauses;
71 };
72 
73 } // namespace analysis
74 } // namespace souffle::ast
souffle::ast::analysis::Analysis::Analysis
Analysis(std::string identifier)
Definition: Analysis.h:40
souffle::ast::analysis::RelationDetailCacheAnalysis::RelationDetailCacheAnalysis
RelationDetailCacheAnalysis()
Definition: RelationDetailCache.h:51
souffle::ast::Relation
Defines a relation with a name, attributes, qualifiers, and internal representation.
Definition: Relation.h:49
souffle::ast::analysis::RelationDetailCacheAnalysis::nameToClauses
std::map< QualifiedName, std::set< Clause * > > nameToClauses
Definition: RelationDetailCache.h:78
Relation.h
souffle::ast::analysis::RelationDetailCacheAnalysis::nameToRelation
std::map< QualifiedName, Relation * > nameToRelation
Definition: RelationDetailCache.h:77
souffle::ast::analysis::RelationDetailCacheAnalysis::run
void run(const TranslationUnit &translationUnit) override
run analysis for a Ast translation unit
Definition: RelationDetailCache.cpp:41
souffle::ast::analysis::RelationDetailCacheAnalysis::getRelation
Relation * getRelation(const QualifiedName &name) const
Definition: RelationDetailCache.h:57
QualifiedName.h
souffle::ast::analysis::RelationDetailCacheAnalysis::getClauses
std::set< Clause * > getClauses(const Relation *rel) const
Definition: RelationDetailCache.h:64
souffle::ast::analysis::RelationDetailCacheAnalysis::name
static constexpr const char * name
Definition: RelationDetailCache.h:49
souffle::ast::analysis::RelationDetailCacheAnalysis::print
void print(std::ostream &os) const override
print the analysis result in HTML format
Definition: RelationDetailCache.cpp:56
souffle::ast
Definition: Aggregator.h:35
souffle::ast::QualifiedName
Qualified Name class defines fully/partially qualified names to identify objects in components.
Definition: QualifiedName.h:39
rel
void rel(size_t limit, bool showLimit=true)
Definition: Tui.h:1086
Analysis.h