hppa: Revise REG+D address support to allow long displacements before reload
[official-gcc.git] / gcc / ada / itypes.ads
blob2a4da5b386bedcd0b30bd94bed84e0cdb6ced705
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-2023, 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 ------------------------------------------------------------------------------
26 -- This package contains declarations for handling of implicit types
28 with Einfo; use Einfo;
29 with Einfo.Entities; use Einfo.Entities;
30 with Sem_Util; use Sem_Util;
31 with Types; use Types;
33 package Itypes is
35 --------------------
36 -- Implicit Types --
37 --------------------
39 -- Implicit types (Itypes) are types and subtypes created by the semantic
40 -- phase or the expander to reflect the underlying semantics. These could
41 -- be generated by building trees for corresponding declarations and then
42 -- analyzing these trees, but there are three reasons for not doing this
43 -- in some cases:
45 -- 1. The declarations would require more tree nodes
47 -- 2. In some cases, the elaboration of these types is associated
48 -- with internal nodes in the tree.
50 -- 3. For some types, notably class wide types, there is no Ada
51 -- declaration that would correspond to the desired entity.
53 -- So instead, implicit types are constructed by simply creating an
54 -- appropriate entity with the help of routines in this package. These
55 -- entities are fully decorated, as described in Einfo (just as though
56 -- they had been created by the normal analysis procedure).
58 -- The type declaration declaring an Itype must be analyzed with checks
59 -- off because this declaration has not been inserted in the tree (if it
60 -- has been then it is not an Itype), and hence checks that would be
61 -- generated during the analysis cannot be inserted in the tree. At any
62 -- rate, Itype analysis should always be done with checks off, otherwise
63 -- duplicate checks will most likely be emitted.
65 -- Unlike types declared explicitly, implicit types are defined on first
66 -- use, which means that Gigi detects the use of such types, and defines
67 -- them at the point of the first use automatically.
69 -- Although Itypes are not explicitly declared, they are associated with
70 -- a specific node in the tree (roughly the node that caused them to be
71 -- created), via the Associated_Node_For_Itype field. This association is
72 -- used particularly by New_Copy_Tree, which uses it to determine whether
73 -- or not to copy a referenced Itype. If the associated node is part of
74 -- the tree to be copied by New_Copy_Tree, then (since the idea of the
75 -- call to New_Copy_Tree is to create a complete duplicate of a tree,
76 -- as though it had appeared separately in the source), the Itype in
77 -- question is duplicated as part of the New_Copy_Tree processing.
79 -- As a consequence of this copying mechanism, the association between
80 -- Itypes and associated nodes must be one-to-one: several Itypes must
81 -- not share an associated node. For example, the semantic decoration
82 -- of an array aggregate generates several Itypes: for each index subtype
83 -- and for the array subtype. The associated node of each index subtype
84 -- is the corresponding range expression.
86 -- Notes on the use of the Parent field of an Itype
88 -- In some cases, we do create a declaration node for an itype, and in
89 -- such cases, the Parent field of the Itype points to this declaration
90 -- in the normal manner. This case can be detected by checking for a
91 -- non-empty Parent field referencing a declaration whose Defining_Entity
92 -- is the Itype in question.
94 -- In some other cases, where we don't generate such a declaration, as
95 -- described above, the Itype is attached to the tree implicitly by being
96 -- referenced elsewhere, e.g. as the Etype of some object. In this case
97 -- the Parent field may be Empty.
99 -- In other cases where we don't generate a declaration for the Itype,
100 -- the Itype may be attached to an arbitrary node in the tree, using
101 -- the Parent field. This Parent field may even reference a declaration
102 -- for a related different entity (hence the description of the tests
103 -- needed for the case where a declaration for the Itype is created).
105 ------------------
106 -- Create_Itype --
107 ------------------
109 function Create_Itype
110 (Ekind : Entity_Kind;
111 Related_Nod : Node_Id;
112 Related_Id : Entity_Id := Empty;
113 Suffix : Character := ' ';
114 Suffix_Index : Int := 0;
115 Scope_Id : Entity_Id := Current_Scope) return Entity_Id;
116 -- Used to create a new Itype
118 -- Related_Nod is the node for which this Itype was created. It is
119 -- set as the Associated_Node_For_Itype of the new Itype. The Sloc of
120 -- the new Itype is that of this node.
122 -- Related_Id is present only if the implicit type name may be referenced
123 -- as a public symbol, and thus needs a unique external name. The name
124 -- is created by a call to:
126 -- New_External_Name (Chars (Related_Id), Suffix, Suffix_Index, 'T')
128 -- If the implicit type does not need an external name, then the
129 -- Related_Id parameter is omitted (and hence Empty). In this case
130 -- Suffix and Suffix_Index are ignored and the implicit type name is
131 -- created by a call to Make_Temporary.
133 -- Note that in all cases, the name starts with "T". This is used
134 -- to identify implicit types in the error message handling circuits.
136 -- The Scope_Id parameter specifies the scope of the created type, and
137 -- is normally the Current_Scope as shown, but can be set otherwise.
139 -- The size/align fields are initialized to unknown (Uint_0).
141 -- If Ekind is in Access_Subprogram_Kind, Can_Use_Internal_Rep is set True,
142 -- unless Always_Compatible_Rep_On_Target is True.
144 ---------------------------------
145 -- Create_Null_Excluding_Itype --
146 ---------------------------------
148 function Create_Null_Excluding_Itype
149 (T : Entity_Id;
150 Related_Nod : Node_Id;
151 Scope_Id : Entity_Id := Current_Scope) return Entity_Id;
152 -- Ada 2005 (AI-231): T is an access type and this subprogram creates and
153 -- returns an internal access-subtype declaration of T that has the null
154 -- exclusion attribute set to True.
156 -- Usage of null-excluding Itypes
157 -- ------------------------------
159 -- type T1 is access ...
160 -- type T2 is not null T1;
162 -- type Rec is record
163 -- Comp : not null T1;
164 -- end record;
166 -- type Arr is array (...) of not null T1;
168 -- Instead of associating the not-null attribute with the defining ids of
169 -- these declarations, we generate an internal subtype declaration of T1
170 -- that has the null exclusion attribute set to true.
172 end Itypes;