retdec
|
An integer constant. More...
#include <const_int.h>
Public Member Functions | |
virtual ShPtr< Value > | clone () override |
Returns a clone of the value. More... | |
virtual bool | isEqualTo (ShPtr< Value > otherValue) const override |
Returns true if this value is equal to otherValue, false otherwise. More... | |
virtual ShPtr< retdec::llvmir2hll::Type > | getType () const override |
Returns the type of the expression. More... | |
virtual void | replace (ShPtr< Expression > oldExpr, ShPtr< Expression > newExpr) override |
Replaces all occurrences of oldExpr with newExpr in the current expression. More... | |
void | flipSign () |
Flip the sign of value. More... | |
bool | isMinSigned () const |
Determines whether the constant has minimum signed value on it's bitwidth. More... | |
bool | isSigned () const |
Returns true if the integer is signed, false otherwise. More... | |
bool | isUnsigned () const |
Returns true if the integer is unsigned, false otherwise. More... | |
llvm::APSInt | getValue () const |
Returns the constant's value. More... | |
std::string | toString (unsigned radix=10, const std::string &prefix="") const |
Converts the constant into a string in the given radix and optionally the given prefix. More... | |
std::string | toHexString (const std::string &prefix="0x") const |
Converts the constant into a string in the hexadecimal format and prepends the given prefix. More... | |
bool | isNegative () const |
Determines whether the constant is negative (< 0). More... | |
bool | isNegativeOne () const |
Determines whether the constant is negative one. More... | |
bool | isPositive () const |
Determines whether the constant is positive (> 0). More... | |
bool | isZero () const |
Determines whether the constant is zero. More... | |
bool | isOne () const |
Determines whether the constant is one. More... | |
bool | isMoreReadableInHexa () const |
Returns true if the constant is more readable in the hexadecimal radix than in the decimal radix, false otherwise. More... | |
Visitor Interface | |
virtual void | accept (Visitor *v) override |
Visitor pattern implementation. More... | |
![]() | |
virtual | ~Value ()=default |
virtual ShPtr< Value > | getSelf () override |
Returns a shared pointer of self. More... | |
std::string | getTextRepr () |
Returns a textual representation of the value. More... | |
![]() | |
void | setMetadata (std::string data) |
Attaches new metadata. More... | |
std::string | getMetadata () const |
Returns the attached metadata. More... | |
bool | hasMetadata () const |
Are there any non-empty metadata? More... | |
![]() | |
Observer ()=default | |
Creates a new observer. More... | |
virtual | ~Observer ()=default |
Destructs the observer. More... | |
virtual void | update (ShPtr< Value > subject, ShPtr< Value > arg=nullptr) |
Subject has changed its state. More... | |
![]() | |
Subject () | |
Creates a new subject. More... | |
virtual | ~Subject ()=default |
Destructs the subject. More... | |
void | addObserver (ObserverPtr observer) |
Adds a new observer to the list of observers. More... | |
void | removeObserver (ObserverPtr observer) |
Removes the selected observer from the list of observers. More... | |
void | removeObservers () |
Removes all observers. More... | |
void | notifyObservers (ShPtr< Value > arg=nullptr) |
Notifies all observers by calling Observer::update() on them. More... | |
Static Public Member Functions | |
static ShPtr< ConstInt > | create (std::int64_t value, unsigned bitWidth, bool isSigned=true) |
Constructs an integer constant initialized to the given value of the given bit width. More... | |
static ShPtr< ConstInt > | create (const llvm::APInt &value, bool isSigned=true) |
Constructs an integer constant initialized to the given value. More... | |
static ShPtr< ConstInt > | create (const llvm::APSInt &value) |
Constructs an integer constant initialized to the given value. More... | |
static ShPtr< ConstInt > | getTwoToPositivePower (ShPtr< ConstInt > x) |
Computes 2^x , where x >= 0 , and returns the result. More... | |
![]() | |
static void | replaceExpression (ShPtr< Expression > oldExpr, ShPtr< Expression > newExpr) |
Replaces oldExpr with newExpr. More... | |
Private Member Functions | |
ConstInt (const llvm::APSInt &value) | |
Constructs an integer constant initialized to the given value. More... | |
Private Attributes | |
llvm::APSInt | value |
Value of the constant. More... | |
ShPtr< IntType > | type |
Type of the constant. More... | |
Additional Inherited Members | |
![]() | |
using | ConcreteObserver = Observer< Value, Value > |
A concrete observer. More... | |
using | ObserverPtr = WkPtr< ConcreteObserver > |
A pointer to an observer. More... | |
![]() | |
using | ObserverContainer = std::vector< ObserverPtr > |
A container to store observers. More... | |
using | observer_iterator = typename ObserverContainer::const_iterator |
![]() | |
Constant ()=default | |
![]() | |
Expression ()=default | |
![]() | |
Value ()=default | |
![]() | |
Visitable ()=default | |
~Visitable ()=default | |
![]() | |
Metadatable () | |
Constructs a new metadatable object. More... | |
![]() | |
observer_iterator | observer_begin () const |
Returns a constant iterator to the first observer. More... | |
observer_iterator | observer_end () const |
Returns a constant iterator past the last observer. More... | |
An integer constant.
Use create() to create instances. Instances of this class have reference object semantics. This class is not meant to be subclassed.
|
explicitprivate |
Constructs an integer constant initialized to the given value.
See create() for more information.
|
overridevirtual |
Visitor pattern implementation.
Subclasses should implement this method as:
where T
is the name of the subclass, and shared_from_this() and ucast<>
are from Decompiler/Support/SmartPtr.h.
Implements retdec::llvmir2hll::Visitable.
Returns a clone of the value.
A clone is (in most cases) an exact copy of the value. This member function provides the copy mechanism for reference objects.
The following parts of values are not cloned:
The following subclasses of Value are not cloned, i.e. they are returned without any copying:
Statements in compound statements (i.e. statements where isCompound()
returns true
) are cloned without their successors; therefore, e.g., just the first statement of every if's clause is cloned.
Implements retdec::llvmir2hll::Value.
|
static |
Constructs an integer constant initialized to the given value.
[in] | value | Value of the constant. |
[in] | isSigned | Is the value of the constant signed? |
Constructs an integer constant initialized to the given value.
[in] | value | Value of the constant. |
|
static |
Constructs an integer constant initialized to the given value of the given bit width.
[in] | value | Value of the constant. |
[in] | bitWidth | Bit width of the constant. |
[in] | isSigned | Is the value of the constant signed? |
This function should be used only for small constants, like -1, 0, 1, which always fit into int.
void retdec::llvmir2hll::ConstInt::flipSign | ( | ) |
Flip the sign of value.
Computes 2^x
, where x >= 0
, and returns the result.
>= 0
Returns the type of the expression.
If an appropriate type cannot be detected, UnknownType
is returned. This may happen, for example, when a binary operator have its operands of incompatible type.
Implements retdec::llvmir2hll::Expression.
llvm::APSInt retdec::llvmir2hll::ConstInt::getValue | ( | ) | const |
Returns the constant's value.
Returns true
if this value is equal to otherValue, false
otherwise.
This member function brings the support of value object semantics into reference objects, namely equality based not only on identity.
This function doesn't consider observers, metadata, etc.
Implements retdec::llvmir2hll::Value.
bool retdec::llvmir2hll::ConstInt::isMinSigned | ( | ) | const |
Determines whether the constant has minimum signed value on it's bitwidth.
bool retdec::llvmir2hll::ConstInt::isMoreReadableInHexa | ( | ) | const |
Returns true
if the constant is more readable in the hexadecimal radix than in the decimal radix, false
otherwise.
A constant integer is more readable in the hexadecimal radix if its absolute value is greater than 4095 (the highest number representable on three bits) and satisfies any of the following conditions:
0xYYY
...Y, where Y
is a hexadecimal digit. Example: 0xfffffff (268435455).0xYZZ
...Z, where Y
and Z
are hexadecimal digits. Example: 0x1000000 (16777216).0xYZYZ
... (possibly with an additional digit X
at the end), where Y
and Z
are hexadecimal digits. Example: 0xf0f0f0f (252645135).0xYYZ
...ZYY, where Y
and Z
are hexadecimal digits. Example: 0xaa00aa (11141290).0xYYY
...ZZZ, where Y
and Z
are hexadecimal digits. Example: 0x111fff (1122303). bool retdec::llvmir2hll::ConstInt::isNegative | ( | ) | const |
Determines whether the constant is negative (< 0).
bool retdec::llvmir2hll::ConstInt::isNegativeOne | ( | ) | const |
Determines whether the constant is negative one.
bool retdec::llvmir2hll::ConstInt::isOne | ( | ) | const |
Determines whether the constant is one.
It returns true
only for +1
; for -1
, it returns false
.
bool retdec::llvmir2hll::ConstInt::isPositive | ( | ) | const |
Determines whether the constant is positive (> 0).
bool retdec::llvmir2hll::ConstInt::isSigned | ( | ) | const |
Returns true
if the integer is signed, false
otherwise.
bool retdec::llvmir2hll::ConstInt::isUnsigned | ( | ) | const |
Returns true
if the integer is unsigned, false
otherwise.
bool retdec::llvmir2hll::ConstInt::isZero | ( | ) | const |
Determines whether the constant is zero.
|
overridevirtual |
Replaces all occurrences of oldExpr with newExpr in the current expression.
[in] | oldExpr | Old expression to be replaced. |
[in] | newExpr | Replacement. |
Note that if oldExpr is the current expression on which this function is called, nothing gets replaced, i.e. the replacements are done only in the members of the current expression on which this function is called.
Implements retdec::llvmir2hll::Expression.
std::string retdec::llvmir2hll::ConstInt::toHexString | ( | const std::string & | prefix = "0x" | ) | const |
Converts the constant into a string in the hexadecimal format and prepends the given prefix.
Calling this function is equivalent to call
where prefix
is by default "0x"
.
std::string retdec::llvmir2hll::ConstInt::toString | ( | unsigned | radix = 10 , |
const std::string & | prefix = "" |
||
) | const |
Converts the constant into a string in the given radix and optionally the given prefix.
If the number is negative, like -5, instead of
this function returns
Alpha characters are printed in lower case. For example, 3899
decimal is converted into 0xf3b
hexadecimal.
|
private |
Value of the constant.