1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2004, Free Software Foundation, Inc. --
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 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 -- This package contains various utility procedures to assist in
28 -- building specific types of tree nodes.
30 with Types
; use Types
;
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.
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.
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.
52 -- It is used when a function returning a Node_Id value is called
53 -- for its side effect (e.g. a call to Make to construct a node)
54 -- but the Node_Id value is not required.
56 procedure Discard_List
(L
: List_Id
);
57 pragma Inline
(Discard_List
);
58 -- This is a dummy procedure that simply returns and does nothing.
59 -- It is used when a function returning a Node_Id value is called
60 -- for its side effect (e.g. a call to the pareser to parse a list
61 -- of compilation units), but the List_Id value is not required.
63 function Make_Byte_Aligned_Attribute_Reference
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.
72 function Make_DT_Component
75 I
: Positive) return Node_Id
;
76 -- Gives a reference to the Ith component of the Dispatch Table of
77 -- a given Tagged Type.
79 -- I = 1 --> Inheritance_Depth
80 -- I = 2 --> Tags (array of ancestors)
81 -- I = 3, 4 --> predefined primitive
82 -- function _Size (X : Typ) return Long_Long_Integer;
83 -- function _Equality (X : Typ; Y : Typ'Class) return Boolean;
84 -- I >= 5 --> User-Defined Primitive Operations
86 function Make_DT_Access
87 (Loc
: Source_Ptr
; Rec
: Node_Id
; Typ
: Entity_Id
) return Node_Id
;
88 -- Create an access to the Dispatch Table by using the Tag field
89 -- of a tagged record : Acc_Dt (Rec.tag).all
91 function Make_Implicit_If_Statement
94 Then_Statements
: List_Id
;
95 Elsif_Parts
: List_Id
:= No_List
;
96 Else_Statements
: List_Id
:= No_List
) return Node_Id
;
97 pragma Inline
(Make_Implicit_If_Statement
);
98 -- This function makes an N_If_Statement node whose fields are filled
99 -- in with the indicated values (see Sinfo), and whose Sloc field is
100 -- is set to Sloc (Node). The effect is identical to calling function
101 -- Nmake.Make_If_Statement except that there is a check for restriction
102 -- No_Implicit_Conditionals, and if this restriction is being violated,
103 -- an error message is posted on Node.
105 function Make_Implicit_Label_Declaration
107 Defining_Identifier
: Node_Id
;
108 Label_Construct
: Node_Id
) return Node_Id
;
109 -- Used to contruct an implicit label declaration node, including setting
110 -- the proper Label_Construct field (since Label_Construct is a semantic
111 -- field, the normal call to Make_Implicit_Label_Declaration does not
114 function Make_Implicit_Loop_Statement
116 Statements
: List_Id
;
117 Identifier
: Node_Id
:= Empty
;
118 Iteration_Scheme
: Node_Id
:= Empty
;
119 Has_Created_Identifier
: Boolean := False;
120 End_Label
: Node_Id
:= Empty
) return Node_Id
;
121 -- This function makes an N_Loop_Statement node whose fields are filled
122 -- in with the indicated values (see Sinfo), and whose Sloc field is
123 -- is set to Sloc (Node). The effect is identical to calling function
124 -- Nmake.Make_Loop_Statement except that there is a check for restrictions
125 -- No_Implicit_Loops and No_Implicit_Conditionals (the first applying in
126 -- all cases, and the second only for while loops), and if one of these
127 -- restrictions is being violated, an error message is posted on Node.
129 function Make_Integer_Literal
131 Intval
: Int
) return Node_Id
;
132 pragma Inline
(Make_Integer_Literal
);
133 -- A convenient form of Make_Integer_Literal taking Int instead of Uint
135 function Make_Raise_Constraint_Error
137 Condition
: Node_Id
:= Empty
;
138 Reason
: RT_Exception_Code
) return Node_Id
;
139 pragma Inline
(Make_Raise_Constraint_Error
);
140 -- A convenient form of Make_Raise_Constraint_Error where the Reason
141 -- is given simply as an enumeration value, rather than a Uint code.
143 function Make_Raise_Program_Error
145 Condition
: Node_Id
:= Empty
;
146 Reason
: RT_Exception_Code
) return Node_Id
;
147 pragma Inline
(Make_Raise_Program_Error
);
148 -- A convenient form of Make_Raise_Program_Error where the Reason
149 -- is given simply as an enumeration value, rather than a Uint code.
151 function Make_Raise_Storage_Error
153 Condition
: Node_Id
:= Empty
;
154 Reason
: RT_Exception_Code
) return Node_Id
;
155 pragma Inline
(Make_Raise_Storage_Error
);
156 -- A convenient form of Make_Raise_Storage_Error where the Reason
157 -- is given simply as an enumeration value, rather than a Uint code.
159 function Make_String_Literal
161 Strval
: String) return Node_Id
;
162 -- A convenient form of Make_String_Literal, where the string value
163 -- is given as a normal string instead of a String_Id value.
165 function Make_Unsuppress_Block
168 Stmts
: List_Id
) return Node_Id
;
169 -- Build a block with a pragma Suppress on 'Check'. Stmts is the
170 -- statements list that needs protection against the check
172 function New_Constraint_Error
(Loc
: Source_Ptr
) return Node_Id
;
173 -- This function builds a tree corresponding to the Ada statement
174 -- "raise Constraint_Error" and returns the root of this tree,
175 -- the N_Raise_Statement node.
177 function New_External_Name
178 (Related_Id
: Name_Id
;
179 Suffix
: Character := ' ';
180 Suffix_Index
: Int
:= 0;
181 Prefix
: Character := ' ') return Name_Id
;
182 function New_External_Name
183 (Related_Id
: Name_Id
;
185 Suffix_Index
: Int
:= 0;
186 Prefix
: Character := ' ') return Name_Id
;
187 -- Builds a new entry in the names table of the form:
189 -- [Prefix &] Related_Id [& Suffix] [& Suffix_Index]
191 -- Prefix is prepended only if Prefix is non-blank (in which case it
192 -- must be an upper case letter other than O,Q,U,W (which are used for
193 -- identifier encoding, see Namet), and T is reserved for use by implicit
194 -- types. and X is reserved for use by debug type encoding (see package
195 -- Exp_Dbug). Note: the reason that Prefix is last is that it is almost
196 -- always omitted. The notable case of Prefix being non-null is when
197 -- it is 'T' for an implicit type.
199 -- Suffix_Index'Image is appended only if the value of Suffix_Index is
200 -- positive, or if Suffix_Index is negative 1, then a unique serialized
201 -- suffix is added. If Suffix_Index is zero, then no index is appended.
203 -- Suffix is also a single upper case letter other than O,Q,U,W,X and is a
204 -- required parameter (T is permitted). The constructed name is stored
205 -- using Find_Name so that it can be located using a subsequent Find_Name
206 -- operation (i.e. it is properly hashed into the names table). The upper
207 -- case letter given as the Suffix argument ensures that the name does
208 -- not clash with any Ada identifier name. These generated names are
209 -- permitted, but not required, to be made public by setting the flag
210 -- Is_Public in the associated entity.
212 function New_External_Name
214 Suffix_Index
: Nat
) return Name_Id
;
215 -- Builds a new entry in the names table of the form
216 -- Suffix & Suffix_Index'Image
217 -- where Suffix is a single upper case letter other than O,Q,U,W,X and is
218 -- a required parameter (T is permitted). The constructed name is stored
219 -- using Find_Name so that it can be located using a subsequent Find_Name
220 -- operation (i.e. it is properly hashed into the names table). The upper
221 -- case letter given as the Suffix argument ensures that the name does
222 -- not clash with any Ada identifier name. These generated names are
223 -- permitted, but not required, to be made public by setting the flag
224 -- Is_Public in the associated entity.
226 function New_Internal_Name
(Id_Char
: Character) return Name_Id
;
227 -- Id_Char is an upper case letter other than O,Q,U,W (which are reserved
228 -- for identifier encoding (see Namet package for details) and X which is
229 -- used for debug encoding (see Exp_Dbug). The letter T is permitted, but
230 -- is reserved by convention for the case of internally generated types.
231 -- The result of the call is a new generated unique name of the form XyyyU
232 -- where X is Id_Char, yyy is a unique serial number, and U is either a
233 -- lower case s or b indicating if the current unit is a spec or a body.
235 -- The name is entered into the names table using Name_Enter rather than
236 -- Name_Find, because there can never be a need to locate the entry using
237 -- the Name_Find procedure later on. Names created by New_Internal_Name
238 -- are guaranteed to be consistent from one compilation to another (i.e.
239 -- if the identical unit is compiled with a semantically consistent set
240 -- of sources, the numbers will be consistent. This means that it is fine
241 -- to use these as public symbols.
243 function New_Occurrence_Of
245 Loc
: Source_Ptr
) return Node_Id
;
246 -- New_Occurrence_Of creates an N_Identifier node which is an
247 -- occurrence of the defining identifier which is passed as its
248 -- argument. The Entity and Etype of the result are set from
249 -- the given defining identifier as follows: Entity is simply
250 -- a copy of Def_Id. Etype is a copy of Def_Id for types, and
251 -- a copy of the Etype of Def_Id for other entities.
253 function New_Reference_To
255 Loc
: Source_Ptr
) return Node_Id
;
256 -- This is like New_Occurrence_Of, but it does not set the Etype field.
257 -- It is used from the expander, where Etype fields are generally not set,
258 -- since they are set when the expanded tree is reanalyzed.
260 function New_Suffixed_Name
261 (Related_Id
: Name_Id
;
262 Suffix
: String) return Name_Id
;
263 -- This function is used to create special suffixed names used by the
264 -- debugger. Suffix is a string of upper case letters, used to construct
265 -- the required name. For instance, the special type used to record the
266 -- fixed-point small is called typ_SMALL where typ is the name of the
267 -- fixed-point type (as passed in Related_Id), and Suffix is "SMALL".
269 function OK_Convert_To
(Typ
: Entity_Id
; Expr
: Node_Id
) return Node_Id
;
270 -- Like Convert_To, except that a conversion node is always generated,
271 -- and the Conversion_OK flag is set on this conversion node.
273 function Unchecked_Convert_To
275 Expr
: Node_Id
) return Node_Id
;
276 -- Like Convert_To, but if a conversion is actually needed, constructs
277 -- an N_Unchecked_Type_Conversion node to do the required conversion.