1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2010-2013, 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 ------------------------
38 -- Adding New Aspects --
39 ------------------------
41 -- In general, each aspect should have a corresponding pragma, so that the
42 -- newly developed functionality is available for Ada versions < Ada 2012.
43 -- When both are defined, it is convenient to first transform the aspect into
44 -- an equivalent pragma in Sem_Ch13.Analyze_Aspect_Specifications, and then
45 -- analyze the pragma in Sem_Prag.Analyze_Pragma.
47 -- To add a new aspect, you need to do the following
49 -- 1. Create a name in snames.ads-tmpl
51 -- 2. Create a value in type Aspect_Id in this unit
53 -- 3. Add a value for the aspect in the global arrays defined in this unit
55 -- 4. Add code for the aspect in Sem_Ch13.Analyze_Aspect_Specifications.
56 -- This may involve adding some nodes to the tree to perform additional
59 -- 5. If the semantic analysis of expressions/names in the aspect should not
60 -- occur at the point the aspect is defined, add code in the adequate
61 -- semantic analysis procedure for the aspect. For example, this is the
62 -- case for aspects Pre and Post on subprograms, which are pre-analyzed
63 -- at the end of the declaration list to which the subprogram belongs,
64 -- and fully analyzed (possibly with expansion) during the semantic
65 -- analysis of subprogram bodies.
67 with Namet
; use Namet
;
68 with Snames
; use Snames
;
69 with Types
; use Types
;
73 -- Type defining recognized aspects
76 (No_Aspect
, -- Dummy entry for no aspect
77 Aspect_Abstract_State
, -- GNAT
80 Aspect_Attach_Handler
,
82 Aspect_Component_Size
,
83 Aspect_Constant_Indexing
,
84 Aspect_Contract_Cases
, -- GNAT
87 Aspect_Default_Component_Value
,
88 Aspect_Default_Iterator
,
90 Aspect_Depends
, -- GNAT
91 Aspect_Dimension
, -- GNAT
92 Aspect_Dimension_System
, -- GNAT
93 Aspect_Dispatching_Domain
,
94 Aspect_Dynamic_Predicate
,
97 Aspect_Global
, -- GNAT
98 Aspect_Implicit_Dereference
,
100 Aspect_Interrupt_Priority
,
101 Aspect_Invariant
, -- GNAT
102 Aspect_Iterator_Element
,
104 Aspect_Machine_Radix
,
105 Aspect_Object_Size
, -- GNAT
108 Aspect_Postcondition
,
111 Aspect_Predicate
, -- GNAT
114 Aspect_Relative_Deadline
,
115 Aspect_Scalar_Storage_Order
, -- GNAT
116 Aspect_Simple_Storage_Pool
, -- GNAT
119 Aspect_SPARK_Mode
, -- GNAT
120 Aspect_Static_Predicate
,
125 Aspect_Synchronization
,
126 Aspect_Test_Case
, -- GNAT
127 Aspect_Type_Invariant
,
129 Aspect_Value_Size
, -- GNAT
130 Aspect_Variable_Indexing
,
131 Aspect_Warnings
, -- GNAT
134 -- The following aspects correspond to library unit pragmas
136 Aspect_All_Calls_Remote
,
137 Aspect_Compiler_Unit
, -- GNAT
138 Aspect_Elaborate_Body
,
140 Aspect_Preelaborate_05
, -- GNAT
142 Aspect_Pure_05
, -- GNAT
143 Aspect_Pure_12
, -- GNAT
144 Aspect_Remote_Call_Interface
,
146 Aspect_Shared_Passive
,
147 Aspect_Universal_Data
, -- GNAT
149 -- Remaining aspects have a static boolean value that turns the aspect
150 -- on or off. They all correspond to pragmas, but are only converted to
151 -- the pragmas where the value is True. A value of False normally means
152 -- that the aspect is ignored, except in the case of derived types where
153 -- the aspect value is inherited from the parent, in which case, we do
154 -- not allow False if we inherit a True value from the parent.
156 Aspect_Ada_2005
, -- GNAT
157 Aspect_Ada_2012
, -- GNAT
160 Aspect_Atomic_Components
,
161 Aspect_Discard_Names
,
163 Aspect_Favor_Top_Level
, -- GNAT
165 Aspect_Independent_Components
,
168 Aspect_Inline_Always
, -- GNAT
169 Aspect_Interrupt_Handler
,
172 Aspect_Persistent_BSS
, -- GNAT
173 Aspect_Preelaborable_Initialization
,
174 Aspect_Pure_Function
, -- GNAT
175 Aspect_Remote_Access_Type
, -- GNAT
176 Aspect_Shared
, -- GNAT (equivalent to Atomic)
177 Aspect_Simple_Storage_Pool_Type
, -- GNAT
178 Aspect_Suppress_Debug_Info
, -- GNAT
179 Aspect_Unchecked_Union
,
180 Aspect_Universal_Aliasing
, -- GNAT
181 Aspect_Unmodified
, -- GNAT
182 Aspect_Unreferenced
, -- GNAT
183 Aspect_Unreferenced_Objects
, -- GNAT
185 Aspect_Volatile_Components
,
187 -- Aspects that have a static boolean value but don't correspond to
190 Aspect_Lock_Free
); -- GNAT
192 subtype Aspect_Id_Exclude_No_Aspect
is
193 Aspect_Id
range Aspect_Id
'Succ (No_Aspect
) .. Aspect_Id
'Last;
194 -- Aspect_Id's excluding No_Aspect
196 -- The following array indicates aspects that accept 'Class
198 Class_Aspect_OK
: constant array (Aspect_Id
) of Boolean :=
199 (Aspect_Invariant
=> True,
201 Aspect_Predicate
=> True,
203 Aspect_Type_Invariant
=> True,
206 -- The following array identifies all implementation defined aspects
208 Implementation_Defined_Aspect
: constant array (Aspect_Id
) of Boolean :=
209 (Aspect_Abstract_State
=> True,
210 Aspect_Ada_2005
=> True,
211 Aspect_Ada_2012
=> True,
212 Aspect_Compiler_Unit
=> True,
213 Aspect_Contract_Cases
=> True,
214 Aspect_Depends
=> True,
215 Aspect_Dimension
=> True,
216 Aspect_Dimension_System
=> True,
217 Aspect_Favor_Top_Level
=> True,
218 Aspect_Global
=> True,
219 Aspect_Inline_Always
=> True,
220 Aspect_Invariant
=> True,
221 Aspect_Lock_Free
=> True,
222 Aspect_Object_Size
=> True,
223 Aspect_Persistent_BSS
=> True,
224 Aspect_Predicate
=> True,
225 Aspect_Preelaborate_05
=> True,
226 Aspect_Pure_05
=> True,
227 Aspect_Pure_12
=> True,
228 Aspect_Pure_Function
=> True,
229 Aspect_Remote_Access_Type
=> True,
230 Aspect_Scalar_Storage_Order
=> True,
231 Aspect_Shared
=> True,
232 Aspect_Simple_Storage_Pool
=> True,
233 Aspect_Simple_Storage_Pool_Type
=> True,
234 Aspect_Suppress_Debug_Info
=> True,
235 Aspect_Test_Case
=> True,
236 Aspect_Universal_Aliasing
=> True,
237 Aspect_Universal_Data
=> True,
238 Aspect_Unmodified
=> True,
239 Aspect_Unreferenced
=> True,
240 Aspect_Unreferenced_Objects
=> True,
241 Aspect_Value_Size
=> True,
242 Aspect_Warnings
=> True,
245 -- The following array indicates aspects for which multiple occurrences of
246 -- the same aspect attached to the same declaration are allowed.
248 No_Duplicates_Allowed
: constant array (Aspect_Id
) of Boolean :=
249 (Aspect_Test_Case
=> False,
252 -- The following subtype defines aspects corresponding to library unit
253 -- pragmas, these can only validly appear as aspects for library units,
254 -- and result in a corresponding pragma being inserted immediately after
255 -- the occurrence of the aspect.
257 subtype Library_Unit_Aspects
is
258 Aspect_Id
range Aspect_All_Calls_Remote
.. Aspect_Universal_Data
;
260 -- The following subtype defines aspects accepting an optional static
261 -- boolean parameter indicating if the aspect should be active or
262 -- cancelling. If the parameter is missing the effective value is True,
263 -- enabling the aspect. If the parameter is present it must be a static
264 -- expression of type Standard.Boolean. If the value is True, then the
265 -- aspect is enabled. If it is False, the aspect is disabled.
267 subtype Boolean_Aspects
is
268 Aspect_Id
range Aspect_Ada_2005
.. Aspect_Id
'Last;
270 subtype Pre_Post_Aspects
is
271 Aspect_Id
range Aspect_Post
.. Aspect_Precondition
;
273 -- The following type is used for indicating allowed expression forms
275 type Aspect_Expression
is
276 (Optional
, -- Optional boolean expression
277 Expression
, -- Required expression
278 Name
); -- Required name
280 -- The following array indicates what argument type is required
282 Aspect_Argument
: constant array (Aspect_Id
) of Aspect_Expression
:=
283 (No_Aspect
=> Optional
,
284 Aspect_Abstract_State
=> Expression
,
285 Aspect_Address
=> Expression
,
286 Aspect_Alignment
=> Expression
,
287 Aspect_Attach_Handler
=> Expression
,
288 Aspect_Bit_Order
=> Expression
,
289 Aspect_Component_Size
=> Expression
,
290 Aspect_Constant_Indexing
=> Name
,
291 Aspect_Contract_Cases
=> Expression
,
292 Aspect_Convention
=> Name
,
293 Aspect_CPU
=> Expression
,
294 Aspect_Default_Component_Value
=> Expression
,
295 Aspect_Default_Iterator
=> Name
,
296 Aspect_Default_Value
=> Expression
,
297 Aspect_Depends
=> Expression
,
298 Aspect_Dimension
=> Expression
,
299 Aspect_Dimension_System
=> Expression
,
300 Aspect_Dispatching_Domain
=> Expression
,
301 Aspect_Dynamic_Predicate
=> Expression
,
302 Aspect_External_Name
=> Expression
,
303 Aspect_External_Tag
=> Expression
,
304 Aspect_Global
=> Expression
,
305 Aspect_Implicit_Dereference
=> Name
,
306 Aspect_Input
=> Name
,
307 Aspect_Interrupt_Priority
=> Expression
,
308 Aspect_Invariant
=> Expression
,
309 Aspect_Iterator_Element
=> Name
,
310 Aspect_Link_Name
=> Expression
,
311 Aspect_Machine_Radix
=> Expression
,
312 Aspect_Object_Size
=> Expression
,
313 Aspect_Output
=> Name
,
314 Aspect_Post
=> Expression
,
315 Aspect_Postcondition
=> Expression
,
316 Aspect_Pre
=> Expression
,
317 Aspect_Precondition
=> Expression
,
318 Aspect_Predicate
=> Expression
,
319 Aspect_Priority
=> Expression
,
321 Aspect_Relative_Deadline
=> Expression
,
322 Aspect_Scalar_Storage_Order
=> Expression
,
323 Aspect_Simple_Storage_Pool
=> Name
,
324 Aspect_Size
=> Expression
,
325 Aspect_Small
=> Expression
,
326 Aspect_SPARK_Mode
=> Name
,
327 Aspect_Static_Predicate
=> Expression
,
328 Aspect_Storage_Pool
=> Name
,
329 Aspect_Storage_Size
=> Expression
,
330 Aspect_Stream_Size
=> Expression
,
331 Aspect_Suppress
=> Name
,
332 Aspect_Synchronization
=> Name
,
333 Aspect_Test_Case
=> Expression
,
334 Aspect_Type_Invariant
=> Expression
,
335 Aspect_Unsuppress
=> Name
,
336 Aspect_Value_Size
=> Expression
,
337 Aspect_Variable_Indexing
=> Name
,
338 Aspect_Warnings
=> Name
,
339 Aspect_Write
=> Name
,
341 Boolean_Aspects
=> Optional
,
342 Library_Unit_Aspects
=> Optional
);
344 -----------------------------------------
345 -- Table Linking Names and Aspect_Id's --
346 -----------------------------------------
348 -- Table linking aspect names and id's
350 Aspect_Names
: constant array (Aspect_Id
) of Name_Id
:=
351 (No_Aspect
=> No_Name
,
352 Aspect_Abstract_State
=> Name_Abstract_State
,
353 Aspect_Ada_2005
=> Name_Ada_2005
,
354 Aspect_Ada_2012
=> Name_Ada_2012
,
355 Aspect_Address
=> Name_Address
,
356 Aspect_Alignment
=> Name_Alignment
,
357 Aspect_All_Calls_Remote
=> Name_All_Calls_Remote
,
358 Aspect_Asynchronous
=> Name_Asynchronous
,
359 Aspect_Atomic
=> Name_Atomic
,
360 Aspect_Atomic_Components
=> Name_Atomic_Components
,
361 Aspect_Attach_Handler
=> Name_Attach_Handler
,
362 Aspect_Bit_Order
=> Name_Bit_Order
,
363 Aspect_Compiler_Unit
=> Name_Compiler_Unit
,
364 Aspect_Component_Size
=> Name_Component_Size
,
365 Aspect_Constant_Indexing
=> Name_Constant_Indexing
,
366 Aspect_Contract_Cases
=> Name_Contract_Cases
,
367 Aspect_Convention
=> Name_Convention
,
368 Aspect_CPU
=> Name_CPU
,
369 Aspect_Default_Iterator
=> Name_Default_Iterator
,
370 Aspect_Default_Value
=> Name_Default_Value
,
371 Aspect_Default_Component_Value
=> Name_Default_Component_Value
,
372 Aspect_Depends
=> Name_Depends
,
373 Aspect_Dimension
=> Name_Dimension
,
374 Aspect_Dimension_System
=> Name_Dimension_System
,
375 Aspect_Discard_Names
=> Name_Discard_Names
,
376 Aspect_Dispatching_Domain
=> Name_Dispatching_Domain
,
377 Aspect_Dynamic_Predicate
=> Name_Dynamic_Predicate
,
378 Aspect_Elaborate_Body
=> Name_Elaborate_Body
,
379 Aspect_External_Name
=> Name_External_Name
,
380 Aspect_External_Tag
=> Name_External_Tag
,
381 Aspect_Export
=> Name_Export
,
382 Aspect_Favor_Top_Level
=> Name_Favor_Top_Level
,
383 Aspect_Global
=> Name_Global
,
384 Aspect_Implicit_Dereference
=> Name_Implicit_Dereference
,
385 Aspect_Import
=> Name_Import
,
386 Aspect_Independent
=> Name_Independent
,
387 Aspect_Independent_Components
=> Name_Independent_Components
,
388 Aspect_Inline
=> Name_Inline
,
389 Aspect_Inline_Always
=> Name_Inline_Always
,
390 Aspect_Input
=> Name_Input
,
391 Aspect_Interrupt_Handler
=> Name_Interrupt_Handler
,
392 Aspect_Interrupt_Priority
=> Name_Interrupt_Priority
,
393 Aspect_Invariant
=> Name_Invariant
,
394 Aspect_Iterator_Element
=> Name_Iterator_Element
,
395 Aspect_Link_Name
=> Name_Link_Name
,
396 Aspect_Lock_Free
=> Name_Lock_Free
,
397 Aspect_Machine_Radix
=> Name_Machine_Radix
,
398 Aspect_No_Return
=> Name_No_Return
,
399 Aspect_Object_Size
=> Name_Object_Size
,
400 Aspect_Output
=> Name_Output
,
401 Aspect_Pack
=> Name_Pack
,
402 Aspect_Persistent_BSS
=> Name_Persistent_BSS
,
403 Aspect_Post
=> Name_Post
,
404 Aspect_Postcondition
=> Name_Postcondition
,
405 Aspect_Pre
=> Name_Pre
,
406 Aspect_Precondition
=> Name_Precondition
,
407 Aspect_Predicate
=> Name_Predicate
,
408 Aspect_Preelaborable_Initialization
=> Name_Preelaborable_Initialization
,
409 Aspect_Preelaborate
=> Name_Preelaborate
,
410 Aspect_Preelaborate_05
=> Name_Preelaborate_05
,
411 Aspect_Priority
=> Name_Priority
,
412 Aspect_Pure
=> Name_Pure
,
413 Aspect_Pure_05
=> Name_Pure_05
,
414 Aspect_Pure_12
=> Name_Pure_12
,
415 Aspect_Pure_Function
=> Name_Pure_Function
,
416 Aspect_Read
=> Name_Read
,
417 Aspect_Relative_Deadline
=> Name_Relative_Deadline
,
418 Aspect_Remote_Access_Type
=> Name_Remote_Access_Type
,
419 Aspect_Remote_Call_Interface
=> Name_Remote_Call_Interface
,
420 Aspect_Remote_Types
=> Name_Remote_Types
,
421 Aspect_Scalar_Storage_Order
=> Name_Scalar_Storage_Order
,
422 Aspect_Shared
=> Name_Shared
,
423 Aspect_Shared_Passive
=> Name_Shared_Passive
,
424 Aspect_Simple_Storage_Pool
=> Name_Simple_Storage_Pool
,
425 Aspect_Simple_Storage_Pool_Type
=> Name_Simple_Storage_Pool_Type
,
426 Aspect_Size
=> Name_Size
,
427 Aspect_Small
=> Name_Small
,
428 Aspect_SPARK_Mode
=> Name_SPARK_Mode
,
429 Aspect_Static_Predicate
=> Name_Static_Predicate
,
430 Aspect_Storage_Pool
=> Name_Storage_Pool
,
431 Aspect_Storage_Size
=> Name_Storage_Size
,
432 Aspect_Stream_Size
=> Name_Stream_Size
,
433 Aspect_Suppress
=> Name_Suppress
,
434 Aspect_Suppress_Debug_Info
=> Name_Suppress_Debug_Info
,
435 Aspect_Synchronization
=> Name_Synchronization
,
436 Aspect_Test_Case
=> Name_Test_Case
,
437 Aspect_Type_Invariant
=> Name_Type_Invariant
,
438 Aspect_Unchecked_Union
=> Name_Unchecked_Union
,
439 Aspect_Universal_Aliasing
=> Name_Universal_Aliasing
,
440 Aspect_Universal_Data
=> Name_Universal_Data
,
441 Aspect_Unmodified
=> Name_Unmodified
,
442 Aspect_Unreferenced
=> Name_Unreferenced
,
443 Aspect_Unreferenced_Objects
=> Name_Unreferenced_Objects
,
444 Aspect_Unsuppress
=> Name_Unsuppress
,
445 Aspect_Value_Size
=> Name_Value_Size
,
446 Aspect_Variable_Indexing
=> Name_Variable_Indexing
,
447 Aspect_Volatile
=> Name_Volatile
,
448 Aspect_Volatile_Components
=> Name_Volatile_Components
,
449 Aspect_Warnings
=> Name_Warnings
,
450 Aspect_Write
=> Name_Write
);
452 function Get_Aspect_Id
(Name
: Name_Id
) return Aspect_Id
;
453 pragma Inline
(Get_Aspect_Id
);
454 -- Given a name Nam, returns the corresponding aspect id value. If the name
455 -- does not match any aspect, then No_Aspect is returned as the result.
457 function Get_Aspect_Id
(Aspect
: Node_Id
) return Aspect_Id
;
458 pragma Inline
(Get_Aspect_Id
);
459 -- Given an aspect specification, return the corresponding aspect_id value.
460 -- If the name does not match any aspect, return No_Aspect.
462 ---------------------------------------------------
463 -- Handling of Aspect Specifications in the Tree --
464 ---------------------------------------------------
466 -- Several kinds of declaration node permit aspect specifications in Ada
467 -- 2012 mode. If there was room in all the corresponding declaration nodes,
468 -- we could just have a field Aspect_Specifications pointing to a list of
469 -- nodes for the aspects (N_Aspect_Specification nodes). But there isn't
470 -- room, so we adopt a different approach.
472 -- The following subprograms provide access to a specialized interface
473 -- implemented internally with a hash table in the body, that provides
474 -- access to aspect specifications.
476 function Aspect_Specifications
(N
: Node_Id
) return List_Id
;
477 -- Given a node N, returns the list of N_Aspect_Specification nodes that
478 -- are attached to this declaration node. If the node is in the class of
479 -- declaration nodes that permit aspect specifications, as defined by the
480 -- predicate above, and if their Has_Aspects flag is set to True, then this
481 -- will always be a non-empty list. If this flag is set to False, then
482 -- No_List is returned. Normally, the only nodes that have Has_Aspects set
483 -- True are the nodes for which Permits_Aspect_Specifications would return
484 -- True (i.e. the declaration nodes defined in the RM as permitting the
485 -- presence of Aspect_Specifications). However, it is possible for the
486 -- flag Has_Aspects to be set on other nodes as a result of Rewrite and
487 -- Replace calls, and this function may be used to retrieve the aspect
488 -- specifications for the original rewritten node in such cases.
490 function Find_Aspect
(Id
: Entity_Id
; A
: Aspect_Id
) return Node_Id
;
491 -- Find the aspect specification of aspect A associated with entity I.
492 -- Return Empty if Id does not have the requested aspect.
494 function Find_Value_Of_Aspect
496 A
: Aspect_Id
) return Node_Id
;
497 -- Find the value of aspect A associated with entity Id. Return Empty if
498 -- Id does not have the requested aspect.
500 function Has_Aspect
(Id
: Entity_Id
; A
: Aspect_Id
) return Boolean;
501 -- Determine whether entity Id has aspect A
503 procedure Move_Aspects
(From
: Node_Id
; To
: Node_Id
);
504 -- Moves aspects from 'From' node to 'To' node. Has_Aspects (To) must be
505 -- False on entry. If Has_Aspects (From) is False, the call has no effect.
506 -- Otherwise the aspects are moved and on return Has_Aspects (To) is True,
507 -- and Has_Aspects (From) is False.
509 function Permits_Aspect_Specifications
(N
: Node_Id
) return Boolean;
510 -- Returns True if the node N is a declaration node that permits aspect
511 -- specifications in the grammar. It is possible for other nodes to have
512 -- aspect specifications as a result of Rewrite or Replace calls.
514 function Same_Aspect
(A1
: Aspect_Id
; A2
: Aspect_Id
) return Boolean;
515 -- Returns True if A1 and A2 are (essentially) the same aspect. This is not
516 -- a simple equality test because e.g. Post and Postcondition are the same.
517 -- This is used for detecting duplicate aspects.
519 procedure Set_Aspect_Specifications
(N
: Node_Id
; L
: List_Id
);
520 -- The node N must be in the class of declaration nodes that permit aspect
521 -- specifications and the Has_Aspects flag must be False on entry. L must
522 -- be a non-empty list of N_Aspect_Specification nodes. This procedure sets
523 -- the Has_Aspects flag to True, and makes an entry that can be retrieved
524 -- by a subsequent Aspect_Specifications call. It is an error to call this
525 -- procedure with a node that does not permit aspect specifications, or a
526 -- node that has its Has_Aspects flag set True on entry, or with L being an
527 -- empty list or No_List.
530 -- Reads contents of Aspect_Specifications hash table from the tree file
532 procedure Tree_Write
;
533 -- Writes contents of Aspect_Specifications hash table to the tree file