From 25314fd2aed81aa5281bc3d93dbcc7919368ebe1 Mon Sep 17 00:00:00 2001 From: Bicker Date: Wed, 22 May 2019 17:45:37 +0200 Subject: Initial commit --- .../__pycache__/addition_operator.cpython-35.pyc | Bin 0 -> 1523 bytes .../__pycache__/and_operator.cpython-35.pyc | Bin 0 -> 1325 bytes .../__pycache__/binary_operator.cpython-35.pyc | Bin 0 -> 1117 bytes .../__pycache__/division_operator.cpython-35.pyc | Bin 0 -> 1604 bytes .../__pycache__/equals_operator.cpython-35.pyc | Bin 0 -> 1142 bytes .../greater_equals_operator.cpython-35.pyc | Bin 0 -> 1626 bytes .../greater_than_operator.cpython-35.pyc | Bin 0 -> 1614 bytes .../less_equals_operator.cpython-35.pyc | Bin 0 -> 1608 bytes .../__pycache__/less_than_operator.cpython-35.pyc | Bin 0 -> 1596 bytes .../multiplication_operator.cpython-35.pyc | Bin 0 -> 1601 bytes .../__pycache__/not_equals_operator.cpython-35.pyc | Bin 0 -> 1158 bytes .../__pycache__/or_operator.cpython-35.pyc | Bin 0 -> 1319 bytes .../subtraction_operator.cpython-35.pyc | Bin 0 -> 1541 bytes .../binary_operators/addition_operator.py | 27 ++++++++++++++++++ .../expressions/binary_operators/and_operator.py | 21 ++++++++++++++ .../binary_operators/binary_operator.py | 17 +++++++++++ .../binary_operators/division_operator.py | 31 +++++++++++++++++++++ .../binary_operators/equals_operator.py | 15 ++++++++++ .../binary_operators/greater_equals_operator.py | 30 ++++++++++++++++++++ .../binary_operators/greater_than_operator.py | 30 ++++++++++++++++++++ .../binary_operators/less_equals_operator.py | 30 ++++++++++++++++++++ .../binary_operators/less_than_operator.py | 30 ++++++++++++++++++++ .../binary_operators/multiplication_operator.py | 30 ++++++++++++++++++++ .../binary_operators/not_equals_operator.py | 15 ++++++++++ .../expressions/binary_operators/or_operator.py | 21 ++++++++++++++ .../binary_operators/subtraction_operator.py | 27 ++++++++++++++++++ 26 files changed, 324 insertions(+) create mode 100644 ql/ast/nodes/expressions/binary_operators/__pycache__/addition_operator.cpython-35.pyc create mode 100644 ql/ast/nodes/expressions/binary_operators/__pycache__/and_operator.cpython-35.pyc create mode 100644 ql/ast/nodes/expressions/binary_operators/__pycache__/binary_operator.cpython-35.pyc create mode 100644 ql/ast/nodes/expressions/binary_operators/__pycache__/division_operator.cpython-35.pyc create mode 100644 ql/ast/nodes/expressions/binary_operators/__pycache__/equals_operator.cpython-35.pyc create mode 100644 ql/ast/nodes/expressions/binary_operators/__pycache__/greater_equals_operator.cpython-35.pyc create mode 100644 ql/ast/nodes/expressions/binary_operators/__pycache__/greater_than_operator.cpython-35.pyc create mode 100644 ql/ast/nodes/expressions/binary_operators/__pycache__/less_equals_operator.cpython-35.pyc create mode 100644 ql/ast/nodes/expressions/binary_operators/__pycache__/less_than_operator.cpython-35.pyc create mode 100644 ql/ast/nodes/expressions/binary_operators/__pycache__/multiplication_operator.cpython-35.pyc create mode 100644 ql/ast/nodes/expressions/binary_operators/__pycache__/not_equals_operator.cpython-35.pyc create mode 100644 ql/ast/nodes/expressions/binary_operators/__pycache__/or_operator.cpython-35.pyc create mode 100644 ql/ast/nodes/expressions/binary_operators/__pycache__/subtraction_operator.cpython-35.pyc create mode 100644 ql/ast/nodes/expressions/binary_operators/addition_operator.py create mode 100644 ql/ast/nodes/expressions/binary_operators/and_operator.py create mode 100644 ql/ast/nodes/expressions/binary_operators/binary_operator.py create mode 100644 ql/ast/nodes/expressions/binary_operators/division_operator.py create mode 100644 ql/ast/nodes/expressions/binary_operators/equals_operator.py create mode 100644 ql/ast/nodes/expressions/binary_operators/greater_equals_operator.py create mode 100644 ql/ast/nodes/expressions/binary_operators/greater_than_operator.py create mode 100644 ql/ast/nodes/expressions/binary_operators/less_equals_operator.py create mode 100644 ql/ast/nodes/expressions/binary_operators/less_than_operator.py create mode 100644 ql/ast/nodes/expressions/binary_operators/multiplication_operator.py create mode 100644 ql/ast/nodes/expressions/binary_operators/not_equals_operator.py create mode 100644 ql/ast/nodes/expressions/binary_operators/or_operator.py create mode 100644 ql/ast/nodes/expressions/binary_operators/subtraction_operator.py (limited to 'ql/ast/nodes/expressions/binary_operators') diff --git a/ql/ast/nodes/expressions/binary_operators/__pycache__/addition_operator.cpython-35.pyc b/ql/ast/nodes/expressions/binary_operators/__pycache__/addition_operator.cpython-35.pyc new file mode 100644 index 0000000..bbc8130 Binary files /dev/null and b/ql/ast/nodes/expressions/binary_operators/__pycache__/addition_operator.cpython-35.pyc differ diff --git a/ql/ast/nodes/expressions/binary_operators/__pycache__/and_operator.cpython-35.pyc b/ql/ast/nodes/expressions/binary_operators/__pycache__/and_operator.cpython-35.pyc new file mode 100644 index 0000000..f004296 Binary files /dev/null and b/ql/ast/nodes/expressions/binary_operators/__pycache__/and_operator.cpython-35.pyc differ diff --git a/ql/ast/nodes/expressions/binary_operators/__pycache__/binary_operator.cpython-35.pyc b/ql/ast/nodes/expressions/binary_operators/__pycache__/binary_operator.cpython-35.pyc new file mode 100644 index 0000000..18d3fc0 Binary files /dev/null and b/ql/ast/nodes/expressions/binary_operators/__pycache__/binary_operator.cpython-35.pyc differ diff --git a/ql/ast/nodes/expressions/binary_operators/__pycache__/division_operator.cpython-35.pyc b/ql/ast/nodes/expressions/binary_operators/__pycache__/division_operator.cpython-35.pyc new file mode 100644 index 0000000..9cd8e0a Binary files /dev/null and b/ql/ast/nodes/expressions/binary_operators/__pycache__/division_operator.cpython-35.pyc differ diff --git a/ql/ast/nodes/expressions/binary_operators/__pycache__/equals_operator.cpython-35.pyc b/ql/ast/nodes/expressions/binary_operators/__pycache__/equals_operator.cpython-35.pyc new file mode 100644 index 0000000..5d48766 Binary files /dev/null and b/ql/ast/nodes/expressions/binary_operators/__pycache__/equals_operator.cpython-35.pyc differ diff --git a/ql/ast/nodes/expressions/binary_operators/__pycache__/greater_equals_operator.cpython-35.pyc b/ql/ast/nodes/expressions/binary_operators/__pycache__/greater_equals_operator.cpython-35.pyc new file mode 100644 index 0000000..888c85c Binary files /dev/null and b/ql/ast/nodes/expressions/binary_operators/__pycache__/greater_equals_operator.cpython-35.pyc differ diff --git a/ql/ast/nodes/expressions/binary_operators/__pycache__/greater_than_operator.cpython-35.pyc b/ql/ast/nodes/expressions/binary_operators/__pycache__/greater_than_operator.cpython-35.pyc new file mode 100644 index 0000000..be0e395 Binary files /dev/null and b/ql/ast/nodes/expressions/binary_operators/__pycache__/greater_than_operator.cpython-35.pyc differ diff --git a/ql/ast/nodes/expressions/binary_operators/__pycache__/less_equals_operator.cpython-35.pyc b/ql/ast/nodes/expressions/binary_operators/__pycache__/less_equals_operator.cpython-35.pyc new file mode 100644 index 0000000..b7e8155 Binary files /dev/null and b/ql/ast/nodes/expressions/binary_operators/__pycache__/less_equals_operator.cpython-35.pyc differ diff --git a/ql/ast/nodes/expressions/binary_operators/__pycache__/less_than_operator.cpython-35.pyc b/ql/ast/nodes/expressions/binary_operators/__pycache__/less_than_operator.cpython-35.pyc new file mode 100644 index 0000000..850a39c Binary files /dev/null and b/ql/ast/nodes/expressions/binary_operators/__pycache__/less_than_operator.cpython-35.pyc differ diff --git a/ql/ast/nodes/expressions/binary_operators/__pycache__/multiplication_operator.cpython-35.pyc b/ql/ast/nodes/expressions/binary_operators/__pycache__/multiplication_operator.cpython-35.pyc new file mode 100644 index 0000000..ff0e1ab Binary files /dev/null and b/ql/ast/nodes/expressions/binary_operators/__pycache__/multiplication_operator.cpython-35.pyc differ diff --git a/ql/ast/nodes/expressions/binary_operators/__pycache__/not_equals_operator.cpython-35.pyc b/ql/ast/nodes/expressions/binary_operators/__pycache__/not_equals_operator.cpython-35.pyc new file mode 100644 index 0000000..fe666cf Binary files /dev/null and b/ql/ast/nodes/expressions/binary_operators/__pycache__/not_equals_operator.cpython-35.pyc differ diff --git a/ql/ast/nodes/expressions/binary_operators/__pycache__/or_operator.cpython-35.pyc b/ql/ast/nodes/expressions/binary_operators/__pycache__/or_operator.cpython-35.pyc new file mode 100644 index 0000000..0b81fc3 Binary files /dev/null and b/ql/ast/nodes/expressions/binary_operators/__pycache__/or_operator.cpython-35.pyc differ diff --git a/ql/ast/nodes/expressions/binary_operators/__pycache__/subtraction_operator.cpython-35.pyc b/ql/ast/nodes/expressions/binary_operators/__pycache__/subtraction_operator.cpython-35.pyc new file mode 100644 index 0000000..cd89879 Binary files /dev/null and b/ql/ast/nodes/expressions/binary_operators/__pycache__/subtraction_operator.cpython-35.pyc differ diff --git a/ql/ast/nodes/expressions/binary_operators/addition_operator.py b/ql/ast/nodes/expressions/binary_operators/addition_operator.py new file mode 100644 index 0000000..d6e4506 --- /dev/null +++ b/ql/ast/nodes/expressions/binary_operators/addition_operator.py @@ -0,0 +1,27 @@ +from ql.ast.nodes.expressions.binary_operators.binary_operator import BinaryOperatorNode +from ql.types.decimal import QLDecimal +from ql.types.integer import QLInteger +from ql.types.money import QLMoney +from ql.types.undefined import QLUndefined + + +class AdditionOperatorNode(BinaryOperatorNode): + def __init__(self, metadata, expression_type, left_expression, right_expression, value): + super(AdditionOperatorNode, self).__init__(metadata, expression_type, + left_expression, right_expression, value) + self.__valid_types = { + (QLDecimal, QLDecimal): QLDecimal, + (QLDecimal, QLInteger): QLDecimal, + (QLInteger, QLInteger): QLInteger, + (QLInteger, QLDecimal): QLDecimal, + (QLMoney, QLMoney): QLMoney, + } + + def get_result_type(self): + if self.__valid_types.get((self.left_expression.expression_type, self.right_expression.expression_type)): + return self.__valid_types.get((self.left_expression.expression_type, self.right_expression.expression_type)) + + return QLUndefined + + def evaluate(self): + self.value = self.left_expression.value + self.right_expression.value diff --git a/ql/ast/nodes/expressions/binary_operators/and_operator.py b/ql/ast/nodes/expressions/binary_operators/and_operator.py new file mode 100644 index 0000000..5981a6b --- /dev/null +++ b/ql/ast/nodes/expressions/binary_operators/and_operator.py @@ -0,0 +1,21 @@ +from ql.ast.nodes.expressions.binary_operators.binary_operator import BinaryOperatorNode +from ql.types.boolean import QLBoolean +from ql.types.undefined import QLUndefined + + +class AndOperatorNode(BinaryOperatorNode): + def __init__(self, metadata, expression_type, left_expression, right_expression, value): + super(AndOperatorNode, self).__init__(metadata, expression_type, + left_expression, right_expression, value) + self.__valid_types = { + (QLBoolean, QLBoolean): QLBoolean, + } + + def get_result_type(self): + if self.__valid_types.get((self.left_expression.expression_type, self.right_expression.expression_type)): + return self.__valid_types.get((self.left_expression.expression_type, self.right_expression.expression_type)) + + return QLUndefined + + def evaluate(self): + self.value = self.left_expression.value and self.right_expression.value diff --git a/ql/ast/nodes/expressions/binary_operators/binary_operator.py b/ql/ast/nodes/expressions/binary_operators/binary_operator.py new file mode 100644 index 0000000..048d927 --- /dev/null +++ b/ql/ast/nodes/expressions/binary_operators/binary_operator.py @@ -0,0 +1,17 @@ +from ql.ast.nodes.expressions.expression import ExpressionNode + + +class BinaryOperatorNode(ExpressionNode): + def __init__(self, metadata, expression_type, left_expression, right_expression, value): + super(BinaryOperatorNode, self).__init__(metadata, expression_type, value) + self.__left_expression = left_expression + self.__right_expression = right_expression + + @property + def left_expression(self): + return self.__left_expression + + @property + def right_expression(self): + return self.__right_expression + diff --git a/ql/ast/nodes/expressions/binary_operators/division_operator.py b/ql/ast/nodes/expressions/binary_operators/division_operator.py new file mode 100644 index 0000000..16d5063 --- /dev/null +++ b/ql/ast/nodes/expressions/binary_operators/division_operator.py @@ -0,0 +1,31 @@ +from ql.ast.nodes.expressions.binary_operators.binary_operator import BinaryOperatorNode +from ql.types.decimal import QLDecimal +from ql.types.integer import QLInteger +from ql.types.money import QLMoney +from ql.types.undefined import QLUndefined + + +class DivisionOperatorNode(BinaryOperatorNode): + def __init__(self, metadata, expression_type, left_expression, right_expression, value): + super(DivisionOperatorNode, self).__init__(metadata, expression_type, + left_expression, right_expression, value) + self.__valid_types = { + (QLDecimal, QLDecimal): QLDecimal, + (QLDecimal, QLInteger): QLDecimal, + (QLInteger, QLInteger): QLDecimal, + (QLInteger, QLDecimal): QLDecimal, + (QLMoney, QLDecimal): QLMoney, + (QLMoney, QLInteger): QLMoney, + } + + def get_result_type(self): + if self.__valid_types.get((self.left_expression.expression_type, self.right_expression.expression_type)): + return self.__valid_types.get((self.left_expression.expression_type, self.right_expression.expression_type)) + + return QLUndefined + + def evaluate(self): + try: + self.value = self.left_expression.value / self.right_expression.value + except ZeroDivisionError: + self.value = QLUndefined() diff --git a/ql/ast/nodes/expressions/binary_operators/equals_operator.py b/ql/ast/nodes/expressions/binary_operators/equals_operator.py new file mode 100644 index 0000000..21315f9 --- /dev/null +++ b/ql/ast/nodes/expressions/binary_operators/equals_operator.py @@ -0,0 +1,15 @@ +from ql.ast.nodes.expressions.binary_operators.binary_operator import BinaryOperatorNode +from ql.types.boolean import QLBoolean + + +class EqualsOperatorNode(BinaryOperatorNode): + def __init__(self, metadata, expression_type, left_expression, right_expression, value): + super(EqualsOperatorNode, self).__init__(metadata, expression_type, + left_expression, right_expression, value) + + @staticmethod + def get_result_type(): + return QLBoolean + + def evaluate(self): + self.value = self.left_expression.value == self.right_expression.value diff --git a/ql/ast/nodes/expressions/binary_operators/greater_equals_operator.py b/ql/ast/nodes/expressions/binary_operators/greater_equals_operator.py new file mode 100644 index 0000000..0512688 --- /dev/null +++ b/ql/ast/nodes/expressions/binary_operators/greater_equals_operator.py @@ -0,0 +1,30 @@ +from ql.ast.nodes.expressions.binary_operators.binary_operator import BinaryOperatorNode +from ql.types.boolean import QLBoolean +from ql.types.date import QLDate +from ql.types.decimal import QLDecimal +from ql.types.integer import QLInteger +from ql.types.money import QLMoney +from ql.types.undefined import QLUndefined + + +class GreaterEqualsOperatorNode(BinaryOperatorNode): + def __init__(self, metadata, expression_type, left_expression, right_expression, value): + super(GreaterEqualsOperatorNode, self).__init__(metadata, expression_type, + left_expression, right_expression, value) + self.__valid_types = [ + (QLDate, QLDate), + (QLDecimal, QLDecimal), + (QLDecimal, QLInteger), + (QLInteger, QLInteger), + (QLInteger, QLDecimal), + (QLMoney, QLMoney), + ] + + def get_result_type(self): + if (self.left_expression.expression_type, self.right_expression.expression_type) in self.__valid_types: + return QLBoolean + + return QLUndefined + + def evaluate(self): + self.value = self.left_expression.value >= self.right_expression.value diff --git a/ql/ast/nodes/expressions/binary_operators/greater_than_operator.py b/ql/ast/nodes/expressions/binary_operators/greater_than_operator.py new file mode 100644 index 0000000..460c909 --- /dev/null +++ b/ql/ast/nodes/expressions/binary_operators/greater_than_operator.py @@ -0,0 +1,30 @@ +from ql.ast.nodes.expressions.binary_operators.binary_operator import BinaryOperatorNode +from ql.types.boolean import QLBoolean +from ql.types.date import QLDate +from ql.types.decimal import QLDecimal +from ql.types.integer import QLInteger +from ql.types.money import QLMoney +from ql.types.undefined import QLUndefined + + +class GreaterThanOperatorNode(BinaryOperatorNode): + def __init__(self, metadata, expression_type, left_expression, right_expression, value): + super(GreaterThanOperatorNode, self).__init__(metadata, expression_type, + left_expression, right_expression, value) + self.__valid_types = [ + (QLDate, QLDate), + (QLDecimal, QLDecimal), + (QLDecimal, QLInteger), + (QLInteger, QLInteger), + (QLInteger, QLDecimal), + (QLMoney, QLMoney), + ] + + def get_result_type(self): + if (self.left_expression.expression_type, self.right_expression.expression_type) in self.__valid_types: + return QLBoolean + + return QLUndefined + + def evaluate(self): + self.value = self.left_expression.value > self.right_expression.value diff --git a/ql/ast/nodes/expressions/binary_operators/less_equals_operator.py b/ql/ast/nodes/expressions/binary_operators/less_equals_operator.py new file mode 100644 index 0000000..f5b86df --- /dev/null +++ b/ql/ast/nodes/expressions/binary_operators/less_equals_operator.py @@ -0,0 +1,30 @@ +from ql.ast.nodes.expressions.binary_operators.binary_operator import BinaryOperatorNode +from ql.types.boolean import QLBoolean +from ql.types.date import QLDate +from ql.types.decimal import QLDecimal +from ql.types.integer import QLInteger +from ql.types.money import QLMoney +from ql.types.undefined import QLUndefined + + +class LessEqualsOperatorNode(BinaryOperatorNode): + def __init__(self, metadata, expression_type, left_expression, right_expression, value): + super(LessEqualsOperatorNode, self).__init__(metadata, expression_type, + left_expression, right_expression, value) + self.__valid_types = [ + (QLDate, QLDate), + (QLDecimal, QLDecimal), + (QLDecimal, QLInteger), + (QLInteger, QLInteger), + (QLInteger, QLDecimal), + (QLMoney, QLMoney), + ] + + def get_result_type(self): + if (self.left_expression.expression_type, self.right_expression.expression_type) in self.__valid_types: + return QLBoolean + + return QLUndefined + + def evaluate(self): + self.value = self.left_expression.value <= self.right_expression.value diff --git a/ql/ast/nodes/expressions/binary_operators/less_than_operator.py b/ql/ast/nodes/expressions/binary_operators/less_than_operator.py new file mode 100644 index 0000000..65b456d --- /dev/null +++ b/ql/ast/nodes/expressions/binary_operators/less_than_operator.py @@ -0,0 +1,30 @@ +from ql.ast.nodes.expressions.binary_operators.binary_operator import BinaryOperatorNode +from ql.types.boolean import QLBoolean +from ql.types.date import QLDate +from ql.types.decimal import QLDecimal +from ql.types.integer import QLInteger +from ql.types.money import QLMoney +from ql.types.undefined import QLUndefined + + +class LessThanOperatorNode(BinaryOperatorNode): + def __init__(self, metadata, expression_type, left_expression, right_expression, value): + super(LessThanOperatorNode, self).__init__(metadata, expression_type, + left_expression, right_expression, value) + self.__valid_types = [ + (QLDate, QLDate), + (QLDecimal, QLDecimal), + (QLDecimal, QLInteger), + (QLInteger, QLInteger), + (QLInteger, QLDecimal), + (QLMoney, QLMoney), + ] + + def get_result_type(self): + if (self.left_expression.expression_type, self.right_expression.expression_type) in self.__valid_types: + return QLBoolean + + return QLUndefined + + def evaluate(self): + self.value = self.left_expression.value < self.right_expression.value diff --git a/ql/ast/nodes/expressions/binary_operators/multiplication_operator.py b/ql/ast/nodes/expressions/binary_operators/multiplication_operator.py new file mode 100644 index 0000000..b014c0e --- /dev/null +++ b/ql/ast/nodes/expressions/binary_operators/multiplication_operator.py @@ -0,0 +1,30 @@ +from ql.ast.nodes.expressions.binary_operators.binary_operator import BinaryOperatorNode +from ql.types.decimal import QLDecimal +from ql.types.integer import QLInteger +from ql.types.money import QLMoney +from ql.types.undefined import QLUndefined + + +class MultiplicationOperatorNode(BinaryOperatorNode): + def __init__(self, metadata, expression_type, left_expression, right_expression, value): + super(MultiplicationOperatorNode, self).__init__(metadata, expression_type, + left_expression, right_expression, value) + self.__valid_types = { + (QLDecimal, QLDecimal): QLDecimal, + (QLDecimal, QLInteger): QLDecimal, + (QLDecimal, QLMoney): QLMoney, + (QLInteger, QLInteger): QLInteger, + (QLInteger, QLDecimal): QLDecimal, + (QLInteger, QLMoney): QLMoney, + (QLMoney, QLDecimal): QLMoney, + (QLMoney, QLInteger): QLMoney, + } + + def get_result_type(self): + if self.__valid_types.get((self.left_expression.expression_type, self.right_expression.expression_type)): + return self.__valid_types.get((self.left_expression.expression_type, self.right_expression.expression_type)) + + return QLUndefined + + def evaluate(self): + self.value = self.left_expression.value * self.right_expression.value diff --git a/ql/ast/nodes/expressions/binary_operators/not_equals_operator.py b/ql/ast/nodes/expressions/binary_operators/not_equals_operator.py new file mode 100644 index 0000000..3be2e5f --- /dev/null +++ b/ql/ast/nodes/expressions/binary_operators/not_equals_operator.py @@ -0,0 +1,15 @@ +from ql.ast.nodes.expressions.binary_operators.binary_operator import BinaryOperatorNode +from ql.types.boolean import QLBoolean + + +class NotEqualsOperatorNode(BinaryOperatorNode): + def __init__(self, metadata, expression_type, left_expression, right_expression, value): + super(NotEqualsOperatorNode, self).__init__(metadata, expression_type, + left_expression, right_expression, value) + + @staticmethod + def get_result_type(): + return QLBoolean + + def evaluate(self): + self.value = self.left_expression.value != self.right_expression.value diff --git a/ql/ast/nodes/expressions/binary_operators/or_operator.py b/ql/ast/nodes/expressions/binary_operators/or_operator.py new file mode 100644 index 0000000..4314868 --- /dev/null +++ b/ql/ast/nodes/expressions/binary_operators/or_operator.py @@ -0,0 +1,21 @@ +from ql.ast.nodes.expressions.binary_operators.binary_operator import BinaryOperatorNode +from ql.types.boolean import QLBoolean +from ql.types.undefined import QLUndefined + + +class OrOperatorNode(BinaryOperatorNode): + def __init__(self, metadata, expression_type, left_expression, right_expression, value): + super(OrOperatorNode, self).__init__(metadata, expression_type, + left_expression, right_expression, value) + self.__valid_types = { + (QLBoolean, QLBoolean): QLBoolean, + } + + def get_result_type(self): + if self.__valid_types.get((self.left_expression.expression_type, self.right_expression.expression_type)): + return self.__valid_types.get((self.left_expression.expression_type, self.right_expression.expression_type)) + + return QLUndefined + + def evaluate(self): + self.value = self.left_expression.value or self.right_expression.value diff --git a/ql/ast/nodes/expressions/binary_operators/subtraction_operator.py b/ql/ast/nodes/expressions/binary_operators/subtraction_operator.py new file mode 100644 index 0000000..8ebda15 --- /dev/null +++ b/ql/ast/nodes/expressions/binary_operators/subtraction_operator.py @@ -0,0 +1,27 @@ +from ql.ast.nodes.expressions.binary_operators.binary_operator import BinaryOperatorNode +from ql.types.decimal import QLDecimal +from ql.types.integer import QLInteger +from ql.types.money import QLMoney +from ql.types.undefined import QLUndefined + + +class SubtractionOperatorNode(BinaryOperatorNode): + def __init__(self, metadata, expression_type, left_expression, right_expression, value): + super(SubtractionOperatorNode, self).__init__(metadata, expression_type, + left_expression, right_expression, value) + self.__valid_types = { + (QLDecimal, QLDecimal): QLDecimal, + (QLDecimal, QLInteger): QLDecimal, + (QLInteger, QLInteger): QLInteger, + (QLInteger, QLDecimal): QLDecimal, + (QLMoney, QLMoney): QLMoney, + } + + def get_result_type(self): + if self.__valid_types.get((self.left_expression.expression_type, self.right_expression.expression_type)): + return self.__valid_types.get((self.left_expression.expression_type, self.right_expression.expression_type)) + + return QLUndefined + + def evaluate(self): + self.value = self.left_expression.value - self.right_expression.value -- cgit v1.2.3