diff options
| author | Bicker <bickerkards@tuta.io> | 2019-05-22 17:45:37 +0200 |
|---|---|---|
| committer | Bicker <bickerkards@tuta.io> | 2019-05-22 17:45:37 +0200 |
| commit | 25314fd2aed81aa5281bc3d93dbcc7919368ebe1 (patch) | |
| tree | 1995521ee652e419926de5fced0f2e3b655e70fb /ql/ast/nodes/expressions/binary_operators/subtraction_operator.py | |
Diffstat (limited to 'ql/ast/nodes/expressions/binary_operators/subtraction_operator.py')
| -rw-r--r-- | ql/ast/nodes/expressions/binary_operators/subtraction_operator.py | 27 |
1 files changed, 27 insertions, 0 deletions
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 |