souffle  2.0.2-371-g6315b36
TypeEnvironment.h
Go to the documentation of this file.
1 /*
2  * Souffle - A Datalog Compiler
3  * Copyright (c) 2019, The Souffle Developers. 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 TypeEnvironment.h
12  *
13  * A wrapper for TypeEnvironment to be used for AST Analysis
14  *
15  ***********************************************************************/
16 
17 #pragma once
18 
19 #include "ast/QualifiedName.h"
20 #include "ast/TranslationUnit.h"
21 #include "ast/Type.h"
22 #include "ast/analysis/Analysis.h"
25 #include <iosfwd>
26 #include <map>
27 #include <set>
28 #include <string>
29 
30 namespace souffle::ast::analysis {
31 
32 class TypeEnvironmentAnalysis : public Analysis {
33 public:
34  static constexpr const char* name = "type-environment";
35 
37 
38  void run(const TranslationUnit& translationUnit) override;
39 
40  void print(std::ostream& os) const override;
41 
42  const TypeEnvironment& getTypeEnvironment() const {
43  return env;
44  }
45 
46  const std::set<QualifiedName>& getPrimitiveTypesInUnion(const QualifiedName& identifier) const {
48  }
49 
50  bool isCyclic(const QualifiedName& identifier) const {
52  }
53 
54 private:
56  std::map<QualifiedName, std::set<QualifiedName>> primitiveTypesInUnions;
57  std::set<QualifiedName> cyclicTypes;
58 
59  /**
60  * Recursively create a type in env, that is
61  * first create its base types and then the type itself.
62  */
63  const Type* createType(
64  const QualifiedName& typeName, const std::map<QualifiedName, const ast::Type*>& nameToType);
65 };
66 
67 } // namespace souffle::ast::analysis
souffle::ast::analysis::Analysis::identifier
const std::string identifier
Definition: Analysis.h:61
souffle::ast::analysis::TypeEnvironmentAnalysis::primitiveTypesInUnions
std::map< QualifiedName, std::set< QualifiedName > > primitiveTypesInUnions
Definition: TypeEnvironment.h:68
TranslationUnit.h
souffle::ast::analysis::TypeEnvironmentAnalysis::getPrimitiveTypesInUnion
const std::set< QualifiedName > & getPrimitiveTypesInUnion(const QualifiedName &identifier) const
Definition: TypeEnvironment.h:58
souffle::ast::analysis::Analysis::Analysis
Analysis(std::string identifier)
Definition: Analysis.h:40
souffle::contains
bool contains(const C &container, const typename C::value_type &element)
A utility to check generically whether a given element is contained in a given container.
Definition: ContainerUtil.h:75
souffle::ast::analysis::TypeEnvironmentAnalysis::isCyclic
bool isCyclic(const QualifiedName &identifier) const
Definition: TypeEnvironment.h:62
souffle::ast::analysis::Type
An abstract base class for types to be covered within a type environment.
Definition: TypeSystem.h:51
souffle::ast::analysis::TypeEnvironmentAnalysis::env
TypeEnvironment env
Definition: TypeEnvironment.h:67
ContainerUtil.h
souffle::ast::analysis::TypeEnvironmentAnalysis::run
void run(const TranslationUnit &translationUnit) override
run analysis for a Ast translation unit
Definition: TypeEnvironment.cpp:120
souffle::ast::analysis::TypeEnvironmentAnalysis::createType
const Type * createType(const QualifiedName &typeName, const std::map< QualifiedName, const ast::Type * > &nameToType)
Recursively create a type in env, that is first create its base types and then the type itself.
Definition: TypeEnvironment.cpp:147
souffle::ast::analysis::TypeEnvironment
A type environment is a set of types.
Definition: TypeSystem.h:401
souffle::ast::TranslationUnit
Translation unit class for the translation pipeline.
Definition: TranslationUnit.h:51
souffle::ast::analysis::TypeEnvironmentAnalysis::cyclicTypes
std::set< QualifiedName > cyclicTypes
Definition: TypeEnvironment.h:69
souffle::ast::analysis::TypeEnvironmentAnalysis::name
static constexpr const char * name
Definition: TypeEnvironment.h:46
Type.h
souffle::ast::analysis::TypeEnvironmentAnalysis::getTypeEnvironment
const TypeEnvironment & getTypeEnvironment() const
Definition: TypeEnvironment.h:54
souffle::ast::analysis::TypeEnvironmentAnalysis::TypeEnvironmentAnalysis
TypeEnvironmentAnalysis()
Definition: TypeEnvironment.h:48
QualifiedName.h
souffle::ast::analysis::TypeEnvironmentAnalysis::print
void print(std::ostream &os) const override
print the analysis result in HTML format
Definition: TypeEnvironment.cpp:231
souffle::ast::analysis
Definition: Aggregate.cpp:39
souffle::ast::QualifiedName
Qualified Name class defines fully/partially qualified names to identify objects in components.
Definition: QualifiedName.h:39
Analysis.h
TypeSystem.h