51 lines
1.7 KiB
C++
51 lines
1.7 KiB
C++
|
|
#ifndef PORYGONLANG_NUMERICEVALVALUE_HPP
|
|
#define PORYGONLANG_NUMERICEVALVALUE_HPP
|
|
|
|
#include <sstream>
|
|
#include <variant>
|
|
#include "EvalValue.hpp"
|
|
#include "../../Utilities/StringUtils.hpp"
|
|
|
|
namespace Porygon::Evaluation {
|
|
class NumericEvalValue : public EvalValue {
|
|
std::variant<int64_t , double> _intValue, _floatValue;
|
|
bool _isFloat;
|
|
public:
|
|
|
|
explicit NumericEvalValue(int64_t i) : _intValue(i), _isFloat(false) {}
|
|
explicit NumericEvalValue(int32_t i) : _intValue(static_cast<int64_t>(i)), _isFloat(false) {}
|
|
explicit NumericEvalValue(double d) : _floatValue(d), _isFloat(true) {}
|
|
explicit NumericEvalValue(float f) : _floatValue(f), _isFloat(true) {}
|
|
|
|
[[nodiscard]]
|
|
virtual bool IsFloat() const{
|
|
return _isFloat;
|
|
}
|
|
|
|
[[nodiscard]]
|
|
inline TypeClass GetTypeClass() const final {
|
|
return TypeClass::Number;
|
|
}
|
|
|
|
bool operator==(const EvalValue *b) const final;
|
|
|
|
bool operator!=(const EvalValue *b) const override {
|
|
return !operator==(b);
|
|
}
|
|
|
|
[[nodiscard]] EvalValue *Clone() const override;
|
|
[[nodiscard]] size_t GetHashCode() const override;
|
|
[[nodiscard]] EvalValue* Cast(shared_ptr<const ScriptType> castType) const final;
|
|
|
|
[[nodiscard]] int64_t EvaluateInteger() const override;
|
|
[[nodiscard]] double EvaluateFloat() const override;
|
|
[[nodiscard]] u16string EvaluateString() const override;
|
|
|
|
[[nodiscard]] EvalValue *BinaryOperation(Binder::BoundBinaryOperation operation, const EvalValue *b) const final;
|
|
[[nodiscard]] EvalValue *UnaryOperation(Binder::BoundUnaryOperation operation) const override;
|
|
};
|
|
}
|
|
|
|
#endif //PORYGONLANG_NUMERICEVALVALUE_HPP
|