mirror of
https://git.suyu.dev/suyu/sirit.git
synced 2024-12-22 12:12:05 +00:00
operand: Move operand_type initialization to constructor
This commit is contained in:
parent
53d572ae7d
commit
4c2981eab5
5 changed files with 11 additions and 15 deletions
|
@ -9,9 +9,8 @@
|
||||||
|
|
||||||
namespace Sirit {
|
namespace Sirit {
|
||||||
|
|
||||||
LiteralNumber::LiteralNumber(u64 raw, bool is_32) : raw{raw}, is_32{is_32} {
|
LiteralNumber::LiteralNumber(u64 raw, bool is_32)
|
||||||
operand_type = OperandType::Number;
|
: Operand{OperandType::Number}, raw{raw}, is_32{is_32} {}
|
||||||
}
|
|
||||||
|
|
||||||
LiteralNumber::~LiteralNumber() = default;
|
LiteralNumber::~LiteralNumber() = default;
|
||||||
|
|
||||||
|
@ -28,7 +27,7 @@ u16 LiteralNumber::GetWordCount() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LiteralNumber::operator==(const Operand& other) const {
|
bool LiteralNumber::operator==(const Operand& other) const {
|
||||||
if (operand_type == other.GetType()) {
|
if (GetType() == other.GetType()) {
|
||||||
const auto& o{static_cast<const LiteralNumber&>(other)};
|
const auto& o{static_cast<const LiteralNumber&>(other)};
|
||||||
return o.raw == raw && o.is_32 == is_32;
|
return o.raw == raw && o.is_32 == is_32;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,9 +10,8 @@
|
||||||
|
|
||||||
namespace Sirit {
|
namespace Sirit {
|
||||||
|
|
||||||
LiteralString::LiteralString(std::string string) : string{std::move(string)} {
|
LiteralString::LiteralString(std::string string)
|
||||||
operand_type = OperandType::String;
|
: Operand{OperandType::String}, string{std::move(string)} {}
|
||||||
}
|
|
||||||
|
|
||||||
LiteralString::~LiteralString() = default;
|
LiteralString::~LiteralString() = default;
|
||||||
|
|
||||||
|
@ -25,7 +24,7 @@ u16 LiteralString::GetWordCount() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LiteralString::operator==(const Operand& other) const {
|
bool LiteralString::operator==(const Operand& other) const {
|
||||||
if (operand_type == other.GetType()) {
|
if (GetType() == other.GetType()) {
|
||||||
return static_cast<const LiteralString&>(other).string == string;
|
return static_cast<const LiteralString&>(other).string == string;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -16,9 +16,7 @@
|
||||||
namespace Sirit {
|
namespace Sirit {
|
||||||
|
|
||||||
Op::Op(spv::Op opcode, std::optional<u32> id, Id result_type)
|
Op::Op(spv::Op opcode, std::optional<u32> id, Id result_type)
|
||||||
: opcode(opcode), result_type(result_type), id(id) {
|
: Operand{OperandType::Op}, opcode(opcode), result_type(result_type), id(id) {}
|
||||||
operand_type = OperandType::Op;
|
|
||||||
}
|
|
||||||
|
|
||||||
Op::~Op() = default;
|
Op::~Op() = default;
|
||||||
|
|
||||||
|
@ -32,7 +30,7 @@ u16 Op::GetWordCount() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Op::operator==(const Operand& other) const {
|
bool Op::operator==(const Operand& other) const {
|
||||||
if (operand_type != other.GetType()) {
|
if (GetType() != other.GetType()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const auto& op = static_cast<const Op&>(other);
|
const auto& op = static_cast<const Op&>(other);
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
namespace Sirit {
|
namespace Sirit {
|
||||||
|
|
||||||
Operand::Operand() = default;
|
Operand::Operand(OperandType operand_type) : operand_type{operand_type} {}
|
||||||
|
|
||||||
Operand::~Operand() = default;
|
Operand::~Operand() = default;
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ enum class OperandType { Invalid, Op, Number, String };
|
||||||
|
|
||||||
class Operand {
|
class Operand {
|
||||||
public:
|
public:
|
||||||
Operand();
|
explicit Operand(OperandType operand_type);
|
||||||
virtual ~Operand();
|
virtual ~Operand();
|
||||||
|
|
||||||
virtual void Fetch(Stream& stream) const;
|
virtual void Fetch(Stream& stream) const;
|
||||||
|
@ -25,7 +25,7 @@ public:
|
||||||
|
|
||||||
OperandType GetType() const;
|
OperandType GetType() const;
|
||||||
|
|
||||||
protected:
|
private:
|
||||||
OperandType operand_type{};
|
OperandType operand_type{};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue