1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2010-2014, 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_Annotate
, -- GNAT
81 Aspect_Attach_Handler
,
83 Aspect_Component_Size
,
84 Aspect_Constant_Indexing
,
85 Aspect_Contract_Cases
, -- GNAT
88 Aspect_Default_Component_Value
,
89 Aspect_Default_Initial_Condition
, -- GNAT
90 Aspect_Default_Iterator
,
92 Aspect_Depends
, -- GNAT
93 Aspect_Dimension
, -- GNAT
94 Aspect_Dimension_System
, -- GNAT
95 Aspect_Dispatching_Domain
,
96 Aspect_Dynamic_Predicate
,
99 Aspect_Global
, -- GNAT
100 Aspect_Implicit_Dereference
,
101 Aspect_Initial_Condition
, -- GNAT
102 Aspect_Initializes
, -- GNAT
104 Aspect_Interrupt_Priority
,
105 Aspect_Invariant
, -- GNAT
106 Aspect_Iterator_Element
,
107 Aspect_Iterable
, -- GNAT
109 Aspect_Linker_Section
, -- GNAT
110 Aspect_Machine_Radix
,
111 Aspect_Object_Size
, -- GNAT
112 Aspect_Obsolescent
, -- GNAT
114 Aspect_Part_Of
, -- GNAT
116 Aspect_Postcondition
,
119 Aspect_Predicate
, -- GNAT
122 Aspect_Refined_Depends
, -- GNAT
123 Aspect_Refined_Global
, -- GNAT
124 Aspect_Refined_Post
, -- GNAT
125 Aspect_Refined_State
, -- GNAT
126 Aspect_Relative_Deadline
,
127 Aspect_Scalar_Storage_Order
, -- GNAT
128 Aspect_Simple_Storage_Pool
, -- GNAT
131 Aspect_SPARK_Mode
, -- GNAT
132 Aspect_Static_Predicate
,
137 Aspect_Synchronization
,
138 Aspect_Test_Case
, -- GNAT
139 Aspect_Type_Invariant
,
141 Aspect_Value_Size
, -- GNAT
142 Aspect_Variable_Indexing
,
143 Aspect_Warnings
, -- GNAT
146 -- The following aspects correspond to library unit pragmas
148 Aspect_All_Calls_Remote
,
149 Aspect_Elaborate_Body
,
150 Aspect_No_Elaboration_Code_All
, -- GNAT
153 Aspect_Remote_Call_Interface
,
155 Aspect_Shared_Passive
,
156 Aspect_Universal_Data
, -- GNAT
158 -- Remaining aspects have a static boolean value that turns the aspect
159 -- on or off. They all correspond to pragmas, but are only converted to
160 -- the pragmas where the value is True. A value of False normally means
161 -- that the aspect is ignored, except in the case of derived types where
162 -- the aspect value is inherited from the parent, in which case, we do
163 -- not allow False if we inherit a True value from the parent.
165 Aspect_Async_Readers
, -- GNAT
166 Aspect_Async_Writers
, -- GNAT
169 Aspect_Atomic_Components
,
170 Aspect_Discard_Names
,
171 Aspect_Effective_Reads
, -- GNAT
172 Aspect_Effective_Writes
, -- GNAT
174 Aspect_Favor_Top_Level
, -- GNAT
176 Aspect_Independent_Components
,
179 Aspect_Inline_Always
, -- GNAT
180 Aspect_Interrupt_Handler
,
183 Aspect_Persistent_BSS
, -- GNAT
184 Aspect_Preelaborable_Initialization
,
185 Aspect_Pure_Function
, -- GNAT
186 Aspect_Remote_Access_Type
, -- GNAT
187 Aspect_Shared
, -- GNAT (equivalent to Atomic)
188 Aspect_Simple_Storage_Pool_Type
, -- GNAT
189 Aspect_Suppress_Debug_Info
, -- GNAT
190 Aspect_Thread_Local_Storage
, -- GNAT
191 Aspect_Unchecked_Union
,
192 Aspect_Universal_Aliasing
, -- GNAT
193 Aspect_Unmodified
, -- GNAT
194 Aspect_Unreferenced
, -- GNAT
195 Aspect_Unreferenced_Objects
, -- GNAT
197 Aspect_Volatile_Components
,
199 -- Aspects that have a static boolean value but don't correspond to
200 -- pragmas with a single argument that it is the entity in question.
202 Aspect_Lock_Free
); -- GNAT
204 subtype Aspect_Id_Exclude_No_Aspect
is
205 Aspect_Id
range Aspect_Id
'Succ (No_Aspect
) .. Aspect_Id
'Last;
206 -- Aspect_Id's excluding No_Aspect
208 -- The following array indicates aspects that accept 'Class
210 Class_Aspect_OK
: constant array (Aspect_Id
) of Boolean :=
211 (Aspect_Input
=> True,
212 Aspect_Invariant
=> True,
213 Aspect_Output
=> True,
215 Aspect_Predicate
=> True,
218 Aspect_Write
=> True,
219 Aspect_Type_Invariant
=> True,
222 -- The following array identifies all implementation defined aspects
224 Implementation_Defined_Aspect
: constant array (Aspect_Id
) of Boolean :=
225 (Aspect_Abstract_State
=> True,
226 Aspect_Annotate
=> True,
227 Aspect_Async_Readers
=> True,
228 Aspect_Async_Writers
=> True,
229 Aspect_Contract_Cases
=> True,
230 Aspect_Depends
=> True,
231 Aspect_Dimension
=> True,
232 Aspect_Dimension_System
=> True,
233 Aspect_Effective_Reads
=> True,
234 Aspect_Effective_Writes
=> True,
235 Aspect_Favor_Top_Level
=> True,
236 Aspect_Global
=> True,
237 Aspect_Inline_Always
=> True,
238 Aspect_Invariant
=> True,
239 Aspect_Lock_Free
=> True,
240 Aspect_Object_Size
=> True,
241 Aspect_Persistent_BSS
=> True,
242 Aspect_Predicate
=> True,
243 Aspect_Pure_Function
=> True,
244 Aspect_Remote_Access_Type
=> True,
245 Aspect_Scalar_Storage_Order
=> True,
246 Aspect_Shared
=> True,
247 Aspect_Simple_Storage_Pool
=> True,
248 Aspect_Simple_Storage_Pool_Type
=> True,
249 Aspect_Suppress_Debug_Info
=> True,
250 Aspect_Thread_Local_Storage
=> True,
251 Aspect_Test_Case
=> True,
252 Aspect_Universal_Aliasing
=> True,
253 Aspect_Universal_Data
=> True,
254 Aspect_Unmodified
=> True,
255 Aspect_Unreferenced
=> True,
256 Aspect_Unreferenced_Objects
=> True,
257 Aspect_Value_Size
=> True,
258 Aspect_Warnings
=> True,
261 -- The following array indicates aspects for which multiple occurrences of
262 -- the same aspect attached to the same declaration are allowed.
264 No_Duplicates_Allowed
: constant array (Aspect_Id
) of Boolean :=
265 (Aspect_Annotate
=> False,
266 Aspect_Test_Case
=> False,
269 -- The following subtype defines aspects corresponding to library unit
270 -- pragmas, these can only validly appear as aspects for library units,
271 -- and result in a corresponding pragma being inserted immediately after
272 -- the occurrence of the aspect.
274 subtype Library_Unit_Aspects
is
275 Aspect_Id
range Aspect_All_Calls_Remote
.. Aspect_Universal_Data
;
277 -- The following subtype defines aspects accepting an optional static
278 -- boolean parameter indicating if the aspect should be active or
279 -- cancelling. If the parameter is missing the effective value is True,
280 -- enabling the aspect. If the parameter is present it must be a static
281 -- expression of type Standard.Boolean. If the value is True, then the
282 -- aspect is enabled. If it is False, the aspect is disabled.
284 subtype Boolean_Aspects
is
285 Aspect_Id
range Aspect_Async_Readers
.. Aspect_Id
'Last;
287 subtype Pre_Post_Aspects
is
288 Aspect_Id
range Aspect_Post
.. Aspect_Precondition
;
290 -- The following type is used for indicating allowed expression forms
292 type Aspect_Expression
is
293 (Expression
, -- Required expression
294 Name
, -- Required name
295 Optional_Expression
, -- Optional boolean expression
296 Optional_Name
); -- Optional name
298 -- The following array indicates what argument type is required
300 Aspect_Argument
: constant array (Aspect_Id
) of Aspect_Expression
:=
301 (No_Aspect
=> Optional_Expression
,
302 Aspect_Abstract_State
=> Expression
,
303 Aspect_Address
=> Expression
,
304 Aspect_Alignment
=> Expression
,
305 Aspect_Annotate
=> Expression
,
306 Aspect_Attach_Handler
=> Expression
,
307 Aspect_Bit_Order
=> Expression
,
308 Aspect_Component_Size
=> Expression
,
309 Aspect_Constant_Indexing
=> Name
,
310 Aspect_Contract_Cases
=> Expression
,
311 Aspect_Convention
=> Name
,
312 Aspect_CPU
=> Expression
,
313 Aspect_Default_Component_Value
=> Expression
,
314 Aspect_Default_Initial_Condition
=> Optional_Expression
,
315 Aspect_Default_Iterator
=> Name
,
316 Aspect_Default_Value
=> Expression
,
317 Aspect_Depends
=> Expression
,
318 Aspect_Dimension
=> Expression
,
319 Aspect_Dimension_System
=> Expression
,
320 Aspect_Dispatching_Domain
=> Expression
,
321 Aspect_Dynamic_Predicate
=> Expression
,
322 Aspect_External_Name
=> Expression
,
323 Aspect_External_Tag
=> Expression
,
324 Aspect_Global
=> Expression
,
325 Aspect_Implicit_Dereference
=> Name
,
326 Aspect_Initial_Condition
=> Expression
,
327 Aspect_Initializes
=> Expression
,
328 Aspect_Input
=> Name
,
329 Aspect_Interrupt_Priority
=> Expression
,
330 Aspect_Invariant
=> Expression
,
331 Aspect_Iterable
=> Expression
,
332 Aspect_Iterator_Element
=> Name
,
333 Aspect_Link_Name
=> Expression
,
334 Aspect_Linker_Section
=> Expression
,
335 Aspect_Machine_Radix
=> Expression
,
336 Aspect_Object_Size
=> Expression
,
337 Aspect_Obsolescent
=> Optional_Expression
,
338 Aspect_Output
=> Name
,
339 Aspect_Part_Of
=> Expression
,
340 Aspect_Post
=> Expression
,
341 Aspect_Postcondition
=> Expression
,
342 Aspect_Pre
=> Expression
,
343 Aspect_Precondition
=> Expression
,
344 Aspect_Predicate
=> Expression
,
345 Aspect_Priority
=> Expression
,
347 Aspect_Refined_Depends
=> Expression
,
348 Aspect_Refined_Global
=> Expression
,
349 Aspect_Refined_Post
=> Expression
,
350 Aspect_Refined_State
=> Expression
,
351 Aspect_Relative_Deadline
=> Expression
,
352 Aspect_Scalar_Storage_Order
=> Expression
,
353 Aspect_Simple_Storage_Pool
=> Name
,
354 Aspect_Size
=> Expression
,
355 Aspect_Small
=> Expression
,
356 Aspect_SPARK_Mode
=> Optional_Name
,
357 Aspect_Static_Predicate
=> Expression
,
358 Aspect_Storage_Pool
=> Name
,
359 Aspect_Storage_Size
=> Expression
,
360 Aspect_Stream_Size
=> Expression
,
361 Aspect_Suppress
=> Name
,
362 Aspect_Synchronization
=> Name
,
363 Aspect_Test_Case
=> Expression
,
364 Aspect_Type_Invariant
=> Expression
,
365 Aspect_Unsuppress
=> Name
,
366 Aspect_Value_Size
=> Expression
,
367 Aspect_Variable_Indexing
=> Name
,
368 Aspect_Warnings
=> Name
,
369 Aspect_Write
=> Name
,
371 Boolean_Aspects
=> Optional_Expression
,
372 Library_Unit_Aspects
=> Optional_Expression
);
374 -----------------------------------------
375 -- Table Linking Names and Aspect_Id's --
376 -----------------------------------------
378 -- Table linking aspect names and id's
380 Aspect_Names
: constant array (Aspect_Id
) of Name_Id
:=
381 (No_Aspect
=> No_Name
,
382 Aspect_Abstract_State
=> Name_Abstract_State
,
383 Aspect_Address
=> Name_Address
,
384 Aspect_Alignment
=> Name_Alignment
,
385 Aspect_All_Calls_Remote
=> Name_All_Calls_Remote
,
386 Aspect_Annotate
=> Name_Annotate
,
387 Aspect_Async_Readers
=> Name_Async_Readers
,
388 Aspect_Async_Writers
=> Name_Async_Writers
,
389 Aspect_Asynchronous
=> Name_Asynchronous
,
390 Aspect_Atomic
=> Name_Atomic
,
391 Aspect_Atomic_Components
=> Name_Atomic_Components
,
392 Aspect_Attach_Handler
=> Name_Attach_Handler
,
393 Aspect_Bit_Order
=> Name_Bit_Order
,
394 Aspect_Component_Size
=> Name_Component_Size
,
395 Aspect_Constant_Indexing
=> Name_Constant_Indexing
,
396 Aspect_Contract_Cases
=> Name_Contract_Cases
,
397 Aspect_Convention
=> Name_Convention
,
398 Aspect_CPU
=> Name_CPU
,
399 Aspect_Default_Component_Value
=> Name_Default_Component_Value
,
400 Aspect_Default_Initial_Condition
=> Name_Default_Initial_Condition
,
401 Aspect_Default_Iterator
=> Name_Default_Iterator
,
402 Aspect_Default_Value
=> Name_Default_Value
,
403 Aspect_Depends
=> Name_Depends
,
404 Aspect_Dimension
=> Name_Dimension
,
405 Aspect_Dimension_System
=> Name_Dimension_System
,
406 Aspect_Discard_Names
=> Name_Discard_Names
,
407 Aspect_Dispatching_Domain
=> Name_Dispatching_Domain
,
408 Aspect_Dynamic_Predicate
=> Name_Dynamic_Predicate
,
409 Aspect_Effective_Reads
=> Name_Effective_Reads
,
410 Aspect_Effective_Writes
=> Name_Effective_Writes
,
411 Aspect_Elaborate_Body
=> Name_Elaborate_Body
,
412 Aspect_External_Name
=> Name_External_Name
,
413 Aspect_External_Tag
=> Name_External_Tag
,
414 Aspect_Export
=> Name_Export
,
415 Aspect_Favor_Top_Level
=> Name_Favor_Top_Level
,
416 Aspect_Global
=> Name_Global
,
417 Aspect_Implicit_Dereference
=> Name_Implicit_Dereference
,
418 Aspect_Import
=> Name_Import
,
419 Aspect_Independent
=> Name_Independent
,
420 Aspect_Independent_Components
=> Name_Independent_Components
,
421 Aspect_Inline
=> Name_Inline
,
422 Aspect_Inline_Always
=> Name_Inline_Always
,
423 Aspect_Initial_Condition
=> Name_Initial_Condition
,
424 Aspect_Initializes
=> Name_Initializes
,
425 Aspect_Input
=> Name_Input
,
426 Aspect_Interrupt_Handler
=> Name_Interrupt_Handler
,
427 Aspect_Interrupt_Priority
=> Name_Interrupt_Priority
,
428 Aspect_Invariant
=> Name_Invariant
,
429 Aspect_Iterator_Element
=> Name_Iterator_Element
,
430 Aspect_Iterable
=> Name_Iterable
,
431 Aspect_Link_Name
=> Name_Link_Name
,
432 Aspect_Linker_Section
=> Name_Linker_Section
,
433 Aspect_Lock_Free
=> Name_Lock_Free
,
434 Aspect_Machine_Radix
=> Name_Machine_Radix
,
435 Aspect_No_Elaboration_Code_All
=> Name_No_Elaboration_Code_All
,
436 Aspect_No_Return
=> Name_No_Return
,
437 Aspect_Object_Size
=> Name_Object_Size
,
438 Aspect_Obsolescent
=> Name_Obsolescent
,
439 Aspect_Output
=> Name_Output
,
440 Aspect_Pack
=> Name_Pack
,
441 Aspect_Part_Of
=> Name_Part_Of
,
442 Aspect_Persistent_BSS
=> Name_Persistent_BSS
,
443 Aspect_Post
=> Name_Post
,
444 Aspect_Postcondition
=> Name_Postcondition
,
445 Aspect_Pre
=> Name_Pre
,
446 Aspect_Precondition
=> Name_Precondition
,
447 Aspect_Predicate
=> Name_Predicate
,
448 Aspect_Preelaborable_Initialization
=> Name_Preelaborable_Initialization
,
449 Aspect_Preelaborate
=> Name_Preelaborate
,
450 Aspect_Priority
=> Name_Priority
,
451 Aspect_Pure
=> Name_Pure
,
452 Aspect_Pure_Function
=> Name_Pure_Function
,
453 Aspect_Read
=> Name_Read
,
454 Aspect_Refined_Depends
=> Name_Refined_Depends
,
455 Aspect_Refined_Global
=> Name_Refined_Global
,
456 Aspect_Refined_Post
=> Name_Refined_Post
,
457 Aspect_Refined_State
=> Name_Refined_State
,
458 Aspect_Relative_Deadline
=> Name_Relative_Deadline
,
459 Aspect_Remote_Access_Type
=> Name_Remote_Access_Type
,
460 Aspect_Remote_Call_Interface
=> Name_Remote_Call_Interface
,
461 Aspect_Remote_Types
=> Name_Remote_Types
,
462 Aspect_Scalar_Storage_Order
=> Name_Scalar_Storage_Order
,
463 Aspect_Shared
=> Name_Shared
,
464 Aspect_Shared_Passive
=> Name_Shared_Passive
,
465 Aspect_Simple_Storage_Pool
=> Name_Simple_Storage_Pool
,
466 Aspect_Simple_Storage_Pool_Type
=> Name_Simple_Storage_Pool_Type
,
467 Aspect_Size
=> Name_Size
,
468 Aspect_Small
=> Name_Small
,
469 Aspect_SPARK_Mode
=> Name_SPARK_Mode
,
470 Aspect_Static_Predicate
=> Name_Static_Predicate
,
471 Aspect_Storage_Pool
=> Name_Storage_Pool
,
472 Aspect_Storage_Size
=> Name_Storage_Size
,
473 Aspect_Stream_Size
=> Name_Stream_Size
,
474 Aspect_Suppress
=> Name_Suppress
,
475 Aspect_Suppress_Debug_Info
=> Name_Suppress_Debug_Info
,
476 Aspect_Thread_Local_Storage
=> Name_Thread_Local_Storage
,
477 Aspect_Synchronization
=> Name_Synchronization
,
478 Aspect_Test_Case
=> Name_Test_Case
,
479 Aspect_Type_Invariant
=> Name_Type_Invariant
,
480 Aspect_Unchecked_Union
=> Name_Unchecked_Union
,
481 Aspect_Universal_Aliasing
=> Name_Universal_Aliasing
,
482 Aspect_Universal_Data
=> Name_Universal_Data
,
483 Aspect_Unmodified
=> Name_Unmodified
,
484 Aspect_Unreferenced
=> Name_Unreferenced
,
485 Aspect_Unreferenced_Objects
=> Name_Unreferenced_Objects
,
486 Aspect_Unsuppress
=> Name_Unsuppress
,
487 Aspect_Value_Size
=> Name_Value_Size
,
488 Aspect_Variable_Indexing
=> Name_Variable_Indexing
,
489 Aspect_Volatile
=> Name_Volatile
,
490 Aspect_Volatile_Components
=> Name_Volatile_Components
,
491 Aspect_Warnings
=> Name_Warnings
,
492 Aspect_Write
=> Name_Write
);
494 function Get_Aspect_Id
(Name
: Name_Id
) return Aspect_Id
;
495 pragma Inline
(Get_Aspect_Id
);
496 -- Given a name Nam, returns the corresponding aspect id value. If the name
497 -- does not match any aspect, then No_Aspect is returned as the result.
499 function Get_Aspect_Id
(Aspect
: Node_Id
) return Aspect_Id
;
500 pragma Inline
(Get_Aspect_Id
);
501 -- Given an aspect specification, return the corresponding aspect_id value.
502 -- If the name does not match any aspect, return No_Aspect.
504 ------------------------------------
505 -- Delaying Evaluation of Aspects --
506 ------------------------------------
508 -- The RM requires that all language defined aspects taking an expression
509 -- delay evaluation of the expression till the freeze point of the entity
510 -- to which the aspect applies. This allows forward references, and is of
511 -- use for example in connection with preconditions and postconditions
512 -- where the requirement of making all references in contracts to local
513 -- functions be backwards references would be onerous.
515 -- For consistency, even attributes like Size are delayed, so we can do:
517 -- type A is range 1 .. 10
518 -- with Size => Not_Defined_Yet;
520 -- Not_Defined_Yet : constant := 64;
522 -- Resulting in A having a size of 64, which gets set when A is frozen.
523 -- Furthermore, we can have a situation like
525 -- type A is range 1 .. 10
526 -- with Size => Not_Defined_Yet;
530 -- Not_Defined_Yet : constant := 64;
532 -- where the Size of A is considered to have been previously specified at
533 -- the point of derivation, even though the actual value of the size is
534 -- not known yet, and in this example B inherits the size value of 64.
536 -- Our normal implementation model (prior to Ada 2012) was simply to copy
537 -- inheritable attributes at the point of derivation. Then any subsequent
538 -- representation items apply either to the parent type, not affecting the
539 -- derived type, or to the derived type, not affecting the parent type.
541 -- To deal with the delayed aspect case, we use two flags. The first is
542 -- set on the parent type if it has delayed representation aspects. This
543 -- flag Has_Delayed_Rep_Aspects indicates that if we derive from this type
544 -- we have to worry about making sure we inherit any delayed aspects. The
545 -- second flag is set on a derived type: May_Have_Inherited_Rep_Aspects
546 -- is set if the parent type has Has_Delayed_Rep_Aspects set.
548 -- When we freeze a derived type, if the May_Have_Inherited_Rep_Aspects
549 -- flag is set, then we call Freeze.Inherit_Delayed_Rep_Aspects when
550 -- the derived type is frozen, which deals with the necessary copying of
551 -- information from the parent type, which must be frozen at that point
552 -- (since freezing the derived type first freezes the parent type).
554 -- SPARK 2014 aspects do not follow the general delay mechanism as they
555 -- act as annotations and cannot modify the attributes of their related
556 -- constructs. To handle forward references in such aspects, the compiler
557 -- delays the analysis of their respective pragmas by collecting them in
558 -- N_Contract nodes. The pragmas are then analyzed at the end of the
559 -- declarative region which contains the related construct. For details,
560 -- see routines Analyze_xxx_In_Decl_Part.
562 -- The following shows which aspects are delayed. There are three cases:
566 -- This aspect is not a representation aspect that can be inherited and
567 -- is always delayed, as required by the language definition.
570 -- There are two cases. There are language defined aspects like
571 -- Convention where the "expression" is simply an uninterpreted
572 -- identifier, and there is no issue of evaluating it and thus no
573 -- issue of delaying the evaluation. The second case is implementation
574 -- defined aspects where we have decided that we don't want to allow
575 -- delays (and for our own aspects we can do what we like).
578 -- These are the cases of representation aspects that are in general
579 -- delayed, and where there is a potential issue of derived types that
580 -- inherit delayed representation values.
582 -- Note: even if this table indicates that an aspect is delayed, we never
583 -- delay Boolean aspects that have a missing expression (taken as True),
584 -- or expressions for delayed rep items that consist of an integer literal
585 -- (most cases of Size etc. in practice), since in these cases we know we
586 -- can get the value of the expression without delay. Note that we still
587 -- need to delay Boolean aspects that are specifically set to True:
589 -- type R is array (0 .. 31) of Boolean
590 -- with Pack => True;
591 -- True : constant Boolean := False;
593 -- This is nonsense, but we need to make it work and result in R not
594 -- being packed, and if we have something like:
596 -- type R is array (0 .. 31) of Boolean
597 -- with Pack => True;
599 -- True : constant Boolean := False;
601 -- This is illegal because the visibility of True changes after the freeze
602 -- point, which is not allowed, and we need the delay mechanism to properly
603 -- diagnose this error.
605 Aspect_Delay
: constant array (Aspect_Id
) of Delay_Type
:=
606 (No_Aspect
=> Always_Delay
,
607 Aspect_Address
=> Always_Delay
,
608 Aspect_All_Calls_Remote
=> Always_Delay
,
609 Aspect_Asynchronous
=> Always_Delay
,
610 Aspect_Attach_Handler
=> Always_Delay
,
611 Aspect_Constant_Indexing
=> Always_Delay
,
612 Aspect_CPU
=> Always_Delay
,
613 Aspect_Default_Iterator
=> Always_Delay
,
614 Aspect_Default_Value
=> Always_Delay
,
615 Aspect_Default_Component_Value
=> Always_Delay
,
616 Aspect_Discard_Names
=> Always_Delay
,
617 Aspect_Dispatching_Domain
=> Always_Delay
,
618 Aspect_Dynamic_Predicate
=> Always_Delay
,
619 Aspect_Elaborate_Body
=> Always_Delay
,
620 Aspect_External_Name
=> Always_Delay
,
621 Aspect_External_Tag
=> Always_Delay
,
622 Aspect_Export
=> Always_Delay
,
623 Aspect_Favor_Top_Level
=> Always_Delay
,
624 Aspect_Implicit_Dereference
=> Always_Delay
,
625 Aspect_Import
=> Always_Delay
,
626 Aspect_Independent
=> Always_Delay
,
627 Aspect_Independent_Components
=> Always_Delay
,
628 Aspect_Inline
=> Always_Delay
,
629 Aspect_Inline_Always
=> Always_Delay
,
630 Aspect_Input
=> Always_Delay
,
631 Aspect_Interrupt_Handler
=> Always_Delay
,
632 Aspect_Interrupt_Priority
=> Always_Delay
,
633 Aspect_Invariant
=> Always_Delay
,
634 Aspect_Iterable
=> Always_Delay
,
635 Aspect_Iterator_Element
=> Always_Delay
,
636 Aspect_Link_Name
=> Always_Delay
,
637 Aspect_Linker_Section
=> Always_Delay
,
638 Aspect_Lock_Free
=> Always_Delay
,
639 Aspect_No_Return
=> Always_Delay
,
640 Aspect_Output
=> Always_Delay
,
641 Aspect_Persistent_BSS
=> Always_Delay
,
642 Aspect_Post
=> Always_Delay
,
643 Aspect_Postcondition
=> Always_Delay
,
644 Aspect_Pre
=> Always_Delay
,
645 Aspect_Precondition
=> Always_Delay
,
646 Aspect_Predicate
=> Always_Delay
,
647 Aspect_Preelaborable_Initialization
=> Always_Delay
,
648 Aspect_Preelaborate
=> Always_Delay
,
649 Aspect_Priority
=> Always_Delay
,
650 Aspect_Pure
=> Always_Delay
,
651 Aspect_Pure_Function
=> Always_Delay
,
652 Aspect_Read
=> Always_Delay
,
653 Aspect_Relative_Deadline
=> Always_Delay
,
654 Aspect_Remote_Access_Type
=> Always_Delay
,
655 Aspect_Remote_Call_Interface
=> Always_Delay
,
656 Aspect_Remote_Types
=> Always_Delay
,
657 Aspect_Shared
=> Always_Delay
,
658 Aspect_Shared_Passive
=> Always_Delay
,
659 Aspect_Simple_Storage_Pool
=> Always_Delay
,
660 Aspect_Simple_Storage_Pool_Type
=> Always_Delay
,
661 Aspect_Static_Predicate
=> Always_Delay
,
662 Aspect_Storage_Pool
=> Always_Delay
,
663 Aspect_Stream_Size
=> Always_Delay
,
664 Aspect_Suppress
=> Always_Delay
,
665 Aspect_Suppress_Debug_Info
=> Always_Delay
,
666 Aspect_Thread_Local_Storage
=> Always_Delay
,
667 Aspect_Type_Invariant
=> Always_Delay
,
668 Aspect_Unchecked_Union
=> Always_Delay
,
669 Aspect_Universal_Aliasing
=> Always_Delay
,
670 Aspect_Universal_Data
=> Always_Delay
,
671 Aspect_Unmodified
=> Always_Delay
,
672 Aspect_Unreferenced
=> Always_Delay
,
673 Aspect_Unreferenced_Objects
=> Always_Delay
,
674 Aspect_Unsuppress
=> Always_Delay
,
675 Aspect_Variable_Indexing
=> Always_Delay
,
676 Aspect_Write
=> Always_Delay
,
678 Aspect_Abstract_State
=> Never_Delay
,
679 Aspect_Annotate
=> Never_Delay
,
680 Aspect_Async_Readers
=> Never_Delay
,
681 Aspect_Async_Writers
=> Never_Delay
,
682 Aspect_Contract_Cases
=> Never_Delay
,
683 Aspect_Convention
=> Never_Delay
,
684 Aspect_Default_Initial_Condition
=> Never_Delay
,
685 Aspect_Depends
=> Never_Delay
,
686 Aspect_Dimension
=> Never_Delay
,
687 Aspect_Dimension_System
=> Never_Delay
,
688 Aspect_Effective_Reads
=> Never_Delay
,
689 Aspect_Effective_Writes
=> Never_Delay
,
690 Aspect_Global
=> Never_Delay
,
691 Aspect_Initial_Condition
=> Never_Delay
,
692 Aspect_Initializes
=> Never_Delay
,
693 Aspect_No_Elaboration_Code_All
=> Never_Delay
,
694 Aspect_Obsolescent
=> Never_Delay
,
695 Aspect_Part_Of
=> Never_Delay
,
696 Aspect_Refined_Depends
=> Never_Delay
,
697 Aspect_Refined_Global
=> Never_Delay
,
698 Aspect_Refined_Post
=> Never_Delay
,
699 Aspect_Refined_State
=> Never_Delay
,
700 Aspect_SPARK_Mode
=> Never_Delay
,
701 Aspect_Synchronization
=> Never_Delay
,
702 Aspect_Test_Case
=> Never_Delay
,
703 Aspect_Warnings
=> Never_Delay
,
705 Aspect_Alignment
=> Rep_Aspect
,
706 Aspect_Atomic
=> Rep_Aspect
,
707 Aspect_Atomic_Components
=> Rep_Aspect
,
708 Aspect_Bit_Order
=> Rep_Aspect
,
709 Aspect_Component_Size
=> Rep_Aspect
,
710 Aspect_Machine_Radix
=> Rep_Aspect
,
711 Aspect_Object_Size
=> Rep_Aspect
,
712 Aspect_Pack
=> Rep_Aspect
,
713 Aspect_Scalar_Storage_Order
=> Rep_Aspect
,
714 Aspect_Size
=> Rep_Aspect
,
715 Aspect_Small
=> Rep_Aspect
,
716 Aspect_Storage_Size
=> Rep_Aspect
,
717 Aspect_Value_Size
=> Rep_Aspect
,
718 Aspect_Volatile
=> Rep_Aspect
,
719 Aspect_Volatile_Components
=> Rep_Aspect
);
721 ------------------------------------------------
722 -- Handling of Aspect Specifications on Stubs --
723 ------------------------------------------------
725 -- Aspects that appear on the following stub nodes
727 -- N_Package_Body_Stub
728 -- N_Protected_Body_Stub
729 -- N_Subprogram_Body_Stub
732 -- are treated as if they apply to the corresponding proper body. Their
733 -- analysis is postponed until the analysis of the proper body takes place
734 -- (see Analyze_Proper_Body). The delay is required because the analysis
735 -- may generate extra code which would be harder to relocate to the body.
736 -- If the proper body is present, the aspect specifications are relocated
737 -- to the corresponding body node:
744 -- The subsequent analysis takes care of the aspect-to-pragma conversions
745 -- and verification of pragma legality. In the case where the proper body
746 -- is not available, the aspect specifications are analyzed on the spot
747 -- (see Analyze_Proper_Body) to catch potential errors.
749 -- The following table lists all aspects that can apply to a subprogram
750 -- body [stub]. For instance, the following example is legal:
752 -- package P with SPARK_Mode ...;
753 -- package body P with SPARK_Mode is ...;
755 -- The table should be synchronized with Pragma_On_Body_Or_Stub_OK in unit
756 -- Sem_Prag if the aspects below are implemented by a pragma.
758 Aspect_On_Body_Or_Stub_OK
: constant array (Aspect_Id
) of Boolean :=
759 (Aspect_Refined_Depends
=> True,
760 Aspect_Refined_Global
=> True,
761 Aspect_Refined_Post
=> True,
762 Aspect_SPARK_Mode
=> True,
763 Aspect_Warnings
=> True,
766 ---------------------------------------------------
767 -- Handling of Aspect Specifications in the Tree --
768 ---------------------------------------------------
770 -- Several kinds of declaration node permit aspect specifications in Ada
771 -- 2012 mode. If there was room in all the corresponding declaration nodes,
772 -- we could just have a field Aspect_Specifications pointing to a list of
773 -- nodes for the aspects (N_Aspect_Specification nodes). But there isn't
774 -- room, so we adopt a different approach.
776 -- The following subprograms provide access to a specialized interface
777 -- implemented internally with a hash table in the body, that provides
778 -- access to aspect specifications.
780 function Aspect_Specifications
(N
: Node_Id
) return List_Id
;
781 -- Given a node N, returns the list of N_Aspect_Specification nodes that
782 -- are attached to this declaration node. If the node is in the class of
783 -- declaration nodes that permit aspect specifications, as defined by the
784 -- predicate above, and if their Has_Aspects flag is set to True, then this
785 -- will always be a non-empty list. If this flag is set to False, then
786 -- No_List is returned. Normally, the only nodes that have Has_Aspects set
787 -- True are the nodes for which Permits_Aspect_Specifications would return
788 -- True (i.e. the declaration nodes defined in the RM as permitting the
789 -- presence of Aspect_Specifications). However, it is possible for the
790 -- flag Has_Aspects to be set on other nodes as a result of Rewrite and
791 -- Replace calls, and this function may be used to retrieve the aspect
792 -- specifications for the original rewritten node in such cases.
794 function Aspects_On_Body_Or_Stub_OK
(N
: Node_Id
) return Boolean;
795 -- N denotes a body [stub] with aspects. Determine whether all aspects of N
796 -- are allowed to appear on a body [stub].
798 procedure Exchange_Aspects
(N1
: Node_Id
; N2
: Node_Id
);
799 -- Exchange the aspect specifications of two nodes. If either node lacks an
800 -- aspect specification list, the routine has no effect. It is assumed that
801 -- both nodes can support aspects.
803 function Find_Aspect
(Id
: Entity_Id
; A
: Aspect_Id
) return Node_Id
;
804 -- Find the aspect specification of aspect A associated with entity I.
805 -- Return Empty if Id does not have the requested aspect.
807 function Find_Value_Of_Aspect
809 A
: Aspect_Id
) return Node_Id
;
810 -- Find the value of aspect A associated with entity Id. Return Empty if
811 -- Id does not have the requested aspect.
813 function Has_Aspect
(Id
: Entity_Id
; A
: Aspect_Id
) return Boolean;
814 -- Determine whether entity Id has aspect A
816 procedure Move_Aspects
(From
: Node_Id
; To
: Node_Id
);
817 -- Relocate the aspect specifications of node From to node To. On entry it
818 -- is assumed that To does not have aspect specifications. If From has no
819 -- aspects, the routine has no effect.
821 procedure Move_Or_Merge_Aspects
(From
: Node_Id
; To
: Node_Id
);
822 -- Relocate the aspect specifications of node From to node To. If To has
823 -- aspects, the aspects of From are added to the aspects of To. If From has
824 -- no aspects, the routine has no effect. When From denotes a subprogram
825 -- body stub that also acts as a spec, the only aspects relocated to node
826 -- To are those from table Aspect_On_Body_Or_Stub_OK and preconditions.
828 function Permits_Aspect_Specifications
(N
: Node_Id
) return Boolean;
829 -- Returns True if the node N is a declaration node that permits aspect
830 -- specifications in the grammar. It is possible for other nodes to have
831 -- aspect specifications as a result of Rewrite or Replace calls.
833 procedure Remove_Aspects
(N
: Node_Id
);
834 -- Delete the aspect specifications associated with node N. If the node has
835 -- no aspects, the routine has no effect.
837 function Same_Aspect
(A1
: Aspect_Id
; A2
: Aspect_Id
) return Boolean;
838 -- Returns True if A1 and A2 are (essentially) the same aspect. This is not
839 -- a simple equality test because e.g. Post and Postcondition are the same.
840 -- This is used for detecting duplicate aspects.
842 procedure Set_Aspect_Specifications
(N
: Node_Id
; L
: List_Id
);
843 -- The node N must be in the class of declaration nodes that permit aspect
844 -- specifications and the Has_Aspects flag must be False on entry. L must
845 -- be a non-empty list of N_Aspect_Specification nodes. This procedure sets
846 -- the Has_Aspects flag to True, and makes an entry that can be retrieved
847 -- by a subsequent Aspect_Specifications call. It is an error to call this
848 -- procedure with a node that does not permit aspect specifications, or a
849 -- node that has its Has_Aspects flag set True on entry, or with L being an
850 -- empty list or No_List.
853 -- Reads contents of Aspect_Specifications hash table from the tree file
855 procedure Tree_Write
;
856 -- Writes contents of Aspect_Specifications hash table to the tree file