retdec
function.h
Go to the documentation of this file.
1 
7 #ifndef RETDEC_CTYPES_FUNCTION_H
8 #define RETDEC_CTYPES_FUNCTION_H
9 
10 #include <memory>
11 #include <string>
12 #include <vector>
13 
18 
19 namespace retdec {
20 namespace ctypes {
21 
22 class Context;
23 class Parameter;
24 class Type;
25 
29 class Function
30 {
31  public:
32  using Parameters = std::vector<Parameter>;
34  using parameter_iterator = Parameters::iterator;
35  using const_parameter_iterator = Parameters::const_iterator;
36 
37  public:
38  static std::shared_ptr<Function> create(
39  const std::shared_ptr<Context> &context,
40  const std::string &name,
41  const std::shared_ptr<Type> &returnType,
42  const Parameters &parameters,
43  const CallConvention &callConvention = CallConvention(),
45  );
46 
47  const std::string &getName() const;
48  std::shared_ptr<FunctionType> getType() const;
49  std::shared_ptr<Type> getReturnType() const;
50 
57 
58  Parameters::size_type getParameterCount() const;
59  const Parameter &getParameter(Parameters::size_type n) const;
60  const std::string &getParameterName(Parameters::size_type n) const;
61  std::shared_ptr<Type> getParameterType(Parameters::size_type n) const;
62 
63  bool isVarArg() const;
65 
68  void setCallConvention(const CallConvention &callConvention);
69  const CallConvention &getCallConvention() const;
71 
77 
80  void setHeaderFile(const HeaderFile &headerFile);
81  HeaderFile getHeaderFile() const;
83 
84  private:
85  // Instances are created by static method create().
86  Function(
87  const std::string &name,
88  const std::shared_ptr<FunctionType> &functionType,
89  const Parameters &parameters
90  );
91 
92  static std::shared_ptr<FunctionType> createFunctionType(
93  const std::shared_ptr<Context> &context,
94  const std::shared_ptr<Type> &returnType,
95  const Parameters &parameters,
96  const CallConvention &callConvention,
97  VarArgness varArgness
98  );
99 
100  private:
101  std::string name;
102  std::shared_ptr<FunctionType> functionType;
106 };
107 
108 } // namespace ctypes
109 } // namespace retdec
110 
111 #endif
A representation of a C call convention.
A representation of a C call convention.
Definition: call_convention.h:19
A representation of a function declaration.
Definition: function_declaration.h:19
VarArgness
Definition: function_type.h:33
A representation of a C function.
Definition: function.h:30
const std::string & getName() const
Definition: function.cpp:26
HeaderFile getHeaderFile() const
Returns header file of function.
Definition: function.cpp:255
bool isVarArg() const
Returns true if function takes variable number of arguments, false otherwise.
Definition: function.cpp:132
const Parameter & getParameter(Parameters::size_type n) const
Returns the n-th parameter.
Definition: function.cpp:97
void setHeaderFile(const HeaderFile &headerFile)
Sets header file of function.
Definition: function.cpp:247
HeaderFile headerFile
Definition: function.h:105
Parameters::iterator parameter_iterator
Definition: function.h:34
void setDeclaration(const FunctionDeclaration &declaration)
Sets function declaration.
Definition: function.cpp:231
std::shared_ptr< Type > getReturnType() const
Returns function's return type.
Definition: function.cpp:42
FunctionDeclaration getDeclaration() const
Returns function declaration.
Definition: function.cpp:239
static std::shared_ptr< Function > create(const std::shared_ptr< Context > &context, const std::string &name, const std::shared_ptr< Type > &returnType, const Parameters &parameters, const CallConvention &callConvention=CallConvention(), VarArgness varArgness=VarArgness::IsNotVarArg)
Creates function.
Definition: function.cpp:154
FunctionDeclaration declaration
Definition: function.h:104
const std::string & getParameterName(Parameters::size_type n) const
Returns the n-th parameter's name.
Definition: function.cpp:110
Parameters::size_type getParameterCount() const
Returns the number of parameters.
Definition: function.cpp:84
Parameters parameters
Definition: function.h:103
Function(const std::string &name, const std::shared_ptr< FunctionType > &functionType, const Parameters &parameters)
Constructs a new function.
Definition: function.cpp:20
std::vector< Parameter > Parameters
Definition: function.h:32
static std::shared_ptr< FunctionType > createFunctionType(const std::shared_ptr< Context > &context, const std::shared_ptr< Type > &returnType, const Parameters &parameters, const CallConvention &callConvention, VarArgness varArgness)
Creates function type.
Definition: function.cpp:194
parameter_iterator parameter_begin()
Returns an iterator to the parameter.
Definition: function.cpp:50
std::shared_ptr< Type > getParameterType(Parameters::size_type n) const
Returns the n-th parameter's type.
Definition: function.cpp:123
std::string name
Definition: function.h:101
const CallConvention & getCallConvention() const
Returns function's call convention.
Definition: function.cpp:223
Parameters::const_iterator const_parameter_iterator
Definition: function.h:35
std::shared_ptr< FunctionType > getType() const
Returns function's function type - return type and parameters' types.
Definition: function.cpp:34
void setCallConvention(const CallConvention &callConvention)
Sets function's call convention.
Definition: function.cpp:215
parameter_iterator parameter_end()
Returns an iterator past the last parameter.
Definition: function.cpp:66
std::shared_ptr< FunctionType > functionType
Definition: function.h:102
A representation of C header file.
Definition: header_file.h:19
A representation of a function parameter.
Definition: parameter.h:24
A representation of a function type.
A representation of a C function declaration.
A representation of C header file.
Definition: archive_wrapper.h:19