From 4df833beb6929d358303604664249752ae946a87 Mon Sep 17 00:00:00 2001
From: Tristan Gingold <tgingold@free.fr>
Date: Tue, 7 Nov 2017 07:55:46 +0100
Subject: Use flist for group declaration.

---
 src/vhdl/disp_vhdl.adb  |  5 ++---
 src/vhdl/iirs.adb       |  8 ++++----
 src/vhdl/iirs.ads       |  4 ++--
 src/vhdl/nodes_meta.adb | 10 +++++-----
 src/vhdl/parse.adb      | 12 +++++++++++-
 src/vhdl/sem_decls.adb  | 10 ++++------
 6 files changed, 28 insertions(+), 21 deletions(-)

diff --git a/src/vhdl/disp_vhdl.adb b/src/vhdl/disp_vhdl.adb
index 5fbf6d657..65c951af0 100644
--- a/src/vhdl/disp_vhdl.adb
+++ b/src/vhdl/disp_vhdl.adb
@@ -1682,7 +1682,7 @@ package body Disp_Vhdl is
 
    procedure Disp_Group_Declaration (Decl : Iir)
    is
-      List : Iir_List;
+      List : Iir_Flist;
       El : Iir;
    begin
       Put ("group ");
@@ -1691,9 +1691,8 @@ package body Disp_Vhdl is
       Disp_Name (Get_Group_Template_Name (Decl));
       Put (" (");
       List := Get_Group_Constituent_List (Decl);
-      for I in Natural loop
+      for I in Flist_First .. Flist_Last (List) loop
          El := Get_Nth_Element (List, I);
-         exit when El = Null_Iir;
          if I /= 0 then
             Put (", ");
          end if;
diff --git a/src/vhdl/iirs.adb b/src/vhdl/iirs.adb
index 39e7f7082..2fb4f5d34 100644
--- a/src/vhdl/iirs.adb
+++ b/src/vhdl/iirs.adb
@@ -2648,20 +2648,20 @@ package body Iirs is
       Set_Field1 (Target, Chain);
    end Set_Entity_Class_Entry_Chain;
 
-   function Get_Group_Constituent_List (Group : Iir) return Iir_List is
+   function Get_Group_Constituent_List (Group : Iir) return Iir_Flist is
    begin
       pragma Assert (Group /= Null_Iir);
       pragma Assert (Has_Group_Constituent_List (Get_Kind (Group)),
                      "no field Group_Constituent_List");
-      return Iir_To_Iir_List (Get_Field1 (Group));
+      return Iir_To_Iir_Flist (Get_Field1 (Group));
    end Get_Group_Constituent_List;
 
-   procedure Set_Group_Constituent_List (Group : Iir; List : Iir_List) is
+   procedure Set_Group_Constituent_List (Group : Iir; List : Iir_Flist) is
    begin
       pragma Assert (Group /= Null_Iir);
       pragma Assert (Has_Group_Constituent_List (Get_Kind (Group)),
                      "no field Group_Constituent_List");
-      Set_Field1 (Group, Iir_List_To_Iir (List));
+      Set_Field1 (Group, Iir_Flist_To_Iir (List));
    end Set_Group_Constituent_List;
 
    function Get_Unit_Chain (Target : Iir) return Iir is
diff --git a/src/vhdl/iirs.ads b/src/vhdl/iirs.ads
index 66fc4bf96..3ec70eaa8 100644
--- a/src/vhdl/iirs.ads
+++ b/src/vhdl/iirs.ads
@@ -6433,8 +6433,8 @@ package Iirs is
    procedure Set_Entity_Class_Entry_Chain (Target : Iir; Chain : Iir);
 
    --  Field: Field1 (uc)
-   function Get_Group_Constituent_List (Group : Iir) return Iir_List;
-   procedure Set_Group_Constituent_List (Group : Iir; List : Iir_List);
+   function Get_Group_Constituent_List (Group : Iir) return Iir_Flist;
+   procedure Set_Group_Constituent_List (Group : Iir; List : Iir_Flist);
 
    --  Chain of physical type units.
    --  The first unit is the primary unit.  If you really need the primary
diff --git a/src/vhdl/nodes_meta.adb b/src/vhdl/nodes_meta.adb
index ef395e224..12e08c5e0 100644
--- a/src/vhdl/nodes_meta.adb
+++ b/src/vhdl/nodes_meta.adb
@@ -146,7 +146,7 @@ package body Nodes_Meta is
       Field_Associated_Type => Type_Iir,
       Field_Enumeration_Literal_List => Type_Iir_Flist,
       Field_Entity_Class_Entry_Chain => Type_Iir,
-      Field_Group_Constituent_List => Type_Iir_List,
+      Field_Group_Constituent_List => Type_Iir_Flist,
       Field_Unit_Chain => Type_Iir,
       Field_Primary_Unit => Type_Iir,
       Field_Identifier => Type_Name_Id,
@@ -5913,6 +5913,8 @@ package body Nodes_Meta is
             return Get_Simple_Aggregate_List (N);
          when Field_Enumeration_Literal_List =>
             return Get_Enumeration_Literal_List (N);
+         when Field_Group_Constituent_List =>
+            return Get_Group_Constituent_List (N);
          when Field_Index_Subtype_List =>
             return Get_Index_Subtype_List (N);
          when Field_Index_Subtype_Definition_List =>
@@ -5939,6 +5941,8 @@ package body Nodes_Meta is
             Set_Simple_Aggregate_List (N, V);
          when Field_Enumeration_Literal_List =>
             Set_Enumeration_Literal_List (N, V);
+         when Field_Group_Constituent_List =>
+            Set_Group_Constituent_List (N, V);
          when Field_Index_Subtype_List =>
             Set_Index_Subtype_List (N, V);
          when Field_Index_Subtype_Definition_List =>
@@ -6087,8 +6091,6 @@ package body Nodes_Meta is
             return Get_Entity_Name_List (N);
          when Field_Signal_List =>
             return Get_Signal_List (N);
-         when Field_Group_Constituent_List =>
-            return Get_Group_Constituent_List (N);
          when Field_Sensitivity_List =>
             return Get_Sensitivity_List (N);
          when Field_Callees_List =>
@@ -6121,8 +6123,6 @@ package body Nodes_Meta is
             Set_Entity_Name_List (N, V);
          when Field_Signal_List =>
             Set_Signal_List (N, V);
-         when Field_Group_Constituent_List =>
-            Set_Group_Constituent_List (N, V);
          when Field_Sensitivity_List =>
             Set_Sensitivity_List (N, V);
          when Field_Callees_List =>
diff --git a/src/vhdl/parse.adb b/src/vhdl/parse.adb
index 6284ac0fe..7653083c3 100644
--- a/src/vhdl/parse.adb
+++ b/src/vhdl/parse.adb
@@ -3875,20 +3875,30 @@ package body Parse is
                Res := Create_Iir (Iir_Kind_Group_Declaration);
                Set_Location (Res, Loc);
                Set_Identifier (Res, Ident);
+
+               --  Skip ':'.
                Scan;
+
                Set_Group_Template_Name
                  (Res, Parse_Name (Allow_Indexes => False));
+
+               --  Skip '('.
                Expect (Tok_Left_Paren);
                Scan;
                List := Create_Iir_List;
-               Set_Group_Constituent_List (Res, List);
                loop
                   Append_Element (List, Parse_Name (Allow_Indexes => False));
                   exit when Current_Token = Tok_Right_Paren;
+
+                  --  Skip ','.
                   Expect (Tok_Comma);
                   Scan;
                end loop;
+
+               --  Skip ')'.
                Scan_Expect (Tok_Semi_Colon);
+
+               Set_Group_Constituent_List (Res, List_To_Flist (List));
                return Res;
             end;
          when others =>
diff --git a/src/vhdl/sem_decls.adb b/src/vhdl/sem_decls.adb
index 4d3fc535e..9d3b71b5e 100644
--- a/src/vhdl/sem_decls.adb
+++ b/src/vhdl/sem_decls.adb
@@ -2716,8 +2716,7 @@ package body Sem_Decls is
    end Sem_Alias_Declaration;
 
    procedure Sem_Group_Template_Declaration
-     (Decl : Iir_Group_Template_Declaration)
-   is
+     (Decl : Iir_Group_Template_Declaration) is
    begin
       Sem_Scopes.Add_Name (Decl);
       Sem_Scopes.Name_Visible (Decl);
@@ -2728,7 +2727,7 @@ package body Sem_Decls is
    is
       use Tokens;
 
-      Constituent_List : Iir_Group_Constituent_List;
+      Constituent_List : Iir_Flist;
       Template : Iir_Group_Template_Declaration;
       Template_Name : Iir;
       Class, Prev_Class : Token_Type;
@@ -2749,9 +2748,8 @@ package body Sem_Decls is
       Constituent_List := Get_Group_Constituent_List (Group);
       El_Entity := Get_Entity_Class_Entry_Chain (Template);
       Prev_Class := Tok_Eof;
-      for I in Natural loop
+      for I in Flist_First .. Flist_Last (Constituent_List) loop
          El := Get_Nth_Element (Constituent_List, I);
-         exit when El = Null_Iir;
 
          Sem_Name (El);
 
@@ -2780,7 +2778,7 @@ package body Sem_Decls is
             Error_Overload (El_Name);
          else
             El := Finish_Sem_Name (El);
-            Replace_Nth_Element (Constituent_List, I, El);
+            Set_Nth_Element (Constituent_List, I, El);
             El_Name := Get_Named_Entity (El);
 
             --  Statements are textually afer the group declaration.  To avoid
-- 
cgit v1.2.3