aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/sem_ch3.adb
diff options
context:
space:
mode:
authorPiotr Trojanek <trojanek@adacore.com>2023-03-29 10:03:29 +0200
committerMarc Poulhiès <poulhies@adacore.com>2023-05-29 10:23:17 +0200
commit1b19e6abc715c60506efff6bd5c705e727e0e373 (patch)
treed862021a896569da76c9d6595d5fcbd016e771e9 /gcc/ada/sem_ch3.adb
parente9fd9efc8d64f944cb480322ee5ed2d0a46db87d (diff)
downloadgcc-1b19e6abc715c60506efff6bd5c705e727e0e373.zip
gcc-1b19e6abc715c60506efff6bd5c705e727e0e373.tar.gz
gcc-1b19e6abc715c60506efff6bd5c705e727e0e373.tar.bz2
ada: Analyze pre/post on access-to-subprogram without a wrapper
Aspects Pre/Post attached to an access-to-subprogram type were relocated to a spec of a wrapper subprogram and analyzed there; the body of the wrapper was only created with expansion enabled. However, there were several problems with this approach. When switch -gnat2022 was missing, we didn't relocate the Pre/Post aspects to wrapper and complained that their placement is incorrect (because we wrongly assumed that relocation is unconditional). Now we gently inform, that these aspects are Ada 2022 features that require -gnat20222 switch. When switch -gnata was missing, we entirely bypassed analysis of the Pre/Post aspects on access-to-subprogram. This was unlike for Pre/Post aspects on subprograms, which are checked for legality regardless of the -gnata switch. Finally, in the GNATprove backend we were picking the Pre/Post contract on an access-to-subprogram type from the wrapper, which was awkward as otherwise we had to ignore the wrapper specs and special-case for their missing bodies. In general, it is cleaner for GNATprove to extract the aspect expressions from where they originally appear and not from various expansion artifacts like access-to-subprogram wrappers (but the same applies to predication functions, type invariant procedures and default initialization procedures). Now we analyze the Pre/Post aspects on the types where they are originally attached, regardless of the -gnata switch. Once we adapt GNATprove to pick the aspect expression from there, we will stop creating the wrapper spec when expansion is disabled. gcc/ada/ * contracts.adb (Add_Pre_Post_Condition): Adapt to handle pre/post of an access-to-subprogram type. (Analyze_Type_Contract): Analyze pre/post of an access-to-subprogram. * contracts.ads (Analyze_Type_Contract): Adapt comment. * sem_ch3.adb (Build_Access_Subprogram_Wrapper): Copy pre/post aspects to wrapper spec and keep it on the type. * sem_prag.adb (Analyze_Pre_Post_Condition): Expect pre/post aspects on access-to-subprogram and complain if they appear without -gnat2022 switch. (Analyze_Pre_Post_Condition_In_Decl_Part): Adapt to handle pre/post on an access-to-subprogram type entity. * sem_attr.adb (Analyze_Attribute_Old_Result): Likewise. (Result): Likewise.
Diffstat (limited to 'gcc/ada/sem_ch3.adb')
-rw-r--r--gcc/ada/sem_ch3.adb15
1 files changed, 3 insertions, 12 deletions
diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb
index 634b1cb..f360be8 100644
--- a/gcc/ada/sem_ch3.adb
+++ b/gcc/ada/sem_ch3.adb
@@ -6848,25 +6848,16 @@ package body Sem_Ch3 is
declare
Asp : Node_Id;
A_Id : Aspect_Id;
- Cond : Node_Id;
- Expr : Node_Id;
begin
Asp := First (Aspect_Specifications (Decl));
while Present (Asp) loop
A_Id := Get_Aspect_Id (Chars (Identifier (Asp)));
if A_Id = Aspect_Pre or else A_Id = Aspect_Post then
- Cond := Asp;
- Expr := Expression (Cond);
- Replace_Type_Name (Expr);
- Next (Asp);
-
- Remove (Cond);
- Append (Cond, Contracts);
-
- else
- Next (Asp);
+ Append (New_Copy_Tree (Asp), Contracts);
+ Replace_Type_Name (Expression (Last (Contracts)));
end if;
+ Next (Asp);
end loop;
end;