aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/sem_util.ads
diff options
context:
space:
mode:
authorGary Dismukes <dismukes@adacore.com>2022-07-07 15:29:21 -0400
committerPierre-Marie de Rodat <derodat@adacore.com>2022-07-13 10:01:18 +0000
commit9f857be34d9c17730e590ee95d0d39953bc1bad4 (patch)
treea4b6e066ade6269aedbd8fba88697fe777083e45 /gcc/ada/sem_util.ads
parent6beeff028f40697a73ac01c3ee715960507849e4 (diff)
[Ada] Add support for defaulted Storage_Model_Type aspect and subaspects
The compiler currently rejects a Storage_Model_Type aspect that is not specified with an aggregate, or that has an aggregate that does not specify all defined "subaspects" (Address_Type, Null_Address, Allocate, etc.). The RFC for this feature defines the aspect to fully default to the native memory model when no aggregate is given, and also allows any subaspects to be specified and others to default in the case where the address type is the native address type (System.Address), whether that address type is explicitly specified or defaulted. This set of changes now supports that defaulting semantics. Note that the subaspect retrieval functions in Sem_Util.Storage_Model_Support (which are called by the compiler back ends) will now return Empty for any subprogram subaspects (Allocate, Deallocate, etc.) that are defaulted in the aspect (that is, in the native model case where the address type is System.Address). Also in the native case, retrieval of defaulted subaspects Address_Type and Null_Address will return the entities for System.Address and System.Null_Address, respectively. Additionally, error checks for multiple associations given for the same subaspect are now done. gcc/ada/ * aspects.ads (Aspect_Argument): Change the association for Aspect_Storage_Model_Type from Expression to Optional_Expression. * exp_util.ads (Find_Storage_Op): Update comment to indicate that Empty can be returned in the case where a storage-model operation is defaulted. * exp_util.adb (Find_Storage_Op): Allow the function to return Empty in Storage_Model_Type case rather than raising Program_Error, so that Procedure_To_Call fields in N_Allocator and N_Free_Statement nodes will be set to Empty in the defaulted native storage-model case. * sem_ch13.adb: Add with and use of System.Case_Util (and reformat context_clause). (Check_Aspect_At_Freeze_Point): Return with no action for a Storage_Model_Type aspect with no expression (fully-defaulted native memory-model case). (Resolve_Storage_Model_Type_Argument): If an Address_Type has not been explicitly specified, then set Addr_Type to denote type System.Address. (Validate_Storage_Model_Type_Aspect): Return immediately in the case where the aspect has no Expression (fully-defaulted native memory-model case). No longer issue an error when Address_Type isn't specified, and instead use type System.Address as the default address type. When the address type is System.Address (whether specified or defaulted), no longer issue errors for any other "subaspects" that aren't specified, since in that case those are allowed to default as well. Remove ??? comment about needing to check for duplicates, which is now addressed. (Check_And_Resolve_Storage_Model_Type_Argument): New procedure to check that an association for a storage-model subaspect in the aggregate has not been specified earlier in the aggregate, and to then resolve the expression of the association and save the resolved entity. Called by Validate_Storage_Model_Type_Aspect. * sem_util.ads (Storage_Model_Support): Update comments on specs of the functions Get_Storage_Model_Type_Entity, Storage_Model_Address_Type, and Storage_Model_Null_Address to indicate the behavior when the address type is System.Address (the native memory-model case). * sem_util.adb (Storage_Model_Support.Get_Storage_Model_Type_Entity): Suppress the search for the given subaspect name (Nam) when the Storage_Model_Type aspect is fully defaulted (i.e., no Expression is present) and simply return. In cases where the search is done, but no association that matches Nam is found, return System.Address for the Name_Address_Type case, return System.Null_Address for the Name_Null_Address case, and return Empty for all other cases.
Diffstat (limited to 'gcc/ada/sem_util.ads')
-rw-r--r--gcc/ada/sem_util.ads15
1 files changed, 10 insertions, 5 deletions
diff --git a/gcc/ada/sem_util.ads b/gcc/ada/sem_util.ads
index 64cf5d041dd..dde5b27faa3 100644
--- a/gcc/ada/sem_util.ads
+++ b/gcc/ada/sem_util.ads
@@ -3680,21 +3680,26 @@ package Sem_Util is
-- Given a type with aspect Storage_Model_Type or an object of such a
-- type, and Nam denoting the name of one of the argument kinds allowed
-- for that aspect, returns the Entity_Id corresponding to the entity
- -- associated with Nam in the aspect. If such an entity is not present,
- -- then returns Empty. (Note: This function is modeled on function
- -- Get_Iterable_Type_Primitive.)
+ -- associated with Nam in the aspect. If an entity was not explicitly
+ -- specified for Nam, then returns Empty, except that in the defaulted
+ -- Address_Type case, System.Address will be returned, and in the
+ -- defaulted Null_Address case, System.Null_Address will be returned.
+ -- (Note: This function is modeled on Get_Iterable_Type_Primitive.)
function Storage_Model_Address_Type
(SM_Obj_Or_Type : Entity_Id) return Entity_Id;
-- Given a type with aspect Storage_Model_Type or an object of such a
-- type, returns the type specified for the Address_Type choice in that
- -- aspect; returns Empty if the type isn't specified.
+ -- aspect; returns type System.Address if the address type was not
+ -- explicitly specified (indicating use of the native memory model).
function Storage_Model_Null_Address
(SM_Obj_Or_Type : Entity_Id) return Entity_Id;
-- Given a type with aspect Storage_Model_Type or an object of such a
-- type, returns the constant specified for the Null_Address choice in
- -- that aspect; returns Empty if the constant object isn't specified.
+ -- that aspect; returns Empty if the constant object isn't specified,
+ -- unless the native memory model is in use (System.Address), in which
+ -- case it returns System.Null_Address.
function Storage_Model_Allocate
(SM_Obj_Or_Type : Entity_Id) return Entity_Id;