aboutsummaryrefslogtreecommitdiff
path: root/ql/ast/nodes/expressions/unary_operators
diff options
context:
space:
mode:
Diffstat (limited to 'ql/ast/nodes/expressions/unary_operators')
-rw-r--r--ql/ast/nodes/expressions/unary_operators/__pycache__/negation_operator.cpython-35.pycbin0 -> 1283 bytes
-rw-r--r--ql/ast/nodes/expressions/unary_operators/__pycache__/negative_operator.cpython-35.pycbin0 -> 1402 bytes
-rw-r--r--ql/ast/nodes/expressions/unary_operators/__pycache__/unary_operator.cpython-35.pycbin0 -> 885 bytes
-rw-r--r--ql/ast/nodes/expressions/unary_operators/negation_operator.py20
-rw-r--r--ql/ast/nodes/expressions/unary_operators/negative_operator.py23
-rw-r--r--ql/ast/nodes/expressions/unary_operators/unary_operator.py11
6 files changed, 54 insertions, 0 deletions
diff --git a/ql/ast/nodes/expressions/unary_operators/__pycache__/negation_operator.cpython-35.pyc b/ql/ast/nodes/expressions/unary_operators/__pycache__/negation_operator.cpython-35.pyc
new file mode 100644
index 0000000..9a6e409
--- /dev/null
+++ b/ql/ast/nodes/expressions/unary_operators/__pycache__/negation_operator.cpython-35.pyc
Binary files differ
diff --git a/ql/ast/nodes/expressions/unary_operators/__pycache__/negative_operator.cpython-35.pyc b/ql/ast/nodes/expressions/unary_operators/__pycache__/negative_operator.cpython-35.pyc
new file mode 100644
index 0000000..45ad495
--- /dev/null
+++ b/ql/ast/nodes/expressions/unary_operators/__pycache__/negative_operator.cpython-35.pyc
Binary files differ
diff --git a/ql/ast/nodes/expressions/unary_operators/__pycache__/unary_operator.cpython-35.pyc b/ql/ast/nodes/expressions/unary_operators/__pycache__/unary_operator.cpython-35.pyc
new file mode 100644
index 0000000..f72b4f0
--- /dev/null
+++ b/ql/ast/nodes/expressions/unary_operators/__pycache__/unary_operator.cpython-35.pyc
Binary files differ
diff --git a/ql/ast/nodes/expressions/unary_operators/negation_operator.py b/ql/ast/nodes/expressions/unary_operators/negation_operator.py
new file mode 100644
index 0000000..7b6b0c5
--- /dev/null
+++ b/ql/ast/nodes/expressions/unary_operators/negation_operator.py
@@ -0,0 +1,20 @@
+from ql.ast.nodes.expressions.unary_operators.unary_operator import UnaryOperatorNode
+from ql.types.boolean import QLBoolean
+from ql.types.undefined import QLUndefined
+
+
+class NegationOperatorNode(UnaryOperatorNode):
+ def __init__(self, metadata, expression_type, expression, value):
+ super(NegationOperatorNode, self).__init__(metadata, expression_type, expression, value)
+ self.__valid_types = {
+ QLBoolean: QLBoolean,
+ }
+
+ def get_result_type(self):
+ if self.__valid_types.get(self.expression.expression_type):
+ return self.__valid_types.get(self.expression.expression_type)
+
+ return QLUndefined
+
+ def evaluate(self):
+ self.value = QLBoolean(not self.expression.value)
diff --git a/ql/ast/nodes/expressions/unary_operators/negative_operator.py b/ql/ast/nodes/expressions/unary_operators/negative_operator.py
new file mode 100644
index 0000000..359ed2e
--- /dev/null
+++ b/ql/ast/nodes/expressions/unary_operators/negative_operator.py
@@ -0,0 +1,23 @@
+from ql.ast.nodes.expressions.unary_operators.unary_operator import UnaryOperatorNode
+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 NegativeOperatorNode(UnaryOperatorNode):
+ def __init__(self, metadata, expression_type, expression, value):
+ super(NegativeOperatorNode, self).__init__(metadata, expression_type, expression, value)
+ self.__valid_types = {
+ QLDecimal: QLDecimal,
+ QLInteger: QLInteger,
+ QLMoney: QLMoney}
+
+ def get_result_type(self):
+ if self.__valid_types.get(self.expression.expression_type):
+ return self.__valid_types.get(self.expression.expression_type)
+
+ return QLUndefined
+
+ def evaluate(self):
+ self.value = -self.expression.value
diff --git a/ql/ast/nodes/expressions/unary_operators/unary_operator.py b/ql/ast/nodes/expressions/unary_operators/unary_operator.py
new file mode 100644
index 0000000..fa75249
--- /dev/null
+++ b/ql/ast/nodes/expressions/unary_operators/unary_operator.py
@@ -0,0 +1,11 @@
+from ql.ast.nodes.expressions.expression import ExpressionNode
+
+
+class UnaryOperatorNode(ExpressionNode):
+ def __init__(self, metadata, expression_type, expression, value):
+ super(UnaryOperatorNode, self).__init__(metadata, expression_type, value)
+ self.__expression = expression
+
+ @property
+ def expression(self):
+ return self.__expression