[multiple changes]
[gcc.git] / gcc / ada / aspects.ads
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- A S P E C T S --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 2010-2013, Free Software Foundation, Inc. --
10 -- --
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. --
17 -- --
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. --
21 -- --
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/>. --
26 -- --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
29 -- --
30 ------------------------------------------------------------------------------
31
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.
36
37 ------------------------
38 -- Adding New Aspects --
39 ------------------------
40
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.
46
47 -- To add a new aspect, you need to do the following
48
49 -- 1. Create a name in snames.ads-tmpl
50
51 -- 2. Create a value in type Aspect_Id in this unit
52
53 -- 3. Add a value for the aspect in the global arrays defined in this unit
54
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
57 -- treatments later.
58
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.
66
67 with Namet; use Namet;
68 with Snames; use Snames;
69 with Types; use Types;
70
71 package Aspects is
72
73 -- Type defining recognized aspects
74
75 type Aspect_Id is
76 (No_Aspect, -- Dummy entry for no aspect
77 Aspect_Abstract_State, -- GNAT
78 Aspect_Address,
79 Aspect_Alignment,
80 Aspect_Attach_Handler,
81 Aspect_Bit_Order,
82 Aspect_Component_Size,
83 Aspect_Constant_Indexing,
84 Aspect_Contract_Cases, -- GNAT
85 Aspect_Convention,
86 Aspect_CPU,
87 Aspect_Default_Component_Value,
88 Aspect_Default_Iterator,
89 Aspect_Default_Value,
90 Aspect_Depends, -- GNAT
91 Aspect_Dimension, -- GNAT
92 Aspect_Dimension_System, -- GNAT
93 Aspect_Dispatching_Domain,
94 Aspect_Dynamic_Predicate,
95 Aspect_External_Name,
96 Aspect_External_Tag,
97 Aspect_Global, -- GNAT
98 Aspect_Implicit_Dereference,
99 Aspect_Input,
100 Aspect_Interrupt_Priority,
101 Aspect_Invariant, -- GNAT
102 Aspect_Iterator_Element,
103 Aspect_Link_Name,
104 Aspect_Machine_Radix,
105 Aspect_Object_Size, -- GNAT
106 Aspect_Output,
107 Aspect_Post,
108 Aspect_Postcondition,
109 Aspect_Pre,
110 Aspect_Precondition,
111 Aspect_Predicate, -- GNAT
112 Aspect_Priority,
113 Aspect_Read,
114 Aspect_Refined_Post, -- GNAT
115 Aspect_Refined_Pre, -- GNAT
116 Aspect_Relative_Deadline,
117 Aspect_Scalar_Storage_Order, -- GNAT
118 Aspect_Simple_Storage_Pool, -- GNAT
119 Aspect_Size,
120 Aspect_Small,
121 Aspect_SPARK_Mode, -- GNAT
122 Aspect_Static_Predicate,
123 Aspect_Storage_Pool,
124 Aspect_Storage_Size,
125 Aspect_Stream_Size,
126 Aspect_Suppress,
127 Aspect_Synchronization,
128 Aspect_Test_Case, -- GNAT
129 Aspect_Type_Invariant,
130 Aspect_Unsuppress,
131 Aspect_Value_Size, -- GNAT
132 Aspect_Variable_Indexing,
133 Aspect_Warnings, -- GNAT
134 Aspect_Write,
135
136 -- The following aspects correspond to library unit pragmas
137
138 Aspect_All_Calls_Remote,
139 Aspect_Compiler_Unit, -- GNAT
140 Aspect_Elaborate_Body,
141 Aspect_Preelaborate,
142 Aspect_Preelaborate_05, -- GNAT
143 Aspect_Pure,
144 Aspect_Pure_05, -- GNAT
145 Aspect_Pure_12, -- GNAT
146 Aspect_Remote_Call_Interface,
147 Aspect_Remote_Types,
148 Aspect_Shared_Passive,
149 Aspect_Universal_Data, -- GNAT
150
151 -- Remaining aspects have a static boolean value that turns the aspect
152 -- on or off. They all correspond to pragmas, but are only converted to
153 -- the pragmas where the value is True. A value of False normally means
154 -- that the aspect is ignored, except in the case of derived types where
155 -- the aspect value is inherited from the parent, in which case, we do
156 -- not allow False if we inherit a True value from the parent.
157
158 Aspect_Ada_2005, -- GNAT
159 Aspect_Ada_2012, -- GNAT
160 Aspect_Asynchronous,
161 Aspect_Atomic,
162 Aspect_Atomic_Components,
163 Aspect_Discard_Names,
164 Aspect_Export,
165 Aspect_Favor_Top_Level, -- GNAT
166 Aspect_Independent,
167 Aspect_Independent_Components,
168 Aspect_Import,
169 Aspect_Inline,
170 Aspect_Inline_Always, -- GNAT
171 Aspect_Interrupt_Handler,
172 Aspect_No_Return,
173 Aspect_Pack,
174 Aspect_Persistent_BSS, -- GNAT
175 Aspect_Preelaborable_Initialization,
176 Aspect_Pure_Function, -- GNAT
177 Aspect_Remote_Access_Type, -- GNAT
178 Aspect_Shared, -- GNAT (equivalent to Atomic)
179 Aspect_Simple_Storage_Pool_Type, -- GNAT
180 Aspect_Suppress_Debug_Info, -- GNAT
181 Aspect_Unchecked_Union,
182 Aspect_Universal_Aliasing, -- GNAT
183 Aspect_Unmodified, -- GNAT
184 Aspect_Unreferenced, -- GNAT
185 Aspect_Unreferenced_Objects, -- GNAT
186 Aspect_Volatile,
187 Aspect_Volatile_Components,
188
189 -- Aspects that have a static boolean value but don't correspond to
190 -- pragmas
191
192 Aspect_Lock_Free); -- GNAT
193
194 subtype Aspect_Id_Exclude_No_Aspect is
195 Aspect_Id range Aspect_Id'Succ (No_Aspect) .. Aspect_Id'Last;
196 -- Aspect_Id's excluding No_Aspect
197
198 -- The following array indicates aspects that accept 'Class
199
200 Class_Aspect_OK : constant array (Aspect_Id) of Boolean :=
201 (Aspect_Invariant => True,
202 Aspect_Pre => True,
203 Aspect_Predicate => True,
204 Aspect_Post => True,
205 Aspect_Type_Invariant => True,
206 others => False);
207
208 -- The following array identifies all implementation defined aspects
209
210 Implementation_Defined_Aspect : constant array (Aspect_Id) of Boolean :=
211 (Aspect_Abstract_State => True,
212 Aspect_Ada_2005 => True,
213 Aspect_Ada_2012 => True,
214 Aspect_Compiler_Unit => True,
215 Aspect_Contract_Cases => True,
216 Aspect_Depends => True,
217 Aspect_Dimension => True,
218 Aspect_Dimension_System => True,
219 Aspect_Favor_Top_Level => True,
220 Aspect_Global => True,
221 Aspect_Inline_Always => True,
222 Aspect_Invariant => True,
223 Aspect_Lock_Free => True,
224 Aspect_Object_Size => True,
225 Aspect_Persistent_BSS => True,
226 Aspect_Predicate => True,
227 Aspect_Preelaborate_05 => True,
228 Aspect_Pure_05 => True,
229 Aspect_Pure_12 => True,
230 Aspect_Pure_Function => True,
231 Aspect_Remote_Access_Type => True,
232 Aspect_Scalar_Storage_Order => True,
233 Aspect_Shared => True,
234 Aspect_Simple_Storage_Pool => True,
235 Aspect_Simple_Storage_Pool_Type => True,
236 Aspect_Suppress_Debug_Info => True,
237 Aspect_Test_Case => True,
238 Aspect_Universal_Aliasing => True,
239 Aspect_Universal_Data => True,
240 Aspect_Unmodified => True,
241 Aspect_Unreferenced => True,
242 Aspect_Unreferenced_Objects => True,
243 Aspect_Value_Size => True,
244 Aspect_Warnings => True,
245 others => False);
246
247 -- The following array indicates aspects for which multiple occurrences of
248 -- the same aspect attached to the same declaration are allowed.
249
250 No_Duplicates_Allowed : constant array (Aspect_Id) of Boolean :=
251 (Aspect_Test_Case => False,
252 others => True);
253
254 -- The following subtype defines aspects corresponding to library unit
255 -- pragmas, these can only validly appear as aspects for library units,
256 -- and result in a corresponding pragma being inserted immediately after
257 -- the occurrence of the aspect.
258
259 subtype Library_Unit_Aspects is
260 Aspect_Id range Aspect_All_Calls_Remote .. Aspect_Universal_Data;
261
262 -- The following subtype defines aspects accepting an optional static
263 -- boolean parameter indicating if the aspect should be active or
264 -- cancelling. If the parameter is missing the effective value is True,
265 -- enabling the aspect. If the parameter is present it must be a static
266 -- expression of type Standard.Boolean. If the value is True, then the
267 -- aspect is enabled. If it is False, the aspect is disabled.
268
269 subtype Boolean_Aspects is
270 Aspect_Id range Aspect_Ada_2005 .. Aspect_Id'Last;
271
272 subtype Pre_Post_Aspects is
273 Aspect_Id range Aspect_Post .. Aspect_Precondition;
274
275 -- The following type is used for indicating allowed expression forms
276
277 type Aspect_Expression is
278 (Expression, -- Required expression
279 Name, -- Required name
280 Optional_Expression, -- Optional boolean expression
281 Optional_Name); -- Optional name
282
283 -- The following array indicates what argument type is required
284
285 Aspect_Argument : constant array (Aspect_Id) of Aspect_Expression :=
286 (No_Aspect => Optional_Expression,
287 Aspect_Abstract_State => Expression,
288 Aspect_Address => Expression,
289 Aspect_Alignment => Expression,
290 Aspect_Attach_Handler => Expression,
291 Aspect_Bit_Order => Expression,
292 Aspect_Component_Size => Expression,
293 Aspect_Constant_Indexing => Name,
294 Aspect_Contract_Cases => Expression,
295 Aspect_Convention => Name,
296 Aspect_CPU => Expression,
297 Aspect_Default_Component_Value => Expression,
298 Aspect_Default_Iterator => Name,
299 Aspect_Default_Value => Expression,
300 Aspect_Depends => Expression,
301 Aspect_Dimension => Expression,
302 Aspect_Dimension_System => Expression,
303 Aspect_Dispatching_Domain => Expression,
304 Aspect_Dynamic_Predicate => Expression,
305 Aspect_External_Name => Expression,
306 Aspect_External_Tag => Expression,
307 Aspect_Global => Expression,
308 Aspect_Implicit_Dereference => Name,
309 Aspect_Input => Name,
310 Aspect_Interrupt_Priority => Expression,
311 Aspect_Invariant => Expression,
312 Aspect_Iterator_Element => Name,
313 Aspect_Link_Name => Expression,
314 Aspect_Machine_Radix => Expression,
315 Aspect_Object_Size => Expression,
316 Aspect_Output => Name,
317 Aspect_Post => Expression,
318 Aspect_Postcondition => Expression,
319 Aspect_Pre => Expression,
320 Aspect_Precondition => Expression,
321 Aspect_Predicate => Expression,
322 Aspect_Priority => Expression,
323 Aspect_Read => Name,
324 Aspect_Refined_Post => Expression,
325 Aspect_Refined_Pre => Expression,
326 Aspect_Relative_Deadline => Expression,
327 Aspect_Scalar_Storage_Order => Expression,
328 Aspect_Simple_Storage_Pool => Name,
329 Aspect_Size => Expression,
330 Aspect_Small => Expression,
331 Aspect_SPARK_Mode => Optional_Name,
332 Aspect_Static_Predicate => Expression,
333 Aspect_Storage_Pool => Name,
334 Aspect_Storage_Size => Expression,
335 Aspect_Stream_Size => Expression,
336 Aspect_Suppress => Name,
337 Aspect_Synchronization => Name,
338 Aspect_Test_Case => Expression,
339 Aspect_Type_Invariant => Expression,
340 Aspect_Unsuppress => Name,
341 Aspect_Value_Size => Expression,
342 Aspect_Variable_Indexing => Name,
343 Aspect_Warnings => Name,
344 Aspect_Write => Name,
345
346 Boolean_Aspects => Optional_Expression,
347 Library_Unit_Aspects => Optional_Expression);
348
349 -----------------------------------------
350 -- Table Linking Names and Aspect_Id's --
351 -----------------------------------------
352
353 -- Table linking aspect names and id's
354
355 Aspect_Names : constant array (Aspect_Id) of Name_Id :=
356 (No_Aspect => No_Name,
357 Aspect_Abstract_State => Name_Abstract_State,
358 Aspect_Ada_2005 => Name_Ada_2005,
359 Aspect_Ada_2012 => Name_Ada_2012,
360 Aspect_Address => Name_Address,
361 Aspect_Alignment => Name_Alignment,
362 Aspect_All_Calls_Remote => Name_All_Calls_Remote,
363 Aspect_Asynchronous => Name_Asynchronous,
364 Aspect_Atomic => Name_Atomic,
365 Aspect_Atomic_Components => Name_Atomic_Components,
366 Aspect_Attach_Handler => Name_Attach_Handler,
367 Aspect_Bit_Order => Name_Bit_Order,
368 Aspect_Compiler_Unit => Name_Compiler_Unit,
369 Aspect_Component_Size => Name_Component_Size,
370 Aspect_Constant_Indexing => Name_Constant_Indexing,
371 Aspect_Contract_Cases => Name_Contract_Cases,
372 Aspect_Convention => Name_Convention,
373 Aspect_CPU => Name_CPU,
374 Aspect_Default_Iterator => Name_Default_Iterator,
375 Aspect_Default_Value => Name_Default_Value,
376 Aspect_Default_Component_Value => Name_Default_Component_Value,
377 Aspect_Depends => Name_Depends,
378 Aspect_Dimension => Name_Dimension,
379 Aspect_Dimension_System => Name_Dimension_System,
380 Aspect_Discard_Names => Name_Discard_Names,
381 Aspect_Dispatching_Domain => Name_Dispatching_Domain,
382 Aspect_Dynamic_Predicate => Name_Dynamic_Predicate,
383 Aspect_Elaborate_Body => Name_Elaborate_Body,
384 Aspect_External_Name => Name_External_Name,
385 Aspect_External_Tag => Name_External_Tag,
386 Aspect_Export => Name_Export,
387 Aspect_Favor_Top_Level => Name_Favor_Top_Level,
388 Aspect_Global => Name_Global,
389 Aspect_Implicit_Dereference => Name_Implicit_Dereference,
390 Aspect_Import => Name_Import,
391 Aspect_Independent => Name_Independent,
392 Aspect_Independent_Components => Name_Independent_Components,
393 Aspect_Inline => Name_Inline,
394 Aspect_Inline_Always => Name_Inline_Always,
395 Aspect_Input => Name_Input,
396 Aspect_Interrupt_Handler => Name_Interrupt_Handler,
397 Aspect_Interrupt_Priority => Name_Interrupt_Priority,
398 Aspect_Invariant => Name_Invariant,
399 Aspect_Iterator_Element => Name_Iterator_Element,
400 Aspect_Link_Name => Name_Link_Name,
401 Aspect_Lock_Free => Name_Lock_Free,
402 Aspect_Machine_Radix => Name_Machine_Radix,
403 Aspect_No_Return => Name_No_Return,
404 Aspect_Object_Size => Name_Object_Size,
405 Aspect_Output => Name_Output,
406 Aspect_Pack => Name_Pack,
407 Aspect_Persistent_BSS => Name_Persistent_BSS,
408 Aspect_Post => Name_Post,
409 Aspect_Postcondition => Name_Postcondition,
410 Aspect_Pre => Name_Pre,
411 Aspect_Precondition => Name_Precondition,
412 Aspect_Predicate => Name_Predicate,
413 Aspect_Preelaborable_Initialization => Name_Preelaborable_Initialization,
414 Aspect_Preelaborate => Name_Preelaborate,
415 Aspect_Preelaborate_05 => Name_Preelaborate_05,
416 Aspect_Priority => Name_Priority,
417 Aspect_Pure => Name_Pure,
418 Aspect_Pure_05 => Name_Pure_05,
419 Aspect_Pure_12 => Name_Pure_12,
420 Aspect_Pure_Function => Name_Pure_Function,
421 Aspect_Read => Name_Read,
422 Aspect_Refined_Post => Name_Refined_Post,
423 Aspect_Refined_Pre => Name_Refined_Pre,
424 Aspect_Relative_Deadline => Name_Relative_Deadline,
425 Aspect_Remote_Access_Type => Name_Remote_Access_Type,
426 Aspect_Remote_Call_Interface => Name_Remote_Call_Interface,
427 Aspect_Remote_Types => Name_Remote_Types,
428 Aspect_Scalar_Storage_Order => Name_Scalar_Storage_Order,
429 Aspect_Shared => Name_Shared,
430 Aspect_Shared_Passive => Name_Shared_Passive,
431 Aspect_Simple_Storage_Pool => Name_Simple_Storage_Pool,
432 Aspect_Simple_Storage_Pool_Type => Name_Simple_Storage_Pool_Type,
433 Aspect_Size => Name_Size,
434 Aspect_Small => Name_Small,
435 Aspect_SPARK_Mode => Name_SPARK_Mode,
436 Aspect_Static_Predicate => Name_Static_Predicate,
437 Aspect_Storage_Pool => Name_Storage_Pool,
438 Aspect_Storage_Size => Name_Storage_Size,
439 Aspect_Stream_Size => Name_Stream_Size,
440 Aspect_Suppress => Name_Suppress,
441 Aspect_Suppress_Debug_Info => Name_Suppress_Debug_Info,
442 Aspect_Synchronization => Name_Synchronization,
443 Aspect_Test_Case => Name_Test_Case,
444 Aspect_Type_Invariant => Name_Type_Invariant,
445 Aspect_Unchecked_Union => Name_Unchecked_Union,
446 Aspect_Universal_Aliasing => Name_Universal_Aliasing,
447 Aspect_Universal_Data => Name_Universal_Data,
448 Aspect_Unmodified => Name_Unmodified,
449 Aspect_Unreferenced => Name_Unreferenced,
450 Aspect_Unreferenced_Objects => Name_Unreferenced_Objects,
451 Aspect_Unsuppress => Name_Unsuppress,
452 Aspect_Value_Size => Name_Value_Size,
453 Aspect_Variable_Indexing => Name_Variable_Indexing,
454 Aspect_Volatile => Name_Volatile,
455 Aspect_Volatile_Components => Name_Volatile_Components,
456 Aspect_Warnings => Name_Warnings,
457 Aspect_Write => Name_Write);
458
459 function Get_Aspect_Id (Name : Name_Id) return Aspect_Id;
460 pragma Inline (Get_Aspect_Id);
461 -- Given a name Nam, returns the corresponding aspect id value. If the name
462 -- does not match any aspect, then No_Aspect is returned as the result.
463
464 function Get_Aspect_Id (Aspect : Node_Id) return Aspect_Id;
465 pragma Inline (Get_Aspect_Id);
466 -- Given an aspect specification, return the corresponding aspect_id value.
467 -- If the name does not match any aspect, return No_Aspect.
468
469 ------------------------------------
470 -- Delaying Evaluation of Aspects --
471 ------------------------------------
472
473 -- The RM requires that all language defined aspects taking an expression
474 -- delay evaluation of the expression till the freeze point of the entity
475 -- to which the aspect applies. This allows forward references, and is of
476 -- use for example in connection with preconditions and postconditions
477 -- where the requirement of making all references in contracts to local
478 -- functions be backwards references would be onerous.
479
480 -- For consistency, even attributes like Size are delayed, so we can do:
481
482 -- type A is range 1 .. 10
483 -- with Size => Not_Defined_Yet;
484 -- ..
485 -- Not_Defined_Yet : constant := 64;
486
487 -- Resulting in A having a size of 64, which gets set when A is frozen.
488 -- Furthermore, we can have a situation like
489
490 -- type A is range 1 .. 10
491 -- with Size => Not_Defined_Yet;
492 -- ..
493 -- type B is new A;
494 -- ..
495 -- Not_Defined_Yet : constant := 64;
496
497 -- where the Size of A is considered to have been previously specified at
498 -- the point of derivation, even though the actual value of the size is
499 -- not known yet, and in this example B inherits the size value of 64.
500
501 -- Our normal implementation model (prior to Ada 2012) was simply to copy
502 -- inheritable attributes at the point of derivation. Then any subsequent
503 -- representation items apply either to the parent type, not affecting the
504 -- derived type, or to the derived type, not affecting the parent type.
505
506 -- To deal with the delayed aspect case, we use two flags. The first is
507 -- set on the parent type if it has delayed representation aspects. This
508 -- flag Has_Delayed_Rep_Aspects indicates that if we derive from this type
509 -- we have to worry about making sure we inherit any delayed aspects. The
510 -- second flag is set on a derived type: May_Have_Inherited_Rep_Aspects
511 -- is set if the parent type has Has_Delayed_Rep_Aspects set.
512
513 -- When we freeze a derived type, if the May_Have_Inherited_Rep_Aspects
514 -- flag is set, then we call Freeze.Inherit_Delayed_Rep_Aspects when
515 -- the derived type is frozen, which deals with the necessary copying of
516 -- information from the parent type, which must be frozen at that point
517 -- (since freezing the derived type first freezes the parent type).
518
519 -- The following shows which aspects are delayed. There are three cases:
520
521 type Delay_Type is
522 (Always_Delay,
523 -- This aspect is not a representation aspect that can be inherited and
524 -- is always delayed, as required by the language definition.
525
526 Never_Delay,
527 -- There are two cases. There are language defined aspects like
528 -- Convention where the "expression" is simply an uninterpreted
529 -- identifier, and there is no issue of evaluating it and thus no
530 -- issue of delaying the evaluation. The second case is implementation
531 -- defined aspects where we have decided that we don't want to allow
532 -- delays (and for our own aspects we can do what we like!).
533
534 Rep_Aspect);
535 -- These are the cases of representation aspects that are in general
536 -- delayed, and where there is a potential issue of derived types that
537 -- inherit delayed representation values.
538
539 -- Note: even if this table indicates that an aspect is delayed, we never
540 -- delay Boolean aspects that have a missing expression (taken as True),
541 -- or expressions for delayed rep items that consist of an integer literal
542 -- (most cases of Size etc. in practice), since in these cases we know we
543 -- can get the value of the expression without delay. Note that we still
544 -- need to delay Boolean aspects that are specifically set to True:
545
546 -- type R is array (0 .. 31) of Boolean
547 -- with Pack => True;
548 -- True : constant Boolean := False;
549
550 -- This is nonsense, but we need to make it work and result in R not
551 -- being packed, and if we have something like:
552
553 -- type R is array (0 .. 31) of Boolean
554 -- with Pack => True;
555 -- RR : R;
556 -- True : constant Boolean := False;
557
558 -- This is illegal because the visibility of True changes after the freeze
559 -- point, which is not allowed, and we need the delay mechanism to properly
560 -- diagnose this error.
561
562 Aspect_Delay : constant array (Aspect_Id) of Delay_Type :=
563 (No_Aspect => Always_Delay,
564 Aspect_Address => Always_Delay,
565 Aspect_All_Calls_Remote => Always_Delay,
566 Aspect_Asynchronous => Always_Delay,
567 Aspect_Attach_Handler => Always_Delay,
568 Aspect_Compiler_Unit => Always_Delay,
569 Aspect_Constant_Indexing => Always_Delay,
570 Aspect_Contract_Cases => Always_Delay,
571 Aspect_CPU => Always_Delay,
572 Aspect_Default_Iterator => Always_Delay,
573 Aspect_Default_Value => Always_Delay,
574 Aspect_Default_Component_Value => Always_Delay,
575 Aspect_Depends => Always_Delay,
576 Aspect_Discard_Names => Always_Delay,
577 Aspect_Dispatching_Domain => Always_Delay,
578 Aspect_Dynamic_Predicate => Always_Delay,
579 Aspect_Elaborate_Body => Always_Delay,
580 Aspect_External_Name => Always_Delay,
581 Aspect_External_Tag => Always_Delay,
582 Aspect_Export => Always_Delay,
583 Aspect_Favor_Top_Level => Always_Delay,
584 Aspect_Global => Always_Delay,
585 Aspect_Implicit_Dereference => Always_Delay,
586 Aspect_Import => Always_Delay,
587 Aspect_Independent => Always_Delay,
588 Aspect_Independent_Components => Always_Delay,
589 Aspect_Inline => Always_Delay,
590 Aspect_Inline_Always => Always_Delay,
591 Aspect_Input => Always_Delay,
592 Aspect_Interrupt_Handler => Always_Delay,
593 Aspect_Interrupt_Priority => Always_Delay,
594 Aspect_Invariant => Always_Delay,
595 Aspect_Iterator_Element => Always_Delay,
596 Aspect_Link_Name => Always_Delay,
597 Aspect_Lock_Free => Always_Delay,
598 Aspect_No_Return => Always_Delay,
599 Aspect_Output => Always_Delay,
600 Aspect_Persistent_BSS => Always_Delay,
601 Aspect_Post => Always_Delay,
602 Aspect_Postcondition => Always_Delay,
603 Aspect_Pre => Always_Delay,
604 Aspect_Precondition => Always_Delay,
605 Aspect_Predicate => Always_Delay,
606 Aspect_Preelaborable_Initialization => Always_Delay,
607 Aspect_Preelaborate => Always_Delay,
608 Aspect_Preelaborate_05 => Always_Delay,
609 Aspect_Priority => Always_Delay,
610 Aspect_Pure => Always_Delay,
611 Aspect_Pure_05 => Always_Delay,
612 Aspect_Pure_12 => Always_Delay,
613 Aspect_Pure_Function => Always_Delay,
614 Aspect_Read => Always_Delay,
615 Aspect_Relative_Deadline => Always_Delay,
616 Aspect_Remote_Access_Type => Always_Delay,
617 Aspect_Remote_Call_Interface => Always_Delay,
618 Aspect_Remote_Types => Always_Delay,
619 Aspect_Shared => Always_Delay,
620 Aspect_Shared_Passive => Always_Delay,
621 Aspect_Simple_Storage_Pool => Always_Delay,
622 Aspect_Simple_Storage_Pool_Type => Always_Delay,
623 Aspect_Static_Predicate => Always_Delay,
624 Aspect_Storage_Pool => Always_Delay,
625 Aspect_Stream_Size => Always_Delay,
626 Aspect_Suppress => Always_Delay,
627 Aspect_Suppress_Debug_Info => Always_Delay,
628 Aspect_Type_Invariant => Always_Delay,
629 Aspect_Unchecked_Union => Always_Delay,
630 Aspect_Universal_Aliasing => Always_Delay,
631 Aspect_Universal_Data => Always_Delay,
632 Aspect_Unmodified => Always_Delay,
633 Aspect_Unreferenced => Always_Delay,
634 Aspect_Unreferenced_Objects => Always_Delay,
635 Aspect_Unsuppress => Always_Delay,
636 Aspect_Variable_Indexing => Always_Delay,
637 Aspect_Write => Always_Delay,
638
639 Aspect_Abstract_State => Never_Delay,
640 Aspect_Ada_2005 => Never_Delay,
641 Aspect_Ada_2012 => Never_Delay,
642 Aspect_Convention => Never_Delay,
643 Aspect_Dimension => Never_Delay,
644 Aspect_Dimension_System => Never_Delay,
645 Aspect_Refined_Post => Never_Delay,
646 Aspect_Refined_Pre => Never_Delay,
647 Aspect_SPARK_Mode => Never_Delay,
648 Aspect_Synchronization => Never_Delay,
649 Aspect_Test_Case => Never_Delay,
650 Aspect_Warnings => Never_Delay,
651
652 Aspect_Alignment => Rep_Aspect,
653 Aspect_Atomic => Rep_Aspect,
654 Aspect_Atomic_Components => Rep_Aspect,
655 Aspect_Bit_Order => Rep_Aspect,
656 Aspect_Component_Size => Rep_Aspect,
657 Aspect_Machine_Radix => Rep_Aspect,
658 Aspect_Object_Size => Rep_Aspect,
659 Aspect_Pack => Rep_Aspect,
660 Aspect_Scalar_Storage_Order => Rep_Aspect,
661 Aspect_Size => Rep_Aspect,
662 Aspect_Small => Rep_Aspect,
663 Aspect_Storage_Size => Rep_Aspect,
664 Aspect_Value_Size => Rep_Aspect,
665 Aspect_Volatile => Rep_Aspect,
666 Aspect_Volatile_Components => Rep_Aspect);
667
668 ------------------------------------------------
669 -- Handling of Aspect Specifications on Stubs --
670 ------------------------------------------------
671
672 -- Aspects that appear on the following stub nodes
673
674 -- N_Package_Body_Stub
675 -- N_Protected_Body_Stub
676 -- N_Subprogram_Body_Stub
677 -- N_Task_Body_Stub
678
679 -- are treated as if they apply to the corresponding proper body. Their
680 -- analysis is postponed until the analysis of the proper body takes place
681 -- (see Analyze_Proper_Body). The delay is required because the analysis
682 -- may generate extra code which would be harder to relocate to the body.
683 -- If the proper body is present, the aspect specifications are relocated
684 -- to the corresponding body node:
685
686 -- N_Package_Body
687 -- N_Protected_Body
688 -- N_Subprogram_Body
689 -- N_Task_Body
690
691 -- The subsequent analysis takes care of the aspect-to-pragma conversions
692 -- and verification of pragma legality. In the case where the proper body
693 -- is not available, the aspect specifications are analyzed on the spot
694 -- (see Analyze_Proper_Body) to catch potential errors.
695
696 -- The following table lists all aspects that can apply to a subprogram
697 -- body [stub]. For instance, the following example is legal:
698
699 -- package P with SPARK_Mode ...;
700 -- package body P with SPARK_Mode is ...;
701
702 -- The table should be synchronized with Pragma_On_Body_Or_Stub_OK in unit
703 -- Sem_Prag if the aspects below are implemented by a pragma.
704
705 Aspect_On_Body_Or_Stub_OK : constant array (Aspect_Id) of Boolean :=
706 (Aspect_Refined_Post => True,
707 Aspect_Refined_Pre => True,
708 Aspect_SPARK_Mode => True,
709 Aspect_Warnings => True,
710 others => False);
711
712 ---------------------------------------------------
713 -- Handling of Aspect Specifications in the Tree --
714 ---------------------------------------------------
715
716 -- Several kinds of declaration node permit aspect specifications in Ada
717 -- 2012 mode. If there was room in all the corresponding declaration nodes,
718 -- we could just have a field Aspect_Specifications pointing to a list of
719 -- nodes for the aspects (N_Aspect_Specification nodes). But there isn't
720 -- room, so we adopt a different approach.
721
722 -- The following subprograms provide access to a specialized interface
723 -- implemented internally with a hash table in the body, that provides
724 -- access to aspect specifications.
725
726 function Aspect_Specifications (N : Node_Id) return List_Id;
727 -- Given a node N, returns the list of N_Aspect_Specification nodes that
728 -- are attached to this declaration node. If the node is in the class of
729 -- declaration nodes that permit aspect specifications, as defined by the
730 -- predicate above, and if their Has_Aspects flag is set to True, then this
731 -- will always be a non-empty list. If this flag is set to False, then
732 -- No_List is returned. Normally, the only nodes that have Has_Aspects set
733 -- True are the nodes for which Permits_Aspect_Specifications would return
734 -- True (i.e. the declaration nodes defined in the RM as permitting the
735 -- presence of Aspect_Specifications). However, it is possible for the
736 -- flag Has_Aspects to be set on other nodes as a result of Rewrite and
737 -- Replace calls, and this function may be used to retrieve the aspect
738 -- specifications for the original rewritten node in such cases.
739
740 function Aspects_On_Body_Or_Stub_OK (N : Node_Id) return Boolean;
741 -- N denotes a body [stub] with aspects. Determine whether all aspects of N
742 -- are allowed to appear on a body [stub].
743
744 function Find_Aspect (Id : Entity_Id; A : Aspect_Id) return Node_Id;
745 -- Find the aspect specification of aspect A associated with entity I.
746 -- Return Empty if Id does not have the requested aspect.
747
748 function Find_Value_Of_Aspect
749 (Id : Entity_Id;
750 A : Aspect_Id) return Node_Id;
751 -- Find the value of aspect A associated with entity Id. Return Empty if
752 -- Id does not have the requested aspect.
753
754 function Has_Aspect (Id : Entity_Id; A : Aspect_Id) return Boolean;
755 -- Determine whether entity Id has aspect A
756
757 procedure Move_Aspects (From : Node_Id; To : Node_Id);
758 -- Relocate the aspect specifications of node From to node To. On entry it
759 -- is assumed that To does not have aspect specifications. If From has no
760 -- aspects, the routine has no effect.
761
762 procedure Move_Or_Merge_Aspects (From : Node_Id; To : Node_Id);
763 -- Relocate the aspect specifications of node From to node To. If To has
764 -- aspects, the aspects of From are added to the aspects of To. If From has
765 -- no aspects, the routine has no effect.
766
767 function Permits_Aspect_Specifications (N : Node_Id) return Boolean;
768 -- Returns True if the node N is a declaration node that permits aspect
769 -- specifications in the grammar. It is possible for other nodes to have
770 -- aspect specifications as a result of Rewrite or Replace calls.
771
772 procedure Remove_Aspects (N : Node_Id);
773 -- Delete the aspect specifications associated with node N. If the node has
774 -- no aspects, the routine has no effect.
775
776 function Same_Aspect (A1 : Aspect_Id; A2 : Aspect_Id) return Boolean;
777 -- Returns True if A1 and A2 are (essentially) the same aspect. This is not
778 -- a simple equality test because e.g. Post and Postcondition are the same.
779 -- This is used for detecting duplicate aspects.
780
781 procedure Set_Aspect_Specifications (N : Node_Id; L : List_Id);
782 -- The node N must be in the class of declaration nodes that permit aspect
783 -- specifications and the Has_Aspects flag must be False on entry. L must
784 -- be a non-empty list of N_Aspect_Specification nodes. This procedure sets
785 -- the Has_Aspects flag to True, and makes an entry that can be retrieved
786 -- by a subsequent Aspect_Specifications call. It is an error to call this
787 -- procedure with a node that does not permit aspect specifications, or a
788 -- node that has its Has_Aspects flag set True on entry, or with L being an
789 -- empty list or No_List.
790
791 procedure Tree_Read;
792 -- Reads contents of Aspect_Specifications hash table from the tree file
793
794 procedure Tree_Write;
795 -- Writes contents of Aspect_Specifications hash table to the tree file
796
797 end Aspects;