Skip to content

Commit

Permalink
Merge branch 'topic/1078' into 'master'
Browse files Browse the repository at this point in the history
Make `BaseSubpSpec`'s `name` property public.

Closes #1078

See merge request eng/libadalang/libadalang!1412
  • Loading branch information
Roldak committed Oct 4, 2023
2 parents df0df7e + 0547f4b commit 0fca97c
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 1 deletion.
7 changes: 6 additions & 1 deletion ada/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 30 additions & 0 deletions testsuite/tests/properties/subp_spec_name/test.adb
Original file line number Diff line number Diff line change
@@ -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;
35 changes: 35 additions & 0 deletions testsuite/tests/properties/subp_spec_name/test.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
Working on node <SubpDecl ["Foo"] test.adb:2:4-2:32>
====================================================

Eval 'node.f_subp_spec.p_name'
Result: <DefiningName "Foo" test.adb:2:14-2:17>

Working on node <NullSubpDecl ["Foo"] test.adb:4:4-4:40>
========================================================

Eval 'node.f_subp_spec.p_name'
Result: <DefiningName "Foo" test.adb:4:14-4:17>

Working on node <ExprFunction ["Bar"] test.adb:7:4-7:53>
========================================================

Eval 'node.f_subp_spec.p_name'
Result: <DefiningName "Bar" test.adb:7:13-7:16>

Working on node <EntryDecl ["Baz"] test.adb:11:7-11:31>
=======================================================

Eval 'node.f_spec.p_name'
Result: <DefiningName "Baz" test.adb:11:13-11:16>

Working on node <ObjectDecl ["X"] test.adb:23:4-23:36>
======================================================

Eval 'node.f_default_expr.p_called_subp_spec.p_name'
Result: <SyntheticDefiningName "image" __standard:4:3-4:54>

Working on node <ObjectDecl ["Y"] test.adb:26:4-26:36>
======================================================

Eval 'node.f_default_expr.p_called_subp_spec.p_name'
Result: <SyntheticDefiningName "image" __standard:4:3-4:54>
2 changes: 2 additions & 0 deletions testsuite/tests/properties/subp_spec_name/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
driver: inline-playground
input_sources: [test.adb]
6 changes: 6 additions & 0 deletions user_manual/changes/1078.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 0fca97c

Please sign in to comment.