This set of changes implements the Preelaborable_Initialization
attribute, corresponding to the existing aspect/pragma, as defined by
AI12-0409 (RM2022 10.2.1(11.6/5-11.8/5). This includes semantic checking
of restrictions on the prefix, and support for the aspect expression
being given by an expression with one or more P_I attributes applied to
formal private or derived types, when the type with the aspect is
specified on types within a generic package declaration (the value of
the aspect in instantiations can be different depending on the actual
types), as well as applying preelaborable-initialization restrictions on
full types when the partial type has such aspects.

Tested on x86_64-pc-linux-gnu, committed on trunk

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.

Attachment: patch.diff.gz
Description: application/gzip

Reply via email to