aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPiotr Trojanek <trojanek@adacore.com>2024-12-05 14:12:25 +0100
committerMarc Poulhiès <dkm@gcc.gnu.org>2025-01-03 16:39:14 +0100
commit9c73f9dcca3b7ed29dd80afea0196729630973be (patch)
tree007ce38938d3c72c64e577e26ab531a6c23576d5 /gcc
parentbfa8e6f2137ba80dcd1ca7106be2cfe967810426 (diff)
downloadgcc-9c73f9dcca3b7ed29dd80afea0196729630973be.zip
gcc-9c73f9dcca3b7ed29dd80afea0196729630973be.tar.gz
gcc-9c73f9dcca3b7ed29dd80afea0196729630973be.tar.bz2
ada: Reuse and simplify counting the length of various lists
Use utility routines to compute number of elements in lists of nodes and chains of formal parameters. Code cleanup; semantics is unaffected. gcc/ada/ChangeLog: * exp_aggr.adb (Others_Check): Reuse List_Length; tune whitespace. * exp_ch3.adb (Constrain_Array): Remove counting of constraints. * exp_disp.adb (Make_DT): Use Elist utility routines; tune whitespace. * sem_ch12.adb (Formal_Dimensions): Reuse List_Length. (Valid_Default_Attribute): Reuse Number_Formals. * sem_prag.adb (Process_Convention): Likewise. * sem_util.adb (Normalize_Actuals): Likewise. (Check_Function_Writable_Actuals): Reuse List_Length.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ada/exp_aggr.adb18
-rw-r--r--gcc/ada/exp_ch3.adb15
-rw-r--r--gcc/ada/exp_disp.adb18
-rw-r--r--gcc/ada/sem_ch12.adb22
-rw-r--r--gcc/ada/sem_prag.adb13
-rw-r--r--gcc/ada/sem_util.adb24
6 files changed, 26 insertions, 84 deletions
diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb
index 64bb05c..dae9d4e 100644
--- a/gcc/ada/exp_aggr.adb
+++ b/gcc/ada/exp_aggr.adb
@@ -5352,17 +5352,10 @@ package body Exp_Aggr is
-- Count the number of discrete choices. Start with -1 because
-- the others choice does not count.
- -- Is there some reason we do not use List_Length here ???
-
Nb_Choices := -1;
Assoc := First (Component_Associations (Sub_Aggr));
while Present (Assoc) loop
- Choice := First (Choice_List (Assoc));
- while Present (Choice) loop
- Nb_Choices := Nb_Choices + 1;
- Next (Choice);
- end loop;
-
+ Nb_Choices := Nb_Choices + List_Length (Choice_List (Assoc));
Next (Assoc);
end loop;
@@ -5379,12 +5372,7 @@ package body Exp_Aggr is
-- choice then compute the number or positional elements.
if Need_To_Check and then Present (Expressions (Sub_Aggr)) then
- Expr := First (Expressions (Sub_Aggr));
- Nb_Elements := Uint_0;
- while Present (Expr) loop
- Nb_Elements := Nb_Elements + 1;
- Next (Expr);
- end loop;
+ Nb_Elements := UI_From_Int (List_Length (Expressions (Sub_Aggr)));
-- If the aggregate contains discrete choices and an others choice
-- compute the smallest and largest discrete choice values.
@@ -5395,7 +5383,7 @@ package body Exp_Aggr is
Table : Case_Table_Type (1 .. Nb_Choices);
-- Used to sort all the different choice values
- J : Pos := 1;
+ J : Pos := 1;
begin
Assoc := First (Component_Associations (Sub_Aggr));
diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb
index 71bca1c..a68b4f1 100644
--- a/gcc/ada/exp_ch3.adb
+++ b/gcc/ada/exp_ch3.adb
@@ -4300,10 +4300,9 @@ package body Exp_Ch3 is
(SI : Node_Id;
Check_List : List_Id)
is
- C : constant Node_Id := Constraint (SI);
- Number_Of_Constraints : Nat := 0;
- Index : Node_Id;
- S, T : Entity_Id;
+ C : constant Node_Id := Constraint (SI);
+ Index : Node_Id;
+ S, T : Entity_Id;
procedure Constrain_Index
(Index : Node_Id;
@@ -4341,12 +4340,6 @@ package body Exp_Ch3 is
T := Designated_Type (T);
end if;
- S := First (Constraints (C));
- while Present (S) loop
- Number_Of_Constraints := Number_Of_Constraints + 1;
- Next (S);
- end loop;
-
-- In either case, the index constraint must provide a discrete
-- range for each index of the array type and the type of each
-- discrete range must be the same as that of the corresponding
@@ -4358,7 +4351,7 @@ package body Exp_Ch3 is
-- Apply constraints to each index type
- for J in 1 .. Number_Of_Constraints loop
+ while Present (S) loop
Constrain_Index (Index, S, Check_List);
Next (Index);
Next (S);
diff --git a/gcc/ada/exp_disp.adb b/gcc/ada/exp_disp.adb
index f250117..9fcc469 100644
--- a/gcc/ada/exp_disp.adb
+++ b/gcc/ada/exp_disp.adb
@@ -4650,7 +4650,6 @@ package body Exp_Disp is
Name_ITable : Name_Id;
Nb_Prim : Nat := 0;
New_Node : Node_Id;
- Num_Ifaces : Nat := 0;
Parent_Typ : Entity_Id;
Predef_Prims : Entity_Id;
Prim : Entity_Id;
@@ -5494,23 +5493,18 @@ package body Exp_Disp is
Collect_Interfaces (Typ, Typ_Ifaces);
- AI := First_Elmt (Typ_Ifaces);
- while Present (AI) loop
- Num_Ifaces := Num_Ifaces + 1;
- Next_Elmt (AI);
- end loop;
-
- if Num_Ifaces = 0 then
+ if Is_Empty_Elmt_List (Typ_Ifaces) then
Iface_Table_Node := Make_Null (Loc);
-- Generate the Interface_Table object
else
declare
- TSD_Ifaces_List : constant List_Id := New_List;
- Elmt : Elmt_Id;
- Offset_To_Top : Node_Id;
- Sec_DT_Tag : Node_Id;
+ Num_Ifaces : constant Pos := List_Length (Typ_Ifaces);
+ TSD_Ifaces_List : constant List_Id := New_List;
+ Elmt : Elmt_Id;
+ Offset_To_Top : Node_Id;
+ Sec_DT_Tag : Node_Id;
Dummy_Object_Ifaces_List : Elist_Id := No_Elist;
Dummy_Object_Ifaces_Comp_List : Elist_Id := No_Elist;
diff --git a/gcc/ada/sem_ch12.adb b/gcc/ada/sem_ch12.adb
index b1d6efd..b52d9dd 100644
--- a/gcc/ada/sem_ch12.adb
+++ b/gcc/ada/sem_ch12.adb
@@ -14010,22 +14010,16 @@ package body Sem_Ch12 is
-----------------------
function Formal_Dimensions return Nat is
- Num : Nat := 0;
- Index : Node_Id;
+ Dims : List_Id;
begin
if Nkind (Def) = N_Constrained_Array_Definition then
- Index := First (Discrete_Subtype_Definitions (Def));
+ Dims := Discrete_Subtype_Definitions (Def);
else
- Index := First (Subtype_Marks (Def));
+ Dims := Subtype_Marks (Def);
end if;
- while Present (Index) loop
- Num := Num + 1;
- Next (Index);
- end loop;
-
- return Num;
+ return List_Length (Dims);
end Formal_Dimensions;
-- Start of processing for Validate_Array_Type_Instance
@@ -18079,7 +18073,6 @@ package body Sem_Ch12 is
Get_Attribute_Id (Attribute_Name (Def));
T : constant Entity_Id := Entity (Prefix (Def));
Is_Fun : constant Boolean := (Ekind (Nam) = E_Function);
- F : Entity_Id;
Num_F : Nat;
OK : Boolean;
@@ -18088,12 +18081,7 @@ package body Sem_Ch12 is
return;
end if;
- Num_F := 0;
- F := First_Formal (Nam);
- while Present (F) loop
- Num_F := Num_F + 1;
- Next_Formal (F);
- end loop;
+ Num_F := Number_Formals (Nam);
case Attr_Id is
when Attribute_Adjacent
diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb
index 50ba96b..081716a 100644
--- a/gcc/ada/sem_prag.adb
+++ b/gcc/ada/sem_prag.adb
@@ -8801,19 +8801,8 @@ package body Sem_Prag is
Minimum : constant Nat :=
Convention_Id'Pos (C) -
Convention_Id'Pos (Convention_C_Variadic_0);
-
- Count : Nat;
- Formal : Entity_Id;
-
begin
- Count := 0;
- Formal := First_Formal (Subp);
- while Present (Formal) loop
- Count := Count + 1;
- Next_Formal (Formal);
- end loop;
-
- if Count < Minimum then
+ if Number_Formals (Subp) < Minimum then
Error_Msg_Uint_1 := UI_From_Int (Minimum);
Error_Pragma_Arg
("argument of pragma% must have at least"
diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
index 6bc50c4..bd798d7 100644
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -2915,7 +2915,7 @@ package body Sem_Util is
Expr_Value (Low_Bound (Aggregate_Bounds (N)))
then
declare
- Count_Components : Uint := Uint_0;
+ Count_Components : Uint;
Num_Components : Uint;
Others_Assoc : Node_Id := Empty;
Others_Choice : Node_Id := Empty;
@@ -2924,13 +2924,8 @@ package body Sem_Util is
begin
-- Count positional associations
- if Present (Expressions (N)) then
- Comp_Expr := First (Expressions (N));
- while Present (Comp_Expr) loop
- Count_Components := Count_Components + 1;
- Next (Comp_Expr);
- end loop;
- end if;
+ Count_Components :=
+ UI_From_Int (List_Length (Expressions (N)));
-- Count the rest of elements and locate the N_Others
-- choice (if any)
@@ -25044,8 +25039,8 @@ package body Sem_Util is
First_Named : Node_Id := Empty;
Found : Boolean;
- Formals_To_Match : Integer := 0;
- Actuals_To_Match : Integer := 0;
+ Formals_To_Match : Int := 0;
+ Actuals_To_Match : Int := 0;
procedure Chain (A : Node_Id);
-- Add named actual at the proper place in the list, using the
@@ -25106,16 +25101,11 @@ package body Sem_Util is
-- The name in the call is a function call that returns an access
-- to subprogram. The designated type has the list of formals.
- Formal := First_Formal (Designated_Type (S));
+ Formals_To_Match := Number_Formals (Designated_Type (S));
else
- Formal := First_Formal (S);
+ Formals_To_Match := Number_Formals (S);
end if;
- while Present (Formal) loop
- Formals_To_Match := Formals_To_Match + 1;
- Next_Formal (Formal);
- end loop;
-
-- Find if there is a named association, and verify that no positional
-- associations appear after named ones.