1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2010-2011, 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 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. --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
30 ------------------------------------------------------------------------------
32 -- This package defines the aspects that are recognized by GNAT in aspect
33 -- specifications. It also contains the subprograms for storing/retrieving
34 -- aspect specifications from the tree. The semantic processing for aspect
35 -- specifications is found in Sem_Ch13.Analyze_Aspect_Specifications.
37 with Namet; use Namet;
38 with Snames; use Snames;
39 with Types; use Types;
43 -- Type defining recognized aspects
46 (No_Aspect, -- Dummy entry for no aspect
49 Aspect_Attach_Handler,
51 Aspect_Component_Size,
52 Aspect_Constant_Indexing,
53 Aspect_Default_Component_Value,
54 Aspect_Default_Iterator,
56 Aspect_Dynamic_Predicate,
58 Aspect_Implicit_Dereference,
60 Aspect_Interrupt_Priority,
62 Aspect_Iterator_Element,
64 Aspect_Object_Size, -- GNAT
70 Aspect_Predicate, -- GNAT
75 Aspect_Static_Predicate,
80 Aspect_Test_Case, -- GNAT
81 Aspect_Type_Invariant,
83 Aspect_Value_Size, -- GNAT
84 Aspect_Variable_Indexing,
88 -- The following aspects correspond to library unit pragmas
90 Aspect_All_Calls_Remote,
91 Aspect_Compiler_Unit, -- GNAT
92 Aspect_Elaborate_Body,
94 Aspect_Preelaborate_05, -- GNAT
96 Aspect_Pure_05, -- GNAT
97 Aspect_Remote_Call_Interface,
99 Aspect_Shared_Passive,
100 Aspect_Universal_Data, -- GNAT
102 -- Remaining aspects have a static boolean value that turns the aspect
103 -- on or off. They all correspond to pragmas, but are only converted to
104 -- the pragmas where the value is True. A value of False normally means
105 -- that the aspect is ignored, except in the case of derived types where
106 -- the aspect value is inherited from the parent, in which case, we do
107 -- not allow False if we inherit a True value from the parent.
109 Aspect_Ada_2005, -- GNAT
110 Aspect_Ada_2012, -- GNAT
113 Aspect_Atomic_Components,
114 Aspect_Discard_Names,
115 Aspect_Favor_Top_Level, -- GNAT
117 Aspect_Independent_Components,
119 Aspect_Inline_Always, -- GNAT
120 Aspect_Interrupt_Handler,
123 Aspect_Persistent_BSS, -- GNAT
124 Aspect_Preelaborable_Initialization,
125 Aspect_Pure_Function, -- GNAT
126 Aspect_Shared, -- GNAT (equivalent to Atomic)
127 Aspect_Suppress_Debug_Info, -- GNAT
128 Aspect_Unchecked_Union,
129 Aspect_Universal_Aliasing, -- GNAT
130 Aspect_Unmodified, -- GNAT
131 Aspect_Unreferenced, -- GNAT
132 Aspect_Unreferenced_Objects, -- GNAT
134 Aspect_Volatile_Components);
136 -- The following array indicates aspects that accept 'Class
138 Class_Aspect_OK : constant array (Aspect_Id) of Boolean :=
139 (Aspect_Invariant => True,
141 Aspect_Predicate => True,
145 -- The following array indicates aspects for which multiple occurrences of
146 -- the same aspect attached to the same declaration are allowed.
148 No_Duplicates_Allowed : constant array (Aspect_Id) of Boolean :=
149 (Aspect_Test_Case => False,
152 -- The following subtype defines aspects corresponding to library unit
153 -- pragmas, these can only validly appear as aspects for library units,
154 -- and result in a corresponding pragma being inserted immediately after
155 -- the occurrence of the aspect.
157 subtype Library_Unit_Aspects is
158 Aspect_Id range Aspect_All_Calls_Remote .. Aspect_Universal_Data;
160 -- The following subtype defines aspects accepting an optional static
161 -- boolean parameter indicating if the aspect should be active or
162 -- cancelling. If the parameter is missing the effective value is True,
163 -- enabling the aspect. If the parameter is present it must be a static
164 -- expression of type Standard.Boolean. If the value is True, then the
165 -- aspect is enabled. If it is False, the aspect is disabled.
167 subtype Boolean_Aspects is
168 Aspect_Id range Aspect_Ada_2005 .. Aspect_Id'Last;
170 subtype Pre_Post_Aspects is
171 Aspect_Id range Aspect_Post .. Aspect_Precondition;
173 -- The following type is used for indicating allowed expression forms
175 type Aspect_Expression is
176 (Optional, -- Optional boolean expression
177 Expression, -- Required expression
178 Name); -- Required name
180 -- The following array indicates what argument type is required
182 Aspect_Argument : constant array (Aspect_Id) of Aspect_Expression :=
183 (No_Aspect => Optional,
184 Aspect_Address => Expression,
185 Aspect_Alignment => Expression,
186 Aspect_Attach_Handler => Expression,
187 Aspect_Bit_Order => Expression,
188 Aspect_Component_Size => Expression,
189 Aspect_Constant_Indexing => Name,
190 Aspect_Default_Component_Value => Expression,
191 Aspect_Default_Iterator => Name,
192 Aspect_Default_Value => Expression,
193 Aspect_Dynamic_Predicate => Expression,
194 Aspect_External_Tag => Expression,
195 Aspect_Implicit_Dereference => Name,
196 Aspect_Input => Name,
197 Aspect_Interrupt_Priority => Expression,
198 Aspect_Invariant => Expression,
199 Aspect_Iterator_Element => Name,
200 Aspect_Machine_Radix => Expression,
201 Aspect_Object_Size => Expression,
202 Aspect_Output => Name,
203 Aspect_Post => Expression,
204 Aspect_Postcondition => Expression,
205 Aspect_Pre => Expression,
206 Aspect_Precondition => Expression,
207 Aspect_Predicate => Expression,
208 Aspect_Priority => Expression,
210 Aspect_Size => Expression,
211 Aspect_Small => Expression,
212 Aspect_Static_Predicate => Expression,
213 Aspect_Storage_Pool => Name,
214 Aspect_Storage_Size => Expression,
215 Aspect_Stream_Size => Expression,
216 Aspect_Suppress => Name,
217 Aspect_Test_Case => Expression,
218 Aspect_Type_Invariant => Expression,
219 Aspect_Unsuppress => Name,
220 Aspect_Value_Size => Expression,
221 Aspect_Variable_Indexing => Name,
222 Aspect_Warnings => Name,
223 Aspect_Write => Name,
225 Library_Unit_Aspects => Optional,
226 Boolean_Aspects => Optional);
228 -----------------------------------------
229 -- Table Linking Names and Aspect_Id's --
230 -----------------------------------------
232 -- Table linking aspect names and id's
234 Aspect_Names : constant array (Aspect_Id) of Name_Id := (
235 No_Aspect => No_Name,
236 Aspect_Ada_2005 => Name_Ada_2005,
237 Aspect_Ada_2012 => Name_Ada_2012,
238 Aspect_Address => Name_Address,
239 Aspect_Alignment => Name_Alignment,
240 Aspect_All_Calls_Remote => Name_All_Calls_Remote,
241 Aspect_Asynchronous => Name_Asynchronous,
242 Aspect_Atomic => Name_Atomic,
243 Aspect_Atomic_Components => Name_Atomic_Components,
244 Aspect_Attach_Handler => Name_Attach_Handler,
245 Aspect_Bit_Order => Name_Bit_Order,
246 Aspect_Compiler_Unit => Name_Compiler_Unit,
247 Aspect_Component_Size => Name_Component_Size,
248 Aspect_Constant_Indexing => Name_Constant_Indexing,
249 Aspect_Default_Iterator => Name_Default_Iterator,
250 Aspect_Default_Value => Name_Default_Value,
251 Aspect_Default_Component_Value => Name_Default_Component_Value,
252 Aspect_Discard_Names => Name_Discard_Names,
253 Aspect_Dynamic_Predicate => Name_Dynamic_Predicate,
254 Aspect_Elaborate_Body => Name_Elaborate_Body,
255 Aspect_External_Tag => Name_External_Tag,
256 Aspect_Favor_Top_Level => Name_Favor_Top_Level,
257 Aspect_Implicit_Dereference => Name_Implicit_Dereference,
258 Aspect_Independent => Name_Independent,
259 Aspect_Independent_Components => Name_Independent_Components,
260 Aspect_Inline => Name_Inline,
261 Aspect_Inline_Always => Name_Inline_Always,
262 Aspect_Input => Name_Input,
263 Aspect_Interrupt_Handler => Name_Interrupt_Handler,
264 Aspect_Interrupt_Priority => Name_Interrupt_Priority,
265 Aspect_Invariant => Name_Invariant,
266 Aspect_Iterator_Element => Name_Iterator_Element,
267 Aspect_Machine_Radix => Name_Machine_Radix,
268 Aspect_No_Return => Name_No_Return,
269 Aspect_Object_Size => Name_Object_Size,
270 Aspect_Output => Name_Output,
271 Aspect_Pack => Name_Pack,
272 Aspect_Persistent_BSS => Name_Persistent_BSS,
273 Aspect_Post => Name_Post,
274 Aspect_Postcondition => Name_Postcondition,
275 Aspect_Pre => Name_Pre,
276 Aspect_Precondition => Name_Precondition,
277 Aspect_Predicate => Name_Predicate,
278 Aspect_Preelaborable_Initialization => Name_Preelaborable_Initialization,
279 Aspect_Preelaborate => Name_Preelaborate,
280 Aspect_Preelaborate_05 => Name_Preelaborate_05,
281 Aspect_Priority => Name_Priority,
282 Aspect_Pure => Name_Pure,
283 Aspect_Pure_05 => Name_Pure_05,
284 Aspect_Pure_Function => Name_Pure_Function,
285 Aspect_Read => Name_Read,
286 Aspect_Remote_Call_Interface => Name_Remote_Call_Interface,
287 Aspect_Remote_Types => Name_Remote_Types,
288 Aspect_Shared => Name_Shared,
289 Aspect_Shared_Passive => Name_Shared_Passive,
290 Aspect_Size => Name_Size,
291 Aspect_Small => Name_Small,
292 Aspect_Static_Predicate => Name_Static_Predicate,
293 Aspect_Storage_Pool => Name_Storage_Pool,
294 Aspect_Storage_Size => Name_Storage_Size,
295 Aspect_Stream_Size => Name_Stream_Size,
296 Aspect_Suppress => Name_Suppress,
297 Aspect_Suppress_Debug_Info => Name_Suppress_Debug_Info,
298 Aspect_Test_Case => Name_Test_Case,
299 Aspect_Type_Invariant => Name_Type_Invariant,
300 Aspect_Unchecked_Union => Name_Unchecked_Union,
301 Aspect_Universal_Aliasing => Name_Universal_Aliasing,
302 Aspect_Universal_Data => Name_Universal_Data,
303 Aspect_Unmodified => Name_Unmodified,
304 Aspect_Unreferenced => Name_Unreferenced,
305 Aspect_Unreferenced_Objects => Name_Unreferenced_Objects,
306 Aspect_Unsuppress => Name_Unsuppress,
307 Aspect_Value_Size => Name_Value_Size,
308 Aspect_Variable_Indexing => Name_Variable_Indexing,
309 Aspect_Volatile => Name_Volatile,
310 Aspect_Volatile_Components => Name_Volatile_Components,
311 Aspect_Warnings => Name_Warnings,
312 Aspect_Write => Name_Write);
314 function Get_Aspect_Id (Name : Name_Id) return Aspect_Id;
315 pragma Inline (Get_Aspect_Id);
316 -- Given a name Nam, returns the corresponding aspect id value. If the name
317 -- does not match any aspect, then No_Aspect is returned as the result.
319 ---------------------------------------------------
320 -- Handling of Aspect Specifications in the Tree --
321 ---------------------------------------------------
323 -- Several kinds of declaration node permit aspect specifications in Ada
324 -- 2012 mode. If there was room in all the corresponding declaration nodes,
325 -- we could just have a field Aspect_Specifications pointing to a list of
326 -- nodes for the aspects (N_Aspect_Specification nodes). But there isn't
327 -- room, so we adopt a different approach.
329 -- The following subprograms provide access to a specialized interface
330 -- implemented internally with a hash table in the body, that provides
331 -- access to aspect specifications.
333 function Permits_Aspect_Specifications (N : Node_Id) return Boolean;
334 -- Returns True if the node N is a declaration node that permits aspect
335 -- specifications in the grammar. It is possible for other nodes to have
336 -- aspect specifications as a result of Rewrite or Replace calls.
338 function Aspect_Specifications (N : Node_Id) return List_Id;
339 -- Given a node N, returns the list of N_Aspect_Specification nodes that
340 -- are attached to this declaration node. If the node is in the class of
341 -- declaration nodes that permit aspect specifications, as defined by the
342 -- predicate above, and if their Has_Aspects flag is set to True, then this
343 -- will always be a non-empty list. If this flag is set to False, then
344 -- No_List is returned. Normally, the only nodes that have Has_Aspects set
345 -- True are the nodes for which Permits_Aspect_Specifications would return
346 -- True (i.e. the declaration nodes defined in the RM as permitting the
347 -- presence of Aspect_Specifications). However, it is possible for the
348 -- flag Has_Aspects to be set on other nodes as a result of Rewrite and
349 -- Replace calls, and this function may be used to retrieve the aspect
350 -- specifications for the original rewritten node in such cases.
352 procedure Set_Aspect_Specifications (N : Node_Id; L : List_Id);
353 -- The node N must be in the class of declaration nodes that permit aspect
354 -- specifications and the Has_Aspects flag must be False on entry. L must
355 -- be a non-empty list of N_Aspect_Specification nodes. This procedure sets
356 -- the Has_Aspects flag to True, and makes an entry that can be retrieved
357 -- by a subsequent Aspect_Specifications call. It is an error to call this
358 -- procedure with a node that does not permit aspect specifications, or a
359 -- node that has its Has_Aspects flag set True on entry, or with L being an
360 -- empty list or No_List.
362 function Find_Aspect (Ent : Entity_Id; A : Aspect_Id) return Node_Id;
363 -- Find value of a given aspect from aspect list of entity
365 procedure Move_Aspects (From : Node_Id; To : Node_Id);
366 -- Moves aspects from 'From' node to 'To' node. Has_Aspects (To) must be
367 -- False on entry. If Has_Aspects (From) is False, the call has no effect.
368 -- Otherwise the aspects are moved and on return Has_Aspects (To) is True,
369 -- and Has_Aspects (From) is False.
371 function Same_Aspect (A1 : Aspect_Id; A2 : Aspect_Id) return Boolean;
372 -- Returns True if A1 and A2 are (essentially) the same aspect. This is not
373 -- a simple equality test because e.g. Post and Postcondition are the same.
374 -- This is used for detecting duplicate aspects.
376 procedure Tree_Write;
377 -- Writes contents of Aspect_Specifications hash table to the tree file
380 -- Reads contents of Aspect_Specifications hash table from the tree file