RISC-V: Add testcases for unsigned scalar .SAT_ADD IMM form 4
[official-gcc.git] / gcc / ada / sem_elab.ads
blob72a46f5654c9144883a5f93326753fe38b8610ad
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-2024, 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 Namet; use Namet;
30 with Types; use Types;
32 package Sem_Elab is
34 -----------
35 -- Types --
36 -----------
38 -- The following type classifies the various enclosing levels used in ABE
39 -- diagnostics.
41 type Enclosing_Level_Kind is
42 (Declaration_Level,
43 -- A construct is at the "declaration level" when it appears within the
44 -- declarations of a block statement, an entry body, a subprogram body,
45 -- or a task body, ignoring enclosing packages. Example:
47 -- package Pack is
48 -- procedure Proc is -- subprogram body
49 -- package Nested is -- enclosing package ignored
50 -- X ... -- at declaration level
52 Generic_Spec_Level,
53 Generic_Body_Level,
54 -- A construct is at the "generic level" when it appears in a
55 -- generic package library unit, ignoring enclosing packages. Example:
57 -- generic
58 -- package Pack is -- generic package spec
59 -- package Nested is -- enclosing package ignored
60 -- X ... -- at generic library level
62 Instantiation_Level,
63 -- A construct is at the "instantiation library level" when it appears
64 -- in a library unit which is also an instantiation. Example:
66 -- package Inst is new Gen; -- at instantiation level
68 Library_Spec_Level,
69 Library_Body_Level,
70 -- A construct is at the "library level" when it appears in a package
71 -- library unit, ignoring enclosing packages. Example:
73 -- package body Pack is -- package body
74 -- package Nested is -- enclosing package ignored
75 -- X ... -- at library level
77 No_Level);
78 -- This value is used to indicate that none of the levels above are in
79 -- effect.
81 subtype Generic_Level is Enclosing_Level_Kind range
82 Generic_Spec_Level ..
83 Generic_Body_Level;
85 subtype Library_Level is Enclosing_Level_Kind range
86 Library_Spec_Level ..
87 Library_Body_Level;
89 subtype Library_Or_Instantiation_Level is Enclosing_Level_Kind range
90 Instantiation_Level ..
91 Library_Body_Level;
93 procedure Build_Call_Marker (N : Node_Id);
94 pragma Inline (Build_Call_Marker);
95 -- Create a call marker for call or requeue statement N and record it for
96 -- later processing by the ABE mechanism.
98 procedure Build_Variable_Reference_Marker
99 (N : Node_Id;
100 Read : Boolean;
101 Write : Boolean);
102 pragma Inline (Build_Variable_Reference_Marker);
103 -- Create a variable reference marker for arbitrary node N if it mentions a
104 -- variable, and record it for later processing by the ABE mechanism. Flag
105 -- Read should be set when the reference denotes a read. Flag Write should
106 -- be set when the reference denotes a write.
108 procedure Check_Elaboration_Scenarios;
109 -- Examine each scenario recorded during analysis/resolution and apply the
110 -- Ada or SPARK elaboration rules taking into account the model in effect.
111 -- This processing detects and diagnoses ABE issues, installs conditional
112 -- ABE checks or guaranteed ABE failures, and ensures the elaboration of
113 -- units.
115 function Find_Enclosing_Level (N : Node_Id) return Enclosing_Level_Kind;
116 pragma Inline (Find_Enclosing_Level);
117 -- Determine the enclosing level of arbitrary node N
119 procedure Initialize;
120 pragma Inline (Initialize);
121 -- Initialize the internal structures of this unit
123 function Is_Controlled_Procedure
124 (Id : Entity_Id;
125 Nam : Name_Id) return Boolean;
126 -- Determine whether subprogram Id denotes controlled primitive operation
127 -- Adjust, Finalize, or Initialize as specified by Nam.
129 procedure Kill_Elaboration_Scenario (N : Node_Id);
130 -- Determine whether arbitrary node N denotes a scenario which requires
131 -- ABE diagnostics or runtime checks and eliminate it from a region with
132 -- dead code.
134 procedure Record_Elaboration_Scenario (N : Node_Id);
135 pragma Inline (Record_Elaboration_Scenario);
136 -- Determine whether atribtray node N denotes a scenario which requires
137 -- ABE diagnostics or runtime checks. If this is the case, store N for
138 -- later processing.
140 ---------------------------------------------------------------------------
141 -- --
142 -- 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 --
143 -- --
144 -- M E C H A N I S M --
145 -- --
146 ---------------------------------------------------------------------------
148 -- This section contains the implementation of the pre-18.x Legacy ABE
149 -- Mechanism. The mechanism can be activated using switch -gnatH (legacy
150 -- elaboration checking mode enabled).
152 procedure Check_Elab_Assign (N : Node_Id);
153 -- N is either the left side of an assignment, or a procedure argument for
154 -- a mode OUT or IN OUT formal. This procedure checks for a possible case
155 -- of access to an entity from elaboration code before the entity has been
156 -- initialized, and issues appropriate warnings.
158 procedure Check_Elab_Call
159 (N : Node_Id;
160 Outer_Scope : Entity_Id := Empty;
161 In_Init_Proc : Boolean := False);
162 -- Check a call for possible elaboration problems. The node N is either an
163 -- N_Function_Call or N_Procedure_Call_Statement node or an access
164 -- attribute reference whose prefix is a subprogram.
166 -- If SPARK_Mode is On, then N can also be a variable reference, since
167 -- SPARK requires the use of Elaborate_All for references to variables
168 -- in other packages.
170 -- The Outer_Scope argument indicates whether this is an outer level
171 -- call from Sem_Res (Outer_Scope set to Empty), or an internal recursive
172 -- call (Outer_Scope set to entity of outermost call, see body). The flag
173 -- In_Init_Proc should be set whenever the current context is a type
174 -- init proc.
176 -- Note: this might better be called Check_Elab_Reference (to recognize
177 -- the SPARK case), but we prefer to keep the original name, since this
178 -- is primarily used for checking for calls that could generate an ABE).
180 procedure Check_Elab_Calls;
181 -- Not all the processing for Check_Elab_Call can be done at the time
182 -- of calls to Check_Elab_Call. This is because for internal calls, we
183 -- need to wait to complete the check until all generic bodies have been
184 -- instantiated. The Check_Elab_Calls procedure cleans up these waiting
185 -- checks. It is called once after the completion of instantiation.
187 procedure Check_Elab_Instantiation
188 (N : Node_Id;
189 Outer_Scope : Entity_Id := Empty);
190 -- Check an instantiation for possible elaboration problems. N is an
191 -- instantiation node (N_Package_Instantiation, N_Function_Instantiation,
192 -- or N_Procedure_Instantiation), and Outer_Scope indicates if this is
193 -- an outer level call from Sem_Ch12 (Outer_Scope set to Empty), or an
194 -- internal recursive call (Outer_Scope set to scope of outermost call,
195 -- see body for further details). The returned value is relevant only
196 -- for an outer level call, and is set to False if an elaboration error
197 -- is bound to occur on the instantiation, and True otherwise. This is
198 -- used by the caller to signal that the body of the instance should
199 -- not be generated (see detailed description in body).
201 procedure Check_Task_Activation (N : Node_Id);
202 -- At the point at which tasks are activated in a package body, check
203 -- that the bodies of the tasks are elaborated.
205 end Sem_Elab;