OSDN Git Service

Delete all lines containing "$Revision:".
[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 --                                                                          --
10 --          Copyright (C) 1992-2002, Free Software Foundation, Inc.         --
11 --                                                                          --
12 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
13 -- terms of the  GNU General Public License as published  by the Free Soft- --
14 -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
15 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
18 -- for  more details.  You should have  received  a copy of the GNU General --
19 -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
20 -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
21 -- MA 02111-1307, USA.                                                      --
22 --                                                                          --
23 -- GNAT was originally developed  by the GNAT team at  New York University. --
24 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
25 --                                                                          --
26 ------------------------------------------------------------------------------
27
28 --  This package contains various utility procedures to assist in
29 --  building specific types of tree nodes.
30
31 with Types; use Types;
32
33 package Tbuild is
34
35    function Checks_Off (N : Node_Id) return Node_Id;
36    pragma Inline (Checks_Off);
37    --  Returns an N_Unchecked_Expression node whose expression is the given
38    --  argument. The results is a subexpression identical to the argument,
39    --  except that it will be analyzed and resolved with checks off.
40
41    function Convert_To (Typ : Entity_Id; Expr : Node_Id) return Node_Id;
42    --  Returns an expression that represents the result of a checked convert
43    --  of expression Exp to type T. If the base type of Exp is T, then no
44    --  conversion is required, and Exp is returned unchanged. Otherwise an
45    --  N_Type_Conversion node is constructed to convert the expression.
46    --  If an N_Type_Conversion node is required, Relocate_Node is used on
47    --  Exp. This means that it is safe to replace a node by a Convert_To
48    --  of itself to some other type.
49
50    function Make_Byte_Aligned_Attribute_Reference
51      (Sloc           : Source_Ptr;
52       Prefix         : Node_Id;
53       Attribute_Name : Name_Id)
54       return           Node_Id;
55    pragma Inline (Make_Byte_Aligned_Attribute_Reference);
56    --  Like the standard Make_Attribute_Reference but the special flag
57    --  Must_Be_Byte_Aligned is set in the attribute reference node. The
58    --  Attribute_Name must be Name_Address or Name_Unrestricted_Access.
59
60    function Make_DT_Component
61      (Loc  : Source_Ptr;
62       Typ  : Entity_Id;
63       I    : Positive)
64       return Node_Id;
65    --  Gives a reference to the Ith component of the Dispatch Table of
66    --  a given Tagged Type.
67    --
68    --  I = 1    --> Inheritance_Depth
69    --  I = 2    --> Tags (array of ancestors)
70    --  I = 3, 4 --> predefined primitive
71    --            function _Size (X : Typ) return Long_Long_Integer;
72    --            function _Equality (X : Typ; Y : Typ'Class) return Boolean;
73    --  I >= 5   --> User-Defined Primitive Operations
74
75    function Make_DT_Access
76      (Loc : Source_Ptr; Rec : Node_Id; Typ : Entity_Id) return Node_Id;
77    --  Create an access to the Dispatch Table by using the Tag field
78    --  of a tagged record : Acc_Dt (Rec.tag).all
79
80    function Make_Implicit_If_Statement
81      (Node            : Node_Id;
82       Condition       : Node_Id;
83       Then_Statements : List_Id;
84       Elsif_Parts     : List_Id := No_List;
85       Else_Statements : List_Id := No_List)
86       return            Node_Id;
87    pragma Inline (Make_Implicit_If_Statement);
88    --  This function makes an N_If_Statement node whose fields are filled
89    --  in with the indicated values (see Sinfo), and whose Sloc field is
90    --  is set to Sloc (Node). The effect is identical to calling function
91    --  Nmake.Make_If_Statement except that there is a check for restriction
92    --  No_Implicit_Conditionals, and if this restriction is being violated,
93    --  an error message is posted on Node.
94
95    function Make_Implicit_Label_Declaration
96      (Loc                 : Source_Ptr;
97       Defining_Identifier : Node_Id;
98       Label_Construct     : Node_Id)
99       return                Node_Id;
100    --  Used to construct an implicit label declaration node, including setting
101    --  the proper Label_Construct field (since Label_Construct is a semantic
102    --  field, the normal call to Make_Implicit_Label_Declaration does not
103    --  set this field).
104
105    function Make_Implicit_Loop_Statement
106      (Node                   : Node_Id;
107       Statements             : List_Id;
108       Identifier             : Node_Id := Empty;
109       Iteration_Scheme       : Node_Id := Empty;
110       Has_Created_Identifier : Boolean := False;
111       End_Label              : Node_Id := Empty)
112       return                   Node_Id;
113    --  This function makes an N_Loop_Statement node whose fields are filled
114    --  in with the indicated values (see Sinfo), and whose Sloc field is
115    --  is set to Sloc (Node). The effect is identical to calling function
116    --  Nmake.Make_Loop_Statement except that there is a check for restrictions
117    --  No_Implicit_Loops and No_Implicit_Conditionals (the first applying in
118    --  all cases, and the second only for while loops), and if one of these
119    --  restrictions is being violated, an error message is posted on Node.
120
121    function Make_Integer_Literal
122      (Loc    : Source_Ptr;
123       Intval : Int)
124       return   Node_Id;
125    pragma Inline (Make_Integer_Literal);
126    --  A convenient form of Make_Integer_Literal taking Int instead of Uint
127
128    function Make_Raise_Constraint_Error
129      (Sloc      : Source_Ptr;
130       Condition : Node_Id := Empty;
131       Reason    : RT_Exception_Code)
132       return      Node_Id;
133    pragma Inline (Make_Raise_Constraint_Error);
134    --  A convenient form of Make_Raise_Constraint_Error where the Reason
135    --  is given simply as an enumeration value, rather than a Uint code.
136
137    function Make_Raise_Program_Error
138      (Sloc      : Source_Ptr;
139       Condition : Node_Id := Empty;
140       Reason    : RT_Exception_Code)
141       return      Node_Id;
142    pragma Inline (Make_Raise_Program_Error);
143    --  A convenient form of Make_Raise_Program_Error where the Reason
144    --  is given simply as an enumeration value, rather than a Uint code.
145
146    function Make_Raise_Storage_Error
147      (Sloc      : Source_Ptr;
148       Condition : Node_Id := Empty;
149       Reason    : RT_Exception_Code)
150       return      Node_Id;
151    pragma Inline (Make_Raise_Storage_Error);
152    --  A convenient form of Make_Raise_Storage_Error where the Reason
153    --  is given simply as an enumeration value, rather than a Uint code.
154
155    function Make_Unsuppress_Block
156      (Loc   : Source_Ptr;
157       Check : Name_Id;
158       Stmts : List_Id)
159       return  Node_Id;
160    --  Build a block with a pragma Suppress on 'Check'. Stmts is the
161    --  statements list that needs protection against the check
162
163    function New_Constraint_Error (Loc : Source_Ptr) return Node_Id;
164    --  This function builds a tree corresponding to the Ada statement
165    --  "raise Constraint_Error" and returns the root of this tree,
166    --  the N_Raise_Statement node.
167
168    function New_External_Name
169      (Related_Id   : Name_Id;
170       Suffix       : Character := ' ';
171       Suffix_Index : Int       := 0;
172       Prefix       : Character := ' ')
173       return         Name_Id;
174    function New_External_Name
175      (Related_Id   : Name_Id;
176       Suffix       : String;
177       Suffix_Index : Int       := 0;
178       Prefix       : Character := ' ')
179       return         Name_Id;
180    --  Builds a new entry in the names table of the form:
181    --
182    --    [Prefix  &] Related_Id [& Suffix] [& Suffix_Index]
183    --
184    --  Prefix is prepended only if Prefix is non-blank (in which case it
185    --  must be an upper case letter other than O,Q,U,W (which are used for
186    --  identifier encoding, see Namet), and T is reserved for use by implicit
187    --  types. and X is reserved for use by debug type encoding (see package
188    --  Exp_Dbug). Note: the reason that Prefix is last is that it is almost
189    --  always omitted. The notable case of Prefix being non-null is when
190    --  it is 'T' for an implicit type.
191
192    --  Suffix_Index'Image is appended only if the value of Suffix_Index is
193    --  positive, or if Suffix_Index is negative 1, then a unique serialized
194    --  suffix is added. If Suffix_Index is zero, then no index is appended.
195
196    --  Suffix is also a single upper case letter other than O,Q,U,W,X and is a
197    --  required parameter (T is permitted). The constructed name is stored
198    --  using Find_Name so that it can be located using a subsequent Find_Name
199    --  operation (i.e. it is properly hashed into the names table). The upper
200    --  case letter given as the Suffix argument ensures that the name does
201    --  not clash with any Ada identifier name. These generated names are
202    --  permitted, but not required, to be made public by setting the flag
203    --  Is_Public in the associated entity.
204
205    function New_External_Name
206      (Suffix       : Character;
207       Suffix_Index : Nat)
208       return         Name_Id;
209    --  Builds a new entry in the names table of the form
210    --    Suffix & Suffix_Index'Image
211    --  where Suffix is a single upper case letter other than O,Q,U,W,X and is
212    --  a required parameter (T is permitted). The constructed name is stored
213    --  using Find_Name so that it can be located using a subsequent Find_Name
214    --  operation (i.e. it is properly hashed into the names table). The upper
215    --  case letter given as the Suffix argument ensures that the name does
216    --  not clash with any Ada identifier name. These generated names are
217    --  permitted, but not required, to be made public by setting the flag
218    --  Is_Public in the associated entity.
219
220    function New_Internal_Name (Id_Char : Character) return Name_Id;
221    --  Id_Char is an upper case letter other than O,Q,U,W (which are reserved
222    --  for identifier encoding (see Namet package for details) and X which is
223    --  used for debug encoding (see Exp_Dbug). The letter T is permitted, but
224    --  is reserved by convention for the case of internally generated types.
225    --  The result of the call is a new generated unique name of the form XyyyU
226    --  where X is Id_Char, yyy is a unique serial number, and U is either a
227    --  lower case s or b indicating if the current unit is a spec or a body.
228    --
229    --  The name is entered into the names table using Name_Enter rather than
230    --  Name_Find, because there can never be a need to locate the entry using
231    --  the Name_Find procedure later on. Names created by New_Internal_Name
232    --  are guaranteed to be consistent from one compilation to another (i.e.
233    --  if the identical unit is compiled with a semantically consistent set
234    --  of sources, the numbers will be consistent. This means that it is fine
235    --  to use these as public symbols.
236
237    function New_Occurrence_Of
238      (Def_Id : Entity_Id;
239       Loc    : Source_Ptr)
240       return   Node_Id;
241    --  New_Occurrence_Of creates an N_Identifier node which is an
242    --  occurrence of the defining identifier which is passed as its
243    --  argument. The Entity and Etype of the result are set from
244    --  the given defining identifier as follows: Entity is simply
245    --  a copy of Def_Id. Etype is a copy of Def_Id for types, and
246    --  a copy of the Etype of Def_Id for other entities.
247
248    function New_Reference_To
249      (Def_Id : Entity_Id;
250       Loc    : Source_Ptr)
251       return   Node_Id;
252    --  This is like New_Occurrence_Of, but it does not set the Etype field.
253    --  It is used from the expander, where Etype fields are generally not set,
254    --  since they are set when the expanded tree is reanalyzed.
255
256    function New_Suffixed_Name
257      (Related_Id : Name_Id;
258       Suffix     : String)
259       return       Name_Id;
260    --  This function is used to create special suffixed names used by the
261    --  debugger. Suffix is a string of upper case letters, used to construct
262    --  the required name. For instance, the special type used to record the
263    --  fixed-point small is called typ_SMALL where typ is the name of the
264    --  fixed-point type (as passed in Related_Id), and Suffix is "SMALL".
265
266    function OK_Convert_To (Typ : Entity_Id; Expr : Node_Id) return Node_Id;
267    --  Like Convert_To, except that a conversion node is always generated,
268    --  and the Conversion_OK flag is set on this conversion node.
269
270    function Unchecked_Convert_To
271      (Typ  : Entity_Id;
272       Expr : Node_Id)
273       return Node_Id;
274    --  Like Convert_To, but if a conversion is actually needed, constructs
275    --  an N_Unchecked_Type_Conversion node to do the required conversion.
276
277 end Tbuild;