retdec
global_var_def.h
Go to the documentation of this file.
1 
7 #ifndef RETDEC_LLVMIR2HLL_IR_GLOBAL_VAR_DEF_H
8 #define RETDEC_LLVMIR2HLL_IR_GLOBAL_VAR_DEF_H
9 
13 
14 namespace retdec {
15 namespace llvmir2hll {
16 
17 class Expression;
18 class Variable;
19 class Visitor;
20 
27 class GlobalVarDef final: public Value {
28 public:
30  ShPtr<Expression> init = nullptr);
31 
32  virtual ShPtr<Value> clone() override;
33  virtual bool isEqualTo(ShPtr<Value> otherValue) const override;
34  void replace(ShPtr<Expression> oldExpr, ShPtr<Expression> newExpr);
35 
36  ShPtr<Variable> getVar() const;
38  bool hasInitializer() const;
39  bool definesExternalVar() const;
40  Address getAddress() const;
41 
42  void setVar(ShPtr<Variable> newVar);
43  void setInitializer(ShPtr<Expression> newInit);
44  void removeInitializer();
45 
48  virtual void update(ShPtr<Value> subject, ShPtr<Value> arg = nullptr) override;
50 
53  virtual void accept(Visitor *v) override;
55 
56 private:
57  // Since instances are created by calling the static function create(), the
58  // constructor can be private.
60  ShPtr<Expression> init = nullptr);
61 
62 private:
65 
68 };
69 
70 } // namespace llvmir2hll
71 } // namespace retdec
72 
73 #endif
Definition: address.h:21
A definition of a global variable.
Definition: global_var_def.h:27
static ShPtr< GlobalVarDef > create(ShPtr< Variable > var, ShPtr< Expression > init=nullptr)
Creates a new definition of a global variable.
Definition: global_var_def.cpp:138
virtual ShPtr< Value > clone() override
Returns a clone of the value.
Definition: global_var_def.cpp:24
void setInitializer(ShPtr< Expression > newInit)
Sets a new initializer.
Definition: global_var_def.cpp:112
virtual void accept(Visitor *v) override
Visitor pattern implementation.
Definition: global_var_def.cpp:187
void replace(ShPtr< Expression > oldExpr, ShPtr< Expression > newExpr)
Definition: global_var_def.cpp:42
virtual void update(ShPtr< Value > subject, ShPtr< Value > arg=nullptr) override
Updates the definition according to the changes of subject.
Definition: global_var_def.cpp:172
virtual bool isEqualTo(ShPtr< Value > otherValue) const override
Returns true if this value is equal to otherValue, false otherwise.
Definition: global_var_def.cpp:33
GlobalVarDef(ShPtr< Variable > var, ShPtr< Expression > init=nullptr)
Constructs a new definition of a global variable.
Definition: global_var_def.cpp:21
void removeInitializer()
Removes the initializer.
Definition: global_var_def.cpp:125
bool definesExternalVar() const
Checks if it defines an external global variable.
Definition: global_var_def.cpp:87
Address getAddress() const
Definition: global_var_def.cpp:91
ShPtr< Variable > getVar() const
Return the variable.
Definition: global_var_def.cpp:61
bool hasInitializer() const
Returns true if the global variable has an initializer, false otherwise.
Definition: global_var_def.cpp:78
void setVar(ShPtr< Variable > newVar)
Sets a new variable.
Definition: global_var_def.cpp:101
ShPtr< Variable > var
Global variable.
Definition: global_var_def.h:64
ShPtr< Expression > getInitializer() const
Returns the variable initializer.
Definition: global_var_def.cpp:70
ShPtr< Expression > init
Initializer of the variable. May be empty.
Definition: global_var_def.h:67
A base class of all objects a module can contain.
Definition: value.h:32
A base class of all visitors.
Definition: visitor.h:95
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.
Aliases for several useful types.
A base class of all objects a module can contain.