sirit/src/literal_number.cpp

37 lines
942 B
C++
Raw Normal View History

2018-08-28 07:16:52 +00: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
* Lesser General Public License version 2.1 or any later version.
*/
#include "literal_number.h"
2018-10-03 03:32:45 +00:00
#include <cassert>
2018-08-28 07:16:52 +00:00
namespace Sirit {
2018-10-03 03:32:45 +00:00
LiteralNumber::LiteralNumber(std::type_index type) : type(type) {
2018-08-28 07:16:52 +00:00
operand_type = OperandType::Number;
}
LiteralNumber::~LiteralNumber() = default;
void LiteralNumber::Fetch(Stream& stream) const {
2018-10-03 03:32:45 +00:00
if (is_32) {
stream.Write(static_cast<u32>(raw));
} else {
stream.Write(raw);
2018-08-28 07:16:52 +00:00
}
}
2018-10-03 03:32:45 +00:00
u16 LiteralNumber::GetWordCount() const { return is_32 ? 1 : 2; }
2018-08-28 07:16:52 +00: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