Commit 4528ead5 by Arnaud Charlet

[multiple changes]

2015-01-06  Bob Duff  <duff@adacore.com>

	* a-cfinve.adb (Copy): Set the discriminant to the Length when
	Capacity = 0.
	* a-cofove.ads (Capacity): Add a postcondition.
	* a-cfinve.ads (Capacity): Add a postcondition.
	(Reserve_Capacity): Correct the postcondition in the case where
	Capacity = 0; that means "Capacity => Length (Container)".
	* a-cofove.adb (Elems[c]): Add a comment
	explaining the dangers and how to avoid them.

2015-01-06  Ed Schonberg  <schonberg@adacore.com>

	* sem_ch12.adb: Code clean up.

From-SVN: r219225
parent 17d01d21
2015-01-06 Bob Duff <duff@adacore.com>
* a-cfinve.adb (Copy): Set the discriminant to the Length when
Capacity = 0.
* a-cofove.ads (Capacity): Add a postcondition.
* a-cfinve.ads (Capacity): Add a postcondition.
(Reserve_Capacity): Correct the postcondition in the case where
Capacity = 0; that means "Capacity => Length (Container)".
* a-cofove.adb (Elems[c]): Add a comment
explaining the dangers and how to avoid them.
2015-01-06 Ed Schonberg <schonberg@adacore.com>
* sem_ch12.adb: Code clean up.
2015-01-06 Arnaud Charlet <charlet@adacore.com> 2015-01-06 Arnaud Charlet <charlet@adacore.com>
* gnatvsn.ads: Bump copyright year. * gnatvsn.ads: Bump copyright year.
......
...@@ -2,8 +2,7 @@ ...@@ -2,8 +2,7 @@
-- -- -- --
-- GNAT LIBRARY COMPONENTS -- -- GNAT LIBRARY COMPONENTS --
-- -- -- --
-- A D A . C O N T A I N E R S -- ADA.CONTAINERS.FORMAL_INDEFINITE_VECTORS --
-- . F O R M A L _ I N D E F I N I T E _ V E C T O R S --
-- -- -- --
-- B o d y -- -- B o d y --
-- -- -- --
...@@ -89,7 +88,8 @@ is ...@@ -89,7 +88,8 @@ is
function Contains function Contains
(Container : Vector; (Container : Vector;
Item : Element_Type) return Boolean is Item : Element_Type) return Boolean
is
(Contains (Container.V, H (Item))); (Contains (Container.V, H (Item)));
---------- ----------
...@@ -98,8 +98,10 @@ is ...@@ -98,8 +98,10 @@ is
function Copy function Copy
(Source : Vector; (Source : Vector;
Capacity : Capacity_Range := 0) return Vector is Capacity : Capacity_Range := 0) return Vector
(Capacity, V => Copy (Source.V, Capacity)); is
((if Capacity = 0 then Length (Source) else Capacity),
V => Copy (Source.V, Capacity));
--------------------- ---------------------
-- Current_To_Last -- -- Current_To_Last --
...@@ -139,7 +141,8 @@ is ...@@ -139,7 +141,8 @@ is
function Find_Index function Find_Index
(Container : Vector; (Container : Vector;
Item : Element_Type; Item : Element_Type;
Index : Index_Type := Index_Type'First) return Extended_Index is Index : Index_Type := Index_Type'First) return Extended_Index
is
(Find_Index (Container.V, H (Item), Index)); (Find_Index (Container.V, H (Item), Index));
------------------- -------------------
...@@ -200,7 +203,9 @@ is ...@@ -200,7 +203,9 @@ is
----------------- -----------------
function Has_Element function Has_Element
(Container : Vector; Position : Extended_Index) return Boolean is (Container : Vector;
Position : Extended_Index) return Boolean
is
(Has_Element (Container.V, Position)); (Has_Element (Container.V, Position));
-------------- --------------
...@@ -272,7 +277,8 @@ is ...@@ -272,7 +277,8 @@ is
function Reverse_Find_Index function Reverse_Find_Index
(Container : Vector; (Container : Vector;
Item : Element_Type; Item : Element_Type;
Index : Index_Type := Index_Type'Last) return Extended_Index is Index : Index_Type := Index_Type'Last) return Extended_Index
is
(Reverse_Find_Index (Container.V, H (Item), Index)); (Reverse_Find_Index (Container.V, H (Item), Index));
---------- ----------
...@@ -290,7 +296,8 @@ is ...@@ -290,7 +296,8 @@ is
function To_Vector function To_Vector
(New_Item : Element_Type; (New_Item : Element_Type;
Length : Capacity_Range) return Vector is Length : Capacity_Range) return Vector
is
begin begin
return (Length, To_Vector (H (New_Item), Length)); return (Length, To_Vector (H (New_Item), Length));
end To_Vector; end To_Vector;
......
...@@ -2,8 +2,7 @@ ...@@ -2,8 +2,7 @@
-- -- -- --
-- GNAT LIBRARY COMPONENTS -- -- GNAT LIBRARY COMPONENTS --
-- -- -- --
-- A D A . C O N T A I N E R S -- ADA.CONTAINERS.FORMAL_INDEFINITE_VECTORS --
-- . F O R M A L _ I N D E F I N I T E _ V E C T O R S --
-- -- -- --
-- S p e c -- -- S p e c --
-- -- -- --
...@@ -41,7 +40,7 @@ generic ...@@ -41,7 +40,7 @@ generic
type Index_Type is range <>; type Index_Type is range <>;
type Element_Type (<>) is private; type Element_Type (<>) is private;
Max_Size_In_Storage_Elements : Natural := Max_Size_In_Storage_Elements : Natural :=
Element_Type'Max_Size_In_Storage_Elements; Element_Type'Max_Size_In_Storage_Elements;
-- This has the same meaning as in Ada.Containers.Bounded_Holders, with the -- This has the same meaning as in Ada.Containers.Bounded_Holders, with the
-- same restrictions. -- same restrictions.
...@@ -81,7 +80,8 @@ is ...@@ -81,7 +80,8 @@ is
Global => null; Global => null;
function Capacity (Container : Vector) return Capacity_Range with function Capacity (Container : Vector) return Capacity_Range with
Global => null; Global => null,
Post => Capacity'Result >= Container.Capacity;
procedure Reserve_Capacity procedure Reserve_Capacity
(Container : in out Vector; (Container : in out Vector;
...@@ -111,7 +111,7 @@ is ...@@ -111,7 +111,7 @@ is
Capacity : Capacity_Range := 0) return Vector Capacity : Capacity_Range := 0) return Vector
with with
Global => null, Global => null,
Pre => (if Bounded then Length (Source) <= Capacity); Pre => (if Bounded then (Capacity = 0 or Length (Source) <= Capacity));
function Element function Element
(Container : Vector; (Container : Vector;
...@@ -133,16 +133,17 @@ is ...@@ -133,16 +133,17 @@ is
New_Item : Vector) New_Item : Vector)
with with
Global => null, Global => null,
Pre => (if Bounded then Pre => (if Bounded
Length (Container) + Length (New_Item) <= Container.Capacity); then Length (Container) + Length (New_Item) <=
Container.Capacity);
procedure Append procedure Append
(Container : in out Vector; (Container : in out Vector;
New_Item : Element_Type) New_Item : Element_Type)
with with
Global => null, Global => null,
Pre => (if Bounded then Pre => (if Bounded
Length (Container) < Container.Capacity); then Length (Container) < Container.Capacity);
procedure Delete_Last procedure Delete_Last
(Container : in out Vector) (Container : in out Vector)
...@@ -243,7 +244,7 @@ private ...@@ -243,7 +244,7 @@ private
package Def is new Formal_Vectors (Index_Type, Holder, "=", Bounded); package Def is new Formal_Vectors (Index_Type, Holder, "=", Bounded);
use Def; use Def;
-- ????Assert that Def subtypes have the same range. -- ????Assert that Def subtypes have the same range
type Vector (Capacity : Capacity_Range) is limited record type Vector (Capacity : Capacity_Range) is limited record
V : Def.Vector (Capacity); V : Def.Vector (Capacity);
......
...@@ -59,6 +59,9 @@ is ...@@ -59,6 +59,9 @@ is
-- possible bounds. This means that the pointer is a thin pointer. This is -- possible bounds. This means that the pointer is a thin pointer. This is
-- necessary because 'Unrestricted_Access doesn't work when it produces -- necessary because 'Unrestricted_Access doesn't work when it produces
-- access-to-unconstrained and is returned from a function. -- access-to-unconstrained and is returned from a function.
--
-- Note that this is dangerous: make sure calls to this use an indexed
-- component or slice that is within the bounds 1 .. Length (Container).
function Get_Element function Get_Element
(Container : Vector; (Container : Vector;
......
...@@ -84,7 +84,8 @@ is ...@@ -84,7 +84,8 @@ is
Global => null; Global => null;
function Capacity (Container : Vector) return Capacity_Range with function Capacity (Container : Vector) return Capacity_Range with
Global => null; Global => null,
Post => Capacity'Result >= Container.Capacity;
procedure Reserve_Capacity procedure Reserve_Capacity
(Container : in out Vector; (Container : in out Vector;
......
...@@ -1804,12 +1804,13 @@ package body Sem_Ch12 is ...@@ -1804,12 +1804,13 @@ package body Sem_Ch12 is
(Defining_Entity (Analyzed_Formal))) (Defining_Entity (Analyzed_Formal)))
and then Ekind (Defining_Entity (Analyzed_Formal)) = and then Ekind (Defining_Entity (Analyzed_Formal)) =
E_Function E_Function
and then Expander_Active
then then
-- If actual is an entity (function or operator), -- If actual is an entity (function or operator),
-- and expander is active, build wrapper for it. -- and expander is active, build wrapper for it.
-- Note that wrappers play no role within a generic. -- Note that wrappers play no role within a generic.
if Present (Match) and then Expander_Active then if Present (Match) then
if Nkind (Match) = N_Operator_Symbol then if Nkind (Match) = N_Operator_Symbol then
-- If the name is a default, find its visible -- If the name is a default, find its visible
...@@ -1837,7 +1838,6 @@ package body Sem_Ch12 is ...@@ -1837,7 +1838,6 @@ package body Sem_Ch12 is
elsif Box_Present (Formal) elsif Box_Present (Formal)
and then Nkind (Defining_Entity (Analyzed_Formal)) = and then Nkind (Defining_Entity (Analyzed_Formal)) =
N_Defining_Operator_Symbol N_Defining_Operator_Symbol
and then Expander_Active
then then
Append_To (Assoc, Append_To (Assoc,
Build_Operator_Wrapper Build_Operator_Wrapper
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment