retdec
function_type.h
Go to the documentation of this file.
1 
7 #ifndef RETDEC_CTYPES_FUNCTION_TYPE_H
8 #define RETDEC_CTYPES_FUNCTION_TYPE_H
9 
10 #include <memory>
11 #include <vector>
12 
14 #include "retdec/ctypes/type.h"
15 
16 namespace retdec {
17 namespace ctypes {
18 
19 class Context;
20 class Parameter;
21 
25 class FunctionType : public Type
26 {
27  public:
28  using Parameters = std::vector<std::shared_ptr<Type>>;
29  using parameter_iterator = Parameters::iterator;
30  using const_parameter_iterator = Parameters::const_iterator;
31 
32  public:
33  enum class VarArgness {
34  IsVarArg,
36  };
37 
38  public:
39  static std::shared_ptr<FunctionType> create(
40  const std::shared_ptr<Context> &context,
41  const std::shared_ptr<Type> &returnType,
42  const Parameters &parameters,
45  );
46 
47  std::shared_ptr<Type> getReturnType() const;
48 
55 
56  Parameters::size_type getParameterCount() const;
57  const Parameters &getParameters() const;
58  std::shared_ptr<Type> getParameter(Parameters::size_type n) const;
59 
60  bool isVarArg() const;
62 
66  const CallConvention &getCallConvention() const;
68 
69  virtual bool isFunction() const override;
70 
73  virtual void accept(Visitor *v) override;
75 
76  private:
78  const std::shared_ptr<Type> &returnType,
79  const Parameters &parameters,
82  );
83 
84  private:
85  std::shared_ptr<Type> returnType;
89 };
90 
91 } // namespace ctypes
92 } // namespace retdec
93 
94 #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 type.
Definition: function_type.h:26
CallConvention callConvention
Definition: function_type.h:87
virtual void accept(Visitor *v) override
Visitor pattern implementation.
Definition: function_type.cpp:170
FunctionType(const std::shared_ptr< Type > &returnType, const Parameters &parameters, const CallConvention &callConvention, VarArgness varArgness)
Constructs a new function type.
Definition: function_type.cpp:20
Parameters::size_type getParameterCount() const
Returns the number of parameters.
Definition: function_type.cpp:111
const Parameters & getParameters() const
Returns function type parameters.
Definition: function_type.cpp:119
void setCallConvention(const CallConvention &callConvention)
Sets function type's call convention.
Definition: function_type.cpp:149
parameter_iterator parameter_end()
Returns an iterator past the last parameter.
Definition: function_type.cpp:93
static std::shared_ptr< FunctionType > create(const std::shared_ptr< Context > &context, const std::shared_ptr< Type > &returnType, const Parameters &parameters, const CallConvention &callConvention=CallConvention(), VarArgness varArgness=VarArgness::IsNotVarArg)
Creates function type.
Definition: function_type.cpp:44
VarArgness varArgness
Definition: function_type.h:88
virtual bool isFunction() const override
Definition: function_type.cpp:165
bool isVarArg() const
Returns true if function takes variable number of arguments, false otherwise.
Definition: function_type.cpp:141
Parameters parameters
Definition: function_type.h:86
Parameters::const_iterator const_parameter_iterator
Definition: function_type.h:30
Parameters::iterator parameter_iterator
Definition: function_type.h:29
VarArgness
Definition: function_type.h:33
const CallConvention & getCallConvention() const
Returns function type's call convention.
Definition: function_type.cpp:157
std::shared_ptr< Type > getParameter(Parameters::size_type n) const
Returns the n-th parameter's type.
Definition: function_type.cpp:132
parameter_iterator parameter_begin()
Returns an iterator to the parameter.
Definition: function_type.cpp:77
std::vector< std::shared_ptr< Type > > Parameters
Definition: function_type.h:28
std::shared_ptr< Type > getReturnType() const
Returns function's return type.
Definition: function_type.cpp:69
std::shared_ptr< Type > returnType
Definition: function_type.h:85
A base class of all C types.
Definition: type.h:22
A base class of all C-types' visitors.
Definition: visitor.h:33
A base class of all C types.
Definition: archive_wrapper.h:19