Skip to content

Commit

Permalink
Merge branch 'topic/1396' into 'master'
Browse files Browse the repository at this point in the history
Handle SyntheticIdentifier in `Name.matches`.

Closes #1396

See merge request eng/libadalang/libadalang!1665
  • Loading branch information
Roldak committed Jun 10, 2024
2 parents 3a68c32 + a957ce9 commit 4eff990
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 26 deletions.
46 changes: 21 additions & 25 deletions ada/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 14 additions & 0 deletions testsuite/tests/properties/call_params/operators.adb
Original file line number Diff line number Diff line change
@@ -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;
20 changes: 20 additions & 0 deletions testsuite/tests/properties/call_params/test.out
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,26 @@ Result: [<ParamActual param=<DefiningName "S" dot.adb:10:21-10:22> actual=<Id "X
<ParamActual param=<DefiningName "V" dot.adb:10:28-10:29> actual=<Int dot.adb:54:10-54:11>>,
<ParamActual param=<DefiningName "W" dot.adb:10:46-10:47> actual=<Int dot.adb:54:18-54:19>>]

Working on node <AssignStmt operators.adb:6:4-6:37>
===================================================

Eval 'node.f_expr.p_call_params'
Result: [<ParamActual param=<SyntheticDefiningName "left" operators.adb:2:14-2:31> actual=<Id "X" operators.adb:6:22-6:23>>,
<ParamActual param=<SyntheticDefiningName "right" operators.adb:2:14-2:31> actual=<Id "Y" operators.adb:6:34-6:35>>]

Working on node <AssignStmt operators.adb:9:4-9:37>
===================================================

Eval 'node.f_expr.p_call_params'
Result: [<ParamActual param=<SyntheticDefiningName "left" operators.adb:2:14-2:31> actual=<Id "Y" operators.adb:9:34-9:35>>,
<ParamActual param=<SyntheticDefiningName "right" operators.adb:2:14-2:31> actual=<Id "X" operators.adb:9:23-9:24>>]

Working on node <AssignStmt operators.adb:12:4-12:26>
=====================================================

Eval 'node.f_expr.p_call_params'
Result: [<ParamActual param=<SyntheticDefiningName "right" operators.adb:2:14-2:31> actual=<Id "Y" operators.adb:12:23-12:24>>]

Working on node <AssignStmt pkg.adb:32:7-32:15>
===============================================

Expand Down
8 changes: 7 additions & 1 deletion testsuite/tests/properties/call_params/test.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 4eff990

Please sign in to comment.