Add initial version of C++17 <memory_resource> header
[official-gcc.git] / gcc / ada / sem_elab.ads
blob359e2f7a65f88346f3a44b02585cef46dea8e109
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S E M _ E L A B --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 1997-2018, 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 which handle access-before-elaboration
27 -- run-time checks and compile-time diagnostics. See the body for details.
29 with Types; use Types;
31 package Sem_Elab is
33 procedure Build_Call_Marker (N : Node_Id);
34 -- Create a call marker for call or requeue statement N and record it for
35 -- later processing by the ABE mechanism.
37 procedure Build_Variable_Reference_Marker
38 (N : Node_Id;
39 Read : Boolean;
40 Write : Boolean);
41 -- Create a variable reference marker for arbitrary node N if it mentions a
42 -- variable, and record it for later processing by the ABE mechanism. Flag
43 -- Read should be set when the reference denotes a read. Flag Write should
44 -- be set when the reference denotes a write.
46 procedure Check_Elaboration_Scenarios;
47 -- Examine each scenario recorded during analysis/resolution and apply the
48 -- Ada or SPARK elaboration rules taking into account the model in effect.
49 -- This processing detects and diagnoses ABE issues, installs conditional
50 -- ABE checks or guaranteed ABE failures, and ensures the elaboration of
51 -- units.
53 -- The following type classifies the various enclosing levels used in ABE
54 -- diagnostics.
56 type Enclosing_Level_Kind is
57 (Declaration_Level,
58 -- A construct is at the "declaration level" when it appears within the
59 -- declarations of a block statement, an entry body, a subprogram body,
60 -- or a task body, ignoring enclosing packages. Example:
62 -- package Pack is
63 -- procedure Proc is -- subprogram body
64 -- package Nested is -- enclosing package ignored
65 -- X ... -- at declaration level
67 Generic_Package_Spec,
68 Generic_Package_Body,
69 -- A construct is at the "generic library level" when it appears in a
70 -- generic package library unit, ignoring enclosing packages. Example:
72 -- generic
73 -- package Pack is -- generic package spec
74 -- package Nested is -- enclosing package ignored
75 -- X ... -- at generic library level
77 Instantiation,
78 -- A construct is at the "instantiation library level" when it appears
79 -- in a library unit which is also an instantiation. Example:
81 -- package Inst is new Gen; -- at instantiation level
83 Package_Spec,
84 Package_Body,
85 -- A construct is at the "library level" when it appears in a package
86 -- library unit, ignoring enclosing packages. Example:
88 -- package body Pack is -- package body
89 -- package Nested is -- enclosing package ignored
90 -- X ... -- at library level
92 No_Level);
93 -- This value is used to indicate that none of the levels above are in
94 -- effect.
96 subtype Any_Library_Level is Enclosing_Level_Kind range
97 Generic_Package_Spec ..
98 Package_Body;
100 subtype Generic_Library_Level is Enclosing_Level_Kind range
101 Generic_Package_Spec ..
102 Generic_Package_Body;
104 subtype Library_Level is Enclosing_Level_Kind range
105 Package_Spec ..
106 Package_Body;
108 subtype Library_Or_Instantiation_Level is Enclosing_Level_Kind range
109 Instantiation ..
110 Package_Body;
112 function Find_Enclosing_Level (N : Node_Id) return Enclosing_Level_Kind;
113 -- Determine the enclosing level of arbitrary node N
115 procedure Initialize;
116 -- Initialize the internal structures of this unit
118 procedure Kill_Elaboration_Scenario (N : Node_Id);
119 -- Determine whether arbitrary node N denotes a scenario which requires
120 -- ABE diagnostics or runtime checks and eliminate it from a region with
121 -- dead code.
123 procedure Record_Elaboration_Scenario (N : Node_Id);
124 -- Determine whether atribtray node N denotes a scenario which requires
125 -- ABE diagnostics or runtime checks. If this is the case, store N into
126 -- a table for later processing.
128 ---------------------------------------------------------------------------
129 -- --
130 -- L E G A C Y A C C E S S B E F O R E E L A B O R A T I O N --
131 -- --
132 -- M E C H A N I S M --
133 -- --
134 ---------------------------------------------------------------------------
136 -- This section contains the implementation of the pre-18.x Legacy ABE
137 -- Mechanism. The mechanism can be activated using switch -gnatH (legacy
138 -- elaboration checking mode enabled).
140 procedure Check_Elab_Assign (N : Node_Id);
141 -- N is either the left side of an assignment, or a procedure argument for
142 -- a mode OUT or IN OUT formal. This procedure checks for a possible case
143 -- of access to an entity from elaboration code before the entity has been
144 -- initialized, and issues appropriate warnings.
146 procedure Check_Elab_Call
147 (N : Node_Id;
148 Outer_Scope : Entity_Id := Empty;
149 In_Init_Proc : Boolean := False);
150 -- Check a call for possible elaboration problems. The node N is either an
151 -- N_Function_Call or N_Procedure_Call_Statement node or an access
152 -- attribute reference whose prefix is a subprogram.
154 -- If SPARK_Mode is On, then N can also be a variable reference, since
155 -- SPARK requires the use of Elaborate_All for references to variables
156 -- in other packages.
158 -- The Outer_Scope argument indicates whether this is an outer level
159 -- call from Sem_Res (Outer_Scope set to Empty), or an internal recursive
160 -- call (Outer_Scope set to entity of outermost call, see body). The flag
161 -- In_Init_Proc should be set whenever the current context is a type
162 -- init proc.
164 -- Note: this might better be called Check_Elab_Reference (to recognize
165 -- the SPARK case), but we prefer to keep the original name, since this
166 -- is primarily used for checking for calls that could generate an ABE).
168 procedure Check_Elab_Calls;
169 -- Not all the processing for Check_Elab_Call can be done at the time
170 -- of calls to Check_Elab_Call. This is because for internal calls, we
171 -- need to wait to complete the check until all generic bodies have been
172 -- instantiated. The Check_Elab_Calls procedure cleans up these waiting
173 -- checks. It is called once after the completion of instantiation.
175 procedure Check_Elab_Instantiation
176 (N : Node_Id;
177 Outer_Scope : Entity_Id := Empty);
178 -- Check an instantiation for possible elaboration problems. N is an
179 -- instantiation node (N_Package_Instantiation, N_Function_Instantiation,
180 -- or N_Procedure_Instantiation), and Outer_Scope indicates if this is
181 -- an outer level call from Sem_Ch12 (Outer_Scope set to Empty), or an
182 -- internal recursive call (Outer_Scope set to scope of outermost call,
183 -- see body for further details). The returned value is relevant only
184 -- for an outer level call, and is set to False if an elaboration error
185 -- is bound to occur on the instantiation, and True otherwise. This is
186 -- used by the caller to signal that the body of the instance should
187 -- not be generated (see detailed description in body).
189 procedure Check_Task_Activation (N : Node_Id);
190 -- At the point at which tasks are activated in a package body, check
191 -- that the bodies of the tasks are elaborated.
193 end Sem_Elab;