aboutsummaryrefslogtreecommitdiff
path: root/gcc/fortran/trans-expr.cc
diff options
context:
space:
mode:
authorGary Dismukes <dismukes@adacore.com>2024-11-04 06:06:21 +0000
committerMarc Poulhiès <dkm@gcc.gnu.org>2025-01-03 16:39:12 +0100
commit758de5fed10a7c964bb06a143a3dc3c308721ddd (patch)
treefda89b7a9b4553b04d59df00b7cf477cdebd7f39 /gcc/fortran/trans-expr.cc
parent4b330318626ec5907436aea8eb9c326da85f1e61 (diff)
downloadgcc-758de5fed10a7c964bb06a143a3dc3c308721ddd.zip
gcc-758de5fed10a7c964bb06a143a3dc3c308721ddd.tar.gz
gcc-758de5fed10a7c964bb06a143a3dc3c308721ddd.tar.bz2
ada: Improve and correct support for inheritance of nonoverriding aspects
This set of changes fixes various issues with the handling of inheritance of nonoverridable aspects (such as for Aggregate, and the indexing and iterator aspects, among others), plus improves some of the error reporting related to those. The prior implementation incorrectly handled types derived from container types with respect to such aspect inheritance, not properly inheriting the parent type's aspects, leading to rejection of legal constructs (such as container aggregates for the derived type). Also, various errors were incorrect (such as stating the wrong aspect) or unclear. In the case of types with indexing aspects, the resolution of indexed names for such types involved locating the eligible indexing functions anew with the analysis of each indexed name, which was both inefficient and wrong in some cases. That is addressed by locating the functions once, when the aspects are resolved, rather doing the location of those in two places, which is a maintenance hazard and could result in inconsistent resolution. Note that this completes work originally undertaken by Ed Schonberg that was also worked on by Steve Baird. gcc/ada/ChangeLog: * diagnostics-constructors.adb (Make_Default_Iterator_Not_Primitive_Error): Revise message to match message change made in sem_ch13.adb. * freeze.adb (Freeze_Record_Type): Output appropriate aspect name in error message, using Get_Name_String. (Freeze_Entity): For derived types, call Analyze_Aspects_At_Freeze_Point on the parent type, and call Inherit_Nonoverridable_Aspects on the type (for both parent type and any progenitor types). Add with_clause for System.Case_Util. * gen_il-fields.ads: Add Aspect_Subprograms to type Opt_Field_Enum. * gen_il-gen-gen_nodes.adb: Add field Aspect_Subprograms to N_Aspect_Specification nodes. * sem_ch4.adb (Try_Container_Indexing): Remove Find_Indexing_Operations and the code calling it. Add new function Indexing_Interpretations for retrieving the eligible indexing functions from the appropriate aspect's Aspect_Subprograms list and call that instead of Find_Value_Of_Aspect. * sem_ch7.adb (Analyze_Package_Specification): In loop over entities, call Analyze_Aspects_At_Freeze_Point for types that have delayed aspects. * sem_ch13.ads (Analyze_Aspects_At_Freeze_Point): Add Nonoverridable_Only formal to restrict processing to nonoverridable aspects. (Check_Function_For_Indexing_Aspect): New exported procedure renamed from Check_One_Function and moved to library level. * sem_ch13.adb (Analyze_Aspects_At_Freeze_Point): Test new formal Nonoverridable_Only formal to skip processing of aspects that are not nonoverridable when the formal is True. Skip the processing for Aspect_Full_Access_Only when Nonoverridable_Only is True. Call Check_Indexing_Functions in the case of indexing aspects (procedure moved from Analyze_Attribute_Definition_Clause to top level). (Analyze_Aspect_Specifications): Locate closest ancestor type with an explicit matching aspect to determine the aspect spec to reference in the error about a nonoverridable aspect not confirming an inherited aspect (skipping intermediate derived parents). Ensures that we retain existing errors flagged on explicit ancestor aspects rather than implicit inherited ones. Change names of variables Parent_Type and Inherited_Aspect to Ancestor_Type and Ancestor_Aspect respectively for clarity. (Analyze_Attribute_Definition_Clause): Move nested subprograms Check_Iterator_Functions and Check_Primitive_Function to top level of package. Move Check_Indexing_Functions (and its nested subprograms) from here to within Analyze_Aspects_At_Freeze_Point (adding some formal parameters and adjusting the code appropriately, and no longer call it from this procedure). (Is_CW_Or_Access_To_CW): Add test for the parent type having the indexing aspect for proper setting of Aspect_Specification_Is_Inherited. Delete "???" comment. (Look_Through_Anon_Access): Remove unneeded tests of Is_Access_Constant and Name_Constant_Indexing, which lead to wrong messages in some cases. (Check_Function_For_Indexing_Aspect): Procedure renamed from Check_One_Function and moved to library level (was nested within Check_Indexing_Functions), plus added formals (including Valid, to check result). Move scope test to beginning, to immediately exclude subprograms not declared immediately within the same scope as the type. Improve several error messages. Add error checking for Constant_Indexing functions. Append the function entity to the Aspect_Subprograms list of the aspect specification. Move code for checking for nonconfirming index aspects and for checking for illegal indexing aspects on full views to Check_Indexing_Functions. (Check_Indexing_Functions): Move procedure Illegal_Indexing from here to within Check_Function_For_Indexing_Aspect. Add a comment to the loop over interpretations about the checking being done as legality rules rather than resolution rules, plus a note referencing AI22-0084. Check for nonconfirming indexing aspects and illegal indexing aspects on full views here rather than in Check_One_Function (now named Check_Function_For_Indexing_Aspect). Remove function Check_One_Function (moved to library level and renamed), and call Check_Function_For_Indexing_Aspect instead. (Check_Inherited_Indexing): Improve spec comment. Remove nested function Same_Chars, and replace call Same_Chars with call to Sem_Util.Same_Name. Replace call to Illegal_Indexing with call to Error_Msg_NE. (Check_One_Function): Unnested from Check_Indexing_Functions, rename to Check_Function_For_Indexing_Aspect, move body to library level, and move declaration to Sem_Ch13 spec. (Analyze_Attribute_Definition_Clause, case Attribute_Default_Iterator): Improve error message related to tagged-type requirement. Suppress call to Check_Iterator_Functions for attribute definition clauses associated with inherited aspects. Remove error checking that is redundant with checking done in Check_Iterator_Functions. (Check_Aspect_At_Freeze_Point, case Attribute_Default_Iterator): Call Check_Iterator_Functions (only if the aspect is not Comes_From_Source). (Check_Iterator_Functions): Procedure unnested from Analyze_Attribute_Definition_Clause. Add formals Typ and Expr. Error messages corrected to say "aspect Default_Iterator" instead of "aspect Iterator". (Valid_Default_Iterator): Improve error message to say "must be a local primitive or class-wide function" instead of "must be a primitive function". (Check_Primitive_Function): Unnested from Analyze_Attribute_Definition_Clause. Add formal Ent. (Rep_Item_Too_Late): Return False when an attribute_definition_clause is not Comes_From_Source, since it was generated by the compiler (such as for an inherited aspect). (Resolve_Aspect_Aggregate): Capture implementation base type. (Valid_Empty): Use implementation base types for result type comparison. (Valid_Add_Named): Use impl base types for comparison of formal's type. (Valid_Add_Unnamed): Use impl base types for comparison of formal's type. (Valid_New_Indexed): Use impl base types for result type comparison. (Validate_Literal_Aspect): Return immediately when aspect does not have Comes_From_Source True (no point in validating inherited aspects). * sem_res.adb (Has_Applicable_User_Defined_Literal): Remove Base_Type comparison and always call Corresponding_Op_Of_Derived_Type for derived types. Add "???" comment about issue with wrapper functions (and indicate that it would be nice to eliminate the call to Corresponding_Primitive_Op). * sem_util.ads (Inherit_Nonoverridable_Aspects): New procedure. (Corresponding_Op_Of_Derived_Type): Update spec comment to indicate return of Ancestor_Op and name changed from Corresponding_Primitive_Op. * sem_util.adb (Check_Inherited_Nonoverridable_Aspects): Fix name in header comment. (Corresponding_Op_Of_Derived_Type): Move declaration of Typ down with other local variables. Remove Assert that doesn't apply in some cases. Simply return Ancestor_Op when it isn't a primitive (it can be a class-wide op). Function name changed from Corresponding_Primitive_Op. (Find_Untagged_Type_Of): Add test of Is_Type (E) as a guard for checking Direct_Primitive_Operations. Remove Assert (False), and return Empty when the primitive is not found. (Profile_Matches_Ancestor): Change comparisons to use implementation base types of the operations' formal and result types. Add tests for interface ancestors. Revise "???" comment. (Is_Confirming): Simplify name-matching test to use the names associated with the aspects rather than going to the N_Attribute_Definition_Clause nodes (may facilitate elimination of those clauses at some point). (Inherit_Nonoverridable_Aspects): New procedure to traverse the aspects of a derived type's parent type and create inherited versions of the parent type's nonoverridable aspects, identifying the appropriate subprograms for each such inherited aspect. (Inherit_Nonoverridable_Aspect): New procedure nested in Inherit_Nonoverridable_Aspects to inherit individual nonoverridable aspects. Identifies the corresponding subprogram(s) associated with an inherited nonoverridable aspect. In the case of indexing aspects, new eligible indexing functions of the type are also identified here, and the entities of all of the identified subprograms are appended to the aspect's Aspect_Subprograms Elist. Add a "???" comment about this. * sinfo.ads: Add documentation for the new Aspect_Subprograms field.
Diffstat (limited to 'gcc/fortran/trans-expr.cc')
0 files changed, 0 insertions, 0 deletions