diff --git a/src/literal_number.cpp b/src/literal_number.cpp index 2203150..dc17b13 100644 --- a/src/literal_number.cpp +++ b/src/literal_number.cpp @@ -9,9 +9,8 @@ namespace Sirit { -LiteralNumber::LiteralNumber(u64 raw, bool is_32) : raw{raw}, is_32{is_32} { - operand_type = OperandType::Number; -} +LiteralNumber::LiteralNumber(u64 raw, bool is_32) + : Operand{OperandType::Number}, raw{raw}, is_32{is_32} {} LiteralNumber::~LiteralNumber() = default; @@ -28,7 +27,7 @@ u16 LiteralNumber::GetWordCount() const { } bool LiteralNumber::operator==(const Operand& other) const { - if (operand_type == other.GetType()) { + if (GetType() == other.GetType()) { const auto& o{static_cast(other)}; return o.raw == raw && o.is_32 == is_32; } diff --git a/src/literal_string.cpp b/src/literal_string.cpp index b81e83b..e04dd8b 100644 --- a/src/literal_string.cpp +++ b/src/literal_string.cpp @@ -10,9 +10,8 @@ namespace Sirit { -LiteralString::LiteralString(std::string string) : string{std::move(string)} { - operand_type = OperandType::String; -} +LiteralString::LiteralString(std::string string) + : Operand{OperandType::String}, string{std::move(string)} {} LiteralString::~LiteralString() = default; @@ -25,7 +24,7 @@ u16 LiteralString::GetWordCount() const { } bool LiteralString::operator==(const Operand& other) const { - if (operand_type == other.GetType()) { + if (GetType() == other.GetType()) { return static_cast(other).string == string; } return false; diff --git a/src/op.cpp b/src/op.cpp index f48316b..8c387c9 100644 --- a/src/op.cpp +++ b/src/op.cpp @@ -16,9 +16,7 @@ namespace Sirit { Op::Op(spv::Op opcode, std::optional id, Id result_type) - : opcode(opcode), result_type(result_type), id(id) { - operand_type = OperandType::Op; -} + : Operand{OperandType::Op}, opcode(opcode), result_type(result_type), id(id) {} Op::~Op() = default; @@ -32,7 +30,7 @@ u16 Op::GetWordCount() const { } bool Op::operator==(const Operand& other) const { - if (operand_type != other.GetType()) { + if (GetType() != other.GetType()) { return false; } const auto& op = static_cast(other); diff --git a/src/operand.cpp b/src/operand.cpp index 1a929b8..e52b4e4 100644 --- a/src/operand.cpp +++ b/src/operand.cpp @@ -9,7 +9,7 @@ namespace Sirit { -Operand::Operand() = default; +Operand::Operand(OperandType operand_type) : operand_type{operand_type} {} Operand::~Operand() = default; diff --git a/src/operand.h b/src/operand.h index 008d30b..4367ce5 100644 --- a/src/operand.h +++ b/src/operand.h @@ -14,7 +14,7 @@ enum class OperandType { Invalid, Op, Number, String }; class Operand { public: - Operand(); + explicit Operand(OperandType operand_type); virtual ~Operand(); virtual void Fetch(Stream& stream) const; @@ -25,7 +25,7 @@ public: OperandType GetType() const; -protected: +private: OperandType operand_type{}; };