2019-05-25 12:59:12 +00:00
|
|
|
|
|
|
|
#include "EvalValues/NumericEvalValue.hpp"
|
|
|
|
#include "Evaluator.hpp"
|
|
|
|
#include "EvaluationException.hpp"
|
|
|
|
#include "../Script.hpp"
|
|
|
|
|
2019-06-01 19:38:39 +00:00
|
|
|
shared_ptr<NumericEvalValue> Evaluator::EvaluateIntegerUnary(BoundUnaryExpression *expression) {
|
2019-05-25 12:59:12 +00:00
|
|
|
switch (expression->GetOperation()){
|
|
|
|
case BoundUnaryOperation::Negation:
|
|
|
|
{
|
|
|
|
auto operandValue = EvaluateIntegerExpression(expression->GetOperand());
|
|
|
|
if (operandValue->IsFloat()){
|
|
|
|
double f = operandValue->EvaluateFloat();
|
2019-06-01 19:38:39 +00:00
|
|
|
return make_shared<FloatEvalValue>(-f);
|
2019-05-25 12:59:12 +00:00
|
|
|
} else{
|
|
|
|
long l = operandValue->EvaluateInteger();
|
2019-06-01 19:38:39 +00:00
|
|
|
return make_shared<IntegerEvalValue>(-l);
|
2019-05-25 12:59:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
case BoundUnaryOperation::LogicalNegation:
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-01 19:38:39 +00:00
|
|
|
shared_ptr<BooleanEvalValue> Evaluator::EvaluateBooleanUnary(BoundUnaryExpression *expression) {
|
2019-05-25 12:59:12 +00:00
|
|
|
switch (expression->GetOperation()){
|
|
|
|
case BoundUnaryOperation::LogicalNegation:
|
|
|
|
{
|
|
|
|
auto val = EvaluateBoolExpression(expression->GetOperand());
|
|
|
|
bool b = val->EvaluateBool();
|
2019-06-01 19:38:39 +00:00
|
|
|
return make_shared<BooleanEvalValue>(!b);
|
2019-05-25 12:59:12 +00:00
|
|
|
}
|
|
|
|
case BoundUnaryOperation::Negation:
|
|
|
|
throw;
|
|
|
|
}
|
2019-05-29 12:55:03 +00:00
|
|
|
}
|