annotate gcc/ada/sem_elab.ads @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT COMPILER COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- S E M _ E L A B --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- S p e c --
kono
parents:
diff changeset
8 -- --
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
9 -- Copyright (C) 1997-2018, Free Software Foundation, Inc. --
111
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- GNAT is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
12 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
kono
parents:
diff changeset
17 -- for more details. You should have received a copy of the GNU General --
kono
parents:
diff changeset
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
kono
parents:
diff changeset
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
kono
parents:
diff changeset
20 -- --
kono
parents:
diff changeset
21 -- GNAT was originally developed by the GNAT team at New York University. --
kono
parents:
diff changeset
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
kono
parents:
diff changeset
23 -- --
kono
parents:
diff changeset
24 ------------------------------------------------------------------------------
kono
parents:
diff changeset
25
kono
parents:
diff changeset
26 -- This package contains routines which handle access-before-elaboration
kono
parents:
diff changeset
27 -- run-time checks and compile-time diagnostics. See the body for details.
kono
parents:
diff changeset
28
kono
parents:
diff changeset
29 with Types; use Types;
kono
parents:
diff changeset
30
kono
parents:
diff changeset
31 package Sem_Elab is
kono
parents:
diff changeset
32
kono
parents:
diff changeset
33 procedure Build_Call_Marker (N : Node_Id);
kono
parents:
diff changeset
34 -- Create a call marker for call or requeue statement N and record it for
kono
parents:
diff changeset
35 -- later processing by the ABE mechanism.
kono
parents:
diff changeset
36
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
37 procedure Build_Variable_Reference_Marker
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
38 (N : Node_Id;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
39 Read : Boolean;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
40 Write : Boolean);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
41 -- Create a variable reference marker for arbitrary node N if it mentions a
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
42 -- variable, and record it for later processing by the ABE mechanism. Flag
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
43 -- Read should be set when the reference denotes a read. Flag Write should
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
44 -- be set when the reference denotes a write.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
45
111
kono
parents:
diff changeset
46 procedure Check_Elaboration_Scenarios;
kono
parents:
diff changeset
47 -- Examine each scenario recorded during analysis/resolution and apply the
kono
parents:
diff changeset
48 -- Ada or SPARK elaboration rules taking into account the model in effect.
kono
parents:
diff changeset
49 -- This processing detects and diagnoses ABE issues, installs conditional
kono
parents:
diff changeset
50 -- ABE checks or guaranteed ABE failures, and ensures the elaboration of
kono
parents:
diff changeset
51 -- units.
kono
parents:
diff changeset
52
kono
parents:
diff changeset
53 -- The following type classifies the various enclosing levels used in ABE
kono
parents:
diff changeset
54 -- diagnostics.
kono
parents:
diff changeset
55
kono
parents:
diff changeset
56 type Enclosing_Level_Kind is
kono
parents:
diff changeset
57 (Declaration_Level,
kono
parents:
diff changeset
58 -- A construct is at the "declaration level" when it appears within the
kono
parents:
diff changeset
59 -- declarations of a block statement, an entry body, a subprogram body,
kono
parents:
diff changeset
60 -- or a task body, ignoring enclosing packages. Example:
kono
parents:
diff changeset
61
kono
parents:
diff changeset
62 -- package Pack is
kono
parents:
diff changeset
63 -- procedure Proc is -- subprogram body
kono
parents:
diff changeset
64 -- package Nested is -- enclosing package ignored
kono
parents:
diff changeset
65 -- X ... -- at declaration level
kono
parents:
diff changeset
66
kono
parents:
diff changeset
67 Generic_Package_Spec,
kono
parents:
diff changeset
68 Generic_Package_Body,
kono
parents:
diff changeset
69 -- A construct is at the "generic library level" when it appears in a
kono
parents:
diff changeset
70 -- generic package library unit, ignoring enclosing packages. Example:
kono
parents:
diff changeset
71
kono
parents:
diff changeset
72 -- generic
kono
parents:
diff changeset
73 -- package Pack is -- generic package spec
kono
parents:
diff changeset
74 -- package Nested is -- enclosing package ignored
kono
parents:
diff changeset
75 -- X ... -- at generic library level
kono
parents:
diff changeset
76
kono
parents:
diff changeset
77 Instantiation,
kono
parents:
diff changeset
78 -- A construct is at the "instantiation library level" when it appears
kono
parents:
diff changeset
79 -- in a library unit which is also an instantiation. Example:
kono
parents:
diff changeset
80
kono
parents:
diff changeset
81 -- package Inst is new Gen; -- at instantiation level
kono
parents:
diff changeset
82
kono
parents:
diff changeset
83 Package_Spec,
kono
parents:
diff changeset
84 Package_Body,
kono
parents:
diff changeset
85 -- A construct is at the "library level" when it appears in a package
kono
parents:
diff changeset
86 -- library unit, ignoring enclosing packages. Example:
kono
parents:
diff changeset
87
kono
parents:
diff changeset
88 -- package body Pack is -- package body
kono
parents:
diff changeset
89 -- package Nested is -- enclosing package ignored
kono
parents:
diff changeset
90 -- X ... -- at library level
kono
parents:
diff changeset
91
kono
parents:
diff changeset
92 No_Level);
kono
parents:
diff changeset
93 -- This value is used to indicate that none of the levels above are in
kono
parents:
diff changeset
94 -- effect.
kono
parents:
diff changeset
95
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
96 subtype Any_Library_Level is Enclosing_Level_Kind range
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
97 Generic_Package_Spec ..
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
98 Package_Body;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
99
111
kono
parents:
diff changeset
100 subtype Generic_Library_Level is Enclosing_Level_Kind range
kono
parents:
diff changeset
101 Generic_Package_Spec ..
kono
parents:
diff changeset
102 Generic_Package_Body;
kono
parents:
diff changeset
103
kono
parents:
diff changeset
104 subtype Library_Level is Enclosing_Level_Kind range
kono
parents:
diff changeset
105 Package_Spec ..
kono
parents:
diff changeset
106 Package_Body;
kono
parents:
diff changeset
107
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
108 subtype Library_Or_Instantiation_Level is Enclosing_Level_Kind range
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
109 Instantiation ..
111
kono
parents:
diff changeset
110 Package_Body;
kono
parents:
diff changeset
111
kono
parents:
diff changeset
112 function Find_Enclosing_Level (N : Node_Id) return Enclosing_Level_Kind;
kono
parents:
diff changeset
113 -- Determine the enclosing level of arbitrary node N
kono
parents:
diff changeset
114
kono
parents:
diff changeset
115 procedure Initialize;
kono
parents:
diff changeset
116 -- Initialize the internal structures of this unit
kono
parents:
diff changeset
117
kono
parents:
diff changeset
118 procedure Kill_Elaboration_Scenario (N : Node_Id);
kono
parents:
diff changeset
119 -- Determine whether arbitrary node N denotes a scenario which requires
kono
parents:
diff changeset
120 -- ABE diagnostics or runtime checks and eliminate it from a region with
kono
parents:
diff changeset
121 -- dead code.
kono
parents:
diff changeset
122
kono
parents:
diff changeset
123 procedure Record_Elaboration_Scenario (N : Node_Id);
kono
parents:
diff changeset
124 -- Determine whether atribtray node N denotes a scenario which requires
kono
parents:
diff changeset
125 -- ABE diagnostics or runtime checks. If this is the case, store N into
kono
parents:
diff changeset
126 -- a table for later processing.
kono
parents:
diff changeset
127
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
128 ---------------------------------------------------------------------------
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
129 -- --
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
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 --
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
131 -- --
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
132 -- M E C H A N I S M --
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
133 -- --
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
134 ---------------------------------------------------------------------------
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
135
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
136 -- This section contains the implementation of the pre-18.x Legacy ABE
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
137 -- Mechanism. The mechanism can be activated using switch -gnatH (legacy
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
138 -- elaboration checking mode enabled).
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
139
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
140 procedure Check_Elab_Assign (N : Node_Id);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
141 -- N is either the left side of an assignment, or a procedure argument for
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
142 -- a mode OUT or IN OUT formal. This procedure checks for a possible case
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
143 -- of access to an entity from elaboration code before the entity has been
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
144 -- initialized, and issues appropriate warnings.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
145
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
146 procedure Check_Elab_Call
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
147 (N : Node_Id;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
148 Outer_Scope : Entity_Id := Empty;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
149 In_Init_Proc : Boolean := False);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
150 -- Check a call for possible elaboration problems. The node N is either an
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
151 -- N_Function_Call or N_Procedure_Call_Statement node or an access
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
152 -- attribute reference whose prefix is a subprogram.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
153 --
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
154 -- If SPARK_Mode is On, then N can also be a variable reference, since
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
155 -- SPARK requires the use of Elaborate_All for references to variables
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
156 -- in other packages.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
157
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
158 -- The Outer_Scope argument indicates whether this is an outer level
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
159 -- call from Sem_Res (Outer_Scope set to Empty), or an internal recursive
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
160 -- call (Outer_Scope set to entity of outermost call, see body). The flag
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
161 -- In_Init_Proc should be set whenever the current context is a type
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
162 -- init proc.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
163
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
164 -- Note: this might better be called Check_Elab_Reference (to recognize
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
165 -- the SPARK case), but we prefer to keep the original name, since this
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
166 -- is primarily used for checking for calls that could generate an ABE).
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
167
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
168 procedure Check_Elab_Calls;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
169 -- Not all the processing for Check_Elab_Call can be done at the time
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
170 -- of calls to Check_Elab_Call. This is because for internal calls, we
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
171 -- need to wait to complete the check until all generic bodies have been
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
172 -- instantiated. The Check_Elab_Calls procedure cleans up these waiting
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
173 -- checks. It is called once after the completion of instantiation.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
174
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
175 procedure Check_Elab_Instantiation
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
176 (N : Node_Id;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
177 Outer_Scope : Entity_Id := Empty);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
178 -- Check an instantiation for possible elaboration problems. N is an
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
179 -- instantiation node (N_Package_Instantiation, N_Function_Instantiation,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
180 -- or N_Procedure_Instantiation), and Outer_Scope indicates if this is
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
181 -- an outer level call from Sem_Ch12 (Outer_Scope set to Empty), or an
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
182 -- internal recursive call (Outer_Scope set to scope of outermost call,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
183 -- see body for further details). The returned value is relevant only
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
184 -- for an outer level call, and is set to False if an elaboration error
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
185 -- is bound to occur on the instantiation, and True otherwise. This is
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
186 -- used by the caller to signal that the body of the instance should
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
187 -- not be generated (see detailed description in body).
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
188
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
189 procedure Check_Task_Activation (N : Node_Id);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
190 -- At the point at which tasks are activated in a package body, check
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
191 -- that the bodies of the tasks are elaborated.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
192
111
kono
parents:
diff changeset
193 end Sem_Elab;