OSDN Git Service

2007-08-14 Robert Dewar <dewar@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / sem_ch3.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                              S E M _ C H 3                               --
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 Nlists; use Nlists;
28 with Types;  use Types;
29
30 package Sem_Ch3  is
31    procedure Analyze_Component_Declaration         (N : Node_Id);
32    procedure Analyze_Incomplete_Type_Decl          (N : Node_Id);
33    procedure Analyze_Itype_Reference               (N : Node_Id);
34    procedure Analyze_Number_Declaration            (N : Node_Id);
35    procedure Analyze_Object_Declaration            (N : Node_Id);
36    procedure Analyze_Others_Choice                 (N : Node_Id);
37    procedure Analyze_Private_Extension_Declaration (N : Node_Id);
38    procedure Analyze_Subtype_Indication            (N : Node_Id);
39    procedure Analyze_Type_Declaration              (N : Node_Id);
40    procedure Analyze_Variant_Part                  (N : Node_Id);
41
42    procedure Analyze_Subtype_Declaration
43      (N    : Node_Id;
44       Skip : Boolean := False);
45    --  Called to analyze a subtype declaration. The parameter Skip is used for
46    --  Ada 2005 (AI-412). We set to True in order to avoid reentering the
47    --  defining identifier of N when analyzing a rewritten incomplete subtype
48    --  declaration.
49
50    function Access_Definition
51      (Related_Nod : Node_Id;
52       N           : Node_Id) return Entity_Id;
53    --  An access definition defines a general access type for a formal
54    --  parameter. The procedure is called when processing formals, when
55    --  the current scope is the subprogram. The Implicit type is attached
56    --  to the Related_Nod put into the enclosing scope, so that the only
57    --  entities defined in the spec are the formals themselves.
58
59    procedure Access_Subprogram_Declaration
60      (T_Name : Entity_Id;
61       T_Def  : Node_Id);
62    --  The subprogram specification yields the signature of an implicit
63    --  type, whose Ekind is Access_Subprogram_Type. This implicit type is
64    --  the designated type of the declared access type. In subprogram calls,
65    --  the signature of the implicit type works like the profile of a regular
66    --  subprogram.
67
68    procedure Analyze_Declarations (L : List_Id);
69    --  Called to analyze a list of declarations (in what context ???). Also
70    --  performs necessary freezing actions (more description needed ???)
71
72    procedure Analyze_Interface_Declaration (T : Entity_Id; Def : Node_Id);
73    --  Analyze an interface declaration or a formal interface declaration
74
75    procedure Analyze_Per_Use_Expression (N : Node_Id; T : Entity_Id);
76    --  Default and per object expressions do not freeze their components,
77    --  and must be analyzed and resolved accordingly. The analysis is
78    --  done by calling the Pre_Analyze_And_Resolve routine and setting
79    --  the global In_Default_Expression flag. See the documentation section
80    --  entitled "Handling of Default and Per-Object Expressions" in sem.ads
81    --  for details. N is the expression to be analyzed, T is the expected type.
82
83    procedure Array_Type_Declaration (T : in out Entity_Id; Def : Node_Id);
84    --  Process an array type declaration. If the array is constrained, we
85    --  create an implicit parent array type, with the same index types and
86    --  component type.
87
88    procedure Access_Type_Declaration (T : Entity_Id; Def : Node_Id);
89    --  Process an access type declaration
90
91    procedure Check_Abstract_Overriding (T : Entity_Id);
92    --  Check that all abstract subprograms inherited from T's parent type
93    --  have been overridden as required, and that nonabstract subprograms
94    --  have not been incorrectly overridden with an abstract subprogram.
95
96    procedure Check_Aliased_Component_Types (T : Entity_Id);
97    --  Given an array type or record type T, check that if the type is
98    --  nonlimited, then the nominal subtype of any components of T
99    --  that have discriminants must be constrained.
100
101    procedure Check_Completion (Body_Id : Node_Id := Empty);
102    --  At the end of a declarative part, verify that all entities that
103    --  require completion have received one. If Body_Id is absent, the
104    --  error indicating a missing completion is placed on the declaration
105    --  that needs completion. If Body_Id is present, it is the defining
106    --  identifier of a package body, and errors are posted on that node,
107    --  rather than on the declarations that require completion in the package
108    --  declaration.
109
110    procedure Derive_Subprogram
111      (New_Subp     : in out Entity_Id;
112       Parent_Subp  : Entity_Id;
113       Derived_Type : Entity_Id;
114       Parent_Type  : Entity_Id;
115       Actual_Subp  : Entity_Id := Empty);
116    --  Derive the subprogram Parent_Subp from Parent_Type, and replace the
117    --  subsidiary subtypes with the derived type to build the specification
118    --  of the inherited subprogram (returned in New_Subp). For tagged types,
119    --  the derived subprogram is aliased to that of the actual (in the
120    --  case where Actual_Subp is nonempty) rather than to the corresponding
121    --  subprogram of the parent type.
122
123    procedure Derive_Subprograms
124      (Parent_Type           : Entity_Id;
125       Derived_Type          : Entity_Id;
126       Generic_Actual        : Entity_Id := Empty);
127    --  To complete type derivation, collect/retrieve the primitive operations
128    --  of the parent type, and replace the subsidiary subtypes with the derived
129    --  type, to build the specs of the inherited ops. For generic actuals, the
130    --  mapping of the primitive operations to those of the parent type is also
131    --  done by rederiving the operations within the instance. For tagged types,
132    --  the derived subprograms are aliased to those of the actual, not those of
133    --  the ancestor. The last two params are used in case of derivation from
134    --  abstract interface types: No_Predefined_Prims is used to avoid the
135    --  derivation of predefined primitives from an abstract interface.
136    --
137    --  Note: one might expect this to be private to the package body, but
138    --  there is one rather unusual usage in package Exp_Dist.
139
140    function Find_Hidden_Interface
141      (Src  : Elist_Id;
142       Dest : Elist_Id) return Entity_Id;
143    --  Ada 2005: Determine whether the interfaces in list Src are all present
144    --  in the list Dest. Return the first differing interface, or Empty
145    --  otherwise.
146
147    function Find_Type_Of_Subtype_Indic (S : Node_Id) return Entity_Id;
148    --  Given a subtype indication S (which is really an N_Subtype_Indication
149    --  node or a plain N_Identifier), find the type of the subtype mark.
150
151    function Find_Type_Name (N : Node_Id) return Entity_Id;
152    --  Enter the identifier in a type definition, or find the entity already
153    --  declared, in the case of the full declaration of an incomplete or
154    --  private type.
155
156    function Get_Discriminant_Value
157      (Discriminant       : Entity_Id;
158       Typ_For_Constraint : Entity_Id;
159       Constraint         : Elist_Id) return Node_Id;
160    --  ??? MORE DOCUMENTATION
161    --  Given a discriminant somewhere in the Typ_For_Constraint tree
162    --  and a Constraint, return the value of that discriminant.
163
164    function Is_Null_Extension (T : Entity_Id) return Boolean;
165    --  Returns True if the tagged type T has an N_Full_Type_Declaration that
166    --  is a null extension, meaning that it has an extension part without any
167    --  components and does not have a known discriminant part.
168
169    function Is_Visible_Component (C : Entity_Id) return Boolean;
170    --  Determines if a record component C is visible in the present context.
171    --  Note that even though component C could appear in the entity chain
172    --  of a record type, C may not be visible in the current context. For
173    --  instance, C may be a component inherited in the full view of a private
174    --  extension which is not visible in the current context.
175
176    procedure Make_Index
177      (I            : Node_Id;
178       Related_Nod  : Node_Id;
179       Related_Id   : Entity_Id := Empty;
180       Suffix_Index : Nat := 1);
181    --  Process an index that is given in an array declaration, an entry
182    --  family declaration or a loop iteration. The index is given by an
183    --  index declaration (a 'box'), or by a discrete range. The later can
184    --  be the name of a discrete type, or a subtype indication.
185    --  Related_Nod is the node where the potential generated implicit types
186    --  will be inserted. The 2 last parameters are used for creating the name.
187
188    procedure Make_Class_Wide_Type (T : Entity_Id);
189    --  A Class_Wide_Type is created for each tagged type definition. The
190    --  attributes of a class wide type are inherited from those of the type T.
191    --  If T is introduced by a private declaration, the corresponding class
192    --  wide type is created at the same time, and therefore there is a private
193    --  and a full declaration for the class wide type type as well.
194
195    function OK_For_Limited_Init_In_05 (Exp : Node_Id) return Boolean;
196    --  Presuming Exp is an expression of an inherently limited type, returns
197    --  True if the expression is allowed in an initialization context by the
198    --  rules of Ada 2005. We use the rule in RM-7.5(2.1/2), "...it is an
199    --  aggregate, a function_call, or a parenthesized expression or
200    --  qualified_expression whose operand is permitted...". Note that in Ada
201    --  95 mode, we sometimes wish to give warnings based on whether the
202    --  program _would_ be legal in Ada 2005. Note that Exp must already have
203    --  been resolved, so we can know whether it's a function call (as opposed
204    --  to an indexed component, for example).
205
206    function OK_For_Limited_Init (Exp : Node_Id) return Boolean;
207    --  Always False in Ada 95 mode. Equivalent to OK_For_Limited_Init_In_05 in
208    --  Ada 2005 mode.
209
210    procedure Process_Full_View (N : Node_Id; Full_T, Priv_T : Entity_Id);
211    --  Process some semantic actions when the full view of a private type is
212    --  encountered and analyzed. The first action is to create the full views
213    --  of the dependant private subtypes. The second action is to recopy the
214    --  primitive operations of the private view (in the tagged case).
215    --  N is the N_Full_Type_Declaration node.
216
217    --    Full_T is the full view of the type whose full declaration is in N.
218    --
219    --    Priv_T is the private view of the type whose full declaration is in N.
220
221    procedure Process_Range_Expr_In_Decl
222      (R           : Node_Id;
223       T           : Entity_Id;
224       Check_List  : List_Id := Empty_List;
225       R_Check_Off : Boolean := False);
226    --  Process a range expression that appears in a declaration context. The
227    --  range is analyzed and resolved with the base type of the given type,
228    --  and an appropriate check for expressions in non-static contexts made
229    --  on the bounds. R is analyzed and resolved using T, so the caller should
230    --  if necessary link R into the tree before the call, and in particular in
231    --  the case of a subtype declaration, it is appropriate to set the parent
232    --  pointer of R so that the types get properly frozen. The Check_List
233    --  parameter is used when the subprogram is called from
234    --  Build_Record_Init_Proc and is used to return a set of constraint
235    --  checking statements generated by the Checks package. R_Check_Off is set
236    --  to True when the call to Range_Check is to be skipped.
237
238    function Process_Subtype
239      (S           : Node_Id;
240       Related_Nod : Node_Id;
241       Related_Id  : Entity_Id := Empty;
242       Suffix      : Character := ' ') return Entity_Id;
243    --  Process a subtype indication S and return corresponding entity.
244    --  Related_Nod is the node where the potential generated implicit types
245    --  will be inserted. The Related_Id and Suffix parameters are used to
246    --  build the associated Implicit type name.
247
248    procedure Process_Discriminants
249      (N    : Node_Id;
250       Prev : Entity_Id := Empty);
251    --  Process the discriminants contained in an N_Full_Type_Declaration or
252    --  N_Incomplete_Type_Decl node N. If the declaration is a completion,
253    --  Prev is entity on the partial view, on which references are posted.
254
255    function Replace_Anonymous_Access_To_Protected_Subprogram
256      (N : Node_Id) return Entity_Id;
257    --  Ada 2005 (AI-254): Create and decorate an internal full type declaration
258    --  for an anonymous access to protected subprogram. For a record component
259    --  declaration, the type is created in the enclosing scope, for an array
260    --  type declaration or an object declaration it is simply placed ahead of
261    --  this declaration.
262
263    procedure Set_Completion_Referenced (E : Entity_Id);
264    --  If E is the completion of a private or incomplete  type declaration,
265    --  or the completion of a deferred constant declaration, mark the entity
266    --  as referenced. Warnings on unused entities, if needed, go on the
267    --  partial view.
268
269 end Sem_Ch3;