retdec
var_def_stmt.h
Go to the documentation of this file.
1 
7 #ifndef RETDEC_LLVMIR2HLL_IR_VAR_DEF_STMT_H
8 #define RETDEC_LLVMIR2HLL_IR_VAR_DEF_STMT_H
9 
12 
13 namespace retdec {
14 namespace llvmir2hll {
15 
16 class Expression;
17 class Variable;
18 class Visitor;
19 
26 class VarDefStmt final: public Statement {
27 public:
29  ShPtr<Expression> init = nullptr,
30  ShPtr<Statement> succ = nullptr,
32 
33  virtual ShPtr<Value> clone() override;
34  virtual bool isEqualTo(ShPtr<Value> otherValue) const override;
35  virtual bool isCompound() override { return false; }
36  virtual void replace(ShPtr<Expression> oldExpr, ShPtr<Expression> newExpr) override;
37  virtual ShPtr<Expression> asExpression() const override;
38 
39  ShPtr<Variable> getVar() const;
41  bool hasInitializer() const;
42 
43  void setVar(ShPtr<Variable> newVar);
44  void setInitializer(ShPtr<Expression> newInit);
45  void removeInitializer();
46 
49  virtual void update(ShPtr<Value> subject, ShPtr<Value> arg = nullptr) override;
51 
54  virtual void accept(Visitor *v) override;
56 
57 private:
58  // Since instances are created by calling the static function create(), the
59  // constructor can be private.
62 
63 private:
66 
69 };
70 
71 } // namespace llvmir2hll
72 } // namespace retdec
73 
74 #endif
Definition: address.h:21
static const uint64_t Undefined
Definition: address.h:47
A representation of a program statement.
Definition: statement.h:39
ShPtr< Statement > succ
Successor statement.
Definition: statement.h:141
A variable definition statement.
Definition: var_def_stmt.h:26
virtual bool isEqualTo(ShPtr< Value > otherValue) const override
Returns true if this value is equal to otherValue, false otherwise.
Definition: var_def_stmt.cpp:34
virtual void accept(Visitor *v) override
Visitor pattern implementation.
Definition: var_def_stmt.cpp:183
ShPtr< Expression > init
Variable initializer.
Definition: var_def_stmt.h:68
virtual bool isCompound() override
Returns true if the statement is a compound statement, false otherwise.
Definition: var_def_stmt.h:35
ShPtr< Variable > getVar() const
Return the variable.
Definition: var_def_stmt.cpp:67
virtual void update(ShPtr< Value > subject, ShPtr< Value > arg=nullptr) override
Updates the statement according to the changes of subject.
Definition: var_def_stmt.cpp:168
virtual ShPtr< Expression > asExpression() const override
Returns the statement as an expression.
Definition: var_def_stmt.cpp:59
VarDefStmt(ShPtr< Variable > var, ShPtr< Expression > init=nullptr, Address a=Address::Undefined)
Constructs a new variable definition statement.
Definition: var_def_stmt.cpp:21
static ShPtr< VarDefStmt > create(ShPtr< Variable > var, ShPtr< Expression > init=nullptr, ShPtr< Statement > succ=nullptr, Address a=Address::Undefined)
Creates a new variable definition statement.
Definition: var_def_stmt.cpp:132
virtual ShPtr< Value > clone() override
Returns a clone of the value.
Definition: var_def_stmt.cpp:24
void setInitializer(ShPtr< Expression > newInit)
Sets a new initializer.
Definition: var_def_stmt.cpp:104
void setVar(ShPtr< Variable > newVar)
Sets a new variable.
Definition: var_def_stmt.cpp:93
ShPtr< Expression > getInitializer() const
Returns the variable initializer.
Definition: var_def_stmt.cpp:76
virtual void replace(ShPtr< Expression > oldExpr, ShPtr< Expression > newExpr) override
Replaces all occurrences of oldExpr with newExpr in the current statement.
Definition: var_def_stmt.cpp:43
bool hasInitializer() const
Returns true if the statement has an initializer, false otherwise.
Definition: var_def_stmt.cpp:83
ShPtr< Variable > var
Variable.
Definition: var_def_stmt.h:65
void removeInitializer()
Removes the initializer.
Definition: var_def_stmt.cpp:117
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.
A representation of a program statement.