OSDN Git Service

PR 33870
[pf3gnuchains/gcc-fork.git] / gcc / ada / itypes.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                               I T Y P E S                                --
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 3,  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 COPYING3.  If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license.          --
20 --                                                                          --
21 -- GNAT was originally developed  by the GNAT team at  New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
23 --                                                                          --
24 ------------------------------------------------------------------------------
25
26 --  This package contains declarations for handling of implicit types
27
28 with Einfo;    use Einfo;
29 with Sem_Util; use Sem_Util;
30 with Types;    use Types;
31
32 package Itypes is
33
34    --------------------
35    -- Implicit Types --
36    --------------------
37
38    --  Implicit types are types and subtypes created by the semantic phase
39    --  or the expander to reflect the underlying semantics. These could be
40    --  generated by building trees for corresponding declarations and then
41    --  analyzing these trees, but there are three reasons for not doing this:
42
43    --    1. The declarations would require more tree nodes
44
45    --    2. In some cases, the elaboration of these types is associated
46    --       with internal nodes in the tree.
47
48    --    3. For some types, notably class wide types, there is no Ada
49    --       declaration that would correspond to the desired entity.
50
51    --  So instead, implicit types are constructed by simply creating an
52    --  appropriate entity with the help of routines in this package. These
53    --  entities are fully decorated, as described in Einfo (just as though
54    --  they had been created by the normal analysis procedure).
55
56    --  The type declaration declaring an Itype must be analyzed with checks
57    --  off because this declaration has not been inserted in the tree (if it
58    --  has been then it is not an itype), and hence checks that would be
59    --  generated during the analysis cannot be inserted in the tree. At any
60    --  rate, itype analysis should always be done with checks off, otherwise
61    --  duplicate checks will most likely be emitted.
62
63    --  Unlike types declared explicitly, implicit types are defined on first
64    --  use, which means that Gigi detects the use of such types, and defines
65    --  them at the point of the first use automatically.
66
67    --  Although Itypes are not explicitly declared, they are associated with
68    --  a specific node in the tree (roughly the node that caused them to be
69    --  created), via the Associated_Node_For_Itype field. This association is
70    --  used particularly by New_Copy_Tree, which uses it to determine whether
71    --  or not to copy a referenced Itype. If the associated node is part of
72    --  the tree to be copied by New_Copy_Tree, then (since the idea of the
73    --  call to New_Copy_Tree is to create a complete duplicate of a tree,
74    --  as though it had appeared separately in the source), the Itype in
75    --  question is duplicated as part of the New_Copy_Tree processing.
76    --  As a consequence of this copying mechanism, the association between
77    --  itypes and associated nodes must be one-to-one: several itypes must
78    --  not share an associated node. For example, the semantic decoration
79    --  of an array aggregate generates several itypes: for each index subtype
80    --  and for the array subtype. The associated node of each index subtype
81    --  is the corresponding range expression.
82
83    -----------------
84    -- Subprograms --
85    -----------------
86
87    function Create_Itype
88      (Ekind        : Entity_Kind;
89       Related_Nod  : Node_Id;
90       Related_Id   : Entity_Id := Empty;
91       Suffix       : Character := ' ';
92       Suffix_Index : Nat       := 0;
93       Scope_Id     : Entity_Id := Current_Scope) return Entity_Id;
94    --  Used to create a new Itype.
95    --
96    --   Related_Nod is the node for which this Itype was created.  It is
97    --   set as the Associated_Node_For_Itype of the new itype.  The Sloc of
98    --   the new Itype is that of this node.
99    --
100    --   Related_Id is present only if the implicit type name may be referenced
101    --   as a public symbol, and thus needs a unique external name. The name
102    --   is created by a call to:
103    --
104    --     New_External_Name (Chars (Related_Id), Suffix, Suffix_Index, 'T')
105    --
106    --   If the implicit type does not need an external name, then the
107    --   Related_Id parameter is omitted (and hence Empty). In this case
108    --   Suffix and Suffix_Index are ignored and the implicit type name is
109    --   created by a call to New_Internal_Name ('T').
110    --
111    --   Note that in all cases, the name starts with "T". This is used
112    --   to identify implicit types in the error message handling circuits.
113    --
114    --  The Scope_Id parameter specifies the scope of the created type, and
115    --  is normally the Current_Scope as shown, but can be set otherwise.
116
117    ---------------------------------
118    -- Create_Null_Excluding_Itype --
119    ---------------------------------
120
121    function Create_Null_Excluding_Itype
122       (T           : Entity_Id;
123        Related_Nod : Node_Id;
124        Scope_Id    : Entity_Id := Current_Scope) return Entity_Id;
125    --  Ada 2005 (AI-231): T is an access type and this subprogram creates and
126    --  returns an internal access-subtype declaration of T that has the null
127    --  exclusion attribute set to True.
128    --
129    --  Usage of null-excluding itypes
130    --  ------------------------------
131    --
132    --      type T1 is access ...
133    --      type T2 is not null T1;
134    --
135    --      type Rec is record
136    --         Comp : not null T1;
137    --      end record;
138    --
139    --      type Arr is array (...) of not null T1;
140    --
141    --  Instead of associating the not-null attribute with the defining ids of
142    --  these declarations, we generate an internal subtype declaration of T1
143    --  that has the null exclusion attribute set to true.
144
145 end Itypes;