retdec
variable.h
Go to the documentation of this file.
1 
7 #ifndef RETDEC_LLVMIR2HLL_IR_VARIABLE_H
8 #define RETDEC_LLVMIR2HLL_IR_VARIABLE_H
9 
10 #include <string>
11 
15 
16 namespace retdec {
17 namespace llvmir2hll {
18 
19 class Type;
20 class Visitor;
21 
28 class Variable final: public Expression {
29 public:
30  static ShPtr<Variable> create(const std::string &name, ShPtr<Type> type,
32 
33  virtual ShPtr<Value> clone() override;
34 
35  virtual bool isEqualTo(ShPtr<Value> otherValue) const override;
36  virtual ShPtr<Type> getType() const override;
37  virtual void replace(ShPtr<Expression> oldExpr,
38  ShPtr<Expression> newExpr) override;
39 
40  const std::string &getInitialName() const;
41  const std::string &getName() const;
42  Address getAddress() const;
43  bool hasName() const;
44  bool isInternal() const;
45  bool isExternal() const;
46  ShPtr<Variable> copy() const;
47 
48  void setName(const std::string &newName);
49  void setType(ShPtr<Type> newType);
50  void setAddress(Address a);
51  void markAsInternal();
52  void markAsExternal();
53 
56  virtual void accept(Visitor *v) override;
58 
59 private:
60  // Since instances are created by calling the static function create(), the
61  // constructor can be private.
62  Variable(const std::string &name, ShPtr<Type> type,
64 
65 private:
67  std::string initialName;
68 
70  std::string name;
71 
74 
76  bool internal;
77 
82 };
83 
84 } // namespace llvmir2hll
85 } // namespace retdec
86 
87 #endif
Definition: address.h:21
static const uint64_t Undefined
Definition: address.h:47
A base class of all expressions.
Definition: expression.h:23
A representation of a variable.
Definition: variable.h:28
void setType(ShPtr< Type > newType)
Sets the variable's type to newType.
Definition: variable.cpp:136
void markAsExternal()
Sets the variable as external.
Definition: variable.cpp:162
static ShPtr< Variable > create(const std::string &name, ShPtr< Type > type, Address a=Address::Undefined)
Creates a new variable.
Definition: variable.cpp:179
Address address
Definition: variable.h:81
virtual ShPtr< Value > clone() override
Returns a clone of the value.
Definition: variable.cpp:23
void setAddress(Address a)
Definition: variable.cpp:142
virtual bool isEqualTo(ShPtr< Value > otherValue) const override
Returns true if this value is equal to otherValue, false otherwise.
Definition: variable.cpp:28
std::string name
Name of the variable.
Definition: variable.h:70
ShPtr< Type > type
Type of the variable.
Definition: variable.h:73
virtual ShPtr< Type > getType() const override
Returns the type of the variable.
Definition: variable.cpp:75
ShPtr< Variable > copy() const
Returns a copy of this variable.
Definition: variable.cpp:116
void markAsInternal()
Sets the variable as internal.
Definition: variable.cpp:152
virtual void accept(Visitor *v) override
Visitor pattern implementation.
Definition: variable.cpp:187
virtual void replace(ShPtr< Expression > oldExpr, ShPtr< Expression > newExpr) override
Replaces all occurrences of oldExpr with newExpr in the current expression.
Definition: variable.cpp:39
bool isInternal() const
Returns true if the variable is internal, false otherwise.
Definition: variable.cpp:96
const std::string & getInitialName() const
Returns the initial name of the variable.
Definition: variable.cpp:50
std::string initialName
Initial name of the variable.
Definition: variable.h:67
bool hasName() const
Returns true if the variable has name, false otherwise.
Definition: variable.cpp:68
const std::string & getName() const
Returns the name of the variable.
Definition: variable.cpp:57
void setName(const std::string &newName)
Sets the variable's name to newName.
Definition: variable.cpp:126
Address getAddress() const
Definition: variable.cpp:61
bool isExternal() const
Returns true if the variable is external, false otherwise.
Definition: variable.cpp:105
Variable(const std::string &name, ShPtr< Type > type, Address a=Address::Undefined)
Constructs a new variable.
Definition: variable.cpp:20
A base class of all visitors.
Definition: visitor.h:95
A base class of all expressions.
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.