aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/sem_ch3.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_ch3.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_ch3.adb')
-rw-r--r--gcc/ada/sem_ch3.adb69
1 files changed, 40 insertions, 29 deletions
diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb
index 8583ac0..a382751 100644
--- a/gcc/ada/sem_ch3.adb
+++ b/gcc/ada/sem_ch3.adb
@@ -2311,9 +2311,7 @@ package body Sem_Ch3 is
Set_Original_Record_Component (Id, Id);
- if Has_Aspects (N) then
- Analyze_Aspect_Specifications (N, Id);
- end if;
+ Analyze_Aspect_Specifications (N, Id);
Analyze_Dimension (N);
end Analyze_Component_Declaration;
@@ -3525,25 +3523,22 @@ package body Sem_Ch3 is
-- them to the entity for the type which is currently the partial
-- view, but which is the one that will be frozen.
- if Has_Aspects (N) then
-
- -- In most cases the partial view is a private type, and both views
- -- appear in different declarative parts. In the unusual case where
- -- the partial view is incomplete, perform the analysis on the
- -- full view, to prevent freezing anomalies with the corresponding
- -- class-wide type, which otherwise might be frozen before the
- -- dispatch table is built.
+ -- In most cases the partial view is a private type, and both views
+ -- appear in different declarative parts. In the unusual case where
+ -- the partial view is incomplete, perform the analysis on the
+ -- full view, to prevent freezing anomalies with the corresponding
+ -- class-wide type, which otherwise might be frozen before the
+ -- dispatch table is built.
- if Prev /= Def_Id
- and then Ekind (Prev) /= E_Incomplete_Type
- then
- Analyze_Aspect_Specifications (N, Prev);
+ if Prev /= Def_Id
+ and then Ekind (Prev) /= E_Incomplete_Type
+ then
+ Analyze_Aspect_Specifications (N, Prev);
- -- Normal case
+ -- Normal case
- else
- Analyze_Aspect_Specifications (N, Def_Id);
- end if;
+ else
+ Analyze_Aspect_Specifications (N, Def_Id);
end if;
if Is_Derived_Type (Prev)
@@ -5323,9 +5318,7 @@ package body Sem_Ch3 is
Set_Encapsulating_State (Id, Empty);
end if;
- if Has_Aspects (N) then
- Analyze_Aspect_Specifications (N, Id);
- end if;
+ Analyze_Aspect_Specifications (N, Id);
Analyze_Dimension (N);
@@ -5604,9 +5597,7 @@ package body Sem_Ch3 is
Set_Has_Private_Extension (Parent_Type);
<<Leave>>
- if Has_Aspects (N) then
- Analyze_Aspect_Specifications (N, T);
- end if;
+ Analyze_Aspect_Specifications (N, T);
end Analyze_Private_Extension_Declaration;
---------------------------------
@@ -6226,9 +6217,7 @@ package body Sem_Ch3 is
Check_Eliminated (Id);
<<Leave>>
- if Has_Aspects (N) then
- Analyze_Aspect_Specifications (N, Id);
- end if;
+ Analyze_Aspect_Specifications (N, Id);
Analyze_Dimension (N);
@@ -7195,6 +7184,11 @@ package body Sem_Ch3 is
Constraint => Constraint (Indic)));
Rewrite (N, New_Indic);
+
+ -- Keep the aspects from the original node
+
+ Move_Aspects (Original_Node (N), N);
+
Analyze (N);
end if;
@@ -7374,6 +7368,10 @@ package body Sem_Ch3 is
Defining_Identifier => Derived_Type,
Subtype_Indication => New_Indic));
+ -- Keep the aspects from the original node
+
+ Move_Aspects (Original_Node (N), N);
+
Analyze (N);
return;
end;
@@ -7802,12 +7800,16 @@ package body Sem_Ch3 is
Make_Range_Constraint (Loc,
Range_Expression => Rang_Expr))));
+ -- Keep the aspects from the orignal node
+
+ Move_Aspects (Original_Node (N), N);
+
Analyze (N);
-- Propagate the aspects from the original type declaration to the
-- declaration of the implicit base.
- Move_Aspects (From => Original_Node (N), To => Type_Decl);
+ Copy_Aspects (From => N, To => Type_Decl);
-- Apply a range check. Since this range expression doesn't have an
-- Etype, we have to specifically pass the Source_Typ parameter. Is
@@ -9466,6 +9468,10 @@ package body Sem_Ch3 is
Defining_Identifier => Derived_Type,
Subtype_Indication => New_Indic));
+ -- Keep the aspects from the original node
+
+ Move_Aspects (Original_Node (N), N);
+
Analyze (N);
-- Derivation of subprograms must be delayed until the full subtype
@@ -10041,6 +10047,11 @@ package body Sem_Ch3 is
Replace_Discriminants (Derived_Type, New_Decl);
end if;
+ -- Relocate the aspects from the original type
+
+ Remove_Aspects (New_Decl);
+ Move_Aspects (N, New_Decl);
+
-- Insert the new derived type declaration
Rewrite (N, New_Decl);