Added namespaces to most classes, general cleanup
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2019-06-17 18:35:12 +02:00
parent 21d3329c55
commit fde102d954
66 changed files with 4301 additions and 3909 deletions

View File

@@ -5,91 +5,87 @@
#include "EvalValues/NumericEvalValue.hpp"
#include "EvalValues/StringEvalValue.hpp"
const shared_ptr<NumericEvalValue> Evaluator::EvaluateIntegerBinary(const BoundBinaryExpression *expression) {
auto leftValue = this -> EvaluateIntegerExpression(expression->GetLeft());
auto rightValue = this -> EvaluateIntegerExpression(expression->GetRight());
using namespace Porygon::Binder;
switch (expression->GetOperation()){
case BoundBinaryOperation ::Addition:
return leftValue.get() -> operator+ (rightValue);
case BoundBinaryOperation::Subtraction:
return leftValue.get() -> operator- (rightValue);
case BoundBinaryOperation::Multiplication:
return leftValue.get() -> operator* (rightValue);
case BoundBinaryOperation::Division:
return leftValue.get() -> operator/ (rightValue);
default:
throw EvaluationException("Can't evaluate operation to numeric");
namespace Porygon::Evaluation {
const shared_ptr<NumericEvalValue> Evaluator::EvaluateIntegerBinary(const BoundBinaryExpression *expression) {
auto leftValue = this->EvaluateIntegerExpression(expression->GetLeft());
auto rightValue = this->EvaluateIntegerExpression(expression->GetRight());
switch (expression->GetOperation()) {
case BoundBinaryOperation::Addition:
return leftValue.get()->operator+(rightValue);
case BoundBinaryOperation::Subtraction:
return leftValue.get()->operator-(rightValue);
case BoundBinaryOperation::Multiplication:
return leftValue.get()->operator*(rightValue);
case BoundBinaryOperation::Division:
return leftValue.get()->operator/(rightValue);
default:
throw EvaluationException("Can't evaluate operation to numeric");
}
}
}
const shared_ptr<BooleanEvalValue> Evaluator::EvaluateBooleanBinary(const BoundBinaryExpression *expression){
switch (expression->GetOperation()){
case BoundBinaryOperation::Equality:
{
auto leftValue = this -> EvaluateExpression(expression->GetLeft());
auto rightValue = this -> EvaluateExpression(expression->GetRight());
bool equals = leftValue.get()->operator==(rightValue.get());
return make_shared<BooleanEvalValue>(equals);
}
case BoundBinaryOperation::Inequality:
{
auto leftValue = this -> EvaluateExpression(expression->GetLeft());
auto rightValue = this -> EvaluateExpression(expression->GetRight());
bool equals = leftValue.get()->operator!=(rightValue.get());
return make_shared<BooleanEvalValue>(equals);
}
case BoundBinaryOperation ::LessThan:
{
auto leftValue = this -> EvaluateIntegerExpression(expression->GetLeft());
auto rightValue = this -> EvaluateIntegerExpression(expression->GetRight());
return leftValue->operator<(rightValue);
}
case BoundBinaryOperation ::LessThanEquals:
{
auto leftValue = this -> EvaluateIntegerExpression(expression->GetLeft());
auto rightValue = this -> EvaluateIntegerExpression(expression->GetRight());
return leftValue->operator<=(rightValue);
}
case BoundBinaryOperation ::GreaterThan:
{
auto leftValue = this -> EvaluateIntegerExpression(expression->GetLeft());
auto rightValue = this -> EvaluateIntegerExpression(expression->GetRight());
return leftValue->operator>(rightValue);
}
case BoundBinaryOperation ::GreaterThanEquals:
{
auto leftValue = this -> EvaluateIntegerExpression(expression->GetLeft());
auto rightValue = this -> EvaluateIntegerExpression(expression->GetRight());
return leftValue->operator>=(rightValue);
}
const shared_ptr<BooleanEvalValue> Evaluator::EvaluateBooleanBinary(const BoundBinaryExpression *expression) {
switch (expression->GetOperation()) {
case BoundBinaryOperation::Equality: {
auto leftValue = this->EvaluateExpression(expression->GetLeft());
auto rightValue = this->EvaluateExpression(expression->GetRight());
bool equals = leftValue.get()->operator==(rightValue.get());
return make_shared<BooleanEvalValue>(equals);
}
case BoundBinaryOperation::Inequality: {
auto leftValue = this->EvaluateExpression(expression->GetLeft());
auto rightValue = this->EvaluateExpression(expression->GetRight());
bool equals = leftValue.get()->operator!=(rightValue.get());
return make_shared<BooleanEvalValue>(equals);
}
case BoundBinaryOperation::LessThan: {
auto leftValue = this->EvaluateIntegerExpression(expression->GetLeft());
auto rightValue = this->EvaluateIntegerExpression(expression->GetRight());
return leftValue->operator<(rightValue);
}
case BoundBinaryOperation::LessThanEquals: {
auto leftValue = this->EvaluateIntegerExpression(expression->GetLeft());
auto rightValue = this->EvaluateIntegerExpression(expression->GetRight());
return leftValue->operator<=(rightValue);
}
case BoundBinaryOperation::GreaterThan: {
auto leftValue = this->EvaluateIntegerExpression(expression->GetLeft());
auto rightValue = this->EvaluateIntegerExpression(expression->GetRight());
return leftValue->operator>(rightValue);
}
case BoundBinaryOperation::GreaterThanEquals: {
auto leftValue = this->EvaluateIntegerExpression(expression->GetLeft());
auto rightValue = this->EvaluateIntegerExpression(expression->GetRight());
return leftValue->operator>=(rightValue);
}
case BoundBinaryOperation::LogicalAnd:
{
auto leftValue = this -> EvaluateBoolExpression(expression->GetLeft());
if (!leftValue->EvaluateBool()) return leftValue;
auto rightValue = this -> EvaluateBoolExpression(expression->GetRight());
return rightValue;
case BoundBinaryOperation::LogicalAnd: {
auto leftValue = this->EvaluateBoolExpression(expression->GetLeft());
if (!leftValue->EvaluateBool()) return leftValue;
auto rightValue = this->EvaluateBoolExpression(expression->GetRight());
return rightValue;
}
case BoundBinaryOperation::LogicalOr: {
auto leftValue = this->EvaluateBoolExpression(expression->GetLeft());
if (leftValue->EvaluateBool()) return leftValue;
auto rightValue = this->EvaluateBoolExpression(expression->GetRight());
return rightValue;
}
default:
throw EvaluationException("Can't evaluate operation to boolean");
}
case BoundBinaryOperation::LogicalOr:
{
auto leftValue = this -> EvaluateBoolExpression(expression->GetLeft());
if (leftValue->EvaluateBool()) return leftValue;
auto rightValue = this -> EvaluateBoolExpression(expression->GetRight());
return rightValue;
}
default:
throw EvaluationException("Can't evaluate operation to boolean");
}
}
const shared_ptr<StringEvalValue> Evaluator::EvaluateStringBinary(const BoundBinaryExpression *expression){
if (expression->GetOperation() != BoundBinaryOperation::Concatenation)
throw;
std::basic_ostringstream<char16_t > stringStream;
auto left = this -> EvaluateStringExpression(expression->GetLeft());
stringStream << *left->EvaluateString();
auto right = this -> EvaluateExpression(expression->GetRight());
stringStream << *right->EvaluateString();
return make_shared<StringEvalValue>(stringStream.str());
const shared_ptr<StringEvalValue> Evaluator::EvaluateStringBinary(const BoundBinaryExpression *expression) {
if (expression->GetOperation() != BoundBinaryOperation::Concatenation)
throw;
std::basic_ostringstream<char16_t> stringStream;
auto left = this->EvaluateStringExpression(expression->GetLeft());
stringStream << *left->EvaluateString();
auto right = this->EvaluateExpression(expression->GetRight());
stringStream << *right->EvaluateString();
return make_shared<StringEvalValue>(stringStream.str());
}
}