aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/local_restrict.ads
diff options
context:
space:
mode:
authorSteve Baird <baird@adacore.com>2023-08-10 14:11:22 -0700
committerMarc Poulhiès <poulhies@adacore.com>2023-11-07 10:15:03 +0100
commit9daee42551e2d63c9e21935fb76b2ccc22f441d1 (patch)
treeb0f653b3fd99ef01bf5e1d9fad293151237c0445 /gcc/ada/local_restrict.ads
parent7c09fcfcf2b922905a69ad8ab98609f42095f49a (diff)
downloadgcc-9daee42551e2d63c9e21935fb76b2ccc22f441d1.zip
gcc-9daee42551e2d63c9e21935fb76b2ccc22f441d1.tar.gz
gcc-9daee42551e2d63c9e21935fb76b2ccc22f441d1.tar.bz2
ada: New Local_Restrictions and User_Aspect aspects.
A GNAT-defined aspect, Local_Restrictions, is defined. This provides a way of enforcing a given restriction for an individual subprogram (and its call-closure) without requiring that the entire program satisfy the restriction. A GNAT-defined aspect, User_Aspect, is defined. This (along with the new User_Aspect_Definition configuration pragma) provides a way of naming a set of aspect specifications which can then be applied to multiple declarations without textual repetition of the set. gcc/ada/ * local_restrict.ads: A new package. Declares Local_Restriction enumeration type and provides operations to check for local restriction violations. * local_restrict.adb: Corresponding package body. Replace "not Present (X)" calls with "No (X)" calls. * aspects.ads: Add a new enumeration elements, Aspect_Local_Restrictions and Aspect_User_Aspect, to the Aspect_Id enumeration type. Update Aspect_Id-indexed aggregates. Add nested package User_Aspect_Support to manage two pieces of state. One is a map from identifiers to User_Aspect_Definition pragmas (updated when such a pragma is encountered). The other is an access-to-subprogram variable that is introduced in order to keep the bulk of semantics out of the closure of package Aspects while allowing a call from aspects.adb to the sem_ch13 procedure that analyzes a User_Aspect aspect specification. * aspects.adb (Find_Aspect): Cope with a case of a block statement with an empty parent. It is not clear whether this is papering over a compiler bug. Add indirect call through the aforementioned access-to-subprogram variable when Find_Aspect enounters an unanalyzed User_Aspect aspect specification. If Find_Aspect is called looking for aspect Foo, then a User_Aspect specification might generate (during analysis) a Foo aspect specification. So the Find_Aspect call needs to trigger that analysis if it has not already taken place. Provide a body for package User_Aspect_Support. Replace "not Present (X)" call with "No (X)" call. * freeze.adb (Freeze_Subprogram): Check local restriction compatibility when a dispatching operation is overridden. * par-prag.adb: Add support for parsing a User_Aspect_Definition pragma. * restrict.ads: We'd like to have the body of package Restrict include a call to a procedure declared in package Local_Restrict. Doing that in the obvious way pulls most of semantics into the closure of package Restrict, and that turns out to cause problems. So we introduce a level of indirection and instead call through an access-to-subprogram value. In this unit, we declare the access-to-subprogram type and object. * restrict.adb (Check Restriction): When a construct is encountered that could violate a global restriction (depending on whether the given restriction is in effect), Check_Restriction is called. At this point, we also check for a violation of any corresponding local restriction that is in effect. For reasons described above, this check is performed via an indirect call. * sem_ch13.ads (Parse_Aspect_Local_Restrictions): A new function, similar to the existing Parse_Aspect_Xxx subprograms. * sem_ch13.adb: Perform semantic analysis of Local_Restrictions and User_Aspect aspect specifications. Declare and call new Validate_Aspect_Local_Restrictions and Analyze_User_Aspect_Aspect_Specification procedures (a reference to the latter is registered during package elaboration). In Analyze_Aspect_Specifications, do not set the Analyzed flag of a User_Aspect aspect specification. Replace "not Present (X)" call with "No (X)" call. Replace 'Image with 'Img in a case where the prefix of the attribute reference is an object; this is done to accomodate older compilers. * sem_ch6.adb (Check_Subtype_Conformant): Include in subtype conformance check a check for overriding-related compatibility of local restrictions. * sem_ch8.adb (Analyze_Subprogram_Renaming): In the case of an instance of a generic that takes a formal subprogram, check that formal and actual are compatible with respect to local restrictions. * sem_prag.adb: Add support for User_Aspect_Definition pragma. * sem_res.adb (Resolve_Call): Check caller/callee compatibility with respect to local restrictions. * snames.ads-tmpl: Add Name_Local_Restrictions, Name_User_Aspect, and Name_User_Aspect_Definition constants. * doc/gnat_rm/implementation_defined_aspects.rst: Document new aspects. * doc/gnat_rm/implementation_defined_pragmas.rst: Document new pragma. * doc/gnat_ugn/the_gnat_compilation_model.rst: Add User_Aspect_Definition to list of GNAT pragmas. * gcc-interface/Make-lang.in: Add local_restrict.o. * gnat-style.texi: Regenerate. * gnat_rm.texi: Regenerate. * gnat_ugn.texi: Regenerate.
Diffstat (limited to 'gcc/ada/local_restrict.ads')
-rw-r--r--gcc/ada/local_restrict.ads59
1 files changed, 59 insertions, 0 deletions
diff --git a/gcc/ada/local_restrict.ads b/gcc/ada/local_restrict.ads
new file mode 100644
index 0000000..cf45054
--- /dev/null
+++ b/gcc/ada/local_restrict.ads
@@ -0,0 +1,59 @@
+------------------------------------------------------------------------------
+-- --
+-- GNAT COMPILER COMPONENTS --
+-- --
+-- L O C A L _ R E S T R I C T --
+-- --
+-- S p e c --
+-- --
+-- Copyright (C) 1992-2023, 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. See the GNU General Public License --
+-- for more details. You should have received a copy of the GNU General --
+-- Public License distributed with GNAT; see file COPYING3. If not, go to --
+-- http://www.gnu.org/licenses for a complete copy of the license. --
+-- --
+-- GNAT was originally developed by the GNAT team at New York University. --
+-- Extensive contributions were provided by Ada Core Technologies Inc. --
+-- --
+------------------------------------------------------------------------------
+
+-- This package deals with the implementation of the Local_Restrictions aspect
+
+with Types; use Types;
+
+package Local_Restrict is
+ type Local_Restriction is (No_Secondary_Stack, No_Heap_Allocations);
+ -- A local restriction can be mentioned in a Local_Restrictions aspect
+ -- specification. A local restriction might apply, for example, to a
+ -- single subprogram. No_Secondary_Stack corresponds to the
+ -- GNAT-defined restriction of the same name. No_Heap_Allocations
+ -- corresponds to the conjunction of the RM-defined restrictions
+ -- No_Allocators and No_Implicit_Heap_Allocations. If a subprogram is
+ -- subject to a local restriction, then any subprogram that it calls
+ -- shall be known to satisfy that restriction.
+
+ type Local_Restriction_Set is array (Local_Restriction) of Boolean;
+
+ procedure Check_Call (Call : Node_Id; Callee : Entity_Id := Empty);
+ -- Check whether a call violates any local restrictions that are
+ -- in effect. An empty callee indicates that the callee should be
+ -- conservatively assumed to violate any local restrictions that
+ -- are in effect (for example, for an entry call or a call through
+ -- an access-to-subprogram value).
+
+ procedure Check_Overriding (Overrider_Op, Overridden_Op : Entity_Id);
+ -- Check that all of the local restrictions in effect for
+ -- Overridden_Op are also in effect for Overrider_Op.
+
+ procedure Check_Actual_Subprogram_For_Instance
+ (Actual_Subp_Name : Node_Id; Formal_Subp : Entity_Id);
+ -- Check that all of the local restrictions in effect for
+ -- Formal_Subp are also in effect for Actual_Subp.
+
+end Local_Restrict;