OSDN Git Service

2008-08-20 Robert Dewar <dewar@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / tbuild.ads
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-2008, 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 various utility procedures to assist in
27 --  building specific types of tree nodes.
28
29 with Namet; use Namet;
30 with Types; use Types;
31
32 package Tbuild is
33
34    function Checks_Off (N : Node_Id) return Node_Id;
35    pragma Inline (Checks_Off);
36    --  Returns an N_Unchecked_Expression node whose expression is the given
37    --  argument. The results is a subexpression identical to the argument,
38    --  except that it will be analyzed and resolved with checks off.
39
40    function Convert_To (Typ : Entity_Id; Expr : Node_Id) return Node_Id;
41    --  Returns an expression that represents the result of a checked convert
42    --  of expression Exp to type T. If the base type of Exp is T, then no
43    --  conversion is required, and Exp is returned unchanged. Otherwise an
44    --  N_Type_Conversion node is constructed to convert the expression.
45    --  If an N_Type_Conversion node is required, Relocate_Node is used on
46    --  Exp. This means that it is safe to replace a node by a Convert_To
47    --  of itself to some other type.
48
49    procedure Discard_Node (N : Node_Or_Entity_Id);
50    pragma Inline (Discard_Node);
51    --  This is a dummy procedure that simply returns and does nothing. It is
52    --  used when a function returning a Node_Id value is called for its side
53    --  effect (e.g. a call to Make to construct a node) but the Node_Id value
54    --  is not required.
55
56    procedure Discard_List (L : List_Id);
57    pragma Inline (Discard_List);
58    --  This is a dummy procedure that simply returns and does nothing. It is
59    --  used when a function returning a Node_Id value is called for its side
60    --  effect (e.g. a call to the parser to parse a list of compilation
61    --  units), but the List_Id value is not required.
62
63    function Make_Byte_Aligned_Attribute_Reference
64      (Sloc           : Source_Ptr;
65       Prefix         : Node_Id;
66       Attribute_Name : Name_Id) return Node_Id;
67    pragma Inline (Make_Byte_Aligned_Attribute_Reference);
68    --  Like the standard Make_Attribute_Reference but the special flag
69    --  Must_Be_Byte_Aligned is set in the attribute reference node. The
70    --  Attribute_Name must be Name_Address or Name_Unrestricted_Access.
71
72    function Make_DT_Access
73      (Loc : Source_Ptr; Rec : Node_Id; Typ : Entity_Id) return Node_Id;
74    --  Create an access to the Dispatch Table by using the Tag field of a
75    --  tagged record : Acc_Dt (Rec.tag).all
76
77    function Make_Implicit_Exception_Handler
78      (Sloc              : Source_Ptr;
79       Choice_Parameter  : Node_Id := Empty;
80       Exception_Choices : List_Id;
81       Statements        : List_Id) return Node_Id;
82    pragma Inline (Make_Implicit_Exception_Handler);
83    --  This is just like Make_Exception_Handler, except that it also sets the
84    --  Local_Raise_Statements field to No_Elist, ensuring that it is properly
85    --  initialized. This should always be used when creating implicit exception
86    --  handlers during expansion (i.e. handlers that do not correspond to user
87    --  source program exception handlers).
88
89    function Make_Implicit_If_Statement
90      (Node            : Node_Id;
91       Condition       : Node_Id;
92       Then_Statements : List_Id;
93       Elsif_Parts     : List_Id := No_List;
94       Else_Statements : List_Id := No_List) return Node_Id;
95    pragma Inline (Make_Implicit_If_Statement);
96    --  This function makes an N_If_Statement node whose fields are filled
97    --  in with the indicated values (see Sinfo), and whose Sloc field is
98    --  is set to Sloc (Node). The effect is identical to calling function
99    --  Nmake.Make_If_Statement except that there is a check for restriction
100    --  No_Implicit_Conditionals, and if this restriction is being violated,
101    --  an error message is posted on Node.
102
103    function Make_Implicit_Label_Declaration
104      (Loc                 : Source_Ptr;
105       Defining_Identifier : Node_Id;
106       Label_Construct     : Node_Id) return Node_Id;
107    --  Used to construct an implicit label declaration node, including setting
108    --  the proper Label_Construct field (since Label_Construct is a semantic
109    --  field, the normal call to Make_Implicit_Label_Declaration does not
110    --  set this field).
111
112    function Make_Implicit_Loop_Statement
113      (Node                   : Node_Id;
114       Statements             : List_Id;
115       Identifier             : Node_Id := Empty;
116       Iteration_Scheme       : Node_Id := Empty;
117       Has_Created_Identifier : Boolean := False;
118       End_Label              : Node_Id := Empty) return Node_Id;
119    --  This function makes an N_Loop_Statement node whose fields are filled
120    --  in with the indicated values (see Sinfo), and whose Sloc field is
121    --  is set to Sloc (Node). The effect is identical to calling function
122    --  Nmake.Make_Loop_Statement except that there is a check for restrictions
123    --  No_Implicit_Loops and No_Implicit_Conditionals (the first applying in
124    --  all cases, and the second only for while loops), and if one of these
125    --  restrictions is being violated, an error message is posted on Node.
126
127    function Make_Integer_Literal
128      (Loc    : Source_Ptr;
129       Intval : Int) return Node_Id;
130    pragma Inline (Make_Integer_Literal);
131    --  A convenient form of Make_Integer_Literal taking Int instead of Uint
132
133    function Make_Linker_Section_Pragma
134      (Ent : Entity_Id;
135       Loc : Source_Ptr;
136       Sec : String) return Node_Id;
137    --  Construct a Linker_Section pragma for entity Ent, using string Sec as
138    --  the section name. Loc is the Sloc value to use in building the pragma.
139
140    function Make_Pragma
141      (Sloc                         : Source_Ptr;
142       Chars                        : Name_Id;
143       Pragma_Argument_Associations : List_Id := No_List;
144       Debug_Statement              : Node_Id := Empty) return Node_Id;
145    --  A convenient form of Make_Pragma not requiring a Pragma_Identifier
146    --  argument (this argument is built from the value given for Chars).
147
148    function Make_Raise_Constraint_Error
149      (Sloc      : Source_Ptr;
150       Condition : Node_Id := Empty;
151       Reason    : RT_Exception_Code) return Node_Id;
152    pragma Inline (Make_Raise_Constraint_Error);
153    --  A convenient form of Make_Raise_Constraint_Error where the Reason
154    --  is given simply as an enumeration value, rather than a Uint code.
155
156    function Make_Raise_Program_Error
157      (Sloc      : Source_Ptr;
158       Condition : Node_Id := Empty;
159       Reason    : RT_Exception_Code) return Node_Id;
160    pragma Inline (Make_Raise_Program_Error);
161    --  A convenient form of Make_Raise_Program_Error where the Reason
162    --  is given simply as an enumeration value, rather than a Uint code.
163
164    function Make_Raise_Storage_Error
165      (Sloc      : Source_Ptr;
166       Condition : Node_Id := Empty;
167       Reason    : RT_Exception_Code) return Node_Id;
168    pragma Inline (Make_Raise_Storage_Error);
169    --  A convenient form of Make_Raise_Storage_Error where the Reason
170    --  is given simply as an enumeration value, rather than a Uint code.
171
172    function Make_String_Literal
173      (Sloc   : Source_Ptr;
174       Strval : String) return Node_Id;
175    --  A convenient form of Make_String_Literal, where the string value
176    --  is given as a normal string instead of a String_Id value.
177
178    function Make_Unsuppress_Block
179      (Loc   : Source_Ptr;
180       Check : Name_Id;
181       Stmts : List_Id) return Node_Id;
182    --  Build a block with a pragma Suppress on 'Check'. Stmts is the
183    --  statements list that needs protection against the check
184
185    function New_Constraint_Error (Loc : Source_Ptr) return Node_Id;
186    --  This function builds a tree corresponding to the Ada statement
187    --  "raise Constraint_Error" and returns the root of this tree,
188    --  the N_Raise_Statement node.
189
190    function New_External_Name
191      (Related_Id   : Name_Id;
192       Suffix       : Character := ' ';
193       Suffix_Index : Int       := 0;
194       Prefix       : Character := ' ') return Name_Id;
195    function New_External_Name
196      (Related_Id   : Name_Id;
197       Suffix       : String;
198       Suffix_Index : Int       := 0;
199       Prefix       : Character := ' ') return Name_Id;
200    --  Builds a new entry in the names table of the form:
201    --
202    --    [Prefix  &] Related_Id [& Suffix] [& Suffix_Index]
203    --
204    --  Prefix is prepended only if Prefix is non-blank (in which case it
205    --  must be an upper case letter other than O,Q,U,W (which are used for
206    --  identifier encoding, see Namet), or an underscore, and T is reserved for
207    --  use by implicit types, and X is reserved for use by debug type encoding
208    --  (see package Exp_Dbug). Note: the reason that Prefix is last is that it
209    --  is almost always omitted. The notable case of Prefix being non-null is
210    --  when it is 'T' for an implicit type.
211
212    --  Suffix_Index'Image is appended only if the value of Suffix_Index is
213    --  positive, or if Suffix_Index is negative 1, then a unique serialized
214    --  suffix is added. If Suffix_Index is zero, then no index is appended.
215
216    --  Suffix is also a single upper case letter other than O,Q,U,W,X and is a
217    --  required parameter (T is permitted). The constructed name is stored
218    --  using Name_Find so that it can be located using a subsequent Name_Find
219    --  operation (i.e. it is properly hashed into the names table). The upper
220    --  case letter given as the Suffix argument ensures that the name does
221    --  not clash with any Ada identifier name. These generated names are
222    --  permitted, but not required, to be made public by setting the flag
223    --  Is_Public in the associated entity.
224
225    function New_External_Name
226      (Suffix       : Character;
227       Suffix_Index : Nat) return Name_Id;
228    --  Builds a new entry in the names table of the form
229    --    Suffix & Suffix_Index'Image
230    --  where Suffix is a single upper case letter other than O,Q,U,W,X and is
231    --  a required parameter (T is permitted). The constructed name is stored
232    --  using Name_Find so that it can be located using a subsequent Name_Find
233    --  operation (i.e. it is properly hashed into the names table). The upper
234    --  case letter given as the Suffix argument ensures that the name does
235    --  not clash with any Ada identifier name. These generated names are
236    --  permitted, but not required, to be made public by setting the flag
237    --  Is_Public in the associated entity.
238
239    function New_Internal_Name (Id_Char : Character) return Name_Id;
240    --  Id_Char is an upper case letter other than O,Q,U,W (which are reserved
241    --  for identifier encoding (see Namet package for details) and X which is
242    --  used for debug encoding (see Exp_Dbug). The letter T is permitted, but
243    --  is reserved by convention for the case of internally generated types.
244    --  The result of the call is a new generated unique name of the form XyyyU
245    --  where X is Id_Char, yyy is a unique serial number, and U is either a
246    --  lower case s or b indicating if the current unit is a spec or a body.
247    --
248    --  The name is entered into the names table using Name_Enter rather than
249    --  Name_Find, because there can never be a need to locate the entry using
250    --  the Name_Find procedure later on. Names created by New_Internal_Name
251    --  are guaranteed to be consistent from one compilation to another (i.e.
252    --  if the identical unit is compiled with a semantically consistent set
253    --  of sources, the numbers will be consistent. This means that it is fine
254    --  to use these as public symbols.
255
256    function New_Occurrence_Of
257      (Def_Id : Entity_Id;
258       Loc    : Source_Ptr) return Node_Id;
259    --  New_Occurrence_Of creates an N_Identifier node which is an
260    --  occurrence of the defining identifier which is passed as its
261    --  argument. The Entity and Etype of the result are set from
262    --  the given defining identifier as follows: Entity is simply
263    --  a copy of Def_Id. Etype is a copy of Def_Id for types, and
264    --  a copy of the Etype of Def_Id for other entities.
265
266    function New_Reference_To
267      (Def_Id : Entity_Id;
268       Loc    : Source_Ptr) return Node_Id;
269    --  This is like New_Occurrence_Of, but it does not set the Etype field.
270    --  It is used from the expander, where Etype fields are generally not set,
271    --  since they are set when the expanded tree is reanalyzed.
272
273    function New_Suffixed_Name
274      (Related_Id : Name_Id;
275       Suffix     : String) return Name_Id;
276    --  This function is used to create special suffixed names used by the
277    --  debugger. Suffix is a string of upper case letters, used to construct
278    --  the required name. For instance, the special type used to record the
279    --  fixed-point small is called typ_SMALL where typ is the name of the
280    --  fixed-point type (as passed in Related_Id), and Suffix is "SMALL".
281
282    function OK_Convert_To (Typ : Entity_Id; Expr : Node_Id) return Node_Id;
283    --  Like Convert_To, except that a conversion node is always generated,
284    --  and the Conversion_OK flag is set on this conversion node.
285
286    function Unchecked_Convert_To
287      (Typ  : Entity_Id;
288       Expr : Node_Id) return Node_Id;
289    --  Like Convert_To, but if a conversion is actually needed, constructs
290    --  an N_Unchecked_Type_Conversion node to do the required conversion.
291
292 end Tbuild;