Rebase.
[official-gcc.git] / gcc / ada / tbuild.ads
blob26869ba8dc82d9d3269993c28525af0722781307
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- T B U I L D --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 1992-2014, 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 various utility procedures to assist in building
27 -- specific types of tree nodes.
29 with Namet; use Namet;
30 with Sinfo; use Sinfo;
31 with Types; use Types;
32 with Uintp; use Uintp;
34 package Tbuild is
36 function Checks_Off (N : Node_Id) return Node_Id;
37 pragma Inline (Checks_Off);
38 -- Returns an N_Unchecked_Expression node whose expression is the given
39 -- argument. The results is a subexpression identical to the argument,
40 -- except that it will be analyzed and resolved with checks off.
42 function Convert_To (Typ : Entity_Id; Expr : Node_Id) return Node_Id;
43 -- Returns an expression that represents the result of a checked convert
44 -- of expression Exp to type T. If the base type of Exp is T, then no
45 -- conversion is required, and Exp is returned unchanged. Otherwise an
46 -- N_Type_Conversion node is constructed to convert the expression.
47 -- If an N_Type_Conversion node is required, Relocate_Node is used on
48 -- Exp. This means that it is safe to replace a node by a Convert_To
49 -- of itself to some other type.
51 procedure Convert_To_And_Rewrite (Typ : Entity_Id; Expr : Node_Id);
52 pragma Inline (Convert_To_And_Rewrite);
53 -- Like the function, except that there is an extra step of calling
54 -- Rewrite on the Expr node and replacing it with the converted result.
55 -- As noted above, this is safe, because Relocate_Node is called.
57 procedure Discard_Node (N : Node_Or_Entity_Id);
58 pragma Inline (Discard_Node);
59 -- This is a dummy procedure that simply returns and does nothing. It is
60 -- used when a function returning a Node_Id value is called for its side
61 -- effect (e.g. a call to Make to construct a node) but the Node_Id value
62 -- is not required.
64 procedure Discard_List (L : List_Id);
65 pragma Inline (Discard_List);
66 -- This is a dummy procedure that simply returns and does nothing. It is
67 -- used when a function returning a Node_Id value is called for its side
68 -- effect (e.g. a call to the parser to parse a list of compilation
69 -- units), but the List_Id value is not required.
71 function Make_Byte_Aligned_Attribute_Reference
72 (Sloc : Source_Ptr;
73 Prefix : Node_Id;
74 Attribute_Name : Name_Id) return Node_Id;
75 pragma Inline (Make_Byte_Aligned_Attribute_Reference);
76 -- Like the standard Make_Attribute_Reference but the special flag
77 -- Must_Be_Byte_Aligned is set in the attribute reference node. The
78 -- Attribute_Name must be Name_Address or Name_Unrestricted_Access.
80 function Make_DT_Access
81 (Loc : Source_Ptr; Rec : Node_Id; Typ : Entity_Id) return Node_Id;
82 -- Create an access to the Dispatch Table by using the Tag field of a
83 -- tagged record : Acc_Dt (Rec.tag).all
85 function Make_Float_Literal
86 (Loc : Source_Ptr;
87 Radix : Uint;
88 Significand : Uint;
89 Exponent : Uint) return Node_Id;
90 -- Create a real literal for the floating point expression value
91 -- Significand * Radix ** Exponent. Radix must be greater than 1.
93 function Make_Implicit_Exception_Handler
94 (Sloc : Source_Ptr;
95 Choice_Parameter : Node_Id := Empty;
96 Exception_Choices : List_Id;
97 Statements : List_Id) return Node_Id;
98 pragma Inline (Make_Implicit_Exception_Handler);
99 -- This is just like Make_Exception_Handler, except that it also sets the
100 -- Local_Raise_Statements field to No_Elist, ensuring that it is properly
101 -- initialized. This should always be used when creating implicit exception
102 -- handlers during expansion (i.e. handlers that do not correspond to user
103 -- source program exception handlers).
105 function Make_Implicit_If_Statement
106 (Node : Node_Id;
107 Condition : Node_Id;
108 Then_Statements : List_Id;
109 Elsif_Parts : List_Id := No_List;
110 Else_Statements : List_Id := No_List) return Node_Id;
111 pragma Inline (Make_Implicit_If_Statement);
112 -- This function makes an N_If_Statement node whose fields are filled
113 -- in with the indicated values (see Sinfo), and whose Sloc field is
114 -- is set to Sloc (Node). The effect is identical to calling function
115 -- Nmake.Make_If_Statement except that there is a check for restriction
116 -- No_Implicit_Conditionals, and if this restriction is being violated,
117 -- an error message is posted on Node.
119 function Make_Implicit_Label_Declaration
120 (Loc : Source_Ptr;
121 Defining_Identifier : Node_Id;
122 Label_Construct : Node_Id) return Node_Id;
123 -- Used to construct an implicit label declaration node, including setting
124 -- the proper Label_Construct field (since Label_Construct is a semantic
125 -- field, the normal call to Make_Implicit_Label_Declaration does not
126 -- set this field).
128 function Make_Implicit_Loop_Statement
129 (Node : Node_Id;
130 Statements : List_Id;
131 Identifier : Node_Id := Empty;
132 Iteration_Scheme : Node_Id := Empty;
133 Has_Created_Identifier : Boolean := False;
134 End_Label : Node_Id := Empty) return Node_Id;
135 -- This function makes an N_Loop_Statement node whose fields are filled
136 -- in with the indicated values (see Sinfo), and whose Sloc field is
137 -- is set to Sloc (Node). The effect is identical to calling function
138 -- Nmake.Make_Loop_Statement except that there is a check for restrictions
139 -- No_Implicit_Loops and No_Implicit_Conditionals (the first applying in
140 -- all cases, and the second only for while loops), and if one of these
141 -- restrictions is being violated, an error message is posted on Node.
143 function Make_Integer_Literal
144 (Loc : Source_Ptr;
145 Intval : Int) return Node_Id;
146 pragma Inline (Make_Integer_Literal);
147 -- A convenient form of Make_Integer_Literal taking Int instead of Uint
149 function Make_Linker_Section_Pragma
150 (Ent : Entity_Id;
151 Loc : Source_Ptr;
152 Sec : String) return Node_Id;
153 -- Construct a Linker_Section pragma for entity Ent, using string Sec as
154 -- the section name. Loc is the Sloc value to use in building the pragma.
156 function Make_Pragma
157 (Sloc : Source_Ptr;
158 Chars : Name_Id;
159 Pragma_Argument_Associations : List_Id := No_List) return Node_Id;
160 -- A convenient form of Make_Pragma not requiring a Pragma_Identifier
161 -- argument (this argument is built from the value given for Chars).
163 function Make_Raise_Constraint_Error
164 (Sloc : Source_Ptr;
165 Condition : Node_Id := Empty;
166 Reason : RT_Exception_Code) return Node_Id;
167 pragma Inline (Make_Raise_Constraint_Error);
168 -- A convenient form of Make_Raise_Constraint_Error where the Reason
169 -- is given simply as an enumeration value, rather than a Uint code.
171 function Make_Raise_Program_Error
172 (Sloc : Source_Ptr;
173 Condition : Node_Id := Empty;
174 Reason : RT_Exception_Code) return Node_Id;
175 pragma Inline (Make_Raise_Program_Error);
176 -- A convenient form of Make_Raise_Program_Error where the Reason
177 -- is given simply as an enumeration value, rather than a Uint code.
179 function Make_Raise_Storage_Error
180 (Sloc : Source_Ptr;
181 Condition : Node_Id := Empty;
182 Reason : RT_Exception_Code) return Node_Id;
183 pragma Inline (Make_Raise_Storage_Error);
184 -- A convenient form of Make_Raise_Storage_Error where the Reason is given
185 -- simply as an enumeration value, rather than a Uint code.
187 function Make_String_Literal
188 (Sloc : Source_Ptr;
189 Strval : String) return Node_Id;
190 -- A convenient form of Make_String_Literal, where the string value is
191 -- given as a normal string instead of a String_Id value.
193 function Make_Temporary
194 (Loc : Source_Ptr;
195 Id : Character;
196 Related_Node : Node_Id := Empty) return Entity_Id;
197 -- This function should be used for all cases where a defining identifier
198 -- is to be built with a name to be obtained by New_Internal_Name (here Id
199 -- is the character passed as the argument to New_Internal_Name). Loc is
200 -- the location for the Sloc value of the resulting Entity. Note that this
201 -- can be used for all kinds of temporary defining identifiers used in
202 -- expansion (objects, subtypes, functions etc).
204 -- Related_Node is used when the defining identifier is for an object that
205 -- captures the value of an expression (e.g. an aggregate). It should be
206 -- set whenever possible to point to the expression that is being captured.
207 -- This is provided to get better error messages, e.g. from CodePeer.
209 function Make_Unsuppress_Block
210 (Loc : Source_Ptr;
211 Check : Name_Id;
212 Stmts : List_Id) return Node_Id;
213 -- Build a block with a pragma Suppress on 'Check'. Stmts is the statements
214 -- list that needs protection against the check
216 function New_Constraint_Error (Loc : Source_Ptr) return Node_Id;
217 -- This function builds a tree corresponding to the Ada statement
218 -- "raise Constraint_Error" and returns the root of this tree,
219 -- the N_Raise_Statement node.
221 function New_Op_Node
222 (New_Node_Kind : Node_Kind;
223 New_Sloc : Source_Ptr) return Node_Id;
224 -- Create node using New_Node and, if its kind is in N_Op, set its Chars
225 -- field accordingly.
227 function New_External_Name
228 (Related_Id : Name_Id;
229 Suffix : Character := ' ';
230 Suffix_Index : Int := 0;
231 Prefix : Character := ' ') return Name_Id;
232 function New_External_Name
233 (Related_Id : Name_Id;
234 Suffix : String;
235 Suffix_Index : Int := 0;
236 Prefix : Character := ' ') return Name_Id;
237 -- Builds a new entry in the names table of the form:
239 -- [Prefix &] Related_Id [& Suffix] [& Suffix_Index]
241 -- Prefix is prepended only if Prefix is non-blank (in which case it
242 -- must be an upper case letter other than O,Q,U,W (which are used for
243 -- identifier encoding, see Namet), or an underscore, and T is reserved for
244 -- use by implicit types, and X is reserved for use by debug type encoding
245 -- (see package Exp_Dbug). Note: the reason that Prefix is last is that it
246 -- is almost always omitted. The notable case of Prefix being non-null is
247 -- when it is 'T' for an implicit type.
249 -- Suffix_Index'Image is appended only if the value of Suffix_Index is
250 -- positive, or if Suffix_Index is negative 1, then a unique serialized
251 -- suffix is added. If Suffix_Index is zero, then no index is appended.
253 -- Suffix is also a single upper case letter other than O,Q,U,W,X (T is
254 -- allowed in this context), or a string of such upper case letters. In
255 -- the case of a string, an initial underscore may be given.
257 -- The constructed name is stored using Name_Find so that it can be located
258 -- using a subsequent Name_Find operation (i.e. it is properly hashed into
259 -- the names table). The upper case letter given as the Suffix argument
260 -- ensures that the name does not clash with any Ada identifier name. These
261 -- generated names are permitted, but not required, to be made public by
262 -- setting the flag Is_Public in the associated entity.
264 -- Note: it is dubious to make them public if they have serial numbers,
265 -- since we are counting on the serial numbers being the same for the
266 -- clients with'ing a package and the actual compilation of the package
267 -- with full expansion. This is a dubious assumption ???
269 function New_External_Name
270 (Suffix : Character;
271 Suffix_Index : Nat) return Name_Id;
272 -- Builds a new entry in the names table of the form
273 -- Suffix & Suffix_Index'Image
274 -- where Suffix is a single upper case letter other than O,Q,U,W,X and is
275 -- a required parameter (T is permitted). The constructed name is stored
276 -- using Name_Find so that it can be located using a subsequent Name_Find
277 -- operation (i.e. it is properly hashed into the names table). The upper
278 -- case letter given as the Suffix argument ensures that the name does
279 -- not clash with any Ada identifier name. These generated names are
280 -- permitted, but not required, to be made public by setting the flag
281 -- Is_Public in the associated entity.
283 -- Note: it is dubious to make these public since they have serial numbers,
284 -- which means we are counting on the serial numbers being the same for the
285 -- clients with'ing a package and the actual compilation of the package
286 -- with full expansion. This is a dubious assumption ???
288 function New_Internal_Name (Id_Char : Character) return Name_Id;
289 -- Id_Char is an upper case letter other than O,Q,U,W (which are reserved
290 -- for identifier encoding (see Namet package for details) and X which is
291 -- used for debug encoding (see Exp_Dbug). The letter T is permitted, but
292 -- is reserved by convention for the case of internally generated types.
293 -- The result of the call is a new generated unique name of the form XyyyU
294 -- where X is Id_Char, yyy is a unique serial number, and U is either a
295 -- lower case s or b indicating if the current unit is a spec or a body.
297 -- The name is entered into the names table using Name_Enter rather than
298 -- Name_Find, because there can never be a need to locate the entry using
299 -- the Name_Find procedure later on. Names created by New_Internal_Name
300 -- are guaranteed to be consistent from one compilation to another (i.e.
301 -- if the identical unit is compiled with a semantically consistent set
302 -- of sources, the numbers will be consistent). This means that it is fine
303 -- to use these as public symbols.
305 -- Note: Nearly all uses of this function are via calls to Make_Temporary,
306 -- but there are just a few cases where it is called directly.
308 -- Note: despite the guarantee of consistency stated above, it is dubious
309 -- to make these public since they have serial numbers, which means we are
310 -- counting on the serial numbers being the same for the clients with'ing
311 -- a package and the actual compilation of the package with full expansion.
312 -- This is a dubious assumption ???
314 function New_Occurrence_Of
315 (Def_Id : Entity_Id;
316 Loc : Source_Ptr) return Node_Id;
317 -- New_Occurrence_Of creates an N_Identifier node which is an occurrence
318 -- of the defining identifier which is passed as its argument. The Entity
319 -- and Etype of the result are set from the given defining identifier as
320 -- follows: Entity is simply a copy of Def_Id. Etype is a copy of Def_Id
321 -- for types, and a copy of the Etype of Def_Id for other entities. Note
322 -- that Is_Static_Expression is set if this call creates an occurrence of
323 -- an enumeration literal.
325 function New_Suffixed_Name
326 (Related_Id : Name_Id;
327 Suffix : String) return Name_Id;
328 -- This function is used to create special suffixed names used by the
329 -- debugger. Suffix is a string of upper case letters, used to construct
330 -- the required name. For instance, the special type used to record the
331 -- fixed-point small is called typ_SMALL where typ is the name of the
332 -- fixed-point type (as passed in Related_Id), and Suffix is "SMALL".
334 function OK_Convert_To (Typ : Entity_Id; Expr : Node_Id) return Node_Id;
335 -- Like Convert_To, except that a conversion node is always generated, and
336 -- the Conversion_OK flag is set on this conversion node.
338 function Unchecked_Convert_To
339 (Typ : Entity_Id;
340 Expr : Node_Id) return Node_Id;
341 -- Like Convert_To, but if a conversion is actually needed, constructs an
342 -- N_Unchecked_Type_Conversion node to do the required conversion.
344 -------------------------------------
345 -- Subprograms for Use by Gnat1drv --
346 -------------------------------------
348 function Make_Id (Str : Text_Buffer) return Node_Id;
349 function Make_SC (Pre, Sel : Node_Id) return Node_Id;
350 procedure Set_RND (Unit : Node_Id);
351 -- Subprograms for call to Get_Target_Parameters in Gnat1drv, see spec
352 -- of package Targparm for full description of these three subprograms.
353 -- These have to be declared at the top level of a package (accessibility
354 -- issues), and Gnat1drv is a procedure, so they can't go there.
356 end Tbuild;