diff options
author | Hristian Kirtchev <kirtchev@adacore.com> | 2018-01-11 08:51:09 +0000 |
---|---|---|
committer | Pierre-Marie de Rodat <pmderodat@gcc.gnu.org> | 2018-01-11 08:51:09 +0000 |
commit | 775192706061030d927945619d3a41c5825e455d (patch) | |
tree | ead74251977d1087036b9eaa9f080a27fb8b4055 | |
parent | a40d994753b00e453f5b97686bebed73e7de6692 (diff) | |
download | gcc-775192706061030d927945619d3a41c5825e455d.zip gcc-775192706061030d927945619d3a41c5825e455d.tar.gz gcc-775192706061030d927945619d3a41c5825e455d.tar.bz2 |
[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
-rw-r--r-- | gcc/ada/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/ada/sem_util.adb | 23 |
2 files changed, 9 insertions, 19 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index ca74b1c..d05467d 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,8 @@ +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> * exp_ch9.adb (Expand_N_Task_Type_Declaration): Simplified diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb index 932454c..c1e16e3 100644 --- a/gcc/ada/sem_util.adb +++ b/gcc/ada/sem_util.adb @@ -7847,8 +7847,7 @@ package body Sem_Util is -------------------------- function Find_Enclosing_Scope (N : Node_Id) return Entity_Id is - Par : Node_Id; - Spec_Id : Entity_Id; + Par : Node_Id; begin -- Examine the parent chain looking for a construct which defines a @@ -7877,7 +7876,8 @@ package body Sem_Util is return Defining_Entity (Par); -- 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 | N_Package_Body @@ -7885,22 +7885,7 @@ package body Sem_Util is | N_Subprogram_Body | N_Task_Body => - Spec_Id := Corresponding_Spec (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; + return Unique_Defining_Entity (Par); -- Special cases |