public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-5728] [Ada] Simplify iteration over record components
@ 2021-12-02 16:28 Pierre-Marie de Rodat
  0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2021-12-02 16:28 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:ea7f9e0530251152b5e6a99f36515032f318c4d1

commit r12-5728-gea7f9e0530251152b5e6a99f36515032f318c4d1
Author: Piotr Trojanek <trojanek@adacore.com>
Date:   Mon Nov 22 12:53:15 2021 +0100

    [Ada] Simplify iteration over record components
    
    gcc/ada/
    
            * freeze.adb (Freeze_Entity): Replace First_Entity/Next_Entity
            with First_Component/Next_Component; remove condition with Ekind
            equal to E_Component.
            * sem_ch13.adb (Check_Record_Representation_Clause): Likewise
            for component-or-discriminant.
            * sem_util.adb (Is_Fully_Initialized_Type): Likewise; rename Ent
            to a more specific Comp.
            * sem_warn.adb (Check_References): Likewise.

Diff:
---
 gcc/ada/freeze.adb   |  8 +++-----
 gcc/ada/sem_ch13.adb | 26 +++++++++-----------------
 gcc/ada/sem_util.adb | 17 ++++++++---------
 gcc/ada/sem_warn.adb |  9 ++++-----
 4 files changed, 24 insertions(+), 36 deletions(-)

diff --git a/gcc/ada/freeze.adb b/gcc/ada/freeze.adb
index ad841cf14e3..6804c046b46 100644
--- a/gcc/ada/freeze.adb
+++ b/gcc/ada/freeze.adb
@@ -6328,11 +6328,9 @@ package body Freeze is
             --  to the components of Rec.
 
          begin
-            Comp := First_Entity (E);
+            Comp := First_Component (E);
             while Present (Comp) loop
-               if Ekind (Comp) = E_Component
-                 and then Has_Delayed_Aspects (Comp)
-               then
+               if Has_Delayed_Aspects (Comp) then
                   if not Rec_Pushed then
                      Push_Scope (E);
                      Rec_Pushed := True;
@@ -6348,7 +6346,7 @@ package body Freeze is
                   Analyze_Aspects_At_Freeze_Point (Comp);
                end if;
 
-               Next_Entity (Comp);
+               Next_Component (Comp);
             end loop;
 
             --  Pop the scope if Rec scope has been pushed on the scope stack
diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb
index d63d60fb385..6ff7046ce4b 100644
--- a/gcc/ada/sem_ch13.adb
+++ b/gcc/ada/sem_ch13.adb
@@ -12284,26 +12284,18 @@ package body Sem_Ch13 is
             --  Find maximum bit of any component of the parent type
 
             Parent_Last_Bit := UI_From_Int (System_Address_Size - 1);
-            Pcomp := First_Entity (Tagged_Parent);
+            Pcomp := First_Component_Or_Discriminant (Tagged_Parent);
             while Present (Pcomp) loop
-               if Ekind (Pcomp) in E_Discriminant | E_Component then
-                  if Present (Component_Bit_Offset (Pcomp))
-                    and then Known_Static_Esize (Pcomp)
-                  then
-                     Parent_Last_Bit :=
-                       UI_Max
-                         (Parent_Last_Bit,
-                          Component_Bit_Offset (Pcomp) + Esize (Pcomp) - 1);
-                  end if;
-               else
-
-                  --  Skip anonymous types generated for constrained array
-                  --  or record components.
-
-                  null;
+               if Present (Component_Bit_Offset (Pcomp))
+                 and then Known_Static_Esize (Pcomp)
+               then
+                  Parent_Last_Bit :=
+                    UI_Max
+                      (Parent_Last_Bit,
+                       Component_Bit_Offset (Pcomp) + Esize (Pcomp) - 1);
                end if;
 
-               Next_Entity (Pcomp);
+               Next_Component_Or_Discriminant (Pcomp);
             end loop;
          end if;
       end;
diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
index 2f5070a9789..c6e18303773 100644
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -17803,15 +17803,14 @@ package body Sem_Util is
          --  Otherwise see if all record components are initialized
 
          declare
-            Ent : Entity_Id;
+            Comp : Entity_Id;
 
          begin
-            Ent := First_Entity (Typ);
-            while Present (Ent) loop
-               if Ekind (Ent) = E_Component
-                 and then (No (Parent (Ent))
-                            or else No (Expression (Parent (Ent))))
-                 and then not Is_Fully_Initialized_Type (Etype (Ent))
+            Comp := First_Component (Typ);
+            while Present (Comp) loop
+               if (No (Parent (Comp))
+                    or else No (Expression (Parent (Comp))))
+                 and then not Is_Fully_Initialized_Type (Etype (Comp))
 
                   --  Special VM case for tag components, which need to be
                   --  defined in this case, but are never initialized as VMs
@@ -17819,12 +17818,12 @@ package body Sem_Util is
                   --  uninitialized case. Note that this applies both to the
                   --  uTag entry and the main vtable pointer (CPP_Class case).
 
-                 and then (Tagged_Type_Expansion or else not Is_Tag (Ent))
+                 and then (Tagged_Type_Expansion or else not Is_Tag (Comp))
                then
                   return False;
                end if;
 
-               Next_Entity (Ent);
+               Next_Component (Comp);
             end loop;
          end;
 
diff --git a/gcc/ada/sem_warn.adb b/gcc/ada/sem_warn.adb
index 2842a2ccb40..951b9f80b52 100644
--- a/gcc/ada/sem_warn.adb
+++ b/gcc/ada/sem_warn.adb
@@ -1548,18 +1548,17 @@ package body Sem_Warn is
                               Comp : Entity_Id;
 
                            begin
-                              Comp := First_Entity (E1T);
+                              Comp := First_Component (E1T);
                               while Present (Comp) loop
-                                 if Ekind (Comp) = E_Component
-                                   and then Nkind (Parent (Comp)) =
-                                              N_Component_Declaration
+                                 if Nkind (Parent (Comp)) =
+                                      N_Component_Declaration
                                    and then No (Expression (Parent (Comp)))
                                  then
                                     Error_Msg_Node_2 := Comp;
                                     exit;
                                  end if;
 
-                                 Next_Entity (Comp);
+                                 Next_Component (Comp);
                               end loop;
                            end;
                         end if;


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-12-02 16:28 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-02 16:28 [gcc r12-5728] [Ada] Simplify iteration over record components Pierre-Marie de Rodat

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).