sirit/src/literal_number.cpp

39 lines
944 B
C++
Raw Normal View History

2018-08-28 09:16:52 +02:00
/* This file is part of the sirit project.
* Copyright (c) 2018 ReinUsesLisp
* This software may be used and distributed according to the terms of the GNU
2018-11-16 08:10:10 +01:00
* Lesser General Public License version 3 or any later version.
2018-08-28 09:16:52 +02:00
*/
2018-10-03 05:32:45 +02:00
#include <cassert>
2019-03-11 07:26:21 +01:00
#include "literal_number.h"
2018-08-28 09:16:52 +02:00
namespace Sirit {
2018-10-03 05:32:45 +02:00
LiteralNumber::LiteralNumber(std::type_index type) : type(type) {
2018-08-28 09:16:52 +02:00
operand_type = OperandType::Number;
}
LiteralNumber::~LiteralNumber() = default;
void LiteralNumber::Fetch(Stream& stream) const {
2018-10-03 05:32:45 +02:00
if (is_32) {
stream.Write(static_cast<u32>(raw));
} else {
stream.Write(raw);
2018-08-28 09:16:52 +02:00
}
}
2019-03-11 07:26:21 +01:00
u16 LiteralNumber::GetWordCount() const {
return is_32 ? 1 : 2;
}
2018-08-28 09:16:52 +02:00
bool LiteralNumber::operator==(const Operand& other) const {
if (operand_type == other.GetType()) {
const auto& o{dynamic_cast<const LiteralNumber&>(other)};
return o.type == type && o.raw == raw;
}
return false;
}
} // namespace Sirit