OSDN Git Service

2007-08-14 Tristan Gingold <gingold@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / sem_ch12.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                             S E M _ C H 1 2                              --
6 --                                                                          --
7 --                                 S p e c                                  --
8 --                                                                          --
9 --          Copyright (C) 1992-2007, 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 with Inline; use Inline;
28 with Types;  use Types;
29
30 package Sem_Ch12 is
31    procedure Analyze_Generic_Package_Declaration        (N : Node_Id);
32    procedure Analyze_Generic_Subprogram_Declaration     (N : Node_Id);
33    procedure Analyze_Package_Instantiation              (N : Node_Id);
34    procedure Analyze_Procedure_Instantiation            (N : Node_Id);
35    procedure Analyze_Function_Instantiation             (N : Node_Id);
36    procedure Analyze_Formal_Object_Declaration          (N : Node_Id);
37    procedure Analyze_Formal_Type_Declaration            (N : Node_Id);
38    procedure Analyze_Formal_Subprogram                  (N : Node_Id);
39    procedure Analyze_Formal_Package                     (N : Node_Id);
40
41    procedure Start_Generic;
42    --  Must be invoked before starting to process a generic spec or body
43
44    procedure End_Generic;
45    --  Must be invoked just at the end of the end of the processing of a
46    --  generic spec or body.
47
48    procedure Check_Generic_Child_Unit
49      (Gen_Id           : Node_Id;
50       Parent_Installed : in out Boolean);
51    --  If the name of the generic unit in an instantiation or a renaming
52    --  is a selected component, then the prefix may be an instance and the
53    --  selector may  designate a child unit. Retrieve the parent generic
54    --  and search for the child unit that must be declared within. Similarly,
55    --  if this is the name of a generic child unit within an instantiation of
56    --  its own parent, retrieve the parent generic.
57
58    function Copy_Generic_Node
59      (N             : Node_Id;
60       Parent_Id     : Node_Id;
61       Instantiating : Boolean) return Node_Id;
62    --  Copy the tree for a generic unit or its body. The unit is copied
63    --  repeatedly: once to produce a copy on which semantic analysis of
64    --  the generic is performed, and once for each instantiation. The tree
65    --  being copied is not semantically analyzed, except that references to
66    --  global entities are marked on terminal nodes.
67
68    function Get_Instance_Of (A : Entity_Id) return Entity_Id;
69    --  Retrieve actual associated with given generic parameter.
70    --  If A is uninstantiated or not a generic parameter, return A.
71
72    function Get_Package_Instantiation_Node (A : Entity_Id) return Node_Id;
73    --  Given the entity of a unit that is an instantiation, retrieve the
74    --  original instance node. This is used when loading the instantiations
75    --  of the ancestors of a child generic that is being instantiated.
76
77    procedure Instantiate_Package_Body
78      (Body_Info     : Pending_Body_Info;
79       Inlined_Body  : Boolean := False;
80       Body_Optional : Boolean := False);
81    --  Called after semantic analysis, to complete the instantiation of
82    --  package instances. The flag Inlined_Body is set if the body is
83    --  being instantiated on the fly for inlined purposes.
84    --
85    --  The flag Body_Optional indicates that the call is for an instance
86    --  that precedes the current instance in the same declarative part.
87    --  This call is needed when instantiating a nested generic whose body
88    --  is to be found in the body of an instance. Normally we instantiate
89    --  package bodies only when they appear in the main unit, or when their
90    --  contents are needed for a nested generic G. If unit U contains several
91    --  instances I1, I2, etc. and I2 contains a nested generic, then when U
92    --  appears in the context of some other unit P that contains an instance
93    --  of G, we compile the body of I2, but not that of I1. However, when we
94    --  compile U as the main unit, we compile both bodies. This will lead to
95    --  lead to link-time errors if the compilation of I1 generates public
96    --  symbols, because those in I2 will receive different names in both
97    --  cases. This forces us to analyze the body of I1 even when U is not the
98    --  main unit. We don't want this additional mechanism to generate an error
99    --  when the body of the generic for I1 is not present, and this is the
100    --  reason for the presence of the flag Body_Optional, which is exchanged
101    --  between the current procedure and Load_Parent_Of_Generic.
102
103    procedure Instantiate_Subprogram_Body
104      (Body_Info : Pending_Body_Info);
105    --  Called after semantic analysis, to complete the instantiation of
106    --  function and procedure instances.
107
108    procedure Save_Global_References (N : Node_Id);
109    --  Traverse the original generic unit, and capture all references to
110    --  entities that are defined outside of the generic in the analyzed
111    --  tree for the template. These references are copied into the original
112    --  tree, so that they appear automatically in every instantiation.
113    --  A critical invariant in this approach is that if an id in the generic
114    --  resolves to a local entity, the corresponding id in the instance
115    --  will resolve to the homologous entity in the instance, even though
116    --  the enclosing context for resolution is different, as long as the
117    --  global references have been captured as described here.
118
119    --  Because instantiations can be nested, the environment of the instance,
120    --  involving the actuals and other data-structures, must be saved and
121    --  restored in stack-like fashion. Front-end inlining also uses these
122    --  structures for the management of private/full views.
123
124    procedure Set_Copied_Sloc_For_Inlined_Body (N : Node_Id; E : Entity_Id);
125    --  This procedure is used when a subprogram body is inlined. This process
126    --  shares the same circuitry as the creation of an instantiated copy of
127    --  a generic template. The call to this procedure establishes a new source
128    --  file entry representing the inlined body as an instantiation, marked as
129    --  an inlined body (so that errout can distinguish cases for generating
130    --  error messages, otherwise the treatment is identical). In this call
131    --  N is the subprogram body and E is the defining identifier of the
132    --  subprogram in quiestion. The resulting Sloc adjustment factor is
133    --  saved as part of the internal state of the Sem_Ch12 package for use
134    --  in subsequent calls to copy nodes.
135
136    procedure Save_Env
137      (Gen_Unit : Entity_Id;
138       Act_Unit : Entity_Id);
139    --   ??? comment needed
140
141    procedure Restore_Env;
142    --   ??? comment needed
143
144    procedure Initialize;
145    --  Initializes internal data structures
146
147    procedure Check_Private_View (N : Node_Id);
148    --  Check whether the type of a generic entity has a different view between
149    --  the point of generic analysis and the point of instantiation. If the
150    --  view has changed, then at the point of instantiation we restore the
151    --  correct view to perform semantic analysis of the instance, and reset
152    --  the current view after instantiation. The processing is driven by the
153    --  current private status of the type of the node, and Has_Private_View,
154    --  a flag that is set at the point of generic compilation. If view and
155    --  flag are inconsistent then the type is updated appropriately.
156    --
157    --  This subprogram is used in Check_Generic_Actuals and Copy_Generic_Node,
158    --  and is exported here for the purpose of front-end inlining (see Exp_Ch6.
159    --  Expand_Inlined_Call.Process_Formals).
160
161 end Sem_Ch12;