From a957ce9d6650be0cce72c10fd1a665e2680534d8 Mon Sep 17 00:00:00 2001 From: Romain Beguet Date: Thu, 6 Jun 2024 14:42:40 +0200 Subject: [PATCH] Handle SyntheticIdentifier in `Name.matches`. --- ada/ast.py | 46 +++++++++---------- .../properties/call_params/operators.adb | 14 ++++++ .../tests/properties/call_params/test.out | 20 ++++++++ .../tests/properties/call_params/test.yaml | 8 +++- 4 files changed, 62 insertions(+), 26 deletions(-) create mode 100644 testsuite/tests/properties/call_params/operators.adb diff --git a/ada/ast.py b/ada/ast.py index 1143f1a6e..09f659ee1 100644 --- a/ada/ast.py +++ b/ada/ast.py @@ -16011,33 +16011,29 @@ def matches(n=T.Name): """ Return whether two names match each other. - This compares the symbol for Identifier and StringLiteral nodes. We - consider that there is no match for all other node kinds. + This only handles Identifiers, SyntheticIdentifiers, StringLiteral, + DefiningName and DottedName nodes: it always returns False for any + other node kind. """ - return Self.match( - lambda id=SyntheticIdentifier: n.cast(Identifier).then( - # We only need to check the case where `n` is an `Identifier` - # as `SyntheticIdentifier`s can only be compared to those - # when matching formals (see AdaNode.match_formals). This case - # will happen when the formal comes from a synthetic operator - # definition, and the actual from a call with a named - # parameter (which will necessarily be an `Identifier`). - lambda other_id: id.sym.equals(other_id.sym) - ), - lambda id=Identifier: n.cast(Identifier).then( - lambda other_id: id.sym.equals(other_id.sym) - ), - lambda sl=StringLiteral: n.cast(StringLiteral).then( - lambda other_sl: sl.sym.equals(other_sl.sym) - ), - lambda dn=DottedName: n.cast(DottedName).then( - lambda sn: And( - sn.prefix.matches(dn.prefix), - sn.suffix.matches(dn.suffix) - ) + return Cond( + Or( + Self.is_a(Identifier, SyntheticIdentifier) + & n.is_a(Identifier, SyntheticIdentifier), + Self.is_a(StringLiteral) & n.is_a(StringLiteral), ), - lambda di=DefiningName: n.matches(di.name), - lambda _: False + Self.name_symbol.equals(n.name_symbol), + + Self.is_a(DefiningName), + Self.cast(DefiningName).name.matches(n), + + n.is_a(DefiningName), + Self.matches(n.cast(DefiningName).name), + + Self.is_a(DottedName) & n.is_a(DottedName), + Self.cast(DottedName).prefix.matches(n.cast(DottedName).prefix) + & Self.cast(DottedName).suffix.matches(n.cast(DottedName).suffix), + + False ) @langkit_property(public=True) diff --git a/testsuite/tests/properties/call_params/operators.adb b/testsuite/tests/properties/call_params/operators.adb new file mode 100644 index 000000000..77d60fcf5 --- /dev/null +++ b/testsuite/tests/properties/call_params/operators.adb @@ -0,0 +1,14 @@ +procedure Operators is + type T is range -100 .. 100; + + X, Y : T := 1; +begin + X := "+" (Left => X, Right => Y); + --% node.f_expr.p_call_params + + Y := "+" (Right => X, Left => Y); + --% node.f_expr.p_call_params + + X := "-" (Right => Y); + --% node.f_expr.p_call_params +end Operators; diff --git a/testsuite/tests/properties/call_params/test.out b/testsuite/tests/properties/call_params/test.out index 12eab68c6..d89e07cf9 100644 --- a/testsuite/tests/properties/call_params/test.out +++ b/testsuite/tests/properties/call_params/test.out @@ -375,6 +375,26 @@ Result: [ actual= actual=>, actual=>] +Working on node +=================================================== + +Eval 'node.f_expr.p_call_params' +Result: [ actual=>, + actual=>] + +Working on node +=================================================== + +Eval 'node.f_expr.p_call_params' +Result: [ actual=>, + actual=>] + +Working on node +===================================================== + +Eval 'node.f_expr.p_call_params' +Result: [ actual=>] + Working on node =============================================== diff --git a/testsuite/tests/properties/call_params/test.yaml b/testsuite/tests/properties/call_params/test.yaml index 3ed972108..1bdd7f569 100644 --- a/testsuite/tests/properties/call_params/test.yaml +++ b/testsuite/tests/properties/call_params/test.yaml @@ -1,2 +1,8 @@ driver: inline-playground -input_sources: [callp.adb, pkg.adb, pkg.ads, dot.adb, call_array.adb] +input_sources: + - callp.adb + - pkg.adb + - pkg.ads + - dot.adb + - call_array.adb + - operators.adb