Add assember CFI directives to millicode division and remainder routines.
[official-gcc.git] / gcc / ada / contracts.ads
blob0a03d19d431068db3a545ea06e9971fbeffadcb3
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- C O N T R A C T S --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 2015-2023, Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
26 -- This package contains routines that perform analysis and expansion of
27 -- various contracts.
29 with Types; use Types;
31 package Contracts is
33 procedure Add_Contract_Item (Prag : Node_Id; Id : Entity_Id);
34 -- Add pragma Prag to the contract of a constant, entry, entry family,
35 -- [generic] package, package body, protected unit, [generic] subprogram,
36 -- subprogram body, variable, task unit, or type denoted by Id.
37 -- The following are valid pragmas:
39 -- Abstract_State
40 -- Async_Readers
41 -- Async_Writers
42 -- Attach_Handler
43 -- Constant_After_Elaboration
44 -- Contract_Cases
45 -- Depends
46 -- Effective_Reads
47 -- Effective_Writes
48 -- Extensions_Visible
49 -- Global
50 -- Initial_Condition
51 -- Initializes
52 -- Interrupt_Handler
53 -- No_Caching
54 -- Part_Of
55 -- Postcondition
56 -- Precondition
57 -- Refined_Depends
58 -- Refined_Global
59 -- Refined_Post
60 -- Refined_States
61 -- Test_Case
62 -- Volatile_Function
64 procedure Analyze_Contracts (L : List_Id);
65 -- Analyze the contracts of all eligible constructs found in list L
67 procedure Analyze_Pragmas_In_Declarations (Body_Id : Entity_Id);
68 -- Perform early analysis of pragmas at the top of a given subprogram's
69 -- declarations.
71 -- The purpose of this is to analyze contract-related pragmas for later
72 -- processing, but also to handle other such pragmas before these
73 -- declarations get moved to an internal wrapper as part of contract
74 -- expansion. For example, pragmas Inline, Ghost, Volatile all need to
75 -- apply directly to the subprogram and not be moved to a wrapper.
77 procedure Analyze_Entry_Or_Subprogram_Body_Contract (Body_Id : Entity_Id);
78 -- Analyze all delayed pragmas chained on the contract of entry or
79 -- subprogram body Body_Id as if they appeared at the end of a declarative
80 -- region. Pragmas in question are:
82 -- Contract_Cases (stand alone subprogram body)
83 -- Depends (stand alone subprogram body)
84 -- Global (stand alone subprogram body)
85 -- Postcondition (stand alone subprogram body)
86 -- Precondition (stand alone subprogram body)
87 -- Refined_Depends
88 -- Refined_Global
89 -- Refined_Post
90 -- Subprogram_Variant (stand alone subprogram body)
91 -- Test_Case (stand alone subprogram body)
93 procedure Analyze_Entry_Or_Subprogram_Contract
94 (Subp_Id : Entity_Id;
95 Freeze_Id : Entity_Id := Empty);
96 -- Analyze all delayed pragmas chained on the contract of entry or
97 -- subprogram Subp_Id as if they appeared at the end of a declarative
98 -- region. The pragmas in question are:
100 -- Contract_Cases
101 -- Depends
102 -- Global
103 -- Postcondition
104 -- Precondition
105 -- Subprogram_Variant
106 -- Test_Case
108 -- Freeze_Id is the entity of a [generic] package body or a [generic]
109 -- subprogram body which "freezes" the contract of Subp_Id.
111 procedure Analyze_Object_Contract
112 (Obj_Id : Entity_Id;
113 Freeze_Id : Entity_Id := Empty);
114 -- Analyze all delayed pragmas chained on the contract of object Obj_Id as
115 -- if they appeared at the end of the declarative region. The pragmas to be
116 -- considered are:
118 -- Async_Readers
119 -- Async_Writers
120 -- Depends (single concurrent object)
121 -- Effective_Reads
122 -- Effective_Writes
123 -- Global (single concurrent object)
124 -- Part_Of
126 -- Freeze_Id is the entity of a [generic] package body or a [generic]
127 -- subprogram body which "freezes" the contract of Obj_Id.
129 procedure Analyze_Type_Contract (Type_Id : Entity_Id);
130 -- Analyze all delayed pragmas chained on the contract of object Obj_Id as
131 -- if they appeared at the end of the declarative region. The pragmas to be
132 -- considered are:
134 -- Async_Readers
135 -- Async_Writers
136 -- Effective_Reads
137 -- Effective_Writes
139 -- In the case of a protected or task type, there will also be
140 -- a call to Analyze_Protected_Contract or Analyze_Task_Contract.
142 procedure Analyze_Package_Body_Contract
143 (Body_Id : Entity_Id;
144 Freeze_Id : Entity_Id := Empty);
145 -- Analyze all delayed pragmas chained on the contract of package body
146 -- Body_Id as if they appeared at the end of a declarative region. The
147 -- pragmas that are considered are:
149 -- Refined_State
151 -- Freeze_Id is the entity of a [generic] package body or a [generic]
152 -- subprogram body which "freezes" the contract of Body_Id.
154 procedure Analyze_Package_Contract (Pack_Id : Entity_Id);
155 -- Analyze all delayed pragmas chained on the contract of package Pack_Id
156 -- as if they appeared at the end of a declarative region. The pragmas
157 -- that are considered are:
159 -- Initial_Condition
160 -- Initializes
162 procedure Analyze_Protected_Contract (Prot_Id : Entity_Id);
163 -- Analyze all delayed pragmas chained on the contract of protected unit
164 -- Prot_Id if they appeared at the end of a declarative region. Currently
165 -- there are no such pragmas.
167 procedure Analyze_Subprogram_Body_Stub_Contract (Stub_Id : Entity_Id);
168 -- Analyze all delayed pragmas chained on the contract of subprogram body
169 -- stub Stub_Id as if they appeared at the end of a declarative region. The
170 -- pragmas in question are:
172 -- Contract_Cases
173 -- Depends
174 -- Global
175 -- Postcondition
176 -- Precondition
177 -- Refined_Depends
178 -- Refined_Global
179 -- Refined_Post
180 -- Test_Case
182 procedure Analyze_Task_Contract (Task_Id : Entity_Id);
183 -- Analyze all delayed pragmas chained on the contract of task unit Task_Id
184 -- as if they appeared at the end of a declarative region. The pragmas in
185 -- question are:
187 -- Depends
188 -- Global
190 procedure Build_Entry_Contract_Wrapper (E : Entity_Id; Decl : Node_Id);
191 -- Build the body of a wrapper procedure for an entry or entry family that
192 -- has contract cases, preconditions, or postconditions, and add it to the
193 -- freeze actions of the related synchronized type.
195 -- The body first verifies the preconditions and case guards of the
196 -- contract cases, then invokes the entry [family], and finally verifies
197 -- the postconditions and the consequences of the contract cases. E denotes
198 -- the entry family. Decl denotes the declaration of the enclosing
199 -- synchronized type.
201 procedure Create_Generic_Contract (Unit : Node_Id);
202 -- Create a contract node for a generic package, generic subprogram, or a
203 -- generic body denoted by Unit by collecting all source contract-related
204 -- pragmas in the contract of the unit.
206 procedure Freeze_Previous_Contracts (Body_Decl : Node_Id);
207 -- Freeze the contracts of all source constructs found in the declarative
208 -- list which contains entry, package, protected, subprogram, or task body
209 -- denoted by Body_Decl. In addition, freeze the contract of the nearest
210 -- enclosing package body.
212 procedure Inherit_Subprogram_Contract
213 (Subp : Entity_Id;
214 From_Subp : Entity_Id);
215 -- Inherit relevant contract items from source subprogram From_Subp. Subp
216 -- denotes the destination subprogram. The inherited items are:
217 -- Extensions_Visible
218 -- ??? it would be nice if this routine handles Pre'Class and Post'Class
220 procedure Instantiate_Subprogram_Contract (Templ : Node_Id; L : List_Id);
221 -- Instantiate all source pragmas found in the contract of the generic
222 -- subprogram declaration template denoted by Templ. The instantiated
223 -- pragmas are added to list L.
225 procedure Make_Class_Precondition_Subps
226 (Subp_Id : Entity_Id;
227 Late_Overriding : Boolean := False);
228 -- Build helpers that at run time evaluate statically and dynamically the
229 -- class-wide preconditions of Subp_Id; build also the indirect-call
230 -- wrapper (ICW) required to check class-wide preconditions when the
231 -- subprogram is invoked through an access-to-subprogram, or when it
232 -- overrides an inherited class-wide precondition (see AI12-0195-1).
233 -- Late_Overriding enables special handling required for late-overriding
234 -- subprograms.
236 -- For example, if we have a subprogram with the following profile:
238 -- procedure Prim (Obj : TagTyp; <additional formals>)
239 -- with Pre'Class => F1 (Obj) and F2(Obj)
241 -- We build the following helper that evaluates statically the class-wide
242 -- precondition:
244 -- function PrimSP (Obj : TagTyp) return Boolean is
245 -- begin
246 -- return F1 (Obj) and F2(Obj);
247 -- end PrimSP;
249 -- ... and the following helper that evaluates dynamically the class-wide
250 -- precondition:
252 -- function PrimDP (Obj : TagTyp'Class; ...) return Boolean is
253 -- begin
254 -- return F1 (Obj) and F2(Obj);
255 -- end PrimSP;
257 -- ... and the following indirect-call wrapper (ICW) that is used by the
258 -- code generated by the compiler for indirect calls:
260 -- procedure PrimICW (Obj : TagTyp; <additional formals> is
261 -- begin
262 -- if not PrimSP (Obj) then
263 -- $raise_assert_failure ("failed precondition in call at ...");
264 -- end if;
266 -- Prim (Obj, ...);
267 -- end Prim;
269 procedure Merge_Class_Conditions (Spec_Id : Entity_Id);
270 -- Merge and preanalyze all class-wide conditions of Spec_Id (class-wide
271 -- preconditions merged with operator or-else; class-wide postconditions
272 -- merged with operator and-then). Ignored pre/postconditions are also
273 -- merged since, although they are not required to generate code, their
274 -- preanalysis is required to perform semantic checks. Resulting merged
275 -- expressions are later installed by the expander in helper subprograms
276 -- which are invoked from the caller side; they are also used to build
277 -- the dispatch-table wrapper (DTW), if required.
279 procedure Preanalyze_Class_Conditions (Spec_Id : Entity_Id);
280 -- Preanalyze class-wide pre-/postconditions of the given subprogram
281 -- specification.
283 procedure Process_Class_Conditions_At_Freeze_Point (Typ : Entity_Id);
284 -- Merge, preanalyze, and check class-wide pre/postconditions of Typ
285 -- primitives.
287 procedure Save_Global_References_In_Contract
288 (Templ : Node_Id;
289 Gen_Id : Entity_Id);
290 -- Save all global references found within the aspect specifications and
291 -- the contract-related source pragmas assocated with generic template
292 -- Templ. Gen_Id denotes the entity of the analyzed generic copy.
294 end Contracts;