OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [gcc/] [ada/] [sem_elab.ads] - Blame information for rev 20

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 12 jlechner
------------------------------------------------------------------------------
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-2005, 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 2,  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 COPYING.  If not, write --
19
-- to  the  Free Software Foundation,  51  Franklin  Street,  Fifth  Floor, --
20
-- Boston, MA 02110-1301, USA.                                              --
21
--                                                                          --
22
-- GNAT was originally developed  by the GNAT team at  New York University. --
23
-- Extensive contributions were provided by Ada Core Technologies Inc.      --
24
--                                                                          --
25
------------------------------------------------------------------------------
26
 
27
--  This package contains the routines used to deal with issuing warnings
28
--  for cases of calls that may require warnings about possible access
29
--  before elaboration.
30
 
31
with Types; use Types;
32
 
33
package Sem_Elab is
34
 
35
   -----------------------------
36
   -- Description of Approach --
37
   -----------------------------
38
 
39
   --  Every non-static call that is encountered by Sem_Res results in
40
   --  a call to Check_Elab_Call, with N being the call node, and Outer
41
   --  set to its default value of True.
42
 
43
   --  The goal of Check_Elab_Call is to determine whether or not the
44
   --  call in question can generate an access before elaboration
45
   --  error (raising Program_Error) either by directly calling a
46
   --  subprogram whose body has not yet been elaborated, or indirectly,
47
   --  by calling a subprogram whose body has been elaborated, but which
48
   --  contains a call to such a subprogram.
49
 
50
   --  The only calls that we need to look at at the outer level are
51
   --  calls that occur in elaboration code. There are two cases. The
52
   --  call can be at the outer level of elaboration code, or it can
53
   --  be within another unit, e.g. the elaboration code of a subprogram.
54
 
55
   --  In the case of an elaboration call at the outer level, we must
56
   --  trace all calls to outer level routines either within the current
57
   --  unit or to other units that are with'ed. For calls within the
58
   --  current unit, we can determine if the body has been elaborated
59
   --  or not, and if it has not, then a warning is generated.
60
 
61
   --  Note that there are two subcases. If the original call directly
62
   --  calls a subprogram whose body has not been elaborated, then we
63
   --  know that an ABE will take place, and we replace the call by
64
   --  a raise of Program_Error. If the call is indirect, then we don't
65
   --  know that the PE will be raised, since the call might be guarded
66
   --  by a conditional. In this case we set Do_Elab_Check on the call
67
   --  so that a dynamic check is generated, and output a warning.
68
 
69
   --  For calls to a subprogram in a with'ed unit, we require that
70
   --  a pragma Elaborate_All or pragma Elaborate be present, or that
71
   --  the referenced unit have a pragma Preelaborate, pragma Pure, or
72
   --  pragma Elaborate_Body. If none of these conditions is met, then
73
   --  a warning is generated that a pragma Elaborate_All may be needed.
74
 
75
   --  For the case of an elaboration call at some inner level, we are
76
   --  interested in tracing only calls to subprograms at the same level,
77
   --  i.e. those that can be called during elaboration. Any calls to
78
   --  outer level routines cannot cause ABE's as a result of the original
79
   --  call (there might be an outer level call to the subprogram from
80
   --  outside that causes the ABE, but that gets analyzed separately).
81
 
82
   --  Note that we never trace calls to inner level subprograms, since
83
   --  these cannot result in ABE's unless there is an elaboration problem
84
   --  at a lower level, which will be separately detected.
85
 
86
   --  Note on pragma Elaborate. The checking here assumes that a pragma
87
   --  Elaborate on a with'ed unit guarantees that subprograms within the
88
   --  unit can be called without causing an ABE. This is not in fact the
89
   --  case since pragma Elaborate does not guarantee the transititive
90
   --  coverage guaranteed by Elaborate_All. However, we leave this issue
91
   --  up to the binder, which has generates warnings if there are possible
92
   --  problems in the use of pragma Elaborate.
93
 
94
   --------------------------------------
95
   -- Instantiation Elaboration Errors --
96
   --------------------------------------
97
 
98
   --  A special case arises when an instantiation appears in a context
99
   --  that is known to be before the body is elaborated, e.g.
100
 
101
   --       generic package x is ...
102
   --       ...
103
   --       package xx is new x;
104
   --       ...
105
   --       package body x is ...
106
 
107
   --  In this situation it is certain that an elaboration error will
108
   --  occur, and an unconditional raise Program_Error statement is
109
   --  inserted before the instantiation, and a warning generated.
110
 
111
   --  The problem is that in this case we have no place to put the
112
   --  body of the instantiation. We can't put it in the normal place,
113
   --  because it is too early, and will cause errors to occur as a
114
   --  result of referencing entities before they are declared.
115
 
116
   --  Our approach in this case is simply to avoid creating the body
117
   --  of the instantiation in such a case. The instantiation spec is
118
   --  modified to include dummy bodies for all subprograms, so that
119
   --  the resulting code does not contain subprogram specs with no
120
   --  corresponding bodies.
121
 
122
   procedure Check_Elab_Call (N : Node_Id; Outer_Scope : Entity_Id := Empty);
123
   --  Check a call for possible elaboration problems. N is either an
124
   --  N_Function_Call or N_Procedure_Call_Statement node, and Outer
125
   --  indicates whether this is an outer level call from Sem_Res
126
   --  (Outer_Scope set to Empty), or an internal recursive call
127
   --  (Outer_Scope set to entity of outermost call, see body).
128
 
129
   procedure Check_Elab_Calls;
130
   --  Not all the processing for Check_Elab_Call can be done at the time
131
   --  of calls to Check_Elab_Call. This is because for internal calls, we
132
   --  need to wait to complete the check until all generic bodies have been
133
   --  instantiated. The Check_Elab_Calls procedure cleans up these waiting
134
   --  checks. It is called once after the completion of instantiation.
135
 
136
   procedure Check_Elab_Instantiation
137
     (N           : Node_Id;
138
      Outer_Scope : Entity_Id := Empty);
139
   --  Check an instantiation for possible elaboration problems. N is an
140
   --  instantiation node (N_Package_Instantiation, N_Function_Instantiation,
141
   --  or N_Procedure_Instantiation), and Outer_Scope indicates if this is
142
   --  an outer level call from Sem_Ch12 (Outer_Scope set to Empty), or an
143
   --  internal recursive call (Outer_Scope set to scope of outermost call,
144
   --  see body for further details). The returned value is relevant only
145
   --  for an outer level call, and is set to False if an elaboration error
146
   --  is bound to occur on the instantiation, and True otherwise. This is
147
   --  used by the caller to signal that the body of the instance should
148
   --  not be generated (see detailed description in body).
149
 
150
   procedure Check_Task_Activation (N : Node_Id);
151
   --  at the point at which tasks are activated in a package body, check
152
   --  that the bodies of the tasks are elaborated.
153
 
154
end Sem_Elab;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.