ROSE 2.23.0
Loading...
Searching...
No Matches
AnalysisTypes.h
1
2
3#ifndef ROSE_Common_Analysis_AnalysisTypes_H
4#define ROSE_Common_Analysis_AnalysisTypes_H 1
5
6#include <RoseFirst.h>
7
8#include <cstdint>
9#include <tuple>
10#include <functional>
11#include <string>
12#include <utility>
13#include <vector>
14
15#include <boost/variant.hpp>
16
17
18namespace Rose::Common::Analysis
19{
20
22enum struct FunctionTypeRelation : int
23{
25 unrelated = 0,
26
28 sametype = 1,
29
31 covariant = 2
32};
33
36template <int /*tag*/>
37struct KeyType
38{
40 using type = std::uintptr_t;
41
43 type key = 0;
44};
45
51template <int tag>
52inline
53bool
54operator==(KeyType<tag> lhs, KeyType<tag> rhs) noexcept
55{
56 return lhs.key == rhs.key;
57}
58
64template <int tag>
65inline
66bool
67operator!=(KeyType<tag> lhs, KeyType<tag> rhs) noexcept
68{
69 return lhs.key != rhs.key;
70}
71
77template <int tag>
78inline
79bool
80operator<(KeyType<tag> lhs, KeyType<tag> rhs) noexcept
81{
82 return lhs.key < rhs.key;
83}
84
90template <int tag>
91inline
92bool
93operator<=(KeyType<tag> lhs, KeyType<tag> rhs) noexcept
94{
95 return lhs.key <= rhs.key;
96}
97
103template <int tag>
104inline
105bool
106operator>(KeyType<tag> lhs, KeyType<tag> rhs) noexcept
107{
108 return lhs.key > rhs.key;
109}
110
116template <int tag>
117inline
118bool
119operator>=(KeyType<tag> lhs, KeyType<tag> rhs) noexcept
120{
121 return lhs.key >= rhs.key;
122}
123
124/*
125template <int tag>
126inline
127std::ostream&
128operator<<(std::ostream& os, KeyType<tag> k) noexcept
129{
130 return os << reinterpret_cast<void*>(k.key);
131}
132*/
133
136{
137
142 template <int tag>
143 bool operator()(KeyType<tag> k) const { return k != KeyType<tag>{}; }
144};
145
146
151template <int tag>
152inline
153bool
154isValidKey(KeyType<tag> k) { return IsValidKey{}(k); }
155
157enum KeyTags { tgNone, tgRoot, tgClass, tgFunc, tgVar, tgFuncType, tgOtherType, tgCast, tgOtherExpr };
158
160using ASTRootType = KeyType<tgRoot>;
161
163using FunctionKeyType = KeyType<tgFunc>;
164
166using ClassKeyType = KeyType<tgClass>;
167
169using VariableKeyType = KeyType<tgVar>;
170
172using FunctionTypeKeyType = KeyType<tgFuncType>;
173
175using TypeKeyType = KeyType<tgOtherType>;
176
178using CastKeyType = KeyType<tgCast>;
179
181using ExpressionKeyType = KeyType<tgOtherExpr>;
182
184using AnyKeyType = boost::variant< ASTRootType, FunctionKeyType, ClassKeyType, VariableKeyType
185 , TypeKeyType, FunctionTypeKeyType
186 , ExpressionKeyType, CastKeyType
187 >;
188
189
191using DataMemberTypeBase = std::tuple<ClassKeyType, bool, bool, bool, bool>;
192
194struct DataMemberType : DataMemberTypeBase
195{
196
198 using base = DataMemberTypeBase;
199
200 using base::base;
201
204 ClassKeyType classType() const { return std::get<0>(*this); }
205
208 bool isConst() const { return std::get<1>(*this); }
209
212 bool hasReference() const { return std::get<2>(*this); }
213
216 bool hasArray() const { return std::get<3>(*this); }
217
220 bool hasInitializer() const { return std::get<4>(*this); }
221};
222
223
224
228using ClassNameFn = std::function<std::string(ClassKeyType)>;
229
233using FuncNameFn = std::function<std::string(FunctionKeyType)>;
234
238using VarNameFn = std::function<std::string(VariableKeyType)>;
239
243using FunctionPredicate = std::function<bool(FunctionKeyType)>;
244
245}
246
247
248namespace std
249{
250
253 template <int tag>
255 {
256
260 std::size_t operator()(const ::Rose::Common::Analysis::KeyType<tag>& k) const noexcept
261 {
262 return std::hash<typename ::Rose::Common::Analysis::KeyType<tag>::type>{}(k.key);
263 }
264 };
265}
266
267
268#endif /*_ANALYSIS_TYPES*/
STL namespace.
Describes the class-valued type and selected qualifiers of a data member.
DataMemberTypeBase base
Base tuple type used for storage.
ClassKeyType classType() const
Returns the class type of this data member, if represented by the frontend.
bool isConst() const
Returns true when the data member type is const-qualified.
bool hasReference() const
Returns true when the data member type contains a reference.
bool hasArray() const
Returns true when the data member type contains an array.
bool hasInitializer() const
Returns true when the data member has an initializer.
Predicate object that tests whether an abstract key is nonzero.
bool operator()(KeyType< tag > k) const
Returns true when k is a nonzero key.
Strongly typed wrapper around an abstract pointer-sized analysis key.
type key
Raw integer key value; zero represents an invalid key.
std::uintptr_t type
Integer storage type used for abstract keys.
std::size_t operator()(const ::Rose::Common::Analysis::KeyType< tag > &k) const noexcept
Returns the hash of the wrapped raw key value.