annotate gcc/ada/itypes.ads @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children 84e7813d76e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT COMPILER COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- I T Y P E S --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- S p e c --
kono
parents:
diff changeset
8 -- --
kono
parents:
diff changeset
9 -- Copyright (C) 1992-2010, Free Software Foundation, Inc. --
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- GNAT is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
12 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
kono
parents:
diff changeset
17 -- for more details. You should have received a copy of the GNU General --
kono
parents:
diff changeset
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
kono
parents:
diff changeset
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
kono
parents:
diff changeset
20 -- --
kono
parents:
diff changeset
21 -- GNAT was originally developed by the GNAT team at New York University. --
kono
parents:
diff changeset
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
kono
parents:
diff changeset
23 -- --
kono
parents:
diff changeset
24 ------------------------------------------------------------------------------
kono
parents:
diff changeset
25
kono
parents:
diff changeset
26 -- This package contains declarations for handling of implicit types
kono
parents:
diff changeset
27
kono
parents:
diff changeset
28 with Einfo; use Einfo;
kono
parents:
diff changeset
29 with Sem_Util; use Sem_Util;
kono
parents:
diff changeset
30 with Types; use Types;
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 package Itypes is
kono
parents:
diff changeset
33
kono
parents:
diff changeset
34 --------------------
kono
parents:
diff changeset
35 -- Implicit Types --
kono
parents:
diff changeset
36 --------------------
kono
parents:
diff changeset
37
kono
parents:
diff changeset
38 -- Implicit types (Itypes) are types and subtypes created by the semantic
kono
parents:
diff changeset
39 -- phase or the expander to reflect the underlying semantics. These could
kono
parents:
diff changeset
40 -- be generated by building trees for corresponding declarations and then
kono
parents:
diff changeset
41 -- analyzing these trees, but there are three reasons for not doing this
kono
parents:
diff changeset
42 -- in some cases:
kono
parents:
diff changeset
43
kono
parents:
diff changeset
44 -- 1. The declarations would require more tree nodes
kono
parents:
diff changeset
45
kono
parents:
diff changeset
46 -- 2. In some cases, the elaboration of these types is associated
kono
parents:
diff changeset
47 -- with internal nodes in the tree.
kono
parents:
diff changeset
48
kono
parents:
diff changeset
49 -- 3. For some types, notably class wide types, there is no Ada
kono
parents:
diff changeset
50 -- declaration that would correspond to the desired entity.
kono
parents:
diff changeset
51
kono
parents:
diff changeset
52 -- So instead, implicit types are constructed by simply creating an
kono
parents:
diff changeset
53 -- appropriate entity with the help of routines in this package. These
kono
parents:
diff changeset
54 -- entities are fully decorated, as described in Einfo (just as though
kono
parents:
diff changeset
55 -- they had been created by the normal analysis procedure).
kono
parents:
diff changeset
56
kono
parents:
diff changeset
57 -- The type declaration declaring an Itype must be analyzed with checks
kono
parents:
diff changeset
58 -- off because this declaration has not been inserted in the tree (if it
kono
parents:
diff changeset
59 -- has been then it is not an Itype), and hence checks that would be
kono
parents:
diff changeset
60 -- generated during the analysis cannot be inserted in the tree. At any
kono
parents:
diff changeset
61 -- rate, Itype analysis should always be done with checks off, otherwise
kono
parents:
diff changeset
62 -- duplicate checks will most likely be emitted.
kono
parents:
diff changeset
63
kono
parents:
diff changeset
64 -- Unlike types declared explicitly, implicit types are defined on first
kono
parents:
diff changeset
65 -- use, which means that Gigi detects the use of such types, and defines
kono
parents:
diff changeset
66 -- them at the point of the first use automatically.
kono
parents:
diff changeset
67
kono
parents:
diff changeset
68 -- Although Itypes are not explicitly declared, they are associated with
kono
parents:
diff changeset
69 -- a specific node in the tree (roughly the node that caused them to be
kono
parents:
diff changeset
70 -- created), via the Associated_Node_For_Itype field. This association is
kono
parents:
diff changeset
71 -- used particularly by New_Copy_Tree, which uses it to determine whether
kono
parents:
diff changeset
72 -- or not to copy a referenced Itype. If the associated node is part of
kono
parents:
diff changeset
73 -- the tree to be copied by New_Copy_Tree, then (since the idea of the
kono
parents:
diff changeset
74 -- call to New_Copy_Tree is to create a complete duplicate of a tree,
kono
parents:
diff changeset
75 -- as though it had appeared separately in the source), the Itype in
kono
parents:
diff changeset
76 -- question is duplicated as part of the New_Copy_Tree processing.
kono
parents:
diff changeset
77
kono
parents:
diff changeset
78 -- As a consequence of this copying mechanism, the association between
kono
parents:
diff changeset
79 -- Itypes and associated nodes must be one-to-one: several Itypes must
kono
parents:
diff changeset
80 -- not share an associated node. For example, the semantic decoration
kono
parents:
diff changeset
81 -- of an array aggregate generates several Itypes: for each index subtype
kono
parents:
diff changeset
82 -- and for the array subtype. The associated node of each index subtype
kono
parents:
diff changeset
83 -- is the corresponding range expression.
kono
parents:
diff changeset
84
kono
parents:
diff changeset
85 -- Notes on the use of the Parent field of an Itype
kono
parents:
diff changeset
86
kono
parents:
diff changeset
87 -- In some cases, we do create a declaration node for an itype, and in
kono
parents:
diff changeset
88 -- such cases, the Parent field of the Itype points to this declaration
kono
parents:
diff changeset
89 -- in the normal manner. This case can be detected by checking for a
kono
parents:
diff changeset
90 -- non-empty Parent field referencing a declaration whose Defining_Entity
kono
parents:
diff changeset
91 -- is the Itype in question.
kono
parents:
diff changeset
92
kono
parents:
diff changeset
93 -- In some other cases, where we don't generate such a declaration, as
kono
parents:
diff changeset
94 -- described above, the Itype is attached to the tree implicitly by being
kono
parents:
diff changeset
95 -- referenced elsewhere, e.g. as the Etype of some object. In this case
kono
parents:
diff changeset
96 -- the Parent field may be Empty.
kono
parents:
diff changeset
97
kono
parents:
diff changeset
98 -- In other cases where we don't generate a declaration for the Itype,
kono
parents:
diff changeset
99 -- the Itype may be attached to an arbitrary node in the tree, using
kono
parents:
diff changeset
100 -- the Parent field. This Parent field may even reference a declaration
kono
parents:
diff changeset
101 -- for a related different entity (hence the description of the tests
kono
parents:
diff changeset
102 -- needed for the case where a declaration for the Itype is created).
kono
parents:
diff changeset
103
kono
parents:
diff changeset
104 ------------------
kono
parents:
diff changeset
105 -- Create_Itype --
kono
parents:
diff changeset
106 ------------------
kono
parents:
diff changeset
107
kono
parents:
diff changeset
108 function Create_Itype
kono
parents:
diff changeset
109 (Ekind : Entity_Kind;
kono
parents:
diff changeset
110 Related_Nod : Node_Id;
kono
parents:
diff changeset
111 Related_Id : Entity_Id := Empty;
kono
parents:
diff changeset
112 Suffix : Character := ' ';
kono
parents:
diff changeset
113 Suffix_Index : Nat := 0;
kono
parents:
diff changeset
114 Scope_Id : Entity_Id := Current_Scope) return Entity_Id;
kono
parents:
diff changeset
115 -- Used to create a new Itype
kono
parents:
diff changeset
116 --
kono
parents:
diff changeset
117 -- Related_Nod is the node for which this Itype was created. It is
kono
parents:
diff changeset
118 -- set as the Associated_Node_For_Itype of the new Itype. The Sloc of
kono
parents:
diff changeset
119 -- the new Itype is that of this node.
kono
parents:
diff changeset
120 --
kono
parents:
diff changeset
121 -- Related_Id is present only if the implicit type name may be referenced
kono
parents:
diff changeset
122 -- as a public symbol, and thus needs a unique external name. The name
kono
parents:
diff changeset
123 -- is created by a call to:
kono
parents:
diff changeset
124 --
kono
parents:
diff changeset
125 -- New_External_Name (Chars (Related_Id), Suffix, Suffix_Index, 'T')
kono
parents:
diff changeset
126 --
kono
parents:
diff changeset
127 -- If the implicit type does not need an external name, then the
kono
parents:
diff changeset
128 -- Related_Id parameter is omitted (and hence Empty). In this case
kono
parents:
diff changeset
129 -- Suffix and Suffix_Index are ignored and the implicit type name is
kono
parents:
diff changeset
130 -- created by a call to Make_Temporary.
kono
parents:
diff changeset
131 --
kono
parents:
diff changeset
132 -- Note that in all cases, the name starts with "T". This is used
kono
parents:
diff changeset
133 -- to identify implicit types in the error message handling circuits.
kono
parents:
diff changeset
134 --
kono
parents:
diff changeset
135 -- The Scope_Id parameter specifies the scope of the created type, and
kono
parents:
diff changeset
136 -- is normally the Current_Scope as shown, but can be set otherwise.
kono
parents:
diff changeset
137 --
kono
parents:
diff changeset
138 -- The size/align fields are initialized to unknown (Uint_0).
kono
parents:
diff changeset
139 --
kono
parents:
diff changeset
140 -- If Ekind is in Access_Subprogram_Kind, Can_Use_Internal_Rep is set True,
kono
parents:
diff changeset
141 -- unless Always_Compatible_Rep_On_Target is True.
kono
parents:
diff changeset
142
kono
parents:
diff changeset
143 ---------------------------------
kono
parents:
diff changeset
144 -- Create_Null_Excluding_Itype --
kono
parents:
diff changeset
145 ---------------------------------
kono
parents:
diff changeset
146
kono
parents:
diff changeset
147 function Create_Null_Excluding_Itype
kono
parents:
diff changeset
148 (T : Entity_Id;
kono
parents:
diff changeset
149 Related_Nod : Node_Id;
kono
parents:
diff changeset
150 Scope_Id : Entity_Id := Current_Scope) return Entity_Id;
kono
parents:
diff changeset
151 -- Ada 2005 (AI-231): T is an access type and this subprogram creates and
kono
parents:
diff changeset
152 -- returns an internal access-subtype declaration of T that has the null
kono
parents:
diff changeset
153 -- exclusion attribute set to True.
kono
parents:
diff changeset
154 --
kono
parents:
diff changeset
155 -- Usage of null-excluding Itypes
kono
parents:
diff changeset
156 -- ------------------------------
kono
parents:
diff changeset
157 --
kono
parents:
diff changeset
158 -- type T1 is access ...
kono
parents:
diff changeset
159 -- type T2 is not null T1;
kono
parents:
diff changeset
160 --
kono
parents:
diff changeset
161 -- type Rec is record
kono
parents:
diff changeset
162 -- Comp : not null T1;
kono
parents:
diff changeset
163 -- end record;
kono
parents:
diff changeset
164 --
kono
parents:
diff changeset
165 -- type Arr is array (...) of not null T1;
kono
parents:
diff changeset
166 --
kono
parents:
diff changeset
167 -- Instead of associating the not-null attribute with the defining ids of
kono
parents:
diff changeset
168 -- these declarations, we generate an internal subtype declaration of T1
kono
parents:
diff changeset
169 -- that has the null exclusion attribute set to true.
kono
parents:
diff changeset
170
kono
parents:
diff changeset
171 end Itypes;