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