Implemented comparison equality operators

This commit is contained in:
2019-06-08 15:38:08 +02:00
parent fc66c15c2f
commit 7d75131822
10 changed files with 274 additions and 0 deletions

View File

@@ -45,6 +45,35 @@ shared_ptr<BooleanEvalValue> Evaluator::EvaluateBooleanBinary(BoundBinaryExpress
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());
BooleanEvalValue* b = leftValue->operator<(rightValue.get());
return shared_ptr<BooleanEvalValue>(b);
}
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);
}
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);
}
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);
}
case BoundBinaryOperation::LogicalAnd:
{
auto leftValue = this -> EvaluateBoolExpression(expression->GetLeft());

View File

@@ -78,3 +78,67 @@ bool NumericEvalValue::operator==(EvalValue *b) {
return this->EvaluateInteger() == numVal->EvaluateInteger();
}
}
BooleanEvalValue *NumericEvalValue::operator<(NumericEvalValue *b) {
if (this->IsFloat()){
if (b->IsFloat()){
return new BooleanEvalValue(this->GetFloatValue() < b->GetFloatValue());
} else{
return new BooleanEvalValue(this->GetFloatValue() < b->GetIntegerValue());
}
} else {
if (b->IsFloat()){
return new BooleanEvalValue(this->GetIntegerValue() < b->GetFloatValue());
} else{
return new BooleanEvalValue(this->GetIntegerValue() < b->GetIntegerValue());
}
}
}
BooleanEvalValue *NumericEvalValue::operator<=(NumericEvalValue *b) {
if (this->IsFloat()){
if (b->IsFloat()){
return new BooleanEvalValue(this->GetFloatValue() <= b->GetFloatValue());
} else{
return new BooleanEvalValue(this->GetFloatValue() <= b->GetIntegerValue());
}
} else {
if (b->IsFloat()){
return new BooleanEvalValue(this->GetIntegerValue() <= b->GetFloatValue());
} else{
return new BooleanEvalValue(this->GetIntegerValue() <= b->GetIntegerValue());
}
}
}
BooleanEvalValue *NumericEvalValue::operator>(NumericEvalValue *b) {
if (this->IsFloat()){
if (b->IsFloat()){
return new BooleanEvalValue(this->GetFloatValue() > b->GetFloatValue());
} else{
return new BooleanEvalValue(this->GetFloatValue() > b->GetIntegerValue());
}
} else {
if (b->IsFloat()){
return new BooleanEvalValue(this->GetIntegerValue() > b->GetFloatValue());
} else{
return new BooleanEvalValue(this->GetIntegerValue() > b->GetIntegerValue());
}
}
}
BooleanEvalValue *NumericEvalValue::operator>=(NumericEvalValue *b) {
if (this->IsFloat()){
if (b->IsFloat()){
return new BooleanEvalValue(this->GetFloatValue() >= b->GetFloatValue());
} else{
return new BooleanEvalValue(this->GetFloatValue() >= b->GetIntegerValue());
}
} else {
if (b->IsFloat()){
return new BooleanEvalValue(this->GetIntegerValue() >= b->GetFloatValue());
} else{
return new BooleanEvalValue(this->GetIntegerValue() >= b->GetIntegerValue());
}
}
}

View File

@@ -22,6 +22,10 @@ public:
NumericEvalValue* operator -(NumericEvalValue* b);
NumericEvalValue* operator *(NumericEvalValue* b);
NumericEvalValue* operator /(NumericEvalValue* b);
BooleanEvalValue* operator <(NumericEvalValue* b);
BooleanEvalValue* operator <=(NumericEvalValue* b);
BooleanEvalValue* operator >(NumericEvalValue* b);
BooleanEvalValue* operator >=(NumericEvalValue* b);
bool operator ==(EvalValue* b) final;
};