aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/sem_util.ads
diff options
context:
space:
mode:
authorBob Duff <duff@adacore.com>2023-09-05 14:40:22 -0400
committerMarc Poulhiès <poulhies@adacore.com>2023-09-15 15:01:29 +0200
commit553c37bedcfb04f52237ef3cdd2a19747c61cde1 (patch)
tree3d93df681fb0727604b4fbec9904a6c64c939914 /gcc/ada/sem_util.ads
parent545af80aef6dcc368f3e50cbd0c2119ddbdde2e7 (diff)
downloadgcc-553c37bedcfb04f52237ef3cdd2a19747c61cde1.zip
gcc-553c37bedcfb04f52237ef3cdd2a19747c61cde1.tar.gz
gcc-553c37bedcfb04f52237ef3cdd2a19747c61cde1.tar.bz2
ada: Clean up scope depth and related code (tech debt)
The main point of this patch is to remove the special case for Atree.F_Scope_Depth_Value in the Assert that Field_Present in Get_Field_Value. Pulling on that thread leads to lots of related cleanup. gcc/ada/ChangeLog: * atree.adb (Node_Kind_Table): Specify parameter explicitly in GNAT.Table instantiations. Use fully qualified references instead of relying on use clauses. (Get_Field_Value): Remove special case for F_Scope_Depth_Value. That is, enable the Field_Present check in that case. (It was already enabled for all other fields.) Violations of this check were already fixed. (Print_Node_Statistics): Sort the output in decreasing order of frequencies. (Print_Field_Statistics): Likewise (sort). * accessibility.adb (Accessibility_Level): Pass Allow_Alt_Model in recursive calls. Apparently, an oversight. (Innermost_Master_Scope_Depth): Need to special-case the 'Old attribute and allocators. * einfo-utils.ads (Scope_Depth): Use Scope_Kind_Id to get predicate checks. (Scope_Depth_Set): Likewise. (Scope_Depth_Default_0): Likewise. * einfo-utils.adb: As for spec. * frontend.adb (Frontend): Remove unnecessary "return;". * gen_il-types.ads (Scope_Kind): New union type. * gen_il-gen-gen_entities.adb (Scope_Kind): New union type. * sem.ads: Move "with Einfo.Entities;" from body to spec. (Scope_Stack_Entry): Declare Entity to be of Scope_Kind_Id to get predicate checks. We had previously been putting non-scopes on the scope stack; this prevents such anomalies. * sem.adb: Move "with Einfo.Entities;" from body to spec. * sem_ch8.ads: Move "with Einfo.Entities;" from body to spec. Add "with Types;". (Push_Scope): Use Scope_Kind_Id to get predicate checks. * sem_ch8.adb: Move "with Einfo.Entities;" from body to spec. Add "with Types;". (Push_Scope): Use Scope_Kind_Id to get predicate checks. (Pop_Scope): Use Scope_Kind_Id on popped entity to get predicate checks. This prevents anomalies where a scope pushed onto the stack is later mutated to a nonscope before being popped. * sem_util.ads (Find_Enclosing_Scope): Add postcondition to ensure that the enclosing scope of a node N is not the same node N. Clearly, N does not enclose itself. * sem_util.adb (Find_Enclosing_Scope): There were several bugs where Find_Enclosing_Scope(N) = N. For example, if N is an entity, then we would typically go up to its declaration, and then back down to the Defining_Entity of the declaration, which is N itself. There were other cases where Find_Enclosing_Scope of an entity disagreed with Scope. Clearly, Find_Enclosing_Scope and Scope should agree (when both are defined). Such bugs caused latent bugs in accessibility.adb related to 'Old, and fixing bugs here caused such bugs to be revealed. These are fixed by calling Scope when N is an entity. Co-authored-by: Ronan Desplanques <desplanques@adacore.com>
Diffstat (limited to 'gcc/ada/sem_util.ads')
-rw-r--r--gcc/ada/sem_util.ads3
1 files changed, 2 insertions, 1 deletions
diff --git a/gcc/ada/sem_util.ads b/gcc/ada/sem_util.ads
index b56a235..92016bc 100644
--- a/gcc/ada/sem_util.ads
+++ b/gcc/ada/sem_util.ads
@@ -889,7 +889,8 @@ package Sem_Util is
-- such a loop exists, return the entity of its identifier (E_Loop scope),
-- otherwise return Empty.
- function Find_Enclosing_Scope (N : Node_Id) return Entity_Id;
+ function Find_Enclosing_Scope (N : Node_Id) return Scope_Kind_Id with
+ Post => Find_Enclosing_Scope'Result /= N;
-- Find the nearest scope which encloses arbitrary node N
function Find_Loop_In_Conditional_Block (N : Node_Id) return Node_Id;