diff options
| author | Charles Brunet <charles.brunet@optelgroup.com> | 2023-08-25 09:41:47 -0400 |
|---|---|---|
| committer | Charles Brunet <charles.brunet@optelgroup.com> | 2023-09-11 07:51:18 -0400 |
| commit | 13ddf8bd025c3ff6257049cab6f3df1072ac0daf (patch) | |
| tree | d1ecc9b3b702179cb45aab4a349df64ace076ec2 | |
| parent | 0f4891cdf46e28d900cc35d57999fecff3ba8598 (diff) | |
| download | meson-13ddf8bd025c3ff6257049cab6f3df1072ac0daf.tar.gz | |
parser: simplify by using Unary and Binary Operator Node
| -rw-r--r-- | mesonbuild/mparser.py | 59 |
1 files changed, 17 insertions, 42 deletions
diff --git a/mesonbuild/mparser.py b/mesonbuild/mparser.py index ffe775037..00b87318c 100644 --- a/mesonbuild/mparser.py +++ b/mesonbuild/mparser.py @@ -401,7 +401,7 @@ class EmptyNode(BaseNode): pass @dataclass(unsafe_hash=True) -class OrNode(BaseNode): +class BinaryOperatorNode(BaseNode): left: BaseNode operator: SymbolNode @@ -413,53 +413,33 @@ class OrNode(BaseNode): self.operator = operator self.right = right -@dataclass(unsafe_hash=True) -class AndNode(BaseNode): - - left: BaseNode - operator: SymbolNode - right: BaseNode +class OrNode(BinaryOperatorNode): + pass - def __init__(self, left: BaseNode, operator: SymbolNode, right: BaseNode): - super().__init__(left.lineno, left.colno, left.filename) - self.left = left - self.operator = operator - self.right = right +class AndNode(BinaryOperatorNode): + pass @dataclass(unsafe_hash=True) -class ComparisonNode(BaseNode): +class ComparisonNode(BinaryOperatorNode): - left: BaseNode - operator: SymbolNode - right: BaseNode ctype: COMPARISONS def __init__(self, ctype: COMPARISONS, left: BaseNode, operator: SymbolNode, right: BaseNode): - super().__init__(left.lineno, left.colno, left.filename) - self.left = left - self.operator = operator - self.right = right + super().__init__(left, operator, right) self.ctype = ctype @dataclass(unsafe_hash=True) -class ArithmeticNode(BaseNode): +class ArithmeticNode(BinaryOperatorNode): - left: BaseNode - right: BaseNode # TODO: use a Literal for operation operation: str - operator: SymbolNode def __init__(self, operation: str, left: BaseNode, operator: SymbolNode, right: BaseNode): - super().__init__(left.lineno, left.colno, left.filename) - self.left = left - self.right = right + super().__init__(left, operator, right) self.operation = operation - self.operator = operator - @dataclass(unsafe_hash=True) -class NotNode(BaseNode): +class UnaryOperatorNode(BaseNode): operator: SymbolNode value: BaseNode @@ -469,6 +449,12 @@ class NotNode(BaseNode): self.operator = operator self.value = value +class NotNode(UnaryOperatorNode): + pass + +class UMinusNode(UnaryOperatorNode): + pass + @dataclass(unsafe_hash=True) class CodeBlockNode(BaseNode): @@ -621,18 +607,6 @@ class TestCaseClauseNode(BaseNode): self.endtestcase = endtestcase @dataclass(unsafe_hash=True) -class UMinusNode(BaseNode): - - operator: SymbolNode - value: BaseNode - - def __init__(self, current_location: Token, operator: SymbolNode, value: BaseNode): - super().__init__(current_location.lineno, current_location.colno, current_location.filename) - self.operator = operator - self.value = value - - -@dataclass(unsafe_hash=True) class TernaryNode(BaseNode): condition: BaseNode @@ -663,6 +637,7 @@ class ParenthesizedNode(BaseNode): self.inner = inner self.rpar = rpar + if T.TYPE_CHECKING: COMPARISONS = Literal['==', '!=', '<', '<=', '>=', '>', 'in', 'notin'] |
