Skip to content

Commit 6a2ae27

Browse files
committed
use shared ptr over optional in literalvalue
1 parent 5bbd4a0 commit 6a2ae27

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

libyul/AST.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,21 @@ using TypedNameList = std::vector<TypedName>;
4545
enum class LiteralKind { Number, Boolean, String };
4646
struct LiteralValue {
4747
using Data = u256;
48-
using RepresentationHint = std::optional<std::string>;
48+
using RepresentationHint = std::shared_ptr<std::string>;
4949

50-
LiteralValue& operator=(u256 const& _v) { data = _v; return *this; }
51-
bool operator<(LiteralValue const& _rhs) const { return data < _rhs.data; }
50+
LiteralValue() = default;
51+
LiteralValue(Data const& _data, std::optional<std::string> const& _s = std::nullopt):
52+
data(_data), representationHint(_s ? std::make_shared<std::string>(*_s) : nullptr) {}
53+
54+
LiteralValue& operator=(Data const& _v) { data = _v; return *this; }
5255
bool operator==(LiteralValue const& _rhs) const { return data == _rhs.data; }
53-
bool operator<(Data const& _rhs) const { return data < _rhs; }
5456
bool operator==(Data const& _rhs) const { return data == _rhs; }
5557
bool operator!=(Data const& _rhs) const { return data != _rhs; }
5658

57-
Data data;
58-
RepresentationHint representationHint {std::nullopt};
59+
Data data {0};
60+
RepresentationHint representationHint {nullptr};
5961
};
60-
struct Literal { langutil::DebugData::ConstPtr debugData; LiteralKind kind{}; LiteralValue value; Type type; };
62+
struct Literal { langutil::DebugData::ConstPtr debugData; LiteralKind kind; LiteralValue value; Type type; };
6163
/// External / internal identifier or label reference
6264
struct Identifier { langutil::DebugData::ConstPtr debugData; YulString name; };
6365
/// Assignment ("x := mload(20:u256)", expects push-1-expression on the right hand

libyul/Utilities.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ bool Less<Literal>::operator()(Literal const& _lhs, Literal const& _rhs) const
136136
if (std::make_tuple(_lhs.kind, _lhs.type) != std::make_tuple(_rhs.kind, _rhs.type))
137137
return std::make_tuple(_lhs.kind, _lhs.type) < std::make_tuple(_rhs.kind, _rhs.type);
138138

139-
return _lhs.value < _rhs.value;
139+
return _lhs.value.data < _rhs.value.data;
140140
}
141141

142142
bool SwitchCaseCompareByLiteralValue::operator()(Case const* _lhs, Case const* _rhs) const

0 commit comments

Comments
 (0)