diff options
author | JCWasmx86 <JCWasmx86@t-online.de> | 2022-10-31 16:47:40 +0100 |
---|---|---|
committer | Charles Brunet <charles.brunet@optelgroup.com> | 2023-09-11 07:51:17 -0400 |
commit | 79ed2415e9a50e5181b203790ec057c6229609a3 (patch) | |
tree | 73fda27c540912174aef4fa5ccebc92bdcdd4bb0 /mesonbuild | |
parent | bd3341f8085686863cb1160f2ab72e6fd6bf47c7 (diff) | |
download | meson-79ed2415e9a50e5181b203790ec057c6229609a3.zip meson-79ed2415e9a50e5181b203790ec057c6229609a3.tar.gz meson-79ed2415e9a50e5181b203790ec057c6229609a3.tar.bz2 |
Add ParenthesizedNode
Diffstat (limited to 'mesonbuild')
-rw-r--r-- | mesonbuild/ast/visitor.py | 4 | ||||
-rw-r--r-- | mesonbuild/interpreterbase/interpreterbase.py | 2 | ||||
-rw-r--r-- | mesonbuild/mparser.py | 11 | ||||
-rw-r--r-- | mesonbuild/optinterpreter.py | 2 |
4 files changed, 18 insertions, 1 deletions
diff --git a/mesonbuild/ast/visitor.py b/mesonbuild/ast/visitor.py index 8a0e77b..51a6620 100644 --- a/mesonbuild/ast/visitor.py +++ b/mesonbuild/ast/visitor.py @@ -144,3 +144,7 @@ class AstVisitor: for key, val in node.kwargs.items(): key.accept(self) val.accept(self) + + def visit_ParenthesizedNode(self, node: mparser.ParenthesizedNode) -> None: + self.visit_default_func(node) + node.inner.accept(self) diff --git a/mesonbuild/interpreterbase/interpreterbase.py b/mesonbuild/interpreterbase/interpreterbase.py index 902f84a..f35da33 100644 --- a/mesonbuild/interpreterbase/interpreterbase.py +++ b/mesonbuild/interpreterbase/interpreterbase.py @@ -239,6 +239,8 @@ class InterpreterBase: raise ContinueRequest() elif isinstance(cur, mparser.BreakNode): raise BreakRequest() + elif isinstance(cur, mparser.ParenthesizedNode): + return self.evaluate_statement(cur.inner) elif isinstance(cur, mparser.TestCaseClauseNode): return self.evaluate_testcase(cur) else: diff --git a/mesonbuild/mparser.py b/mesonbuild/mparser.py index fb4e433..3697d8a 100644 --- a/mesonbuild/mparser.py +++ b/mesonbuild/mparser.py @@ -577,6 +577,15 @@ class TernaryNode(BaseNode): self.trueblock = trueblock self.falseblock = falseblock +@dataclass(unsafe_hash=True) +class ParenthesizedNode(BaseNode): + + inner: BaseNode + + def __init__(self, inner: BaseNode, lineno: int, colno: int, end_lineno: int, end_colno: int): + super().__init__(lineno, colno, inner.filename, end_lineno=end_lineno, end_colno=end_colno) + self.inner = inner + if T.TYPE_CHECKING: COMPARISONS = Literal['==', '!=', '<', '<=', '>=', '>', 'in', 'notin'] @@ -778,7 +787,7 @@ class Parser: if self.accept('lparen'): e = self.statement() self.block_expect('rparen', block_start) - return e + return ParenthesizedNode(e, block_start.lineno, block_start.colno, self.current.lineno, self.current.colno) elif self.accept('lbracket'): args = self.args() self.block_expect('rbracket', block_start) diff --git a/mesonbuild/optinterpreter.py b/mesonbuild/optinterpreter.py index 8ad84aa..37ef55a 100644 --- a/mesonbuild/optinterpreter.py +++ b/mesonbuild/optinterpreter.py @@ -113,6 +113,8 @@ class OptionInterpreter: def reduce_single(self, arg: T.Union[str, mparser.BaseNode]) -> 'TYPE_var': if isinstance(arg, str): return arg + if isinstance(arg, mparser.ParenthesizedNode): + return self.reduce_single(arg.inner) elif isinstance(arg, (mparser.StringNode, mparser.BooleanNode, mparser.NumberNode)): return arg.value |