From 0547f4b28c3473bf70c3b75842e8f0d8bc6753b3 Mon Sep 17 00:00:00 2001 From: Romain Beguet Date: Thu, 14 Sep 2023 11:33:30 +0200 Subject: [PATCH] Make BaseSubpSpec's name property public. --- ada/ast.py | 7 +++- .../tests/properties/subp_spec_name/test.adb | 30 ++++++++++++++++ .../tests/properties/subp_spec_name/test.out | 35 +++++++++++++++++++ .../tests/properties/subp_spec_name/test.yaml | 2 ++ user_manual/changes/1078.yaml | 6 ++++ 5 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 testsuite/tests/properties/subp_spec_name/test.adb create mode 100644 testsuite/tests/properties/subp_spec_name/test.out create mode 100644 testsuite/tests/properties/subp_spec_name/test.yaml create mode 100644 user_manual/changes/1078.yaml diff --git a/ada/ast.py b/ada/ast.py index 8d2c2c606..0eedb7dc4 100644 --- a/ada/ast.py +++ b/ada/ast.py @@ -18311,7 +18311,12 @@ class BaseSubpSpec(BaseFormalParamHolder): Base class for subprogram specifications (:rmlink:`6.1`). """ - name = AbstractProperty(type=T.DefiningName.entity) + name = AbstractProperty( + type=T.DefiningName.entity, public=True, doc=""" + Syntax property. Return the name of the subprogram defined by this + specification. + """ + ) returns = AbstractProperty( type=T.TypeExpr.entity, public=True, doc=""" Syntax property. Return the type expression node corresponding to the diff --git a/testsuite/tests/properties/subp_spec_name/test.adb b/testsuite/tests/properties/subp_spec_name/test.adb new file mode 100644 index 000000000..58c9ab259 --- /dev/null +++ b/testsuite/tests/properties/subp_spec_name/test.adb @@ -0,0 +1,30 @@ +procedure Test is + procedure Foo (X : Integer); + --% node.f_subp_spec.p_name + procedure Foo (X : integer) is null; + --% node.f_subp_spec.p_name + + function Bar (X : Integer) return Integer is (X); + --% node.f_subp_spec.p_name + + task T is + entry Baz (X : Integer); + --% node.f_spec.p_name + end T; + + task body T is + begin + accept Baz (X : Integer) do + -- this is not a subprogram specification + null; + end Baz; + end T; + + X : String := Integer'Image (2); + --% node.f_default_expr.p_called_subp_spec.p_name + + Y : String := Integer'(2)'Image; + --% node.f_default_expr.p_called_subp_spec.p_name +begin + null; +end Test; diff --git a/testsuite/tests/properties/subp_spec_name/test.out b/testsuite/tests/properties/subp_spec_name/test.out new file mode 100644 index 000000000..f52b4477f --- /dev/null +++ b/testsuite/tests/properties/subp_spec_name/test.out @@ -0,0 +1,35 @@ +Working on node +==================================================== + +Eval 'node.f_subp_spec.p_name' +Result: + +Working on node +======================================================== + +Eval 'node.f_subp_spec.p_name' +Result: + +Working on node +======================================================== + +Eval 'node.f_subp_spec.p_name' +Result: + +Working on node +======================================================= + +Eval 'node.f_spec.p_name' +Result: + +Working on node +====================================================== + +Eval 'node.f_default_expr.p_called_subp_spec.p_name' +Result: + +Working on node +====================================================== + +Eval 'node.f_default_expr.p_called_subp_spec.p_name' +Result: diff --git a/testsuite/tests/properties/subp_spec_name/test.yaml b/testsuite/tests/properties/subp_spec_name/test.yaml new file mode 100644 index 000000000..35ad4d5c4 --- /dev/null +++ b/testsuite/tests/properties/subp_spec_name/test.yaml @@ -0,0 +1,2 @@ +driver: inline-playground +input_sources: [test.adb] diff --git a/user_manual/changes/1078.yaml b/user_manual/changes/1078.yaml new file mode 100644 index 000000000..e789908a3 --- /dev/null +++ b/user_manual/changes/1078.yaml @@ -0,0 +1,6 @@ +type: new-feature +title: Make ``BaseSubpSpec``'s ``name`` property public +description: | + This allows retrieving the name of the subprogram from its specification + without having to navigate to the subprogram decl itself first. +date: 2023-09-14