Small optimization for binary binding
This commit is contained in:
parent
2cdb9abdb6
commit
9cc5c14b43
|
@ -70,10 +70,12 @@ BoundExpression* Binder::BindBinaryOperator(BinaryExpression* expression){
|
||||||
auto rightNumeric = (NumericScriptType*)boundRightType;
|
auto rightNumeric = (NumericScriptType*)boundRightType;
|
||||||
if (leftNumeric->IsAwareOfFloat() && rightNumeric->IsAwareOfFloat()){
|
if (leftNumeric->IsAwareOfFloat() && rightNumeric->IsAwareOfFloat()){
|
||||||
return new BoundBinaryExpression(boundLeft, boundRight,
|
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{
|
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
|
//TODO: String Concatenation
|
||||||
|
@ -84,10 +86,13 @@ BoundExpression* Binder::BindBinaryOperator(BinaryExpression* expression){
|
||||||
auto rightNumeric = (NumericScriptType*)boundRightType;
|
auto rightNumeric = (NumericScriptType*)boundRightType;
|
||||||
if (leftNumeric->IsAwareOfFloat() && rightNumeric->IsAwareOfFloat()){
|
if (leftNumeric->IsAwareOfFloat() && rightNumeric->IsAwareOfFloat()){
|
||||||
return new BoundBinaryExpression(boundLeft, boundRight,
|
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{
|
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;
|
break;
|
||||||
|
@ -97,10 +102,13 @@ BoundExpression* Binder::BindBinaryOperator(BinaryExpression* expression){
|
||||||
auto rightNumeric = (NumericScriptType*)boundRightType;
|
auto rightNumeric = (NumericScriptType*)boundRightType;
|
||||||
if (leftNumeric->IsAwareOfFloat() && rightNumeric->IsAwareOfFloat()){
|
if (leftNumeric->IsAwareOfFloat() && rightNumeric->IsAwareOfFloat()){
|
||||||
return new BoundBinaryExpression(boundLeft, boundRight,
|
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{
|
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;
|
break;
|
||||||
|
@ -110,22 +118,28 @@ BoundExpression* Binder::BindBinaryOperator(BinaryExpression* expression){
|
||||||
auto rightNumeric = (NumericScriptType*)boundRightType;
|
auto rightNumeric = (NumericScriptType*)boundRightType;
|
||||||
if (leftNumeric->IsAwareOfFloat() && rightNumeric->IsAwareOfFloat()){
|
if (leftNumeric->IsAwareOfFloat() && rightNumeric->IsAwareOfFloat()){
|
||||||
return new BoundBinaryExpression(boundLeft, boundRight,
|
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{
|
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;
|
break;
|
||||||
case BinaryOperatorKind ::Equality:
|
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:
|
case BinaryOperatorKind ::LogicalAnd:
|
||||||
if (boundLeftType->GetClass() == TypeClass::Bool && boundRightType->GetClass() == TypeClass::Bool)
|
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;
|
break;
|
||||||
case BinaryOperatorKind ::LogicalOr:
|
case BinaryOperatorKind ::LogicalOr:
|
||||||
if (boundLeftType->GetClass() == TypeClass::Bool && boundRightType->GetClass() == TypeClass::Bool)
|
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;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -135,8 +135,9 @@ class BoundBinaryExpression : public BoundExpression {
|
||||||
BoundExpression* _right;
|
BoundExpression* _right;
|
||||||
BoundBinaryOperation _operation;
|
BoundBinaryOperation _operation;
|
||||||
public:
|
public:
|
||||||
BoundBinaryExpression(BoundExpression* left, BoundExpression* right, BoundBinaryOperation op, ScriptType* result)
|
BoundBinaryExpression(BoundExpression* left, BoundExpression* right, BoundBinaryOperation op, ScriptType* result,
|
||||||
: BoundExpression(left->GetStartPosition(), right->GetEndPosition() - left->GetStartPosition(), result){
|
unsigned int start, unsigned int length)
|
||||||
|
: BoundExpression(start, length, result){
|
||||||
_left = left;
|
_left = left;
|
||||||
_right = right;
|
_right = right;
|
||||||
_operation = op;
|
_operation = op;
|
||||||
|
|
Loading…
Reference in New Issue