souffle
2.0.2-371-g6315b36
ast
analysis
SumTypeBranches.h
Go to the documentation of this file.
1
/*
2
* Souffle - A Datalog Compiler
3
* Copyright (c) 2020, 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 SumTypeBranches.h
12
*
13
* A wrapper/cache for calculating a mapping between branches and types that declare them.
14
*
15
***********************************************************************/
16
17
#pragma once
18
#include "
ast/analysis/Analysis.h
"
19
#include "
ast/analysis/TypeSystem.h
"
20
#include "
souffle/utility/ContainerUtil.h
"
21
#include <map>
22
#include <string>
23
24
namespace
souffle::ast
{
25
26
namespace
analysis {
27
28
class
SumTypeBranchesAnalysis :
public
Analysis {
29
public
:
30
static
constexpr
const
char
*
name
=
"sum-type-branches"
;
31
32
SumTypeBranchesAnalysis
() :
Analysis
(
name
) {}
33
34
void
run
(
const
TranslationUnit& translationUnit)
override
;
35
36
/**
37
* A type can be nullptr in case of a malformed program.
38
*/
39
const
Type*
getType
(
const
std::string& branch)
const
{
40
if
(
contains
(
branchToType
, branch)) {
41
return
branchToType
.at(branch);
42
}
else
{
43
return
nullptr
;
44
}
45
}
46
47
const
AlgebraicDataType&
unsafeGetType
(
const
std::string& branch)
const
{
48
return
*as<AlgebraicDataType>(
branchToType
.at(branch));
49
}
50
51
private
:
52
std::map<std::string, const Type*>
branchToType
;
53
};
54
55
}
// namespace analysis
56
}
// namespace souffle::ast
souffle::ast::analysis::SumTypeBranchesAnalysis::name
static constexpr const char * name
Definition:
SumTypeBranches.h:48
souffle::ast::analysis::SumTypeBranchesAnalysis::SumTypeBranchesAnalysis
SumTypeBranchesAnalysis()
Definition:
SumTypeBranches.h:50
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::SumTypeBranchesAnalysis::branchToType
std::map< std::string, const Type * > branchToType
Definition:
SumTypeBranches.h:70
ContainerUtil.h
souffle::ast::analysis::SumTypeBranchesAnalysis::run
void run(const TranslationUnit &translationUnit) override
run analysis for a Ast translation unit
Definition:
SumTypeBranches.cpp:36
souffle::ast
Definition:
Aggregator.h:35
souffle::ast::analysis::SumTypeBranchesAnalysis::getType
const Type * getType(const std::string &branch) const
A type can be nullptr in case of a malformed program.
Definition:
SumTypeBranches.h:57
Analysis.h
souffle::ast::analysis::SumTypeBranchesAnalysis::unsafeGetType
const AlgebraicDataType & unsafeGetType(const std::string &branch) const
Definition:
SumTypeBranches.h:65
TypeSystem.h
Generated by
1.8.17