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