aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/sem_ch7.adb
diff options
context:
space:
mode:
authorGary Dismukes <dismukes@adacore.com>2021-06-22 00:47:00 -0400
committerPierre-Marie de Rodat <derodat@adacore.com>2021-09-20 12:31:31 +0000
commit3450ded1eddb35b7f9030c5545d1e542cef5f8b2 (patch)
tree8c6d1980e37a5cd632b2ef321dbe417a9ff7a69a /gcc/ada/sem_ch7.adb
parentc83448aaf907f3895194167098b7003ed932583d (diff)
downloadgcc-3450ded1eddb35b7f9030c5545d1e542cef5f8b2.zip
gcc-3450ded1eddb35b7f9030c5545d1e542cef5f8b2.tar.gz
gcc-3450ded1eddb35b7f9030c5545d1e542cef5f8b2.tar.bz2
[Ada] Implementation of Preelaborable_Initialization attribute for AI12-0409
gcc/ada/ * exp_attr.adb (Expand_N_Attribute_Reference): Fold Preelaborable_Initialization attribute in cases where it hasn't been folded by the analyzer. * exp_disp.adb (Original_View_In_Visible_Part): This function is removed and moved to sem_util.adb. * sem_attr.adb (Attribute_22): Add Attribute_Preelaborable_Initialization as an Ada 2022 attribute. (Analyze_Attribute, Attribute_Preelaborable_Initialization): Check that the prefix of the attribute is either a formal private or derived type, or a composite type declared within the visible part of a package or generic package. (Eval_Attribute): Perform folding of Preelaborable_Initialization attribute based on Has_Preelaborable_Initialization applied to the prefix type. * sem_ch3.adb (Resolve_Aspects): Add specialized code for Preelaborable_Initialization used at the end of a package visible part for setting Known_To_Have_Preelab_Init on types that are specified with True or that have a conjunction of one or more P_I attributes applied to formal types. * sem_ch7.adb (Analyze_Package_Specification): On call to Has_Preelaborable_Initialization, pass True for new formal Formal_Types_Have_Preelab_Init, so that error checking treats subcomponents that are declared within types in generics as having preelaborable initialization when the subcomponents are of formal types. * sem_ch13.adb (Analyze_Aspects_At_Freeze_Point): Add test for P_I to prevent calling Make_Pragma_From_Boolean_Aspect, since this aspect is handled specially and the Known_To_Have_Preelab_Init flag will get set on types that have the aspect by other means. (Analyze_Aspect_Specifications.Analyze_One_Aspect): Add test for Aspect_Preelaborable_Initialization for allowing the aspect to be specified on formal type declarations. (Is_Operational_Item): Treat Attribute_Put_Image as an operational attribute. The need for this was encountered while working on these changes. * sem_util.ads (Has_Preelaborable_Initialization): Add Formal_Types_Have_Preelab_Init as a new formal parameter that defaults to False. (Is_Conjunction_Of_Formal_Preelab_Init_Attributes): New function. (Original_View_In_Visible_Part): Moved here from exp_disp.adb, so it can be called by Analyze_Attribute. * sem_util.adb (Has_Preelaborable_Initialization): Return True for formal private and derived types when new formal Formal_Types_Have_Preelab_Init is True, and pass along the Formal_Types_Have_Preelab_Init flag in the array component case. (Check_Components): Pass along Formal_Types_Have_Preelab_Init flag on call to Has_Preelaborable_Initialization. (Is_Conjunction_Of_Formal_Preelab_Init_Attributes): New function that returns True when passed an expression that includes one or more attributes for Preelaborable_Initialization applied to prefixes that denote formal types. (Is_Formal_Preelab_Init_Attribute): New utility function nested within Is_Conjunction_Of_Formal_Preelab_Init_Attributes that determines whether a node is a P_I attribute applied to a generic formal type. (Original_View_In_Visible_Part): Moved here from exp_util.adb, so it can be called by Analyze_Attribute. * snames.ads-tmpl: Add note near the start of spec giving details about what needs to be done when adding a name that corresponds to both an attribute and a pragma. Delete existing occurrence of Name_Preelaborable_Initialization, and add a note comment in the list of Name_* constants at that place, indicating that it's included in type Pragma_Id, etc., echoing other such comments for names that are both an attribute and a pragma. Insert Name_Preelaborable_Initialization in the alphabetized set of Name_* constants corresponding to attributes (between First_Attribute_Name and Last_Attribute_Name). (type Attribute_Id): Add new literal Attribute_Preelaborable_Initialization. (type Pragma_Id): Move Pragma_Preelaborable_Initialization from its current position to the end of the type, in the special set of pragma literals that have corresponding atttributes. Add to accompanying comment, indicating that functions Get_Pragma_Id and Is_Pragma_Name need to be updated when adding a pragma literal to the special set. * snames.adb-tmpl (Get_Pragma_Id): Add case alternative for Pragma_Preelaborable_Initialization. (Is_Pragma_Name): Add test for Name_Preelaborable_Initialization.
Diffstat (limited to 'gcc/ada/sem_ch7.adb')
-rw-r--r--gcc/ada/sem_ch7.adb9
1 files changed, 7 insertions, 2 deletions
diff --git a/gcc/ada/sem_ch7.adb b/gcc/ada/sem_ch7.adb
index f30a9aa..30eade2 100644
--- a/gcc/ada/sem_ch7.adb
+++ b/gcc/ada/sem_ch7.adb
@@ -1768,11 +1768,16 @@ package body Sem_Ch7 is
end if;
-- Check preelaborable initialization for full type completing a
- -- private type for which pragma Preelaborable_Initialization given.
+ -- private type when aspect Preelaborable_Initialization is True.
+ -- We pass True for the parameter Formal_Types_Have_Preelab_Init
+ -- to take into account the rule that presumes that subcomponents
+ -- of generic formal types mentioned in the type's P_I aspect have
+ -- preelaborable initialization (see RM 10.2.1(11.8/5)).
if Is_Type (E)
and then Must_Have_Preelab_Init (E)
- and then not Has_Preelaborable_Initialization (E)
+ and then not Has_Preelaborable_Initialization
+ (E, Formal_Types_Have_Preelab_Init => True)
then
Error_Msg_N
("full view of & does not have preelaborable initialization", E);