From 3bb4836fe169a7430a4a3e964e3ea63d2e358e4b Mon Sep 17 00:00:00 2001 From: Ed Schonberg Date: Thu, 23 Jul 2020 11:51:39 -0400 Subject: [PATCH] [Ada] AI12-0339: Empty function for Aggregate aspect of Ada containers gcc/ada/ * sinfo.ads, sinfo.adb: The flag Box_Present can appear in Iterated_Element_Association nodes. * sem_aggr.adb (Resolve_Aggregate): Call Resolve_Container_Aggregate when type of context has corresponding aspect. * sem_type.adb (Covers): In Ada_2020 an aggregate is compatible with a type that carries the corresponding aspect. * exp_ch3.adb (Make_Controlling_Function_Wrappers): Do not create declarations and bodies for inherited primitive functions of null extensions that dispatch on result, when current scope includes an immediately visible non-overloadable homonym of the function. * libgnat/a-cborse.adb, libgnat/a-cborse.ads, libgnat/a-cbhase.ads, libgnat/a-cbhase.adb, libgnat/a-cborma.adb, libgnat/a-cborma.ads, libgnat/a-cbhama.adb, libgnat/a-cbhama.ads, libgnat/a-cbdlli.adb, libgnat/a-cbdlli.ads, libgnat/a-convec.ads, libgnat/a-ciorse.ads, libgnat/a-cihase.ads, libgnat/a-cihase.adb, libgnat/a-ciorma.ads, libgnat/a-cihama.ads, libgnat/a-cihama.adb, libgnat/a-cidlli.ads, libgnat/a-cidlli.adb, libgnat/a-coinve.adb, libgnat/a-cobove.adb, libgnat/a-cobove.ads, libgnat/a-convec.adb, libgnat/a-coinve.ads, libgnat/a-coorse.ads, libgnat/a-cohase.adb, libgnat/a-cohase.ads, libgnat/a-coorma.ads, libgnat/a-cohama.adb, libgnat/a-cohama.ads, libgnat/a-cdlili.ads: Add primitive function Empty for use in aspect Aggregate, and add corresponding body or expression function. --- gcc/ada/exp_ch3.adb | 25 +++++++++++++++++++++++++ gcc/ada/libgnat/a-cbdlli.adb | 11 +++++++++++ gcc/ada/libgnat/a-cbdlli.ads | 4 +++- gcc/ada/libgnat/a-cbhama.adb | 11 +++++++++++ gcc/ada/libgnat/a-cbhama.ads | 4 +++- gcc/ada/libgnat/a-cbhase.adb | 11 +++++++++++ gcc/ada/libgnat/a-cbhase.ads | 4 +++- gcc/ada/libgnat/a-cborma.adb | 11 +++++++++++ gcc/ada/libgnat/a-cborma.ads | 4 +++- gcc/ada/libgnat/a-cborse.adb | 11 +++++++++++ gcc/ada/libgnat/a-cborse.ads | 4 +++- gcc/ada/libgnat/a-cdlili.ads | 4 +++- gcc/ada/libgnat/a-cidlli.adb | 12 ++++++++++++ gcc/ada/libgnat/a-cidlli.ads | 10 +++++++++- gcc/ada/libgnat/a-cihama.adb | 11 +++++++++++ gcc/ada/libgnat/a-cihama.ads | 4 +++- gcc/ada/libgnat/a-cihase.adb | 11 +++++++++++ gcc/ada/libgnat/a-cihase.ads | 4 +++- gcc/ada/libgnat/a-ciorma.ads | 5 ++++- gcc/ada/libgnat/a-ciorse.ads | 4 +++- gcc/ada/libgnat/a-cobove.adb | 11 +++++++++++ gcc/ada/libgnat/a-cobove.ads | 4 +++- gcc/ada/libgnat/a-cohama.adb | 11 +++++++++++ gcc/ada/libgnat/a-cohama.ads | 4 +++- gcc/ada/libgnat/a-cohase.adb | 11 +++++++++++ gcc/ada/libgnat/a-cohase.ads | 4 +++- gcc/ada/libgnat/a-coinve.adb | 11 +++++++++++ gcc/ada/libgnat/a-coinve.ads | 2 ++ gcc/ada/libgnat/a-convec.adb | 11 +++++++++++ gcc/ada/libgnat/a-convec.ads | 4 +++- gcc/ada/libgnat/a-coorma.ads | 4 +++- gcc/ada/libgnat/a-coorse.ads | 4 +++- gcc/ada/sem_aggr.adb | 5 +++++ gcc/ada/sem_type.adb | 9 +++++++++ gcc/ada/sinfo.adb | 6 ++++-- gcc/ada/sinfo.ads | 1 + 36 files changed, 248 insertions(+), 19 deletions(-) diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb index 8b8462a..c5cc496 100644 --- a/gcc/ada/exp_ch3.adb +++ b/gcc/ada/exp_ch3.adb @@ -9471,6 +9471,31 @@ package body Exp_Ch3 is (Is_Null_Extension (Etype (Subp)) and then Etype (Alias (Subp)) /= Etype (Subp)) then + -- If there is a non-overloadable homonym in the current + -- scope, the implicit declaration remains invisible. + -- We check the current entity with the same name, or its + -- homonym in case the derivation takes place after the + -- hiding object declaration. + + if Present (Current_Entity (Subp)) then + declare + Curr : constant Entity_Id := Current_Entity (Subp); + Prev : constant Entity_Id := Homonym (Curr); + begin + if (Comes_From_Source (Curr) + and then Scope (Curr) = Current_Scope + and then not Is_Overloadable (Curr)) + or else + (Present (Prev) + and then Comes_From_Source (Prev) + and then Scope (Prev) = Current_Scope + and then not Is_Overloadable (Prev)) + then + goto Next_Prim; + end if; + end; + end if; + Formal_List := No_List; Formal := First_Formal (Subp); diff --git a/gcc/ada/libgnat/a-cbdlli.adb b/gcc/ada/libgnat/a-cbdlli.adb index fa8174b..a0c356d 100644 --- a/gcc/ada/libgnat/a-cbdlli.adb +++ b/gcc/ada/libgnat/a-cbdlli.adb @@ -518,6 +518,17 @@ is return Position.Container.Nodes (Position.Node).Element; end Element; + ----------- + -- Empty -- + ----------- + + function Empty (Capacity : Count_Type := 10) return List is + begin + return Result : List (Capacity) do + null; + end return; + end Empty; + -------------- -- Finalize -- -------------- diff --git a/gcc/ada/libgnat/a-cbdlli.ads b/gcc/ada/libgnat/a-cbdlli.ads index 7e8627a..183c01e 100644 --- a/gcc/ada/libgnat/a-cbdlli.ads +++ b/gcc/ada/libgnat/a-cbdlli.ads @@ -56,7 +56,7 @@ is Variable_Indexing => Reference, Default_Iterator => Iterate, Iterator_Element => Element_Type, - Aggregate => (Empty => Empty_List, + Aggregate => (Empty => Empty, Add_Unnamed => Append_One); pragma Preelaborable_Initialization (List); @@ -67,6 +67,8 @@ is No_Element : constant Cursor; + function Empty (Capacity : Count_Type := 10) return List; + function Has_Element (Position : Cursor) return Boolean; package List_Iterator_Interfaces is new diff --git a/gcc/ada/libgnat/a-cbhama.adb b/gcc/ada/libgnat/a-cbhama.adb index b2137c1..7f0c0e6 100644 --- a/gcc/ada/libgnat/a-cbhama.adb +++ b/gcc/ada/libgnat/a-cbhama.adb @@ -364,6 +364,17 @@ is return Position.Container.Nodes (Position.Node).Element; end Element; + ----------- + -- Empty -- + ----------- + + function Empty (Capacity : Count_Type) return Map is + begin + return Result : Map (Capacity, 0) do + null; + end return; + end Empty; + ------------------------- -- Equivalent_Key_Node -- ------------------------- diff --git a/gcc/ada/libgnat/a-cbhama.ads b/gcc/ada/libgnat/a-cbhama.ads index 9a1aee9..7a1d0f6 100644 --- a/gcc/ada/libgnat/a-cbhama.ads +++ b/gcc/ada/libgnat/a-cbhama.ads @@ -58,7 +58,7 @@ is Variable_Indexing => Reference, Default_Iterator => Iterate, Iterator_Element => Element_Type, - Aggregate => (Empty => Empty_Map, + Aggregate => (Empty => Empty, Add_Named => Insert); pragma Preelaborable_Initialization (Map); @@ -70,6 +70,8 @@ is -- Map objects declared without an initialization expression are -- initialized to the value Empty_Map. + function Empty (Capacity : Count_Type) return Map; + No_Element : constant Cursor; -- Cursor objects declared without an initialization expression are -- initialized to the value No_Element. diff --git a/gcc/ada/libgnat/a-cbhase.adb b/gcc/ada/libgnat/a-cbhase.adb index db61f77..293d722 100644 --- a/gcc/ada/libgnat/a-cbhase.adb +++ b/gcc/ada/libgnat/a-cbhase.adb @@ -456,6 +456,17 @@ is end; end Element; + ----------- + -- Empty -- + ----------- + + function Empty (Capacity : Count_Type := 10) return Set is + begin + return Result : Set (Capacity, 0) do + Reserve_Capacity (Result, Capacity); + end return; + end Empty; + --------------------- -- Equivalent_Sets -- --------------------- diff --git a/gcc/ada/libgnat/a-cbhase.ads b/gcc/ada/libgnat/a-cbhase.ads index 70a3119..c82a123 100644 --- a/gcc/ada/libgnat/a-cbhase.ads +++ b/gcc/ada/libgnat/a-cbhase.ads @@ -60,7 +60,7 @@ is with Constant_Indexing => Constant_Reference, Default_Iterator => Iterate, Iterator_Element => Element_Type, - Aggregate => (Empty => Empty_Set, + Aggregate => (Empty => Empty, Add_Unnamed => Include); pragma Preelaborable_Initialization (Set); @@ -72,6 +72,8 @@ is -- Set objects declared without an initialization expression are -- initialized to the value Empty_Set. + function Empty (Capacity : Count_Type := 10) return Set; + No_Element : constant Cursor; -- Cursor objects declared without an initialization expression are -- initialized to the value No_Element. diff --git a/gcc/ada/libgnat/a-cborma.adb b/gcc/ada/libgnat/a-cborma.adb index 23e21da..5401847 100644 --- a/gcc/ada/libgnat/a-cborma.adb +++ b/gcc/ada/libgnat/a-cborma.adb @@ -573,6 +573,17 @@ is return Container.Nodes (Node).Element; end Element; + ----------- + -- Empty -- + ----------- + + function Empty (Capacity : Count_Type := 10) return Map is + begin + return Result : Map (Capacity) do + null; + end return; + end Empty; + --------------------- -- Equivalent_Keys -- --------------------- diff --git a/gcc/ada/libgnat/a-cborma.ads b/gcc/ada/libgnat/a-cborma.ads index b10b0d0..4da71bc 100644 --- a/gcc/ada/libgnat/a-cborma.ads +++ b/gcc/ada/libgnat/a-cborma.ads @@ -59,7 +59,7 @@ is Variable_Indexing => Reference, Default_Iterator => Iterate, Iterator_Element => Element_Type, - Aggregate => (Empty => Empty_Map, + Aggregate => (Empty => Empty, Add_Named => Insert); pragma Preelaborable_Initialization (Map); @@ -69,6 +69,8 @@ is Empty_Map : constant Map; + function Empty (Capacity : Count_Type := 10) return Map; + No_Element : constant Cursor; function Has_Element (Position : Cursor) return Boolean; diff --git a/gcc/ada/libgnat/a-cborse.adb b/gcc/ada/libgnat/a-cborse.adb index 2daad8e..e4a2de8 100644 --- a/gcc/ada/libgnat/a-cborse.adb +++ b/gcc/ada/libgnat/a-cborse.adb @@ -549,6 +549,17 @@ is return Position.Container.Nodes (Position.Node).Element; end Element; + ----------- + -- Empty -- + ----------- + + function Empty (Capacity : Count_Type := 10) return Set is + begin + return Result : Set (Capacity) do + null; + end return; + end Empty; + ------------------------- -- Equivalent_Elements -- ------------------------- diff --git a/gcc/ada/libgnat/a-cborse.ads b/gcc/ada/libgnat/a-cborse.ads index 90e68e3..92a6df7 100644 --- a/gcc/ada/libgnat/a-cborse.ads +++ b/gcc/ada/libgnat/a-cborse.ads @@ -58,7 +58,7 @@ is with Constant_Indexing => Constant_Reference, Default_Iterator => Iterate, Iterator_Element => Element_Type, - Aggregate => (Empty => Empty_Set, + Aggregate => (Empty => Empty, Add_Unnamed => Include); pragma Preelaborable_Initialization (Set); @@ -68,6 +68,8 @@ is Empty_Set : constant Set; + function Empty (Capacity : Count_Type := 10) return Set; + No_Element : constant Cursor; function Has_Element (Position : Cursor) return Boolean; diff --git a/gcc/ada/libgnat/a-cdlili.ads b/gcc/ada/libgnat/a-cdlili.ads index dc52564..35c4352 100644 --- a/gcc/ada/libgnat/a-cdlili.ads +++ b/gcc/ada/libgnat/a-cdlili.ads @@ -57,7 +57,7 @@ is Variable_Indexing => Reference, Default_Iterator => Iterate, Iterator_Element => Element_Type, - Aggregate => (Empty => Empty_List, + Aggregate => (Empty => Empty, Add_Unnamed => Append_One); pragma Preelaborable_Initialization (List); @@ -66,6 +66,7 @@ is pragma Preelaborable_Initialization (Cursor); Empty_List : constant List; + function Empty return List; No_Element : constant Cursor; @@ -391,6 +392,7 @@ private -- Returns a pointer to the element designated by Position. Empty_List : constant List := (Controlled with others => <>); + function Empty return List is (Empty_List); No_Element : constant Cursor := Cursor'(null, null); diff --git a/gcc/ada/libgnat/a-cidlli.adb b/gcc/ada/libgnat/a-cidlli.adb index 2928606..a62338f 100644 --- a/gcc/ada/libgnat/a-cidlli.adb +++ b/gcc/ada/libgnat/a-cidlli.adb @@ -185,6 +185,18 @@ is Insert (Container, No_Element, New_Item, Count); end Append; + --------------- + -- Append_One -- + --------------- + + procedure Append_One + (Container : in out List; + New_Item : Element_Type) + is + begin + Insert (Container, No_Element, New_Item, 1); + end Append_One; + ------------ -- Assign -- ------------ diff --git a/gcc/ada/libgnat/a-cidlli.ads b/gcc/ada/libgnat/a-cidlli.ads index fe9c7e1..5e63cf2 100644 --- a/gcc/ada/libgnat/a-cidlli.ads +++ b/gcc/ada/libgnat/a-cidlli.ads @@ -55,7 +55,9 @@ is Constant_Indexing => Constant_Reference, Variable_Indexing => Reference, Default_Iterator => Iterate, - Iterator_Element => Element_Type; + Iterator_Element => Element_Type, + Aggregate => (Empty => Empty, + Add_Unnamed => Append_One); pragma Preelaborable_Initialization (List); @@ -63,6 +65,7 @@ is pragma Preelaborable_Initialization (Cursor); Empty_List : constant List; + function Empty return List; No_Element : constant Cursor; @@ -146,6 +149,10 @@ is New_Item : Element_Type; Count : Count_Type := 1); + procedure Append_One + (Container : in out List; + New_Item : Element_Type); + procedure Delete (Container : in out List; Position : in out Cursor; @@ -376,6 +383,7 @@ private -- Returns a pointer to the element designated by Position. Empty_List : constant List := List'(Controlled with others => <>); + function Empty return List is (Empty_List); No_Element : constant Cursor := Cursor'(null, null); diff --git a/gcc/ada/libgnat/a-cihama.adb b/gcc/ada/libgnat/a-cihama.adb index 2b4499c..64f662f 100644 --- a/gcc/ada/libgnat/a-cihama.adb +++ b/gcc/ada/libgnat/a-cihama.adb @@ -385,6 +385,17 @@ is return Position.Node.Element.all; end Element; + ----------- + -- Empty -- + ----------- + + function Empty (Capacity : Count_Type := 1000) return Map is + begin + return Result : Map do + Reserve_Capacity (Result, Capacity); + end return; + end Empty; + ------------------------- -- Equivalent_Key_Node -- ------------------------- diff --git a/gcc/ada/libgnat/a-cihama.ads b/gcc/ada/libgnat/a-cihama.ads index f923314..ccf5f4e 100644 --- a/gcc/ada/libgnat/a-cihama.ads +++ b/gcc/ada/libgnat/a-cihama.ads @@ -58,7 +58,7 @@ is Variable_Indexing => Reference, Default_Iterator => Iterate, Iterator_Element => Element_Type, - Aggregate => (Empty => Empty_Map, + Aggregate => (Empty => Empty, Add_Named => Insert); pragma Preelaborable_Initialization (Map); @@ -70,6 +70,8 @@ is -- Map objects declared without an initialization expression are -- initialized to the value Empty_Map. + function Empty (Capacity : Count_Type := 1000) return Map; + No_Element : constant Cursor; -- Cursor objects declared without an initialization expression are -- initialized to the value No_Element. diff --git a/gcc/ada/libgnat/a-cihase.adb b/gcc/ada/libgnat/a-cihase.adb index dc0cfed..ebc9152 100644 --- a/gcc/ada/libgnat/a-cihase.adb +++ b/gcc/ada/libgnat/a-cihase.adb @@ -506,6 +506,17 @@ is return Position.Node.Element.all; end Element; + ----------- + -- Empty -- + ----------- + + function Empty (Capacity : Count_Type := 1000) return Set is + begin + return Result : Set do + Reserve_Capacity (Result, Capacity); + end return; + end Empty; + --------------------- -- Equivalent_Sets -- --------------------- diff --git a/gcc/ada/libgnat/a-cihase.ads b/gcc/ada/libgnat/a-cihase.ads index 965071c..cdfd86e 100644 --- a/gcc/ada/libgnat/a-cihase.ads +++ b/gcc/ada/libgnat/a-cihase.ads @@ -60,7 +60,7 @@ is with Constant_Indexing => Constant_Reference, Default_Iterator => Iterate, Iterator_Element => Element_Type, - Aggregate => (Empty => Empty_Set, + Aggregate => (Empty => Empty, Add_Unnamed => Include); pragma Preelaborable_Initialization (Set); @@ -72,6 +72,8 @@ is -- Set objects declared without an initialization expression are -- initialized to the value Empty_Set. + function Empty (Capacity : Count_Type := 1000) return Set; + No_Element : constant Cursor; -- Cursor objects declared without an initialization expression are -- initialized to the value No_Element. diff --git a/gcc/ada/libgnat/a-ciorma.ads b/gcc/ada/libgnat/a-ciorma.ads index dbc5948..17f5dfd 100644 --- a/gcc/ada/libgnat/a-ciorma.ads +++ b/gcc/ada/libgnat/a-ciorma.ads @@ -59,7 +59,7 @@ is Variable_Indexing => Reference, Default_Iterator => Iterate, Iterator_Element => Element_Type, - Aggregate => (Empty => Empty_Map, + Aggregate => (Empty => Empty, Add_Named => Insert); pragma Preelaborable_Initialization (Map); @@ -69,6 +69,8 @@ is Empty_Map : constant Map; + function Empty return Map; + No_Element : constant Cursor; function Has_Element (Position : Cursor) return Boolean; @@ -369,6 +371,7 @@ private -- Returns a pointer to the element designated by Position. Empty_Map : constant Map := (Controlled with others => <>); + function Empty return Map is (Empty_Map); No_Element : constant Cursor := Cursor'(null, null); diff --git a/gcc/ada/libgnat/a-ciorse.ads b/gcc/ada/libgnat/a-ciorse.ads index b75a7a3..1b6e317 100644 --- a/gcc/ada/libgnat/a-ciorse.ads +++ b/gcc/ada/libgnat/a-ciorse.ads @@ -58,7 +58,7 @@ is Constant_Indexing => Constant_Reference, Default_Iterator => Iterate, Iterator_Element => Element_Type, - Aggregate => (Empty => Empty_Set, + Aggregate => (Empty => Empty, Add_Unnamed => Include); pragma Preelaborable_Initialization (Set); @@ -67,6 +67,7 @@ is pragma Preelaborable_Initialization (Cursor); Empty_Set : constant Set; + function Empty return Set; No_Element : constant Cursor; @@ -448,6 +449,7 @@ private -- Returns a pointer to the element designated by Position. Empty_Set : constant Set := (Controlled with others => <>); + function Empty return Set is (Empty_Set); No_Element : constant Cursor := Cursor'(null, null); diff --git a/gcc/ada/libgnat/a-cobove.adb b/gcc/ada/libgnat/a-cobove.adb index ba105a2..0408741 100644 --- a/gcc/ada/libgnat/a-cobove.adb +++ b/gcc/ada/libgnat/a-cobove.adb @@ -708,6 +708,17 @@ package body Ada.Containers.Bounded_Vectors is end if; end Element; + ----------- + -- Empty -- + ----------- + + function Empty (Capacity : Count_Type := 10) return Vector is + begin + return Result : Vector (Capacity) do + Reserve_Capacity (Result, Capacity); + end return; + end Empty; + -------------- -- Finalize -- -------------- diff --git a/gcc/ada/libgnat/a-cobove.ads b/gcc/ada/libgnat/a-cobove.ads index d0a1251..ab4ce4e 100644 --- a/gcc/ada/libgnat/a-cobove.ads +++ b/gcc/ada/libgnat/a-cobove.ads @@ -60,7 +60,7 @@ package Ada.Containers.Bounded_Vectors is Variable_Indexing => Reference, Default_Iterator => Iterate, Iterator_Element => Element_Type, - Aggregate => (Empty => Empty_Vector, + Aggregate => (Empty => Empty, Add_Unnamed => Append_One, New_Indexed => New_Vector, Assign_Indexed => Replace_Element); @@ -79,6 +79,8 @@ package Ada.Containers.Bounded_Vectors is package Vector_Iterator_Interfaces is new Ada.Iterator_Interfaces (Cursor, Has_Element); + function Empty (Capacity : Count_Type := 10) return Vector; + overriding function "=" (Left, Right : Vector) return Boolean; function New_Vector (First, Last : Index_Type) return Vector diff --git a/gcc/ada/libgnat/a-cohama.adb b/gcc/ada/libgnat/a-cohama.adb index 44bf3d5..1475330 100644 --- a/gcc/ada/libgnat/a-cohama.adb +++ b/gcc/ada/libgnat/a-cohama.adb @@ -367,6 +367,17 @@ is return Position.Node.Element; end Element; + ----------- + -- Empty -- + ----------- + + function Empty (Capacity : Count_Type := 1000) return Map is + begin + return Result : Map do + Reserve_Capacity (Result, Capacity); + end return; + end Empty; + ------------------------- -- Equivalent_Key_Node -- ------------------------- diff --git a/gcc/ada/libgnat/a-cohama.ads b/gcc/ada/libgnat/a-cohama.ads index cb5d2c5..21b6935 100644 --- a/gcc/ada/libgnat/a-cohama.ads +++ b/gcc/ada/libgnat/a-cohama.ads @@ -102,7 +102,7 @@ is Variable_Indexing => Reference, Default_Iterator => Iterate, Iterator_Element => Element_Type, - Aggregate => (Empty => Empty_Map, + Aggregate => (Empty => Empty, Add_Named => Insert); pragma Preelaborable_Initialization (Map); @@ -118,6 +118,8 @@ is -- Cursor objects declared without an initialization expression are -- initialized to the value No_Element. + function Empty (Capacity : Count_Type := 1000) return Map; + function Has_Element (Position : Cursor) return Boolean; -- Returns True if Position designates an element, and returns False -- otherwise. diff --git a/gcc/ada/libgnat/a-cohase.adb b/gcc/ada/libgnat/a-cohase.adb index 4de3dac..63e44e1 100644 --- a/gcc/ada/libgnat/a-cohase.adb +++ b/gcc/ada/libgnat/a-cohase.adb @@ -468,6 +468,17 @@ is return Position.Node.Element; end Element; + ----------- + -- Empty -- + ----------- + + function Empty (Capacity : Count_Type := 1000) return Set is + begin + return Result : Set do + Reserve_Capacity (Result, Capacity); + end return; + end Empty; + --------------------- -- Equivalent_Sets -- --------------------- diff --git a/gcc/ada/libgnat/a-cohase.ads b/gcc/ada/libgnat/a-cohase.ads index 451f592..a0aca52 100644 --- a/gcc/ada/libgnat/a-cohase.ads +++ b/gcc/ada/libgnat/a-cohase.ads @@ -61,7 +61,7 @@ is Constant_Indexing => Constant_Reference, Default_Iterator => Iterate, Iterator_Element => Element_Type, - Aggregate => (Empty => Empty_Set, + Aggregate => (Empty => Empty, Add_Unnamed => Include); pragma Preelaborable_Initialization (Set); @@ -83,6 +83,8 @@ is package Set_Iterator_Interfaces is new Ada.Iterator_Interfaces (Cursor, Has_Element); + function Empty (Capacity : Count_Type := 1000) return Set; + function "=" (Left, Right : Set) return Boolean; -- For each element in Left, set equality attempts to find the equal -- element in Right; if a search fails, then set equality immediately diff --git a/gcc/ada/libgnat/a-coinve.adb b/gcc/ada/libgnat/a-coinve.adb index 48e81f1..10711ff 100644 --- a/gcc/ada/libgnat/a-coinve.adb +++ b/gcc/ada/libgnat/a-coinve.adb @@ -745,6 +745,17 @@ is end; end Element; + ----------- + -- Empty -- + ----------- + + function Empty (Capacity : Count_Type := 10) return Vector is + begin + return Result : Vector do + Reserve_Capacity (Result, Capacity); + end return; + end Empty; + -------------- -- Finalize -- -------------- diff --git a/gcc/ada/libgnat/a-coinve.ads b/gcc/ada/libgnat/a-coinve.ads index 1f15722..593b63e 100644 --- a/gcc/ada/libgnat/a-coinve.ads +++ b/gcc/ada/libgnat/a-coinve.ads @@ -77,6 +77,8 @@ is No_Element : constant Cursor; + function Empty (Capacity : Count_Type := 10) return Vector; + function Has_Element (Position : Cursor) return Boolean; package Vector_Iterator_Interfaces is new diff --git a/gcc/ada/libgnat/a-convec.adb b/gcc/ada/libgnat/a-convec.adb index 0a79376..a43be97 100644 --- a/gcc/ada/libgnat/a-convec.adb +++ b/gcc/ada/libgnat/a-convec.adb @@ -614,6 +614,17 @@ is return Position.Container.Elements.EA (Position.Index); end Element; + ----------- + -- Empty -- + ----------- + + function Empty (Capacity : Count_Type := 10) return Vector is + begin + return Result : Vector do + Reserve_Capacity (Result, Capacity); + end return; + end Empty; + -------------- -- Finalize -- -------------- diff --git a/gcc/ada/libgnat/a-convec.ads b/gcc/ada/libgnat/a-convec.ads index ebc90cf..f969e6f 100644 --- a/gcc/ada/libgnat/a-convec.ads +++ b/gcc/ada/libgnat/a-convec.ads @@ -94,7 +94,7 @@ is Variable_Indexing => Reference, Default_Iterator => Iterate, Iterator_Element => Element_Type, - Aggregate => (Empty => Empty_Vector, + Aggregate => (Empty => Empty, Add_Unnamed => Append_One, New_Indexed => New_Vector, Assign_Indexed => Replace_Element); @@ -122,6 +122,8 @@ is Empty_Vector : constant Vector; -- Empty_Vector represents the empty vector object. It has a length of 0. + function Empty (Capacity : Count_Type := 10) return Vector; + overriding function "=" (Left, Right : Vector) return Boolean; -- If Left and Right denote the same vector object, then the function -- returns True. If Left and Right have different lengths, then the diff --git a/gcc/ada/libgnat/a-coorma.ads b/gcc/ada/libgnat/a-coorma.ads index f80836e..7f65a7f 100644 --- a/gcc/ada/libgnat/a-coorma.ads +++ b/gcc/ada/libgnat/a-coorma.ads @@ -59,13 +59,14 @@ is Variable_Indexing => Reference, Default_Iterator => Iterate, Iterator_Element => Element_Type, - Aggregate => (Empty => Empty_Map, + Aggregate => (Empty => Empty, Add_Named => Insert); type Cursor is private; pragma Preelaborable_Initialization (Cursor); Empty_Map : constant Map; + function Empty return Map; No_Element : constant Cursor; @@ -373,6 +374,7 @@ private -- Returns a pointer to the element designated by Position. Empty_Map : constant Map := (Controlled with others => <>); + function Empty return Map is (Empty_Map); No_Element : constant Cursor := Cursor'(null, null); diff --git a/gcc/ada/libgnat/a-coorse.ads b/gcc/ada/libgnat/a-coorse.ads index a5577e9..1ccf290 100644 --- a/gcc/ada/libgnat/a-coorse.ads +++ b/gcc/ada/libgnat/a-coorse.ads @@ -58,7 +58,7 @@ is with Constant_Indexing => Constant_Reference, Default_Iterator => Iterate, Iterator_Element => Element_Type; - -- Aggregate => (Empty => Empty_Set, + -- Aggregate => (Empty => Empty, -- Add_Unnamed => Include); pragma Preelaborable_Initialization (Set); @@ -69,6 +69,7 @@ is function Has_Element (Position : Cursor) return Boolean; Empty_Set : constant Set; + function Empty return Set; No_Element : constant Cursor; @@ -434,6 +435,7 @@ private -- Returns a pointer to the element designated by Position. Empty_Set : constant Set := (Controlled with others => <>); + function Empty return Set is (Empty_Set); No_Element : constant Cursor := Cursor'(null, null); diff --git a/gcc/ada/sem_aggr.adb b/gcc/ada/sem_aggr.adb index e5cdb4f..c7d1e49 100644 --- a/gcc/ada/sem_aggr.adb +++ b/gcc/ada/sem_aggr.adb @@ -899,6 +899,11 @@ package body Sem_Aggr is elsif Is_Array_Type (Typ) and then Null_Record_Present (N) then Error_Msg_N ("null record forbidden in array aggregate", N); + elsif Present (Find_Aspect (Typ, Aspect_Aggregate)) + and then Ekind (Typ) /= E_Record_Type + then + Resolve_Container_Aggregate (N, Typ); + elsif Is_Record_Type (Typ) then Resolve_Record_Aggregate (N, Typ); diff --git a/gcc/ada/sem_type.adb b/gcc/ada/sem_type.adb index a5e62a7..3b1f48e 100644 --- a/gcc/ada/sem_type.adb +++ b/gcc/ada/sem_type.adb @@ -1009,6 +1009,15 @@ package body Sem_Type is elsif T2 = Any_Composite and then Is_Aggregate_Type (T1) then return True; + -- In Ada_2020, an aggregate is compatible with the type that + -- as the ccorrespoding aspect. + + elsif Ada_Version >= Ada_2020 + and then T2 = Any_Composite + and then Present (Find_Aspect (T1, Aspect_Aggregate)) + then + return True; + -- If the expected type is an anonymous access, the designated type must -- cover that of the expression. Use the base type for this check: even -- though access subtypes are rare in sources, they are generated for diff --git a/gcc/ada/sinfo.adb b/gcc/ada/sinfo.adb index 065d3c6..82bc8a5 100644 --- a/gcc/ada/sinfo.adb +++ b/gcc/ada/sinfo.adb @@ -368,7 +368,8 @@ package body Sinfo is or else NT (N).Nkind = N_Formal_Concrete_Subprogram_Declaration or else NT (N).Nkind = N_Formal_Package_Declaration or else NT (N).Nkind = N_Generic_Association - or else NT (N).Nkind = N_Iterated_Component_Association); + or else NT (N).Nkind = N_Iterated_Component_Association + or else NT (N).Nkind = N_Iterated_Element_Association); return Flag15 (N); end Box_Present; @@ -3873,7 +3874,8 @@ package body Sinfo is or else NT (N).Nkind = N_Formal_Concrete_Subprogram_Declaration or else NT (N).Nkind = N_Formal_Package_Declaration or else NT (N).Nkind = N_Generic_Association - or else NT (N).Nkind = N_Iterated_Component_Association); + or else NT (N).Nkind = N_Iterated_Component_Association + or else NT (N).Nkind = N_Iterated_Element_Association); Set_Flag15 (N, Val); end Set_Box_Present; diff --git a/gcc/ada/sinfo.ads b/gcc/ada/sinfo.ads index 4f0a41f..551f43f 100644 --- a/gcc/ada/sinfo.ads +++ b/gcc/ada/sinfo.ads @@ -4251,6 +4251,7 @@ package Sinfo is -- Expression (Node3) -- Loop_Parameter_Specification (Node4) -- Loop_Actions (List5-Sem) + -- Box_Present (Flag15) -- Exactly one of Iterator_Specification or Loop_Parameter_ -- specification is present. If the Key_Expression is absent, -- 2.7.4