Mark evalValues as const
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2019-06-17 17:43:54 +02:00
parent d91caa7f32
commit 21d3329c55
14 changed files with 204 additions and 215 deletions

View File

@@ -5,31 +5,25 @@
#include "EvalValues/NumericEvalValue.hpp"
#include "EvalValues/StringEvalValue.hpp"
shared_ptr<NumericEvalValue> Evaluator::EvaluateIntegerBinary(const BoundBinaryExpression *expression) {
const shared_ptr<NumericEvalValue> Evaluator::EvaluateIntegerBinary(const BoundBinaryExpression *expression) {
auto leftValue = this -> EvaluateIntegerExpression(expression->GetLeft());
auto rightValue = this -> EvaluateIntegerExpression(expression->GetRight());
NumericEvalValue* result;
switch (expression->GetOperation()){
case BoundBinaryOperation ::Addition:
result = leftValue.get() -> operator+ (rightValue.get());
break;
return leftValue.get() -> operator+ (rightValue);
case BoundBinaryOperation::Subtraction:
result = leftValue.get() -> operator- (rightValue.get());
break;
return leftValue.get() -> operator- (rightValue);
case BoundBinaryOperation::Multiplication:
result = leftValue.get() -> operator* (rightValue.get());
break;
return leftValue.get() -> operator* (rightValue);
case BoundBinaryOperation::Division:
result = leftValue.get() -> operator/ (rightValue.get());
break;
return leftValue.get() -> operator/ (rightValue);
default:
throw EvaluationException("Can't evaluate operation to numeric");
}
return shared_ptr<NumericEvalValue>(result);
}
shared_ptr<BooleanEvalValue> Evaluator::EvaluateBooleanBinary(const BoundBinaryExpression* expression){
const shared_ptr<BooleanEvalValue> Evaluator::EvaluateBooleanBinary(const BoundBinaryExpression *expression){
switch (expression->GetOperation()){
case BoundBinaryOperation::Equality:
{
@@ -49,29 +43,25 @@ shared_ptr<BooleanEvalValue> Evaluator::EvaluateBooleanBinary(const BoundBinaryE
{
auto leftValue = this -> EvaluateIntegerExpression(expression->GetLeft());
auto rightValue = this -> EvaluateIntegerExpression(expression->GetRight());
BooleanEvalValue* b = leftValue->operator<(rightValue.get());
return shared_ptr<BooleanEvalValue>(b);
return leftValue->operator<(rightValue);
}
case BoundBinaryOperation ::LessThanEquals:
{
auto leftValue = this -> EvaluateIntegerExpression(expression->GetLeft());
auto rightValue = this -> EvaluateIntegerExpression(expression->GetRight());
BooleanEvalValue* b = leftValue->operator<=(rightValue.get());
return shared_ptr<BooleanEvalValue>(b);
return leftValue->operator<=(rightValue);
}
case BoundBinaryOperation ::GreaterThan:
{
auto leftValue = this -> EvaluateIntegerExpression(expression->GetLeft());
auto rightValue = this -> EvaluateIntegerExpression(expression->GetRight());
BooleanEvalValue* b = leftValue->operator>(rightValue.get());
return shared_ptr<BooleanEvalValue>(b);
return leftValue->operator>(rightValue);
}
case BoundBinaryOperation ::GreaterThanEquals:
{
auto leftValue = this -> EvaluateIntegerExpression(expression->GetLeft());
auto rightValue = this -> EvaluateIntegerExpression(expression->GetRight());
BooleanEvalValue* b = leftValue->operator>=(rightValue.get());
return shared_ptr<BooleanEvalValue>(b);
return leftValue->operator>=(rightValue);
}
case BoundBinaryOperation::LogicalAnd:
@@ -93,13 +83,13 @@ shared_ptr<BooleanEvalValue> Evaluator::EvaluateBooleanBinary(const BoundBinaryE
}
}
shared_ptr<StringEvalValue> Evaluator::EvaluateStringBinary(const BoundBinaryExpression* expression){
const shared_ptr<StringEvalValue> Evaluator::EvaluateStringBinary(const BoundBinaryExpression *expression){
if (expression->GetOperation() != BoundBinaryOperation::Concatenation)
throw;
std::basic_ostringstream<char16_t > strs;
std::basic_ostringstream<char16_t > stringStream;
auto left = this -> EvaluateStringExpression(expression->GetLeft());
strs << *left->EvaluateString();
stringStream << *left->EvaluateString();
auto right = this -> EvaluateExpression(expression->GetRight());
strs << *right->EvaluateString();
return make_shared<StringEvalValue>(strs.str());
stringStream << *right->EvaluateString();
return make_shared<StringEvalValue>(stringStream.str());
}