Commit 77519270 by Hristian Kirtchev Committed by Pierre-Marie de Rodat

[Ada] Finding proper scope when inside entry body

This patch modifies routine Find_Enclosing_Scope which obtains the scope of an
arbitrary node to return the unique defining entity of an enclosing body. This
automatically takes care of the following corner cases:

   * The body is a subprogram body which does not complete a previous
     declaration. In this case the proper scope is the entity of the
     body.

   * The body is an entry body. Due to a limitation in the AST, the
     entry body does not store its correcponsing spec, but utilizes a
     roundabout way of obtaining it. Regardless of the limitation, the
     proper scope is the entity of the entry declaration.

The issue was discovered during the development of the GNATprove tool and
is not visible to end users. No simple test is available because this would
require a debug session.

2018-01-11  Hristian Kirtchev  <kirtchev@adacore.com>

gcc/ada/

	* sem_util.adb (Find_Enclosing_Scope): Return the unique defining
	entity when the enclosing construct is a body.

From-SVN: r256489
parent a40d9947
2018-01-11 Hristian Kirtchev <kirtchev@adacore.com>
* sem_util.adb (Find_Enclosing_Scope): Return the unique defining
entity when the enclosing construct is a body.
2018-01-11 Patrick Bernardi <bernardi@adacore.com> 2018-01-11 Patrick Bernardi <bernardi@adacore.com>
* exp_ch9.adb (Expand_N_Task_Type_Declaration): Simplified * exp_ch9.adb (Expand_N_Task_Type_Declaration): Simplified
......
...@@ -7847,8 +7847,7 @@ package body Sem_Util is ...@@ -7847,8 +7847,7 @@ package body Sem_Util is
-------------------------- --------------------------
function Find_Enclosing_Scope (N : Node_Id) return Entity_Id is function Find_Enclosing_Scope (N : Node_Id) return Entity_Id is
Par : Node_Id; Par : Node_Id;
Spec_Id : Entity_Id;
begin begin
-- Examine the parent chain looking for a construct which defines a -- Examine the parent chain looking for a construct which defines a
...@@ -7877,7 +7876,8 @@ package body Sem_Util is ...@@ -7877,7 +7876,8 @@ package body Sem_Util is
return Defining_Entity (Par); return Defining_Entity (Par);
-- The construct denotes a body, the proper scope is the entity of -- The construct denotes a body, the proper scope is the entity of
-- the corresponding spec. -- the corresponding spec or that of the body if the body does not
-- complete a previous declaration.
when N_Entry_Body when N_Entry_Body
| N_Package_Body | N_Package_Body
...@@ -7885,22 +7885,7 @@ package body Sem_Util is ...@@ -7885,22 +7885,7 @@ package body Sem_Util is
| N_Subprogram_Body | N_Subprogram_Body
| N_Task_Body | N_Task_Body
=> =>
Spec_Id := Corresponding_Spec (Par); return Unique_Defining_Entity (Par);
-- The defining entity of a stand-alone subprogram body defines
-- a scope.
if Nkind (Par) = N_Subprogram_Body and then No (Spec_Id) then
return Defining_Entity (Par);
-- Otherwise there should be corresponding spec which defines a
-- scope.
else
pragma Assert (Present (Spec_Id));
return Spec_Id;
end if;
-- Special cases -- Special cases
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment