2011-03-24 Paolo Bonzini <bonzini@gnu.org>
[official-gcc.git] / gcc / ada / tbuild.ads
blob9ba042705922d9772f70aad3311cfff41cb6b329
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-2010, 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 Discard_Node (N : Node_Or_Entity_Id);
52 pragma Inline (Discard_Node);
53 -- This is a dummy procedure that simply returns and does nothing. It is
54 -- used when a function returning a Node_Id value is called for its side
55 -- effect (e.g. a call to Make to construct a node) but the Node_Id value
56 -- is not required.
58 procedure Discard_List (L : List_Id);
59 pragma Inline (Discard_List);
60 -- This is a dummy procedure that simply returns and does nothing. It is
61 -- used when a function returning a Node_Id value is called for its side
62 -- effect (e.g. a call to the parser to parse a list of compilation
63 -- units), but the List_Id value is not required.
65 function Make_Byte_Aligned_Attribute_Reference
66 (Sloc : Source_Ptr;
67 Prefix : Node_Id;
68 Attribute_Name : Name_Id) return Node_Id;
69 pragma Inline (Make_Byte_Aligned_Attribute_Reference);
70 -- Like the standard Make_Attribute_Reference but the special flag
71 -- Must_Be_Byte_Aligned is set in the attribute reference node. The
72 -- Attribute_Name must be Name_Address or Name_Unrestricted_Access.
74 function Make_DT_Access
75 (Loc : Source_Ptr; Rec : Node_Id; Typ : Entity_Id) return Node_Id;
76 -- Create an access to the Dispatch Table by using the Tag field of a
77 -- tagged record : Acc_Dt (Rec.tag).all
79 function Make_Float_Literal
80 (Loc : Source_Ptr;
81 Radix : Uint;
82 Significand : Uint;
83 Exponent : Uint) return Node_Id;
84 -- Create a real literal for the floating point expression value
85 -- Significand * Radix ** Exponent. Radix must be greater than 1.
87 function Make_Implicit_Exception_Handler
88 (Sloc : Source_Ptr;
89 Choice_Parameter : Node_Id := Empty;
90 Exception_Choices : List_Id;
91 Statements : List_Id) return Node_Id;
92 pragma Inline (Make_Implicit_Exception_Handler);
93 -- This is just like Make_Exception_Handler, except that it also sets the
94 -- Local_Raise_Statements field to No_Elist, ensuring that it is properly
95 -- initialized. This should always be used when creating implicit exception
96 -- handlers during expansion (i.e. handlers that do not correspond to user
97 -- source program exception handlers).
99 function Make_Implicit_If_Statement
100 (Node : Node_Id;
101 Condition : Node_Id;
102 Then_Statements : List_Id;
103 Elsif_Parts : List_Id := No_List;
104 Else_Statements : List_Id := No_List) return Node_Id;
105 pragma Inline (Make_Implicit_If_Statement);
106 -- This function makes an N_If_Statement node whose fields are filled
107 -- in with the indicated values (see Sinfo), and whose Sloc field is
108 -- is set to Sloc (Node). The effect is identical to calling function
109 -- Nmake.Make_If_Statement except that there is a check for restriction
110 -- No_Implicit_Conditionals, and if this restriction is being violated,
111 -- an error message is posted on Node.
113 function Make_Implicit_Label_Declaration
114 (Loc : Source_Ptr;
115 Defining_Identifier : Node_Id;
116 Label_Construct : Node_Id) return Node_Id;
117 -- Used to construct an implicit label declaration node, including setting
118 -- the proper Label_Construct field (since Label_Construct is a semantic
119 -- field, the normal call to Make_Implicit_Label_Declaration does not
120 -- set this field).
122 function Make_Implicit_Loop_Statement
123 (Node : Node_Id;
124 Statements : List_Id;
125 Identifier : Node_Id := Empty;
126 Iteration_Scheme : Node_Id := Empty;
127 Has_Created_Identifier : Boolean := False;
128 End_Label : Node_Id := Empty) return Node_Id;
129 -- This function makes an N_Loop_Statement node whose fields are filled
130 -- in with the indicated values (see Sinfo), and whose Sloc field is
131 -- is set to Sloc (Node). The effect is identical to calling function
132 -- Nmake.Make_Loop_Statement except that there is a check for restrictions
133 -- No_Implicit_Loops and No_Implicit_Conditionals (the first applying in
134 -- all cases, and the second only for while loops), and if one of these
135 -- restrictions is being violated, an error message is posted on Node.
137 function Make_Integer_Literal
138 (Loc : Source_Ptr;
139 Intval : Int) return Node_Id;
140 pragma Inline (Make_Integer_Literal);
141 -- A convenient form of Make_Integer_Literal taking Int instead of Uint
143 function Make_Linker_Section_Pragma
144 (Ent : Entity_Id;
145 Loc : Source_Ptr;
146 Sec : String) return Node_Id;
147 -- Construct a Linker_Section pragma for entity Ent, using string Sec as
148 -- the section name. Loc is the Sloc value to use in building the pragma.
150 function Make_Pragma
151 (Sloc : Source_Ptr;
152 Chars : Name_Id;
153 Pragma_Argument_Associations : List_Id := No_List;
154 Debug_Statement : Node_Id := Empty) return Node_Id;
155 -- A convenient form of Make_Pragma not requiring a Pragma_Identifier
156 -- argument (this argument is built from the value given for Chars).
158 function Make_Raise_Constraint_Error
159 (Sloc : Source_Ptr;
160 Condition : Node_Id := Empty;
161 Reason : RT_Exception_Code) return Node_Id;
162 pragma Inline (Make_Raise_Constraint_Error);
163 -- A convenient form of Make_Raise_Constraint_Error where the Reason
164 -- is given simply as an enumeration value, rather than a Uint code.
166 function Make_Raise_Program_Error
167 (Sloc : Source_Ptr;
168 Condition : Node_Id := Empty;
169 Reason : RT_Exception_Code) return Node_Id;
170 pragma Inline (Make_Raise_Program_Error);
171 -- A convenient form of Make_Raise_Program_Error where the Reason
172 -- is given simply as an enumeration value, rather than a Uint code.
174 function Make_Raise_Storage_Error
175 (Sloc : Source_Ptr;
176 Condition : Node_Id := Empty;
177 Reason : RT_Exception_Code) return Node_Id;
178 pragma Inline (Make_Raise_Storage_Error);
179 -- A convenient form of Make_Raise_Storage_Error where the Reason is given
180 -- simply as an enumeration value, rather than a Uint code.
182 function Make_String_Literal
183 (Sloc : Source_Ptr;
184 Strval : String) return Node_Id;
185 -- A convenient form of Make_String_Literal, where the string value is
186 -- given as a normal string instead of a String_Id value.
188 function Make_Temporary
189 (Loc : Source_Ptr;
190 Id : Character;
191 Related_Node : Node_Id := Empty) return Entity_Id;
192 -- This function should be used for all cases where a defining identifier
193 -- is to be built with a name to be obtained by New_Internal_Name (here Id
194 -- is the character passed as the argument to New_Internal_Name). Loc is
195 -- the location for the Sloc value of the resulting Entity. Note that this
196 -- can be used for all kinds of temporary defining identifiers used in
197 -- expansion (objects, subtypes, functions etc).
199 -- Related_Node is used when the defining identifier is for an object that
200 -- captures the value of an expression (e.g. an aggregate). It should be
201 -- set whenever possible to point to the expression that is being captured.
202 -- This is provided to get better error messages, e.g. from CodePeer.
204 -- Make_Temp_Id would probably be a better name for this function???
206 function Make_Unsuppress_Block
207 (Loc : Source_Ptr;
208 Check : Name_Id;
209 Stmts : List_Id) return Node_Id;
210 -- Build a block with a pragma Suppress on 'Check'. Stmts is the statements
211 -- list that needs protection against the check
213 function New_Constraint_Error (Loc : Source_Ptr) return Node_Id;
214 -- This function builds a tree corresponding to the Ada statement
215 -- "raise Constraint_Error" and returns the root of this tree,
216 -- the N_Raise_Statement node.
218 function New_Op_Node
219 (New_Node_Kind : Node_Kind;
220 New_Sloc : Source_Ptr) return Node_Id;
221 -- Create node using New_Node and, if its kind is in N_Op, set its Chars
222 -- field accordingly.
224 function New_External_Name
225 (Related_Id : Name_Id;
226 Suffix : Character := ' ';
227 Suffix_Index : Int := 0;
228 Prefix : Character := ' ') return Name_Id;
229 function New_External_Name
230 (Related_Id : Name_Id;
231 Suffix : String;
232 Suffix_Index : Int := 0;
233 Prefix : Character := ' ') return Name_Id;
234 -- Builds a new entry in the names table of the form:
236 -- [Prefix &] Related_Id [& Suffix] [& Suffix_Index]
238 -- Prefix is prepended only if Prefix is non-blank (in which case it
239 -- must be an upper case letter other than O,Q,U,W (which are used for
240 -- identifier encoding, see Namet), or an underscore, and T is reserved for
241 -- use by implicit types, and X is reserved for use by debug type encoding
242 -- (see package Exp_Dbug). Note: the reason that Prefix is last is that it
243 -- is almost always omitted. The notable case of Prefix being non-null is
244 -- when it is 'T' for an implicit type.
246 -- Suffix_Index'Image is appended only if the value of Suffix_Index is
247 -- positive, or if Suffix_Index is negative 1, then a unique serialized
248 -- suffix is added. If Suffix_Index is zero, then no index is appended.
250 -- Suffix is also a single upper case letter other than O,Q,U,W,X and is a
251 -- required parameter (T is permitted). The constructed name is stored
252 -- using Name_Find so that it can be located using a subsequent Name_Find
253 -- operation (i.e. it is properly hashed into the names table). The upper
254 -- case letter given as the Suffix argument ensures that the name does
255 -- not clash with any Ada identifier name. These generated names are
256 -- permitted, but not required, to be made public by setting the flag
257 -- Is_Public in the associated entity.
259 function New_External_Name
260 (Suffix : Character;
261 Suffix_Index : Nat) return Name_Id;
262 -- Builds a new entry in the names table of the form
263 -- Suffix & Suffix_Index'Image
264 -- where Suffix is a single upper case letter other than O,Q,U,W,X and is
265 -- a required parameter (T is permitted). The constructed name is stored
266 -- using Name_Find so that it can be located using a subsequent Name_Find
267 -- operation (i.e. it is properly hashed into the names table). The upper
268 -- case letter given as the Suffix argument ensures that the name does
269 -- not clash with any Ada identifier name. These generated names are
270 -- permitted, but not required, to be made public by setting the flag
271 -- Is_Public in the associated entity.
273 function New_Internal_Name (Id_Char : Character) return Name_Id;
274 -- Id_Char is an upper case letter other than O,Q,U,W (which are reserved
275 -- for identifier encoding (see Namet package for details) and X which is
276 -- used for debug encoding (see Exp_Dbug). The letter T is permitted, but
277 -- is reserved by convention for the case of internally generated types.
278 -- The result of the call is a new generated unique name of the form XyyyU
279 -- where X is Id_Char, yyy is a unique serial number, and U is either a
280 -- lower case s or b indicating if the current unit is a spec or a body.
282 -- The name is entered into the names table using Name_Enter rather than
283 -- Name_Find, because there can never be a need to locate the entry using
284 -- the Name_Find procedure later on. Names created by New_Internal_Name
285 -- are guaranteed to be consistent from one compilation to another (i.e.
286 -- if the identical unit is compiled with a semantically consistent set
287 -- of sources, the numbers will be consistent. This means that it is fine
288 -- to use these as public symbols.
290 -- Note: Nearly all uses of this function are via calls to Make_Temporary,
291 -- but there are just a few cases where it is called directly.
293 function New_Occurrence_Of
294 (Def_Id : Entity_Id;
295 Loc : Source_Ptr) return Node_Id;
296 -- New_Occurrence_Of creates an N_Identifier node which is an occurrence
297 -- of the defining identifier which is passed as its argument. The Entity
298 -- and Etype of the result are set from the given defining identifier as
299 -- follows: Entity is simply a copy of Def_Id. Etype is a copy of Def_Id
300 -- for types, and a copy of the Etype of Def_Id for other entities.
302 function New_Reference_To
303 (Def_Id : Entity_Id;
304 Loc : Source_Ptr) return Node_Id;
305 -- This is like New_Occurrence_Of, but it does not set the Etype field. It
306 -- is used from the expander, where Etype fields are generally not set,
307 -- since they are set when the expanded tree is reanalyzed.
309 function New_Suffixed_Name
310 (Related_Id : Name_Id;
311 Suffix : String) return Name_Id;
312 -- This function is used to create special suffixed names used by the
313 -- debugger. Suffix is a string of upper case letters, used to construct
314 -- the required name. For instance, the special type used to record the
315 -- fixed-point small is called typ_SMALL where typ is the name of the
316 -- fixed-point type (as passed in Related_Id), and Suffix is "SMALL".
318 function OK_Convert_To (Typ : Entity_Id; Expr : Node_Id) return Node_Id;
319 -- Like Convert_To, except that a conversion node is always generated, and
320 -- the Conversion_OK flag is set on this conversion node.
322 function Unchecked_Convert_To
323 (Typ : Entity_Id;
324 Expr : Node_Id) return Node_Id;
325 -- Like Convert_To, but if a conversion is actually needed, constructs an
326 -- N_Unchecked_Type_Conversion node to do the required conversion.
328 end Tbuild;