retdec
function_type.h
Go to the documentation of this file.
1 
7 #ifndef RETDEC_LLVMIR2HLL_IR_FUNCTION_TYPE_H
8 #define RETDEC_LLVMIR2HLL_IR_FUNCTION_TYPE_H
9 
10 #include <cstddef>
11 
15 
16 namespace retdec {
17 namespace llvmir2hll {
18 
19 class Visitor;
20 
27 class FunctionType final: public Type {
28 private:
30  using Params = std::vector<ShPtr<Type>>;
31 
32 public:
34  using param_iterator = Params::const_iterator;
35 
36 public:
38 
39  virtual ShPtr<Value> clone() override;
40  virtual bool isEqualTo(ShPtr<Value> otherValue) const override;
41 
45  ShPtr<Type> getRetType() const;
47 
50  bool hasParams() const;
51  bool hasParam(std::size_t n) const;
52  std::size_t getNumOfParams() const;
53  void addParam(ShPtr<Type> paramType);
54  ShPtr<Type> getParam(std::size_t n) const;
55 
57  param_iterator param_end() const;
59 
62  void setVarArg(bool isVarArg = true);
63  bool isVarArg() const;
65 
68  virtual void accept(Visitor *v) override;
70 
71 private:
72  // Since instances are created by calling the static function create(), the
73  // constructor can be private.
75 
76 private:
79 
82 
84  bool varArg;
85 };
86 
87 } // namespace llvmir2hll
88 } // namespace retdec
89 
90 #endif
A representation of a function type.
Definition: function_type.h:27
std::size_t getNumOfParams() const
Returns the number of parameters.
Definition: function_type.cpp:107
virtual void accept(Visitor *v) override
Visitor pattern implementation.
Definition: function_type.cpp:172
bool varArg
Takes the function a variable number of arguments?
Definition: function_type.h:84
ShPtr< Type > getRetType() const
Returns the return type.
Definition: function_type.cpp:77
bool hasParam(std::size_t n) const
Returns true if there is an n-th parameter, false otherwise.
Definition: function_type.cpp:97
static ShPtr< FunctionType > create(ShPtr< Type > retType=VoidType::create())
Creates a new function type.
Definition: function_type.cpp:168
virtual ShPtr< Value > clone() override
Returns a clone of the value.
Definition: function_type.cpp:26
virtual bool isEqualTo(ShPtr< Value > otherValue) const override
Returns true if this value is equal to otherValue, false otherwise.
Definition: function_type.cpp:34
Params::const_iterator param_iterator
Parameter iterator.
Definition: function_type.h:34
ShPtr< Type > retType
Return type.
Definition: function_type.h:78
ShPtr< Type > getParam(std::size_t n) const
Returns the n-th parameter.
Definition: function_type.cpp:127
FunctionType(ShPtr< Type > retType=VoidType::create())
Constructs a new function type.
Definition: function_type.cpp:23
void addParam(ShPtr< Type > paramType)
Adds a new parameter.
Definition: function_type.cpp:114
bool isVarArg() const
Returns true if the function takes a variable number of arguments, false otherwise.
Definition: function_type.cpp:161
bool hasParams() const
Returns true if the function has some parameters, false otherwise.
Definition: function_type.cpp:88
std::vector< ShPtr< Type > > Params
Container to store types of parameters.
Definition: function_type.h:30
param_iterator param_begin() const
Returns a constant iterator to the parameter.
Definition: function_type.cpp:138
param_iterator param_end() const
Returns a constant iterator past the last parameter.
Definition: function_type.cpp:145
void setRetType(ShPtr< Type > retType)
Sets a new return type.
Definition: function_type.cpp:70
void setVarArg(bool isVarArg=true)
Sets the function either as taking a variable number of arguments or not.
Definition: function_type.cpp:153
Params params
Parameters.
Definition: function_type.h:81
A base class of all types.
Definition: type.h:20
A base class of all visitors.
Definition: visitor.h:95
static ShPtr< VoidType > create()
Creates a void type.
Definition: void_type.cpp:42
A base class of all types.
A representation of an void type.
A library providing API for working with back-end IR.
std::shared_ptr< T > ShPtr
An alias for a shared pointer.
Definition: smart_ptr.h:18
Definition: archive_wrapper.h:19
Declarations, aliases, macros, etc. for the use of smart pointers.