Add hppa-openbsd target
[official-gcc.git] / gcc / ada / sem_elab.ads
blobbf2c6ce75585d7d53e27f0a55121df805d3f8346
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S E M _ E L A B --
6 -- --
7 -- S p e c --
8 -- --
9 -- --
10 -- Copyright (C) 1997-2001 Free Software Foundation, Inc. --
11 -- --
12 -- GNAT is free software; you can redistribute it and/or modify it under --
13 -- terms of the GNU General Public License as published by the Free Soft- --
14 -- ware Foundation; either version 2, or (at your option) any later ver- --
15 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
18 -- for more details. You should have received a copy of the GNU General --
19 -- Public License distributed with GNAT; see file COPYING. If not, write --
20 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
21 -- MA 02111-1307, USA. --
22 -- --
23 -- GNAT was originally developed by the GNAT team at New York University. --
24 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
25 -- --
26 ------------------------------------------------------------------------------
28 -- This package contains the routines used to deal with issuing warnings
29 -- for cases of calls that may require warnings about possible access
30 -- before elaboration.
32 with Types; use Types;
34 package Sem_Elab is
36 -----------------------------
37 -- Description of Approach --
38 -----------------------------
40 -- Every non-static call that is encountered by Sem_Res results in
41 -- a call to Check_Elab_Call, with N being the call node, and Outer
42 -- set to its default value of True.
44 -- The goal of Check_Elab_Call is to determine whether or not the
45 -- call in question can generate an access before elaboration
46 -- error (raising Program_Error) either by directly calling a
47 -- subprogram whose body has not yet been elaborated, or indirectly,
48 -- by calling a subprogram whose body has been elaborated, but which
49 -- contains a call to such a subprogram.
51 -- The only calls that we need to look at at the outer level are
52 -- calls that occur in elaboration code. There are two cases. The
53 -- call can be at the outer level of elaboration code, or it can
54 -- be within another unit, e.g. the elaboration code of a subprogram.
56 -- In the case of an elaboration call at the outer level, we must
57 -- trace all calls to outer level routines either within the current
58 -- unit or to other units that are with'ed. For calls within the
59 -- current unit, we can determine if the body has been elaborated
60 -- or not, and if it has not, then a warning is generated.
62 -- Note that there are two subcases. If the original call directly
63 -- calls a subprogram whose body has not been elaborated, then we
64 -- know that an ABE will take place, and we replace the call by
65 -- a raise of Program_Error. If the call is indirect, then we don't
66 -- know that the PE will be raised, since the call might be guarded
67 -- by a conditional. In this case we set Do_Elab_Check on the call
68 -- so that a dynamic check is generated, and output a warning.
70 -- For calls to a subprogram in a with'ed unit, we require that
71 -- a pragma Elaborate_All or pragma Elaborate be present, or that
72 -- the referenced unit have a pragma Preelaborate, pragma Pure, or
73 -- pragma Elaborate_Body. If none of these conditions is met, then
74 -- a warning is generated that a pragma Elaborate_All may be needed.
76 -- For the case of an elaboration call at some inner level, we are
77 -- interested in tracing only calls to subprograms at the same level,
78 -- i.e. those that can be called during elaboration. Any calls to
79 -- outer level routines cannot cause ABE's as a result of the original
80 -- call (there might be an outer level call to the subprogram from
81 -- outside that causes the ABE, but that gets analyzed separately).
83 -- Note that we never trace calls to inner level subprograms, since
84 -- these cannot result in ABE's unless there is an elaboration problem
85 -- at a lower level, which will be separately detected.
87 -- Note on pragma Elaborate. The checking here assumes that a pragma
88 -- Elaborate on a with'ed unit guarantees that subprograms within the
89 -- unit can be called without causing an ABE. This is not in fact the
90 -- case since pragma Elaborate does not guarantee the transititive
91 -- coverage guaranteed by Elaborate_All. However, we leave this issue
92 -- up to the binder, which has generates warnings if there are possible
93 -- problems in the use of pragma Elaborate.
95 --------------------------------------
96 -- Instantiation Elaboration Errors --
97 --------------------------------------
99 -- A special case arises when an instantiation appears in a context
100 -- that is known to be before the body is elaborated, e.g.
102 -- generic package x is ...
103 -- ...
104 -- package xx is new x;
105 -- ...
106 -- package body x is ...
108 -- In this situation it is certain that an elaboration error will
109 -- occur, and an unconditional raise Program_Error statement is
110 -- inserted before the instantiation, and a warning generated.
112 -- The problem is that in this case we have no place to put the
113 -- body of the instantiation. We can't put it in the normal place,
114 -- because it is too early, and will cause errors to occur as a
115 -- result of referencing entities before they are declared.
117 -- Our approach in this case is simply to avoid creating the body
118 -- of the instantiation in such a case. The instantiation spec is
119 -- modified to include dummy bodies for all subprograms, so that
120 -- the resulting code does not contain subprogram specs with no
121 -- corresponding bodies.
123 procedure Check_Elab_Call (N : Node_Id; Outer_Scope : Entity_Id := Empty);
124 -- Check a call for possible elaboration problems. N is either an
125 -- N_Function_Call or N_Procedure_Call_Statement node, and Outer
126 -- indicates whether this is an outer level call from Sem_Res
127 -- (Outer_Scope set to Empty), or an internal recursive call
128 -- (Outer_Scope set to entity of outermost call, see body).
130 procedure Check_Elab_Calls;
131 -- Not all the processing for Check_Elab_Call can be done at the time
132 -- of calls to Check_Elab_Call. This is because for internal calls, we
133 -- need to wait to complete the check until all generic bodies have been
134 -- instantiated. The Check_Elab_Calls procedure cleans up these waiting
135 -- checks. It is called once after the completion of instantiation.
137 procedure Check_Elab_Instantiation
138 (N : Node_Id;
139 Outer_Scope : Entity_Id := Empty);
140 -- Check an instantiation for possible elaboration problems. N is an
141 -- instantiation node (N_Package_Instantiation, N_Function_Instantiation,
142 -- or N_Procedure_Instantiation), and Outer_Scope indicates if this is
143 -- an outer level call from Sem_Ch12 (Outer_Scope set to Empty), or an
144 -- internal recursive call (Outer_Scope set to scope of outermost call,
145 -- see body for further details). The returned value is relevant only
146 -- for an outer level call, and is set to False if an elaboration error
147 -- is bound to occur on the instantiation, and True otherwise. This is
148 -- used by the caller to signal that the body of the instance should
149 -- not be generated (see detailed description in body).
151 procedure Check_Task_Activation (N : Node_Id);
152 -- at the point at which tasks are activated in a package body, check
153 -- that the bodies of the tasks are elaborated.
155 end Sem_Elab;