diff --git a/ada/ast.py b/ada/ast.py index a41ae68bf..1fe9ee12b 100644 --- a/ada/ast.py +++ b/ada/ast.py @@ -1650,6 +1650,12 @@ def gnat_xref(): lambda p: p.is_a(T.GenericDecl) ).cast(T.GenericDecl).decl.defining_name, + # Deferred constants case + bd._.is_a(T.ObjectDecl) + & Not(bd.cast(T.ObjectDecl).has_constant.is_null) + & bd.is_in_private_part, + Entity.cast(T.Name).enclosing_defining_name.previous_part, + bd.then(lambda bd: bd.is_a(T.DiscriminantSpec)), bd.semantic_parent.cast(T.BasicDecl).defining_name, diff --git a/testsuite/tests/name_resolution/gnat_xref_deferred_constants/prj.gpr b/testsuite/tests/name_resolution/gnat_xref_deferred_constants/prj.gpr new file mode 100644 index 000000000..4b29ca3fd --- /dev/null +++ b/testsuite/tests/name_resolution/gnat_xref_deferred_constants/prj.gpr @@ -0,0 +1,4 @@ +project Prj is + for Source_Dirs use ("."); + for Main use ("test.adb"); +end Prj; diff --git a/testsuite/tests/name_resolution/gnat_xref_deferred_constants/test.adb b/testsuite/tests/name_resolution/gnat_xref_deferred_constants/test.adb new file mode 100644 index 000000000..58a7deb1a --- /dev/null +++ b/testsuite/tests/name_resolution/gnat_xref_deferred_constants/test.adb @@ -0,0 +1,9 @@ +procedure Test is + package P is + U, V : constant Integer; + private + U, V : constant Integer := 1; + end P; +begin + null; +end Test; diff --git a/testsuite/tests/name_resolution/gnat_xref_deferred_constants/test.out b/testsuite/tests/name_resolution/gnat_xref_deferred_constants/test.out new file mode 100644 index 000000000..b5aee1ff3 --- /dev/null +++ b/testsuite/tests/name_resolution/gnat_xref_deferred_constants/test.out @@ -0,0 +1,15 @@ +== test.adb == +test.adb:1:11 => test.adb:1:11 (LAL: ok) +test.adb:5:7 => test.adb:3:7 (LAL: ok) +test.adb:5:10 => test.adb:3:10 (LAL: ok) +test.adb:6:8 => test.adb:2:12 (LAL: ok) +test.adb:9:5 => test.adb:1:11 (LAL: ok) + +Stats: +GNAT xrefs have 5 entries +LAL xrefs have: + * 5 OK entries (100.00%) + * 0 DIFFERENT entries (0.00%) + * 0 ERROR entries (0.00%) + * 0 MISSING entries (0.00%) + * 0 ADDITIONAL entries (0.00%) diff --git a/testsuite/tests/name_resolution/gnat_xref_deferred_constants/test.yaml b/testsuite/tests/name_resolution/gnat_xref_deferred_constants/test.yaml new file mode 100644 index 000000000..9efa742f3 --- /dev/null +++ b/testsuite/tests/name_resolution/gnat_xref_deferred_constants/test.yaml @@ -0,0 +1,2 @@ +driver: gnat-compare +project_file: prj.gpr