retdec
const_array.h
Go to the documentation of this file.
1 
7 #ifndef RETDEC_LLVMIR2HLL_IR_CONST_ARRAY_H
8 #define RETDEC_LLVMIR2HLL_IR_CONST_ARRAY_H
9 
10 #include <cstddef>
11 #include <vector>
12 
16 
17 namespace retdec {
18 namespace llvmir2hll {
19 
20 class Expression;
21 class Visitor;
22 
30 class ConstArray final: public Constant {
31 public:
33  using ArrayValue = std::vector<ShPtr<Expression>>;
34 
36  using init_iterator = ArrayValue::const_iterator;
37 
38 public:
41 
42  virtual ShPtr<Value> clone() override;
43 
44  virtual bool isEqualTo(ShPtr<Value> otherValue) const override;
45  virtual ShPtr<Type> getType() const override;
46  virtual void replace(ShPtr<Expression> oldExpr,
47  ShPtr<Expression> newExpr) override;
48 
49  bool isInitialized() const;
50  bool isEmpty() const;
53 
56  const ArrayValue &getInitializedValue() const;
57 
58  init_iterator init_begin() const;
59  init_iterator init_end() const;
61 
64  virtual void update(ShPtr<Value> subject,
65  ShPtr<Value> arg = nullptr) override;
67 
70  virtual void accept(Visitor *v) override;
72 
73 private:
76 
79 
82 
83 private:
84  // Since instances are created by calling the static function create(),
85  // constructors can be private.
87 };
88 
89 } // namespace llvmir2hll
90 } // namespace retdec
91 
92 #endif
std::vector< std::size_t > Dimensions
Array dimensions.
Definition: array_type.h:30
An array constant.
Definition: const_array.h:30
ShPtr< ArrayType > type
The type of the array.
Definition: const_array.h:81
ArrayValue::const_iterator init_iterator
Initialized array iterator.
Definition: const_array.h:36
init_iterator init_begin() const
Returns an iterator to the first item of the initialized array.
Definition: const_array.cpp:117
virtual void update(ShPtr< Value > subject, ShPtr< Value > arg=nullptr) override
Updates the array according to the changes of subject.
Definition: const_array.cpp:229
bool isInitialized() const
Returns true if the array is initialized, false otherwise.
Definition: const_array.cpp:140
virtual void replace(ShPtr< Expression > oldExpr, ShPtr< Expression > newExpr) override
Replaces all occurrences of oldExpr with newExpr in the current expression.
Definition: const_array.cpp:77
static ShPtr< ConstArray > create(ArrayValue value, ShPtr< ArrayType > type)
Creates an array constant initialized to the given value and type.
Definition: const_array.cpp:182
std::vector< ShPtr< Expression > > ArrayValue
Underlying type of the array's value.
Definition: const_array.h:33
bool isEmpty() const
Returns true if the array is empty, false otherwise.
Definition: const_array.cpp:150
virtual ShPtr< Value > clone() override
Returns a clone of the value.
Definition: const_array.cpp:24
ArrayType::Dimensions getDimensions() const
Returns the dimensions of the array.
Definition: const_array.cpp:168
ConstArray(ArrayValue value, ShPtr< ArrayType > type)
Constructs an array constant.
Definition: const_array.cpp:21
virtual bool isEqualTo(ShPtr< Value > otherValue) const override
Returns true if this value is equal to otherValue, false otherwise.
Definition: const_array.cpp:35
ArrayValue value
Value of an initialized array.
Definition: const_array.h:75
virtual ShPtr< Type > getType() const override
Returns the type of the expression.
Definition: const_array.cpp:73
const ArrayValue & getInitializedValue() const
Returns the value of an initialized array.
Definition: const_array.cpp:103
virtual void accept(Visitor *v) override
Visitor pattern implementation.
Definition: const_array.cpp:247
ShPtr< Type > getContainedType() const
Returns the type of items in the array.
Definition: const_array.cpp:161
bool initialized
Is the array initialized?
Definition: const_array.h:78
static ShPtr< ConstArray > createUninitialized(ShPtr< ArrayType > type)
Creates an uninitialized array constant of the given type.
Definition: const_array.cpp:205
init_iterator init_end() const
Returns an iterator past the last item of the initialized array.
Definition: const_array.cpp:131
A base class for all constants.
Definition: constant.h:20
A base class of all visitors.
Definition: visitor.h:95
A base class for all constants.
A representation of an array 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.