aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/sem_ch3.adb
diff options
context:
space:
mode:
authorPiotr Trojanek <trojanek@adacore.com>2024-01-31 15:32:22 +0100
committerMarc Poulhiès <poulhies@adacore.com>2024-05-13 10:03:33 +0200
commitc1ece0ca7d31f191c97ff0bdc72e0f0416e72774 (patch)
treefe131d002887eb621e930dd226533e75d84175f7 /gcc/ada/sem_ch3.adb
parentb3eef3b124d1eee9cd261fb072d6e1667cd2501a (diff)
downloadgcc-c1ece0ca7d31f191c97ff0bdc72e0f0416e72774.zip
gcc-c1ece0ca7d31f191c97ff0bdc72e0f0416e72774.tar.gz
gcc-c1ece0ca7d31f191c97ff0bdc72e0f0416e72774.tar.bz2
ada: Remove guards against traversal of empty list of aspects
When iterating over Aspect_Specifications, we can use First/Next directly even if the Aspect_Specifications returns a No_List or the list has no items. Code cleanup. gcc/ada/ * aspects.adb (Copy_Aspects): Style fix. * contracts.adb (Analyze_Contracts): Style fix. (Save_Global_References_In_Contract): Remove extra guards. * par_sco.adb (Traverse_Aspects): Move guard to the caller and make it consistent with Save_Global_References_In_Contract. * sem_ch12.adb (Has_Contracts): Remove extra guards. * sem_ch3.adb (Delayed_Aspect_Present, Get_Partial_View_Aspect, Check_Duplicate_Aspects): Likewise. * sem_disp.adb (Check_Dispatching_Operation): Likewise.
Diffstat (limited to 'gcc/ada/sem_ch3.adb')
-rw-r--r--gcc/ada/sem_ch3.adb91
1 files changed, 42 insertions, 49 deletions
diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb
index 1d95b12..2bff0bb 100644
--- a/gcc/ada/sem_ch3.adb
+++ b/gcc/ada/sem_ch3.adb
@@ -4153,24 +4153,22 @@ package body Sem_Ch3 is
A_Id : Aspect_Id;
begin
- if Present (Aspect_Specifications (N)) then
- A := First (Aspect_Specifications (N));
+ A := First (Aspect_Specifications (N));
- while Present (A) loop
- A_Id := Get_Aspect_Id (Chars (Identifier (A)));
+ while Present (A) loop
+ A_Id := Get_Aspect_Id (Chars (Identifier (A)));
- if A_Id = Aspect_Address then
+ if A_Id = Aspect_Address then
- -- Set flag on object entity, for later processing at
- -- the freeze point.
+ -- Set flag on object entity, for later processing at the
+ -- freeze point.
- Set_Has_Delayed_Aspects (Id);
- return True;
- end if;
+ Set_Has_Delayed_Aspects (Id);
+ return True;
+ end if;
- Next (A);
- end loop;
- end if;
+ Next (A);
+ end loop;
return False;
end Delayed_Aspect_Present;
@@ -18013,16 +18011,14 @@ package body Sem_Ch3 is
Prev_Asp : Node_Id;
begin
- if Present (Prev_Asps) then
- Prev_Asp := First (Prev_Asps);
- while Present (Prev_Asp) loop
- if Get_Aspect_Id (Prev_Asp) = Asp_Id then
- return Prev_Asp;
- end if;
+ Prev_Asp := First (Prev_Asps);
+ while Present (Prev_Asp) loop
+ if Get_Aspect_Id (Prev_Asp) = Asp_Id then
+ return Prev_Asp;
+ end if;
- Next (Prev_Asp);
- end loop;
- end if;
+ Next (Prev_Asp);
+ end loop;
return Empty;
end Get_Partial_View_Aspect;
@@ -18036,38 +18032,35 @@ package body Sem_Ch3 is
-- Start of processing for Check_Duplicate_Aspects
begin
- if Present (Full_Asps) then
- Full_Asp := First (Full_Asps);
- while Present (Full_Asp) loop
- Part_Asp := Get_Partial_View_Aspect (Full_Asp);
+ Full_Asp := First (Full_Asps);
+ while Present (Full_Asp) loop
+ Part_Asp := Get_Partial_View_Aspect (Full_Asp);
- -- An aspect and its class-wide counterpart are two distinct
- -- aspects and may apply to both views of an entity.
+ -- An aspect and its class-wide counterpart are two distinct
+ -- aspects and may apply to both views of an entity.
- if Present (Part_Asp)
- and then Class_Present (Part_Asp) = Class_Present (Full_Asp)
- then
- Error_Msg_N
- ("aspect already specified in private declaration",
- Full_Asp);
+ if Present (Part_Asp)
+ and then Class_Present (Part_Asp) = Class_Present (Full_Asp)
+ then
+ Error_Msg_N
+ ("aspect already specified in private declaration", Full_Asp);
- Remove (Full_Asp);
- return;
- end if;
+ Remove (Full_Asp);
+ return;
+ end if;
- if Has_Discriminants (Prev)
- and then not Has_Unknown_Discriminants (Prev)
- and then Get_Aspect_Id (Full_Asp) =
- Aspect_Implicit_Dereference
- then
- Error_Msg_N
- ("cannot specify aspect if partial view has known "
- & "discriminants", Full_Asp);
- end if;
+ if Has_Discriminants (Prev)
+ and then not Has_Unknown_Discriminants (Prev)
+ and then Get_Aspect_Id (Full_Asp) =
+ Aspect_Implicit_Dereference
+ then
+ Error_Msg_N
+ ("cannot specify aspect if partial view has known "
+ & "discriminants", Full_Asp);
+ end if;
- Next (Full_Asp);
- end loop;
- end if;
+ Next (Full_Asp);
+ end loop;
end Check_Duplicate_Aspects;
------------------