aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/sem_ch5.adb
diff options
context:
space:
mode:
authorJustin Squirek <squirek@adacore.com>2024-05-09 05:04:03 +0000
committerMarc Poulhiès <poulhies@adacore.com>2024-06-14 09:34:19 +0200
commit262a5ffc41471aa4909f23279278dd37724da744 (patch)
treec92e3b98bf066e302e7b26c45398e0136d255889 /gcc/ada/sem_ch5.adb
parent1feb6d81a3ab587382817cd7a39222b6c83f68ac (diff)
downloadgcc-262a5ffc41471aa4909f23279278dd37724da744.zip
gcc-262a5ffc41471aa4909f23279278dd37724da744.tar.gz
gcc-262a5ffc41471aa4909f23279278dd37724da744.tar.bz2
ada: Add prototype for mutably tagged types
This patch implements mutably tagged types via the new Size'Class aspect. gcc/ada/ * doc/gnat_rm/gnat_language_extensions.rst: Add documentation for mutably tagged type feature. * aspects.ads: Add registration for 'Size'Class. * einfo.ads: Add documentation for new components Class_Wide_Equivalent_Type and Is_Mutably_Tagged_Type. * exp_aggr.adb (Gen_Assign): Assume associated mutably tagged type when class-wide equivalent type is encountered. (Contains_Mutably_Tagged_Type): New subprogram. (Convert_To_Positional): Assume associated mutably tagged type when class-wide equivalent type is encountered. (Is_Static_Element): Assume associated mutably tagged type when class-wide equivalent type is encountered. (Expand_Array_Aggregate): Assume associated mutably tagged type when class-wide equivalent type is encountered. (Expand_Record_Aggregate): Force mutably tagged records to be expanded into assignments. * exp_ch3.adb (Build_Array_Init_Proc): Assume associated mutably tagged type when class-wide equivalent type is encountered. (Simple_Initialization_OK): Disallow simple initialization for class-wide equivalent types. (Build_Init_Statements): Assume associated mutably tagged type when class-wide equivalent type is encountered. (Expand_Freeze_Array_Type): Ignore building of record init procs for mutably tagged types. (Expand_N_Full_Type_Declaration): Replace mutably tagged type declarations with their associated class-wide equivalent types. (Default_Initialize_Object): Add special handling for mutably tagged types. * exp_ch4.adb (Expand_N_Allocator): Add initialization for mutably tagged types. (Expand_Record_Equality): Generate mutably tagged unchecked conversions. * exp_ch5.adb (Expand_N_Assignment_Statement): Generate a special assignment case for class-wide equivalent types which does tag assignments and ignores certain checks. * exp_ch6.adb (Expand_Call_Helper): Propagate constrained extra formal actuals for mutably tagged types. * exp_ch7.adb (Make_Init_Call): Handle mutably tagged type initialization. * exp_util.adb (Make_CW_Equivalent_Type): Modify to handle mutably tagged objects which contain no initialization expression. (Make_Subtype_From_Expr): Modify call to Make_CW_Equivalent_Type. * exp_util.ads (Make_CW_Equivalent_Type): Move declaration from body to spec. * freeze.adb (Size_Known): No longer return false automatically when a class-wide type is encountered. (Freeze_Entity): Ignore error messages about size not being known for mutably tagged types. * gen_il-fields.ads: Register new fields Class_Wide_Equivalent_Type and Is_Mutably_Tagged_Type. * gen_il-gen-gen_entities.adb: Register new fields Class_Wide_Equivalent_Type and Is_Mutably_Tagged_Type for type entities. * mutably_tagged.adb, mutably_tagged.ads (Corresponding_Mutably_Tagged_Type): New subprogram. (Depends_On_Mutably_Tagged_Ext_Comp): New subprogram. (Get_Corresponding_Mutably_Tagged_Type_If_Present): New subprogram. (Get_Corresponding_Tagged_Type_If_Present): New subprogram. (Is_Mutably_Tagged_Conversion): New subprogram. (Is_Mutably_Tagged_CW_Equivalent_Type): New subprogram. (Make_Mutably_Tagged_Conversion): New subprogram. (Make_CW_Size_Compile_Check): New subprogram. (Make_Mutably_Tagged_CW_Check): New subprogram. * sem_aggr.adb (Resolve_Array_Aggregate): Skip tag checks for class-wide equivalent types. (Resolve_Aggr_Expr): Assume associated mutably tagged type when class-wide equivalent type is encountered. * sem_attr.adb (Analyze_Attribute): Allow 'Tag on mutably tagged types. (Resolve_Attribute): Detect errors for dependence of mutably tagged extension type component. * sem_ch12.adb (Instantiate_Object): Detect errors for dependence of mutably tagged extension type component. * sem_ch13.adb (Analyze_One_Aspect): Propagate 'Size'Class to class-wide type. (Analyze_Attribute_Definition_Clause): Add handling of 'Size'Class by generating class-wide equivalent types and checking for illegal uses. * sem_ch2.adb (Analyze_Identifier): Generate unchecked conversion for class-wide equivalent types. * sem_ch3.adb (Analyze_Component_Declaration): Avoid unconstrained errors on mutably tagged types. (Analyze_Object_Declaration): Rewrite declarations of mutably tagged types to use class-wide equivalent types. (Array_Type_Declaration): Modify arrays of mutably tagged types to use their corresponding class-wide equivalent types. (Derived_Type_Declaration): Add various checks for mutably tagged derived types. * sem_ch4.adb (Analyze_Allocator): Replace reference to mutably tagged type with cooresponding tagged type. (Process_Indexed_Component): Generate unchecked conversion for class-wide equivalent type. (Analyze_One_Call): Generate unchecked conversion for class-wide equivalent types. (Analyze_Selected_Component): Assume reference to class-wide equivalent type is associated mutably tagged type. (Analyze_Type_Conversion): Generate unchecked conversion for class-wide equivalent type. * sem_ch5.adb (Analyze_Assignment): Assume associated mutably tagged type when class-wide equivalent type is encountered. (Analyze_Iterator_Specification): Detect errors for dependence of mutably tagged extension type component. * sem_ch6.adb (Create_Extra_Formals): Add code to generate extra formal for mutably tagged types to signal if they are constrained. * sem_ch8.adb (Analyze_Object_Renaming): Detect error on renaming of mutably tagged extension type component. (Analyze_Renaming_Primitive_Operation): Detect error on renaming of mutably tagged extension type component. * sem_res.adb (Resolve_Actuals): Allow class-wide arguments on class-wide equivalent types. (Valid_Conversion): Assume associated mutably tagged type when class-wide equivalent type is encountered. * sem_util.adb (Is_Fully_Initialized_Type): Flag mutably tagged types as fully initialized. (Needs_Simple_Initalization): Flag class-wide equivalent types as needing initialization. * gnat_rm.texi: Regenerate. * gcc-interface/Make-lang.in: Add entry for mutably_tagged.o.
Diffstat (limited to 'gcc/ada/sem_ch5.adb')
-rw-r--r--gcc/ada/sem_ch5.adb36
1 files changed, 31 insertions, 5 deletions
diff --git a/gcc/ada/sem_ch5.adb b/gcc/ada/sem_ch5.adb
index 1e09e57..b92ceb1 100644
--- a/gcc/ada/sem_ch5.adb
+++ b/gcc/ada/sem_ch5.adb
@@ -39,6 +39,7 @@ with Freeze; use Freeze;
with Ghost; use Ghost;
with Lib; use Lib;
with Lib.Xref; use Lib.Xref;
+with Mutably_Tagged; use Mutably_Tagged;
with Namet; use Namet;
with Nlists; use Nlists;
with Nmake; use Nmake;
@@ -676,11 +677,17 @@ package body Sem_Ch5 is
Set_Assignment_Type (Lhs, T1);
- -- If the target of the assignment is an entity of a mutable type and
- -- the expression is a conditional expression, its alternatives can be
- -- of different subtypes of the nominal type of the LHS, so they must be
- -- resolved with the base type, given that their subtype may differ from
- -- that of the target mutable object.
+ -- When analyzing a mutably tagged class-wide equivalent type pretend we
+ -- are actually looking at the mutably tagged type itself for proper
+ -- analysis.
+
+ T1 := Get_Corresponding_Mutably_Tagged_Type_If_Present (T1);
+
+ -- If the target of the assignment is an entity of a mutably tagged type
+ -- and the expression is a conditional expression, its alternatives can
+ -- be of different subtypes of the nominal type of the LHS, so they must
+ -- be resolved with the base type, given that their subtype may differ
+ -- from that of the target mutable object.
if Is_Entity_Name (Lhs)
and then Is_Assignable (Entity (Lhs))
@@ -2500,6 +2507,13 @@ package body Sem_Ch5 is
Error_Msg_N
("iterable name cannot be a discriminant-dependent "
& "component of a mutable object", N);
+
+ elsif Depends_On_Mutably_Tagged_Ext_Comp
+ (Original_Node (Iter_Name))
+ then
+ Error_Msg_N
+ ("iterable name cannot depend on a mutably tagged component",
+ N);
end if;
Check_Subtype_Definition (Component_Type (Typ));
@@ -2630,6 +2644,13 @@ package body Sem_Ch5 is
Error_Msg_N
("container cannot be a discriminant-dependent "
& "component of a mutable object", N);
+
+ elsif Depends_On_Mutably_Tagged_Ext_Comp
+ (Orig_Iter_Name)
+ then
+ Error_Msg_N
+ ("container cannot depend on a mutably tagged "
+ & "component", N);
end if;
end if;
end;
@@ -2716,6 +2737,11 @@ package body Sem_Ch5 is
Error_Msg_N
("container cannot be a discriminant-dependent "
& "component of a mutable object", N);
+
+ elsif Depends_On_Mutably_Tagged_Ext_Comp (Obj) then
+ Error_Msg_N
+ ("container cannot depend on a mutably tagged"
+ & " component", N);
end if;
end;
end if;