retdec
context.h
Go to the documentation of this file.
1 
7 #ifndef RETDEC_CTYPES_CONTEXT_H
8 #define RETDEC_CTYPES_CONTEXT_H
9 
10 #include <map>
11 #include <memory>
12 #include <string>
13 #include <unordered_map>
14 #include <utility>
15 
18 
19 namespace retdec {
20 namespace ctypes {
21 
22 class Annotation;
23 class Function;
24 class PointerType;
25 class ReferenceType;
26 class Type;
27 
31 class Context
32 {
33  public:
36  bool hasFunctionWithName(const std::string &name) const;
37  std::shared_ptr<Function> getFunctionWithName(const std::string &name) const;
38  void addFunction(const std::shared_ptr<Function> &function);
40 
43  bool hasFunctionType(const std::shared_ptr<Type> &returnType,
44  const FunctionType::Parameters &parameters,
45  const CallConvention &callConvention,
46  FunctionType::VarArgness varArgness) const;
47  std::shared_ptr<FunctionType> getFunctionType(const std::shared_ptr<Type> &returnType,
48  const FunctionType::Parameters &parameters,
49  const CallConvention &callConvention,
50  FunctionType::VarArgness varArgness) const;
51  void addFunctionType(const std::shared_ptr<FunctionType> &functionType);
53 
56  bool hasNamedType(const std::string &name) const;
57  std::shared_ptr<Type> getNamedType(const std::string &name)const;
58  void addNamedType(const std::shared_ptr<Type> &type);
60 
63  bool hasPointerType(const std::shared_ptr<Type> &pointedType) const;
64  std::shared_ptr<PointerType> getPointerType(
65  const std::shared_ptr<Type> &pointedType)const;
66  void addPointerType(const std::shared_ptr<PointerType> &pointerType);
68 
71  bool hasReferenceType(const std::shared_ptr<Type> &referencedType) const;
72  std::shared_ptr<ReferenceType> getReferenceType(
73  const std::shared_ptr<Type> &referencedType) const;
74  void addReferenceType(const std::shared_ptr<ReferenceType> &referenceType);
76 
79  bool hasArrayType(const std::shared_ptr<Type> &elementType,
80  const ArrayType::Dimensions &dimensions) const;
81  std::shared_ptr<ArrayType> getArrayType(const std::shared_ptr<Type> &elementType,
82  const ArrayType::Dimensions &dimensions) const;
83  void addArrayType(const std::shared_ptr<ArrayType> &arrayType);
85 
88  bool hasAnnotation(const std::string &name) const;
89  std::shared_ptr<Annotation> getAnnotation(const std::string &name)const;
90  void addAnnotation(const std::shared_ptr<Annotation> &annot);
92 
93  private:
94  using Functions = std::unordered_map<std::string, std::shared_ptr<Function>>;
97 
98  using FunctionTypes = std::map<
99  std::tuple<std::shared_ptr<Type>, FunctionType::Parameters, std::string, bool>,
100  std::shared_ptr<FunctionType>
101  >;
104 
105  using NamedTypes = std::unordered_map<std::string, std::shared_ptr<Type>>;
108 
109  using PointerTypes = std::unordered_map<std::shared_ptr<Type>,
110  std::shared_ptr<PointerType>>;
113 
114  using ReferenceTypes = std::unordered_map<std::shared_ptr<Type>,
115  std::shared_ptr<ReferenceType>>;
118 
119  using ArrayTypes = std::map<
120  std::pair<std::shared_ptr<Type>, ArrayType::Dimensions>,
121  std::shared_ptr<ArrayType>
122  >;
125 
126  using Annotations = std::unordered_map<std::string, std::shared_ptr<Annotation>>;
129 };
130 
131 } // namespace ctypes
132 } // namespace retdec
133 
134 #endif
std::vector< DimensionType > Dimensions
Definition: array_type.h:27
A representation of a C call convention.
Definition: call_convention.h:19
Container for all C functions and types.
Definition: context.h:32
void addFunction(const std::shared_ptr< Function > &function)
Inserts new function to context.
Definition: context.cpp:48
void addFunctionType(const std::shared_ptr< FunctionType > &functionType)
Inserts new function type to context.
Definition: context.cpp:105
void addReferenceType(const std::shared_ptr< ReferenceType > &referenceType)
Inserts new referenceType with specific name to context.
Definition: context.cpp:232
std::shared_ptr< Annotation > getAnnotation(const std::string &name) const
Returns annotation from context.
Definition: context.cpp:301
std::unordered_map< std::shared_ptr< Type >, std::shared_ptr< ReferenceType > > ReferenceTypes
Definition: context.h:115
std::unordered_map< std::string, std::shared_ptr< Type > > NamedTypes
Definition: context.h:105
std::shared_ptr< Type > getNamedType(const std::string &name) const
Returns type with specific name from context.
Definition: context.cpp:133
void addArrayType(const std::shared_ptr< ArrayType > &arrayType)
Adds array type to context.
Definition: context.cpp:277
std::unordered_map< std::string, std::shared_ptr< Function > > Functions
Definition: context.h:94
std::shared_ptr< ReferenceType > getReferenceType(const std::shared_ptr< Type > &referencedType) const
Returns referenceType from context.
Definition: context.cpp:218
ReferenceTypes referenceTypes
Stored reference types, key is type that they reference.
Definition: context.h:117
bool hasPointerType(const std::shared_ptr< Type > &pointedType) const
Checks if context contains pointer type.
Definition: context.cpp:159
std::map< std::tuple< std::shared_ptr< Type >, FunctionType::Parameters, std::string, bool >, std::shared_ptr< FunctionType > > FunctionTypes
Definition: context.h:101
PointerTypes pointerTypes
Stored pointer types, key is type that they point to.
Definition: context.h:112
std::shared_ptr< Function > getFunctionWithName(const std::string &name) const
Returns function from context.
Definition: context.cpp:35
FunctionTypes functionTypes
Stored function types, key is return type and parameters' types.
Definition: context.h:103
std::shared_ptr< FunctionType > getFunctionType(const std::shared_ptr< Type > &returnType, const FunctionType::Parameters &parameters, const CallConvention &callConvention, FunctionType::VarArgness varArgness) const
Returns function type from context.
Definition: context.cpp:85
std::map< std::pair< std::shared_ptr< Type >, ArrayType::Dimensions >, std::shared_ptr< ArrayType > > ArrayTypes
Definition: context.h:122
std::shared_ptr< ArrayType > getArrayType(const std::shared_ptr< Type > &elementType, const ArrayType::Dimensions &dimensions) const
Returns array type from context.
Definition: context.cpp:263
std::unordered_map< std::shared_ptr< Type >, std::shared_ptr< PointerType > > PointerTypes
Definition: context.h:110
ArrayTypes arrayTypes
Stored array types, key is element type and dimensions.
Definition: context.h:124
bool hasFunctionWithName(const std::string &name) const
Checks if context contains function.
Definition: context.cpp:25
std::shared_ptr< PointerType > getPointerType(const std::shared_ptr< Type > &pointedType) const
Returns pointerType from context.
Definition: context.cpp:174
void addAnnotation(const std::shared_ptr< Annotation > &annot)
Adds annotation to context.
Definition: context.cpp:309
void addNamedType(const std::shared_ptr< Type > &type)
Inserts new type with specific name to context.
Definition: context.cpp:144
bool hasReferenceType(const std::shared_ptr< Type > &referencedType) const
Checks if context contains reference type.
Definition: context.cpp:203
Annotations annotations
Stored annotations.
Definition: context.h:128
Functions functions
Stored functions.
Definition: context.h:96
bool hasAnnotation(const std::string &name) const
Checks if context contains annotation.
Definition: context.cpp:291
void addPointerType(const std::shared_ptr< PointerType > &pointerType)
Inserts new pointerType with specific name to context.
Definition: context.cpp:188
bool hasArrayType(const std::shared_ptr< Type > &elementType, const ArrayType::Dimensions &dimensions) const
Checks if context contains array type.
Definition: context.cpp:247
NamedTypes namedTypes
Stored types that can be identified by name.
Definition: context.h:107
bool hasNamedType(const std::string &name) const
Checks if context contains type with specific name.
Definition: context.cpp:123
bool hasFunctionType(const std::shared_ptr< Type > &returnType, const FunctionType::Parameters &parameters, const CallConvention &callConvention, FunctionType::VarArgness varArgness) const
Checks if context contains function type.
Definition: context.cpp:63
std::unordered_map< std::string, std::shared_ptr< Annotation > > Annotations
Definition: context.h:126
VarArgness
Definition: function_type.h:33
std::vector< std::shared_ptr< Type > > Parameters
Definition: function_type.h:28
A representation of array types.
A representation of a function type.
Definition: archive_wrapper.h:19