Small optimization for binary binding

This commit is contained in:
Deukhoofd 2019-05-22 12:29:29 +02:00
parent 2cdb9abdb6
commit 9cc5c14b43
No known key found for this signature in database
GPG Key ID: B4C087AC81641654
2 changed files with 28 additions and 13 deletions

View File

@ -70,10 +70,12 @@ BoundExpression* Binder::BindBinaryOperator(BinaryExpression* expression){
auto rightNumeric = (NumericScriptType*)boundRightType;
if (leftNumeric->IsAwareOfFloat() && rightNumeric->IsAwareOfFloat()){
return new BoundBinaryExpression(boundLeft, boundRight,
BoundBinaryOperation::Addition, new NumericScriptType(true, leftNumeric->IsFloat() || rightNumeric->IsFloat()));
BoundBinaryOperation::Addition, new NumericScriptType(true, leftNumeric->IsFloat() || rightNumeric->IsFloat()),
expression->GetStartPosition(), expression->GetLength());
}
else{
return new BoundBinaryExpression(boundLeft, boundRight, BoundBinaryOperation::Addition, new NumericScriptType(false, false));
return new BoundBinaryExpression(boundLeft, boundRight, BoundBinaryOperation::Addition, new NumericScriptType(false, false),
expression->GetStartPosition(), expression->GetLength());
}
}
//TODO: String Concatenation
@ -84,10 +86,13 @@ BoundExpression* Binder::BindBinaryOperator(BinaryExpression* expression){
auto rightNumeric = (NumericScriptType*)boundRightType;
if (leftNumeric->IsAwareOfFloat() && rightNumeric->IsAwareOfFloat()){
return new BoundBinaryExpression(boundLeft, boundRight,
BoundBinaryOperation::Subtraction, new NumericScriptType(true, leftNumeric->IsFloat() || rightNumeric->IsFloat()));
BoundBinaryOperation::Subtraction,
new NumericScriptType(true, leftNumeric->IsFloat() || rightNumeric->IsFloat()),
expression->GetStartPosition(), expression->GetLength());
}
else{
return new BoundBinaryExpression(boundLeft, boundRight, BoundBinaryOperation::Subtraction, new NumericScriptType(false, false));
return new BoundBinaryExpression(boundLeft, boundRight, BoundBinaryOperation::Subtraction, new NumericScriptType(false, false),
expression->GetStartPosition(), expression->GetLength());
}
}
break;
@ -97,10 +102,13 @@ BoundExpression* Binder::BindBinaryOperator(BinaryExpression* expression){
auto rightNumeric = (NumericScriptType*)boundRightType;
if (leftNumeric->IsAwareOfFloat() && rightNumeric->IsAwareOfFloat()){
return new BoundBinaryExpression(boundLeft, boundRight,
BoundBinaryOperation::Multiplication, new NumericScriptType(true, leftNumeric->IsFloat() || rightNumeric->IsFloat()));
BoundBinaryOperation::Multiplication,
new NumericScriptType(true, leftNumeric->IsFloat() || rightNumeric->IsFloat()),
expression->GetStartPosition(), expression->GetLength());
}
else{
return new BoundBinaryExpression(boundLeft, boundRight, BoundBinaryOperation::Multiplication, new NumericScriptType(false, false));
return new BoundBinaryExpression(boundLeft, boundRight, BoundBinaryOperation::Multiplication, new NumericScriptType(false, false),
expression->GetStartPosition(), expression->GetLength());
}
}
break;
@ -110,22 +118,28 @@ BoundExpression* Binder::BindBinaryOperator(BinaryExpression* expression){
auto rightNumeric = (NumericScriptType*)boundRightType;
if (leftNumeric->IsAwareOfFloat() && rightNumeric->IsAwareOfFloat()){
return new BoundBinaryExpression(boundLeft, boundRight,
BoundBinaryOperation::Division, new NumericScriptType(true, leftNumeric->IsFloat() || rightNumeric->IsFloat()));
BoundBinaryOperation::Division,
new NumericScriptType(true, leftNumeric->IsFloat() || rightNumeric->IsFloat()),
expression->GetStartPosition(), expression->GetLength());
}
else{
return new BoundBinaryExpression(boundLeft, boundRight, BoundBinaryOperation::Division, new NumericScriptType(false, false));
return new BoundBinaryExpression(boundLeft, boundRight, BoundBinaryOperation::Division, new NumericScriptType(false, false),
expression->GetStartPosition(), expression->GetLength());
}
}
break;
case BinaryOperatorKind ::Equality:
return new BoundBinaryExpression(boundLeft, boundRight, BoundBinaryOperation::Equality, new ScriptType(TypeClass::Bool));
return new BoundBinaryExpression(boundLeft, boundRight, BoundBinaryOperation::Equality, new ScriptType(TypeClass::Bool),
expression->GetStartPosition(), expression->GetLength());
case BinaryOperatorKind ::LogicalAnd:
if (boundLeftType->GetClass() == TypeClass::Bool && boundRightType->GetClass() == TypeClass::Bool)
return new BoundBinaryExpression(boundLeft, boundRight, BoundBinaryOperation::LogicalAnd, new ScriptType(TypeClass::Bool));
return new BoundBinaryExpression(boundLeft, boundRight, BoundBinaryOperation::LogicalAnd, new ScriptType(TypeClass::Bool),
expression->GetStartPosition(), expression->GetLength());
break;
case BinaryOperatorKind ::LogicalOr:
if (boundLeftType->GetClass() == TypeClass::Bool && boundRightType->GetClass() == TypeClass::Bool)
return new BoundBinaryExpression(boundLeft, boundRight, BoundBinaryOperation::LogicalOr, new ScriptType(TypeClass::Bool));
return new BoundBinaryExpression(boundLeft, boundRight, BoundBinaryOperation::LogicalOr, new ScriptType(TypeClass::Bool),
expression->GetStartPosition(), expression->GetLength());
break;
default:
break;

View File

@ -135,8 +135,9 @@ class BoundBinaryExpression : public BoundExpression {
BoundExpression* _right;
BoundBinaryOperation _operation;
public:
BoundBinaryExpression(BoundExpression* left, BoundExpression* right, BoundBinaryOperation op, ScriptType* result)
: BoundExpression(left->GetStartPosition(), right->GetEndPosition() - left->GetStartPosition(), result){
BoundBinaryExpression(BoundExpression* left, BoundExpression* right, BoundBinaryOperation op, ScriptType* result,
unsigned int start, unsigned int length)
: BoundExpression(start, length, result){
_left = left;
_right = right;
_operation = op;