retdec
const_string.h
Go to the documentation of this file.
1 
7 #ifndef RETDEC_LLVMIR2HLL_IR_CONST_STRING_H
8 #define RETDEC_LLVMIR2HLL_IR_CONST_STRING_H
9 
10 #include <cstdint>
11 #include <string>
12 
15 #include "retdec/utils/string.h"
16 
17 namespace retdec {
18 namespace llvmir2hll {
19 
20 class Expression;
21 class Visitor;
22 class StringType;
23 
32 class ConstString final: public Constant {
33 public:
36 
39 
40 public:
41  static ShPtr<ConstString> create(const UnderlyingStringType &value, std::size_t charSize);
42  static ShPtr<ConstString> create(const std::string &str);
43 
44  virtual ShPtr<Value> clone() override;
45 
46  virtual bool isEqualTo(ShPtr<Value> otherValue) const override;
47  virtual ShPtr<Type> getType() const override;
48  virtual void replace(ShPtr<Expression> oldExpr,
49  ShPtr<Expression> newExpr) override;
50 
52  std::string getValueAsEscapedCString() const;
53  std::size_t getCharSize() const;
54  bool is8BitString() const;
55  bool isWideString() const;
56 
59  virtual void accept(Visitor *v) override;
61 
62 private:
65 
66  // How large are characters in the string (in bits)?
67  std::size_t charSize;
68 
71 
72 private:
73  // Since instances are created by calling the static function create(), the
74  // constructor can be private.
75  ConstString(const UnderlyingStringType &value, std::size_t charSize);
76 };
77 
78 } // namespace llvmir2hll
79 } // namespace retdec
80 
81 #endif
A generic string constant.
Definition: const_string.h:32
bool isWideString() const
Is the string a wide string?
Definition: const_string.cpp:85
retdec::utils::WideCharType UnderlyingCharType
Underlying character type.
Definition: const_string.h:35
virtual ShPtr< Type > getType() const override
Returns the type of the expression.
Definition: const_string.cpp:44
std::size_t charSize
Definition: const_string.h:67
virtual bool isEqualTo(ShPtr< Value > otherValue) const override
Returns true if this value is equal to otherValue, false otherwise.
Definition: const_string.cpp:35
bool is8BitString() const
Is the string an 8-bit string?
Definition: const_string.cpp:78
UnderlyingStringType getValue() const
Returns the constant's value.
Definition: const_string.cpp:57
virtual void replace(ShPtr< Expression > oldExpr, ShPtr< Expression > newExpr) override
Replaces all occurrences of oldExpr with newExpr in the current expression.
Definition: const_string.cpp:48
virtual ShPtr< Value > clone() override
Returns a clone of the value.
Definition: const_string.cpp:29
ShPtr< StringType > type
Type.
Definition: const_string.h:70
static ShPtr< ConstString > create(const UnderlyingStringType &value, std::size_t charSize)
Constructs a string constant initialized to the given value.
Definition: const_string.cpp:98
virtual void accept(Visitor *v) override
Visitor pattern implementation.
Definition: const_string.cpp:113
retdec::utils::WideStringType UnderlyingStringType
Underlying string type.
Definition: const_string.h:38
std::size_t getCharSize() const
Returns how large are characters in the string (in bits).
Definition: const_string.cpp:71
std::string getValueAsEscapedCString() const
Returns the constant's value as an escaped C string.
Definition: const_string.cpp:64
ConstString(const UnderlyingStringType &value, std::size_t charSize)
Constructs a string constant initialized to the given value.
Definition: const_string.cpp:25
UnderlyingStringType value
Value.
Definition: const_string.h:64
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 library providing API for working with back-end IR.
StringType
Definition: string.h:16
std::shared_ptr< T > ShPtr
An alias for a shared pointer.
Definition: smart_ptr.h:18
std::basic_string< WideCharType > WideStringType
Definition: string.h:26
std::uint32_t WideCharType
Definition: string.h:22
Definition: archive_wrapper.h:19
Declarations, aliases, macros, etc. for the use of smart pointers.
String utilities.