gcc/gcc/ada/a-conhel.adb

187 lines
6.1 KiB
Ada
Raw Normal View History

------------------------------------------------------------------------------
-- --
-- GNAT LIBRARY COMPONENTS --
-- --
-- A D A . C O N T A I N E R S . H E L P E R S --
-- --
-- B o d y --
-- --
-- Copyright (C) 2015-2016, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
------------------------------------------------------------------------------
package body Ada.Containers.Helpers is
package body Generic_Implementation is
sem_ch13.adb (Analyze_One_Aspect): Avoid analyzing the expression in a 'Disable_Controlled attribute when... 2015-10-20 Bob Duff <duff@adacore.com> * sem_ch13.adb (Analyze_One_Aspect): Avoid analyzing the expression in a 'Disable_Controlled attribute when Expander_Active is False, because otherwise, we get errors about nonstatic expressions in pragma-Preelaborate generic packages. * restrict.ads: minor whitespace cleanup in comment 2015-10-20 Bob Duff <duff@adacore.com> * a-conhel.adb: Remove "use SAC;", because otherwise the compiler complains about use clauses in run-time units. Use "use type" instead. * a-btgbso.adb, a-btgbso.ads, a-cbdlli.adb, a-cbdlli.ads, * a-cbhama.adb, a-cbhama.ads, a-cbhase.adb, a-cbhase.ads, * a-cbmutr.adb, a-cbmutr.ads, a-cborma.adb, a-cborma.ads, * a-cborse.adb, a-cborse.ads, a-cdlili.adb, a-cdlili.ads, * a-chtgbk.adb, a-chtgbk.ads, a-chtgbo.adb, a-chtgbo.ads, * a-chtgke.adb, a-chtgke.ads, a-chtgop.adb, a-chtgop.ads, * a-cidlli.adb, a-cidlli.ads, a-cihama.adb, a-cihama.ads, * a-cihase.adb, a-cihase.ads, a-cimutr.adb, a-cimutr.ads, * a-ciorma.adb, a-ciorma.ads, a-ciormu.adb, a-ciormu.ads, * a-ciorse.adb, a-ciorse.ads, a-cobove.adb, a-cobove.ads, * a-cohama.adb, a-cohama.ads, a-cohase.adb, a-cohase.ads, * a-cohata.ads, a-coinve.adb, a-comutr.adb, a-comutr.ads, * a-convec.adb, a-coorma.adb, a-coorma.ads, a-coormu.adb, * a-coormu.ads, a-coorse.adb, a-coorse.ads, a-crbltr.ads, * a-crbtgk.adb, a-crbtgk.ads, a-crbtgo.adb, a-crbtgo.ads, * a-rbtgbk.adb, a-rbtgbk.ads, a-rbtgbo.adb, a-rbtgbo.ads, * a-rbtgso.adb, a-rbtgso.ads: Change all the predefined containers to share the tampering machinery in Ada.Containers.Helpers. This reduces the amount of duplicated code, and takes advantage of efficiency improvements in Helpers. Protect all run-time checks and supporting machinery with "if Checks" or "if T_Check", so this code can be suppressed with pragma Suppress or -gnatp. Add Pseudo_Reference and Get_Element_Access to remaining containers, so that the compiler can optimize "for ... of" loops. From-SVN: r229041
2015-10-20 12:23:46 +02:00
use type SAC.Atomic_Unsigned;
------------
-- Adjust --
------------
procedure Adjust (Control : in out Reference_Control_Type) is
begin
if Control.T_Counts /= null then
Lock (Control.T_Counts.all);
end if;
end Adjust;
----------
-- Busy --
----------
procedure Busy (T_Counts : in out Tamper_Counts) is
begin
if T_Check then
sem_ch13.adb (Analyze_One_Aspect): Avoid analyzing the expression in a 'Disable_Controlled attribute when... 2015-10-20 Bob Duff <duff@adacore.com> * sem_ch13.adb (Analyze_One_Aspect): Avoid analyzing the expression in a 'Disable_Controlled attribute when Expander_Active is False, because otherwise, we get errors about nonstatic expressions in pragma-Preelaborate generic packages. * restrict.ads: minor whitespace cleanup in comment 2015-10-20 Bob Duff <duff@adacore.com> * a-conhel.adb: Remove "use SAC;", because otherwise the compiler complains about use clauses in run-time units. Use "use type" instead. * a-btgbso.adb, a-btgbso.ads, a-cbdlli.adb, a-cbdlli.ads, * a-cbhama.adb, a-cbhama.ads, a-cbhase.adb, a-cbhase.ads, * a-cbmutr.adb, a-cbmutr.ads, a-cborma.adb, a-cborma.ads, * a-cborse.adb, a-cborse.ads, a-cdlili.adb, a-cdlili.ads, * a-chtgbk.adb, a-chtgbk.ads, a-chtgbo.adb, a-chtgbo.ads, * a-chtgke.adb, a-chtgke.ads, a-chtgop.adb, a-chtgop.ads, * a-cidlli.adb, a-cidlli.ads, a-cihama.adb, a-cihama.ads, * a-cihase.adb, a-cihase.ads, a-cimutr.adb, a-cimutr.ads, * a-ciorma.adb, a-ciorma.ads, a-ciormu.adb, a-ciormu.ads, * a-ciorse.adb, a-ciorse.ads, a-cobove.adb, a-cobove.ads, * a-cohama.adb, a-cohama.ads, a-cohase.adb, a-cohase.ads, * a-cohata.ads, a-coinve.adb, a-comutr.adb, a-comutr.ads, * a-convec.adb, a-coorma.adb, a-coorma.ads, a-coormu.adb, * a-coormu.ads, a-coorse.adb, a-coorse.ads, a-crbltr.ads, * a-crbtgk.adb, a-crbtgk.ads, a-crbtgo.adb, a-crbtgo.ads, * a-rbtgbk.adb, a-rbtgbk.ads, a-rbtgbo.adb, a-rbtgbo.ads, * a-rbtgso.adb, a-rbtgso.ads: Change all the predefined containers to share the tampering machinery in Ada.Containers.Helpers. This reduces the amount of duplicated code, and takes advantage of efficiency improvements in Helpers. Protect all run-time checks and supporting machinery with "if Checks" or "if T_Check", so this code can be suppressed with pragma Suppress or -gnatp. Add Pseudo_Reference and Get_Element_Access to remaining containers, so that the compiler can optimize "for ... of" loops. From-SVN: r229041
2015-10-20 12:23:46 +02:00
SAC.Increment (T_Counts.Busy);
end if;
end Busy;
--------------
-- Finalize --
--------------
procedure Finalize (Control : in out Reference_Control_Type) is
begin
if Control.T_Counts /= null then
Unlock (Control.T_Counts.all);
Control.T_Counts := null;
end if;
end Finalize;
-- No need to protect against double Finalize here, because these types
-- are limited.
procedure Finalize (Busy : in out With_Busy) is
pragma Warnings (Off);
pragma Assert (T_Check); -- not called if check suppressed
pragma Warnings (On);
begin
Unbusy (Busy.T_Counts.all);
end Finalize;
procedure Finalize (Lock : in out With_Lock) is
pragma Warnings (Off);
pragma Assert (T_Check); -- not called if check suppressed
pragma Warnings (On);
begin
Unlock (Lock.T_Counts.all);
end Finalize;
----------------
-- Initialize --
----------------
procedure Initialize (Busy : in out With_Busy) is
pragma Warnings (Off);
pragma Assert (T_Check); -- not called if check suppressed
pragma Warnings (On);
begin
Generic_Implementation.Busy (Busy.T_Counts.all);
end Initialize;
procedure Initialize (Lock : in out With_Lock) is
pragma Warnings (Off);
pragma Assert (T_Check); -- not called if check suppressed
pragma Warnings (On);
begin
Generic_Implementation.Lock (Lock.T_Counts.all);
end Initialize;
----------
-- Lock --
----------
procedure Lock (T_Counts : in out Tamper_Counts) is
begin
if T_Check then
sem_ch13.adb (Analyze_One_Aspect): Avoid analyzing the expression in a 'Disable_Controlled attribute when... 2015-10-20 Bob Duff <duff@adacore.com> * sem_ch13.adb (Analyze_One_Aspect): Avoid analyzing the expression in a 'Disable_Controlled attribute when Expander_Active is False, because otherwise, we get errors about nonstatic expressions in pragma-Preelaborate generic packages. * restrict.ads: minor whitespace cleanup in comment 2015-10-20 Bob Duff <duff@adacore.com> * a-conhel.adb: Remove "use SAC;", because otherwise the compiler complains about use clauses in run-time units. Use "use type" instead. * a-btgbso.adb, a-btgbso.ads, a-cbdlli.adb, a-cbdlli.ads, * a-cbhama.adb, a-cbhama.ads, a-cbhase.adb, a-cbhase.ads, * a-cbmutr.adb, a-cbmutr.ads, a-cborma.adb, a-cborma.ads, * a-cborse.adb, a-cborse.ads, a-cdlili.adb, a-cdlili.ads, * a-chtgbk.adb, a-chtgbk.ads, a-chtgbo.adb, a-chtgbo.ads, * a-chtgke.adb, a-chtgke.ads, a-chtgop.adb, a-chtgop.ads, * a-cidlli.adb, a-cidlli.ads, a-cihama.adb, a-cihama.ads, * a-cihase.adb, a-cihase.ads, a-cimutr.adb, a-cimutr.ads, * a-ciorma.adb, a-ciorma.ads, a-ciormu.adb, a-ciormu.ads, * a-ciorse.adb, a-ciorse.ads, a-cobove.adb, a-cobove.ads, * a-cohama.adb, a-cohama.ads, a-cohase.adb, a-cohase.ads, * a-cohata.ads, a-coinve.adb, a-comutr.adb, a-comutr.ads, * a-convec.adb, a-coorma.adb, a-coorma.ads, a-coormu.adb, * a-coormu.ads, a-coorse.adb, a-coorse.ads, a-crbltr.ads, * a-crbtgk.adb, a-crbtgk.ads, a-crbtgo.adb, a-crbtgo.ads, * a-rbtgbk.adb, a-rbtgbk.ads, a-rbtgbo.adb, a-rbtgbo.ads, * a-rbtgso.adb, a-rbtgso.ads: Change all the predefined containers to share the tampering machinery in Ada.Containers.Helpers. This reduces the amount of duplicated code, and takes advantage of efficiency improvements in Helpers. Protect all run-time checks and supporting machinery with "if Checks" or "if T_Check", so this code can be suppressed with pragma Suppress or -gnatp. Add Pseudo_Reference and Get_Element_Access to remaining containers, so that the compiler can optimize "for ... of" loops. From-SVN: r229041
2015-10-20 12:23:46 +02:00
SAC.Increment (T_Counts.Lock);
SAC.Increment (T_Counts.Busy);
end if;
end Lock;
--------------
-- TC_Check --
--------------
procedure TC_Check (T_Counts : Tamper_Counts) is
begin
if T_Check and then T_Counts.Busy > 0 then
raise Program_Error with
"attempt to tamper with cursors";
end if;
sem_ch13.adb (Analyze_One_Aspect): Avoid analyzing the expression in a 'Disable_Controlled attribute when... 2015-10-20 Bob Duff <duff@adacore.com> * sem_ch13.adb (Analyze_One_Aspect): Avoid analyzing the expression in a 'Disable_Controlled attribute when Expander_Active is False, because otherwise, we get errors about nonstatic expressions in pragma-Preelaborate generic packages. * restrict.ads: minor whitespace cleanup in comment 2015-10-20 Bob Duff <duff@adacore.com> * a-conhel.adb: Remove "use SAC;", because otherwise the compiler complains about use clauses in run-time units. Use "use type" instead. * a-btgbso.adb, a-btgbso.ads, a-cbdlli.adb, a-cbdlli.ads, * a-cbhama.adb, a-cbhama.ads, a-cbhase.adb, a-cbhase.ads, * a-cbmutr.adb, a-cbmutr.ads, a-cborma.adb, a-cborma.ads, * a-cborse.adb, a-cborse.ads, a-cdlili.adb, a-cdlili.ads, * a-chtgbk.adb, a-chtgbk.ads, a-chtgbo.adb, a-chtgbo.ads, * a-chtgke.adb, a-chtgke.ads, a-chtgop.adb, a-chtgop.ads, * a-cidlli.adb, a-cidlli.ads, a-cihama.adb, a-cihama.ads, * a-cihase.adb, a-cihase.ads, a-cimutr.adb, a-cimutr.ads, * a-ciorma.adb, a-ciorma.ads, a-ciormu.adb, a-ciormu.ads, * a-ciorse.adb, a-ciorse.ads, a-cobove.adb, a-cobove.ads, * a-cohama.adb, a-cohama.ads, a-cohase.adb, a-cohase.ads, * a-cohata.ads, a-coinve.adb, a-comutr.adb, a-comutr.ads, * a-convec.adb, a-coorma.adb, a-coorma.ads, a-coormu.adb, * a-coormu.ads, a-coorse.adb, a-coorse.ads, a-crbltr.ads, * a-crbtgk.adb, a-crbtgk.ads, a-crbtgo.adb, a-crbtgo.ads, * a-rbtgbk.adb, a-rbtgbk.ads, a-rbtgbo.adb, a-rbtgbo.ads, * a-rbtgso.adb, a-rbtgso.ads: Change all the predefined containers to share the tampering machinery in Ada.Containers.Helpers. This reduces the amount of duplicated code, and takes advantage of efficiency improvements in Helpers. Protect all run-time checks and supporting machinery with "if Checks" or "if T_Check", so this code can be suppressed with pragma Suppress or -gnatp. Add Pseudo_Reference and Get_Element_Access to remaining containers, so that the compiler can optimize "for ... of" loops. From-SVN: r229041
2015-10-20 12:23:46 +02:00
-- The lock status (which monitors "element tampering") always
-- implies that the busy status (which monitors "cursor tampering")
-- is set too; this is a representation invariant. Thus if the busy
-- bit is not set, then the lock bit must not be set either.
pragma Assert (T_Counts.Lock = 0);
end TC_Check;
--------------
-- TE_Check --
--------------
procedure TE_Check (T_Counts : Tamper_Counts) is
begin
if T_Check and then T_Counts.Lock > 0 then
raise Program_Error with
"attempt to tamper with elements";
end if;
end TE_Check;
------------
-- Unbusy --
------------
procedure Unbusy (T_Counts : in out Tamper_Counts) is
begin
if T_Check then
sem_ch13.adb (Analyze_One_Aspect): Avoid analyzing the expression in a 'Disable_Controlled attribute when... 2015-10-20 Bob Duff <duff@adacore.com> * sem_ch13.adb (Analyze_One_Aspect): Avoid analyzing the expression in a 'Disable_Controlled attribute when Expander_Active is False, because otherwise, we get errors about nonstatic expressions in pragma-Preelaborate generic packages. * restrict.ads: minor whitespace cleanup in comment 2015-10-20 Bob Duff <duff@adacore.com> * a-conhel.adb: Remove "use SAC;", because otherwise the compiler complains about use clauses in run-time units. Use "use type" instead. * a-btgbso.adb, a-btgbso.ads, a-cbdlli.adb, a-cbdlli.ads, * a-cbhama.adb, a-cbhama.ads, a-cbhase.adb, a-cbhase.ads, * a-cbmutr.adb, a-cbmutr.ads, a-cborma.adb, a-cborma.ads, * a-cborse.adb, a-cborse.ads, a-cdlili.adb, a-cdlili.ads, * a-chtgbk.adb, a-chtgbk.ads, a-chtgbo.adb, a-chtgbo.ads, * a-chtgke.adb, a-chtgke.ads, a-chtgop.adb, a-chtgop.ads, * a-cidlli.adb, a-cidlli.ads, a-cihama.adb, a-cihama.ads, * a-cihase.adb, a-cihase.ads, a-cimutr.adb, a-cimutr.ads, * a-ciorma.adb, a-ciorma.ads, a-ciormu.adb, a-ciormu.ads, * a-ciorse.adb, a-ciorse.ads, a-cobove.adb, a-cobove.ads, * a-cohama.adb, a-cohama.ads, a-cohase.adb, a-cohase.ads, * a-cohata.ads, a-coinve.adb, a-comutr.adb, a-comutr.ads, * a-convec.adb, a-coorma.adb, a-coorma.ads, a-coormu.adb, * a-coormu.ads, a-coorse.adb, a-coorse.ads, a-crbltr.ads, * a-crbtgk.adb, a-crbtgk.ads, a-crbtgo.adb, a-crbtgo.ads, * a-rbtgbk.adb, a-rbtgbk.ads, a-rbtgbo.adb, a-rbtgbo.ads, * a-rbtgso.adb, a-rbtgso.ads: Change all the predefined containers to share the tampering machinery in Ada.Containers.Helpers. This reduces the amount of duplicated code, and takes advantage of efficiency improvements in Helpers. Protect all run-time checks and supporting machinery with "if Checks" or "if T_Check", so this code can be suppressed with pragma Suppress or -gnatp. Add Pseudo_Reference and Get_Element_Access to remaining containers, so that the compiler can optimize "for ... of" loops. From-SVN: r229041
2015-10-20 12:23:46 +02:00
SAC.Decrement (T_Counts.Busy);
end if;
end Unbusy;
------------
-- Unlock --
------------
procedure Unlock (T_Counts : in out Tamper_Counts) is
begin
if T_Check then
sem_ch13.adb (Analyze_One_Aspect): Avoid analyzing the expression in a 'Disable_Controlled attribute when... 2015-10-20 Bob Duff <duff@adacore.com> * sem_ch13.adb (Analyze_One_Aspect): Avoid analyzing the expression in a 'Disable_Controlled attribute when Expander_Active is False, because otherwise, we get errors about nonstatic expressions in pragma-Preelaborate generic packages. * restrict.ads: minor whitespace cleanup in comment 2015-10-20 Bob Duff <duff@adacore.com> * a-conhel.adb: Remove "use SAC;", because otherwise the compiler complains about use clauses in run-time units. Use "use type" instead. * a-btgbso.adb, a-btgbso.ads, a-cbdlli.adb, a-cbdlli.ads, * a-cbhama.adb, a-cbhama.ads, a-cbhase.adb, a-cbhase.ads, * a-cbmutr.adb, a-cbmutr.ads, a-cborma.adb, a-cborma.ads, * a-cborse.adb, a-cborse.ads, a-cdlili.adb, a-cdlili.ads, * a-chtgbk.adb, a-chtgbk.ads, a-chtgbo.adb, a-chtgbo.ads, * a-chtgke.adb, a-chtgke.ads, a-chtgop.adb, a-chtgop.ads, * a-cidlli.adb, a-cidlli.ads, a-cihama.adb, a-cihama.ads, * a-cihase.adb, a-cihase.ads, a-cimutr.adb, a-cimutr.ads, * a-ciorma.adb, a-ciorma.ads, a-ciormu.adb, a-ciormu.ads, * a-ciorse.adb, a-ciorse.ads, a-cobove.adb, a-cobove.ads, * a-cohama.adb, a-cohama.ads, a-cohase.adb, a-cohase.ads, * a-cohata.ads, a-coinve.adb, a-comutr.adb, a-comutr.ads, * a-convec.adb, a-coorma.adb, a-coorma.ads, a-coormu.adb, * a-coormu.ads, a-coorse.adb, a-coorse.ads, a-crbltr.ads, * a-crbtgk.adb, a-crbtgk.ads, a-crbtgo.adb, a-crbtgo.ads, * a-rbtgbk.adb, a-rbtgbk.ads, a-rbtgbo.adb, a-rbtgbo.ads, * a-rbtgso.adb, a-rbtgso.ads: Change all the predefined containers to share the tampering machinery in Ada.Containers.Helpers. This reduces the amount of duplicated code, and takes advantage of efficiency improvements in Helpers. Protect all run-time checks and supporting machinery with "if Checks" or "if T_Check", so this code can be suppressed with pragma Suppress or -gnatp. Add Pseudo_Reference and Get_Element_Access to remaining containers, so that the compiler can optimize "for ... of" loops. From-SVN: r229041
2015-10-20 12:23:46 +02:00
SAC.Decrement (T_Counts.Lock);
SAC.Decrement (T_Counts.Busy);
end if;
end Unlock;
-----------------
-- Zero_Counts --
-----------------
procedure Zero_Counts (T_Counts : out Tamper_Counts) is
begin
if T_Check then
T_Counts := (others => <>);
end if;
end Zero_Counts;
end Generic_Implementation;
end Ada.Containers.Helpers;