aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/sem_ch6.adb
diff options
context:
space:
mode:
authorViljar Indus <indus@adacore.com>2023-07-26 13:29:14 +0300
committerMarc Poulhiès <poulhies@adacore.com>2023-11-07 10:15:04 +0100
commit76bf4321331b1d453555602407029344e1e1ee4a (patch)
treee3821e6f7bd7bf4dad7756bef8be642efbbfcafc /gcc/ada/sem_ch6.adb
parentde4588f3680ccd0861e6b9a0a04e96d46fae178b (diff)
downloadgcc-76bf4321331b1d453555602407029344e1e1ee4a.zip
gcc-76bf4321331b1d453555602407029344e1e1ee4a.tar.gz
gcc-76bf4321331b1d453555602407029344e1e1ee4a.tar.bz2
ada: Implement Aspects as fields under nodes
In the previous implementation Aspect Specifications were stored in a separate table and not directly under each node. This implementation included a lot of extra code that needed to be maintained manually. The new implementation stores Aspect_Specfications as a syntactic field under each node. This removes the extra code that was needed to store, traverse and clone aspects for nodes. gcc/ada/ * aspects.adb (Exchange_Aspects): Removed. This method was typically called after a Rewrite method. Now since the Rewrite switches the aspects between the new and the old node it is no longer needed. (Has_Aspects): Converted to a utility method that performs the same before as the previous Has_Aspects field did. Meaning it shows whether a node actually has aspects or not. (Copy_Aspects): New utility method that performs a deep copy of the From nodes aspects. (Aspect_Specfications): Removed. No longer needed. Replaced by the primitive operation for the Aspect_Specification fields. (Set_Aspect_Specifications): Likewise. (Aspect_Specifications_Hash_Table): Remove the table and all the utility methods for storing the old aspects. * aspects.ads: Likewise. * atree.adb (Copy_Separate_Tree): Remove custom code for aspects. (New_Copy): Likewise. (Replace): Likewise. (Rewrite): Likewise. * exp_ch3.adb (Expand_N_Object_Declaration): Keep the aspects from the old node. * exp_ch6.adb (Validate_Subprogram_Calls): Previously aspects were ignored because they were not on the tree. Explicitly ignore them here when traversing the tree. * exp_unst.adb (Build_Tables): Likewise * gen_il-fields.ads: Remove Has_Aspects and add Aspect_Specifications fields. * gen_il-gen-gen_nodes.adb: Add Aspect_Specification fields for all nodes that can have aspects. Additionally add Expression_Copy for Aspect_Speficiations to avoid reusing the Associated_Node for generic instantiation and aspect analysis. * ghost.adb (Remove_Ignored_Ghost_Node): Remove call to Remove_Aspects. The rewritten node is a Null_Statement that cannot have aspects and there is not anything to gain from removing them from the Orignal_Node of N since it technically is not part of the active tree. * inline.adb (Process_Formals_In_Aspects): Simplify code for node traversal. * par-ch13.adb: Avoid setting the parent explicitly for the Aspect_Specifications list. This is done explicitly in the setter. * par-ch6.adb: Likewise. * par_sco.adb (Traverse_Aspects): Handle early return. * sem_ch10.adb: Simplify code for Analyze_Aspect_Specifications. * sem_ch11.adb: Likewise. * sem_ch12.adb (Analyze_Formal_Derived_Interface_Type): Keep the aspects from the orignal node after rewrite. (Analyze_Formal_Derived_Type): Likewise. (Analyze_Formal_Interface_Type): Likewise. (Analyze_Formal_Object_Declaration): Simplify code for Analyze_Aspect_Specifications. (Analyze_Formal_Package_Declaration): Likewise. (Analyze_Formal_Subprogram_Declaration): Likewise. (Analyze_Formal_Type_Declaration): Likewise. (Analyze_Generic_Package_Declaration): Remove Exchange_Aspects. The new node already has the correct aspects after the rewrite. Also simplify code for Analyze_Aspect_Specifications. (Analyze_Generic_Subprogram_Declaration): Likewise. (Analyze_Package_Instantiation): Simplify code for Analyze_Aspect_Specifications. (Build_Instance_Compilation_Unit_Nodes): Remove explicit copy of aspects that is no longer needed. (Save_References): Update the traversal code to handle Aspect_Specifications in the tree. (Copy_Generic_Node): Remove explicit copy for aspects. New_Copy took care of that already. * sem_ch13.adb (Analyze_Aspect_Specifications): Add early return to simplify code for its calls. Avoid reusing the Entity(Associated_Node) field for storing the original expression. Instead use the new Expression_Copy field since Entity(Associated_Node) is also used in generic instantiation. (Analyze_Aspects_On_Subprogram_Body_Or_Stub): Simlify call to Analyze_Aspect_Specifications. (Check_Aspect_At_End_Of_Declarations): Use Expression_Copy instead of Entity. (Check_Aspect_At_Freeze_Point): Likewise. * sem_ch3.adb: Simplify calls to Analyze_Aspect_Specifications. * sem_ch6.adb (Analyze_Abstract_Subprogram_Declaration): Simplify call to Analyze_Aspect_Specifications. (Analyze_Expression_Function): Keep the aspects from the original node after a rewrite. (Analyze_Generic_Subprogram_Body): Remove Exchange aspects that is no longer needed. Simplify call to Analyze_Aspect_Specifications. (Analyze_Null_Procedure): Keep the aspects from the original node after a rewrite. (Analyze_Subprogram_Body_Helper): Simplify calls to Analyze_Aspect_Specifications. (Analyze_Subprogram_Declaration): Likewise. * sem_ch7.adb (Analyze_Package_Body_Helper): Remove Exchange aspects that is no longer needed. Simplify call to Analyze_Aspect_Specifications. (Analyze_Package_Declaration): Simplify call to Analyze_Aspect_Specifications. (Analyze_Private_Type_Declaration): Likewise. * sem_ch8.adb: Simplify calls to Analyze_Aspect_Specifications. * sem_ch9.adb (Analyze_Entry_Body): Simplify call to Analyze_Aspects_On_Subprogram_Body_Or_Stub. (Analyze_Entry_Declaration): Simplify call to Analyze_Aspect_Specifications. (Analyze_Protected_Body): Likewise. (Analyze_Protected_Type_Declaration): Likewise. (Analyze_Single_Protected_Declaration): Keep the aspects from the original node after a rewrite. Simplify call to Analyze_Aspect_Specifications. (Analyze_Single_Task_Declaration): Likewise. (Analyze_Task_Body): Simplify call to Analyze_Aspect_Specifications. (Analyze_Task_Type_Declaration): Simplify calls to Analyze_Aspect_Specifications. * sem_dim.adb: Remove explicitly setting the parents for the Aspect_Specification list. * sem_disp.adb: Remove the with that is no longer required since Aspect_Specifications is a node operation now. * sem_util.adb (Copy_Node_With_Replacement): Remove explicit code for aspects. * treepr.adb (Print_Field): Remove the version that was used for printing aspects. (Print_Node): Remove aspect specific code.
Diffstat (limited to 'gcc/ada/sem_ch6.adb')
-rw-r--r--gcc/ada/sem_ch6.adb36
1 files changed, 10 insertions, 26 deletions
diff --git a/gcc/ada/sem_ch6.adb b/gcc/ada/sem_ch6.adb
index 00f7e37..3dd2659 100644
--- a/gcc/ada/sem_ch6.adb
+++ b/gcc/ada/sem_ch6.adb
@@ -290,9 +290,7 @@ package body Sem_Ch6 is
Generate_Reference_To_Formals (Subp_Id);
Check_Eliminated (Subp_Id);
- if Has_Aspects (N) then
- Analyze_Aspect_Specifications (N, Subp_Id);
- end if;
+ Analyze_Aspect_Specifications (N, Subp_Id);
end Analyze_Abstract_Subprogram_Declaration;
---------------------------------
@@ -430,11 +428,10 @@ package body Sem_Ch6 is
Generate_Reference (Prev, Defining_Entity (N), 'b', Force => True);
Rewrite (N, New_Body);
- -- Remove any existing aspects from the original node because the act
- -- of rewriting causes the list to be shared between the two nodes.
+ -- Keep the aspects from the original node
Orig_N := Original_Node (N);
- Remove_Aspects (Orig_N);
+ Move_Aspects (Orig_N, N);
-- Propagate any pragmas that apply to expression function to the
-- proper body when the expression function acts as a completion.
@@ -488,11 +485,10 @@ package body Sem_Ch6 is
Rewrite (N, Make_Subprogram_Declaration (Loc, Specification => Spec));
- -- Remove any existing aspects from the original node because the act
- -- of rewriting causes the list to be shared between the two nodes.
+ -- Keep the aspects from the original node
Orig_N := Original_Node (N);
- Remove_Aspects (Orig_N);
+ Move_Aspects (Orig_N, N);
Analyze (N);
@@ -1139,11 +1135,6 @@ package body Sem_Ch6 is
New_N := Copy_Generic_Node (N, Empty, Instantiating => False);
Rewrite (N, New_N);
- -- Once the contents of the generic copy and the template are
- -- swapped, do the same for their respective aspect specifications.
-
- Exchange_Aspects (N, New_N);
-
-- Collect all contract-related source pragmas found within the
-- template and attach them to the contract of the subprogram body.
-- This contract is used in the capture of global references within
@@ -1289,9 +1280,7 @@ package body Sem_Ch6 is
-- Analyze any aspect specifications that appear on the generic
-- subprogram body.
- if Has_Aspects (N) then
- Analyze_Aspects_On_Subprogram_Body_Or_Stub (N);
- end if;
+ Analyze_Aspects_On_Subprogram_Body_Or_Stub (N);
-- Process the contract of the subprogram body after analyzing all
-- the contract-related pragmas within the declarations.
@@ -1506,6 +1495,7 @@ package body Sem_Ch6 is
Is_Completion := True;
Rewrite (N, Null_Body);
+ Move_Aspects (Original_Node (N), N);
Analyze (N);
end if;
@@ -4363,9 +4353,7 @@ package body Sem_Ch6 is
-- or a statement part, and it cannot be inlined.
if Nkind (N) = N_Subprogram_Body_Stub then
- if Has_Aspects (N) then
- Analyze_Aspects_On_Subprogram_Body_Or_Stub (N);
- end if;
+ Analyze_Aspects_On_Subprogram_Body_Or_Stub (N);
goto Leave;
end if;
@@ -4612,9 +4600,7 @@ package body Sem_Ch6 is
-- Analyze any aspect specifications that appear on the subprogram body
- if Has_Aspects (N) then
- Analyze_Aspects_On_Subprogram_Body_Or_Stub (N);
- end if;
+ Analyze_Aspects_On_Subprogram_Body_Or_Stub (N);
-- Process the contract of the subprogram body after analyzing all the
-- contract-related pragmas within the declarations.
@@ -5251,9 +5237,7 @@ package body Sem_Ch6 is
-- case the subprogram is a compilation unit and one of its aspects is
-- converted into a categorization pragma.
- if Has_Aspects (N) then
- Analyze_Aspect_Specifications (N, Designator);
- end if;
+ Analyze_Aspect_Specifications (N, Designator);
-- The legality of a function specification in SPARK depends on whether
-- the function is a function with or without side-effects. Analyze the