aspects.adb, [...] (Aspect_Id): New GNAT aspect Aspect_Contract_Case.
[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-2012, 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 with Namet; use Namet;
38 with Snames; use Snames;
39 with Types; use Types;
40
41 package Aspects is
42
43 -- Type defining recognized aspects
44
45 type Aspect_Id is
46 (No_Aspect, -- Dummy entry for no aspect
47 Aspect_Address,
48 Aspect_Alignment,
49 Aspect_Attach_Handler,
50 Aspect_Bit_Order,
51 Aspect_Component_Size,
52 Aspect_Constant_Indexing,
53 Aspect_Contract_Case, -- GNAT
54 Aspect_CPU,
55 Aspect_Default_Component_Value,
56 Aspect_Default_Iterator,
57 Aspect_Default_Value,
58 Aspect_Dimension, -- GNAT
59 Aspect_Dimension_System, -- GNAT
60 Aspect_Dispatching_Domain,
61 Aspect_Dynamic_Predicate,
62 Aspect_External_Tag,
63 Aspect_Implicit_Dereference,
64 Aspect_Input,
65 Aspect_Interrupt_Priority,
66 Aspect_Invariant,
67 Aspect_Iterator_Element,
68 Aspect_Machine_Radix,
69 Aspect_Object_Size, -- GNAT
70 Aspect_Output,
71 Aspect_Post,
72 Aspect_Postcondition,
73 Aspect_Pre,
74 Aspect_Precondition,
75 Aspect_Predicate, -- GNAT
76 Aspect_Priority,
77 Aspect_Read,
78 Aspect_Scalar_Storage_Order, -- GNAT
79 Aspect_Simple_Storage_Pool, -- GNAT
80 Aspect_Size,
81 Aspect_Small,
82 Aspect_Static_Predicate,
83 Aspect_Storage_Pool,
84 Aspect_Storage_Size,
85 Aspect_Stream_Size,
86 Aspect_Suppress,
87 Aspect_Synchronization,
88 Aspect_Test_Case, -- GNAT
89 Aspect_Type_Invariant,
90 Aspect_Unsuppress,
91 Aspect_Value_Size, -- GNAT
92 Aspect_Variable_Indexing,
93 Aspect_Warnings,
94 Aspect_Write,
95
96 -- The following aspects correspond to library unit pragmas
97
98 Aspect_All_Calls_Remote,
99 Aspect_Compiler_Unit, -- GNAT
100 Aspect_Elaborate_Body,
101 Aspect_Preelaborate,
102 Aspect_Preelaborate_05, -- GNAT
103 Aspect_Pure,
104 Aspect_Pure_05, -- GNAT
105 Aspect_Pure_12, -- GNAT
106 Aspect_Remote_Call_Interface,
107 Aspect_Remote_Types,
108 Aspect_Shared_Passive,
109 Aspect_Universal_Data, -- GNAT
110
111 -- Remaining aspects have a static boolean value that turns the aspect
112 -- on or off. They all correspond to pragmas, but are only converted to
113 -- the pragmas where the value is True. A value of False normally means
114 -- that the aspect is ignored, except in the case of derived types where
115 -- the aspect value is inherited from the parent, in which case, we do
116 -- not allow False if we inherit a True value from the parent.
117
118 Aspect_Ada_2005, -- GNAT
119 Aspect_Ada_2012, -- GNAT
120 Aspect_Asynchronous,
121 Aspect_Atomic,
122 Aspect_Atomic_Components,
123 Aspect_Discard_Names,
124 Aspect_Favor_Top_Level, -- GNAT
125 Aspect_Independent,
126 Aspect_Independent_Components,
127 Aspect_Inline,
128 Aspect_Inline_Always, -- GNAT
129 Aspect_Interrupt_Handler,
130 Aspect_No_Return,
131 Aspect_Pack,
132 Aspect_Persistent_BSS, -- GNAT
133 Aspect_Preelaborable_Initialization,
134 Aspect_Pure_Function, -- GNAT
135 Aspect_Remote_Access_Type, -- GNAT
136 Aspect_Shared, -- GNAT (equivalent to Atomic)
137 Aspect_Simple_Storage_Pool_Type, -- GNAT
138 Aspect_Suppress_Debug_Info, -- GNAT
139 Aspect_Unchecked_Union,
140 Aspect_Universal_Aliasing, -- GNAT
141 Aspect_Unmodified, -- GNAT
142 Aspect_Unreferenced, -- GNAT
143 Aspect_Unreferenced_Objects, -- GNAT
144 Aspect_Volatile,
145 Aspect_Volatile_Components);
146
147 -- The following array indicates aspects that accept 'Class
148
149 Class_Aspect_OK : constant array (Aspect_Id) of Boolean :=
150 (Aspect_Invariant => True,
151 Aspect_Pre => True,
152 Aspect_Predicate => True,
153 Aspect_Post => True,
154 others => False);
155
156 -- The following array indicates aspects that a subtype inherits from
157 -- its base type. True means that the subtype inherits the aspect from
158 -- its base type. False means it is not inherited.
159
160 Base_Aspect : constant array (Aspect_Id) of Boolean :=
161 (Aspect_Atomic => True,
162 Aspect_Atomic_Components => True,
163 Aspect_Discard_Names => True,
164 Aspect_Independent_Components => True,
165 Aspect_Iterator_Element => True,
166 Aspect_Constant_Indexing => True,
167 Aspect_Default_Iterator => True,
168 Aspect_Type_Invariant => True,
169 Aspect_Unchecked_Union => True,
170 Aspect_Variable_Indexing => True,
171 Aspect_Volatile => True,
172 others => False);
173
174 -- The following array identifies all implementation defined aspects
175
176 Impl_Defined_Aspects : constant array (Aspect_Id) of Boolean :=
177 (Aspect_Ada_2005 => True,
178 Aspect_Ada_2012 => True,
179 Aspect_Compiler_Unit => True,
180 Aspect_Contract_Case => True,
181 Aspect_Dimension => True,
182 Aspect_Dimension_System => True,
183 Aspect_Favor_Top_Level => True,
184 Aspect_Inline_Always => True,
185 Aspect_Object_Size => True,
186 Aspect_Persistent_BSS => True,
187 Aspect_Predicate => True,
188 Aspect_Preelaborate_05 => True,
189 Aspect_Pure_05 => True,
190 Aspect_Pure_12 => True,
191 Aspect_Pure_Function => True,
192 Aspect_Remote_Access_Type => True,
193 Aspect_Shared => True,
194 Aspect_Scalar_Storage_Order => True,
195 Aspect_Simple_Storage_Pool => True,
196 Aspect_Simple_Storage_Pool_Type => True,
197 Aspect_Suppress_Debug_Info => True,
198 Aspect_Test_Case => True,
199 Aspect_Universal_Data => True,
200 Aspect_Universal_Aliasing => True,
201 Aspect_Unmodified => True,
202 Aspect_Unreferenced => True,
203 Aspect_Unreferenced_Objects => True,
204 Aspect_Value_Size => True,
205 others => False);
206
207 -- The following array indicates aspects for which multiple occurrences of
208 -- the same aspect attached to the same declaration are allowed.
209
210 No_Duplicates_Allowed : constant array (Aspect_Id) of Boolean :=
211 (Aspect_Contract_Case => False,
212 Aspect_Test_Case => False,
213 others => True);
214
215 -- The following array indicates type aspects that are inherited and apply
216 -- to the class-wide type as well.
217
218 Inherited_Aspect : constant array (Aspect_Id) of Boolean :=
219 (Aspect_Constant_Indexing => True,
220 Aspect_Default_Iterator => True,
221 Aspect_Implicit_Dereference => True,
222 Aspect_Iterator_Element => True,
223 Aspect_Remote_Types => True,
224 Aspect_Variable_Indexing => True,
225 others => False);
226
227 -- The following subtype defines aspects corresponding to library unit
228 -- pragmas, these can only validly appear as aspects for library units,
229 -- and result in a corresponding pragma being inserted immediately after
230 -- the occurrence of the aspect.
231
232 subtype Library_Unit_Aspects is
233 Aspect_Id range Aspect_All_Calls_Remote .. Aspect_Universal_Data;
234
235 -- The following subtype defines aspects accepting an optional static
236 -- boolean parameter indicating if the aspect should be active or
237 -- cancelling. If the parameter is missing the effective value is True,
238 -- enabling the aspect. If the parameter is present it must be a static
239 -- expression of type Standard.Boolean. If the value is True, then the
240 -- aspect is enabled. If it is False, the aspect is disabled.
241
242 subtype Boolean_Aspects is
243 Aspect_Id range Aspect_Ada_2005 .. Aspect_Id'Last;
244
245 subtype Pre_Post_Aspects is
246 Aspect_Id range Aspect_Post .. Aspect_Precondition;
247
248 -- The following type is used for indicating allowed expression forms
249
250 type Aspect_Expression is
251 (Optional, -- Optional boolean expression
252 Expression, -- Required expression
253 Name); -- Required name
254
255 -- The following array indicates what argument type is required
256
257 Aspect_Argument : constant array (Aspect_Id) of Aspect_Expression :=
258 (No_Aspect => Optional,
259 Aspect_Address => Expression,
260 Aspect_Alignment => Expression,
261 Aspect_Attach_Handler => Expression,
262 Aspect_Bit_Order => Expression,
263 Aspect_Component_Size => Expression,
264 Aspect_Constant_Indexing => Name,
265 Aspect_Contract_Case => Expression,
266 Aspect_CPU => Expression,
267 Aspect_Default_Component_Value => Expression,
268 Aspect_Default_Iterator => Name,
269 Aspect_Default_Value => Expression,
270 Aspect_Dimension => Expression,
271 Aspect_Dimension_System => Expression,
272 Aspect_Dispatching_Domain => Expression,
273 Aspect_Dynamic_Predicate => Expression,
274 Aspect_External_Tag => Expression,
275 Aspect_Implicit_Dereference => Name,
276 Aspect_Input => Name,
277 Aspect_Interrupt_Priority => Expression,
278 Aspect_Invariant => Expression,
279 Aspect_Iterator_Element => Name,
280 Aspect_Machine_Radix => Expression,
281 Aspect_Object_Size => Expression,
282 Aspect_Output => Name,
283 Aspect_Post => Expression,
284 Aspect_Postcondition => Expression,
285 Aspect_Pre => Expression,
286 Aspect_Precondition => Expression,
287 Aspect_Predicate => Expression,
288 Aspect_Priority => Expression,
289 Aspect_Read => Name,
290 Aspect_Scalar_Storage_Order => Expression,
291 Aspect_Simple_Storage_Pool => Name,
292 Aspect_Size => Expression,
293 Aspect_Small => Expression,
294 Aspect_Static_Predicate => Expression,
295 Aspect_Storage_Pool => Name,
296 Aspect_Storage_Size => Expression,
297 Aspect_Stream_Size => Expression,
298 Aspect_Suppress => Name,
299 Aspect_Synchronization => Name,
300 Aspect_Test_Case => Expression,
301 Aspect_Type_Invariant => Expression,
302 Aspect_Unsuppress => Name,
303 Aspect_Value_Size => Expression,
304 Aspect_Variable_Indexing => Name,
305 Aspect_Warnings => Name,
306 Aspect_Write => Name,
307
308 Library_Unit_Aspects => Optional,
309 Boolean_Aspects => Optional);
310
311 -----------------------------------------
312 -- Table Linking Names and Aspect_Id's --
313 -----------------------------------------
314
315 -- Table linking aspect names and id's
316
317 Aspect_Names : constant array (Aspect_Id) of Name_Id := (
318 No_Aspect => No_Name,
319 Aspect_Ada_2005 => Name_Ada_2005,
320 Aspect_Ada_2012 => Name_Ada_2012,
321 Aspect_Address => Name_Address,
322 Aspect_Alignment => Name_Alignment,
323 Aspect_All_Calls_Remote => Name_All_Calls_Remote,
324 Aspect_Asynchronous => Name_Asynchronous,
325 Aspect_Atomic => Name_Atomic,
326 Aspect_Atomic_Components => Name_Atomic_Components,
327 Aspect_Attach_Handler => Name_Attach_Handler,
328 Aspect_Bit_Order => Name_Bit_Order,
329 Aspect_Compiler_Unit => Name_Compiler_Unit,
330 Aspect_Component_Size => Name_Component_Size,
331 Aspect_Constant_Indexing => Name_Constant_Indexing,
332 Aspect_Contract_Case => Name_Contract_Case,
333 Aspect_CPU => Name_CPU,
334 Aspect_Default_Iterator => Name_Default_Iterator,
335 Aspect_Default_Value => Name_Default_Value,
336 Aspect_Default_Component_Value => Name_Default_Component_Value,
337 Aspect_Dimension => Name_Dimension,
338 Aspect_Dimension_System => Name_Dimension_System,
339 Aspect_Discard_Names => Name_Discard_Names,
340 Aspect_Dispatching_Domain => Name_Dispatching_Domain,
341 Aspect_Dynamic_Predicate => Name_Dynamic_Predicate,
342 Aspect_Elaborate_Body => Name_Elaborate_Body,
343 Aspect_External_Tag => Name_External_Tag,
344 Aspect_Favor_Top_Level => Name_Favor_Top_Level,
345 Aspect_Implicit_Dereference => Name_Implicit_Dereference,
346 Aspect_Independent => Name_Independent,
347 Aspect_Independent_Components => Name_Independent_Components,
348 Aspect_Inline => Name_Inline,
349 Aspect_Inline_Always => Name_Inline_Always,
350 Aspect_Input => Name_Input,
351 Aspect_Interrupt_Handler => Name_Interrupt_Handler,
352 Aspect_Interrupt_Priority => Name_Interrupt_Priority,
353 Aspect_Invariant => Name_Invariant,
354 Aspect_Iterator_Element => Name_Iterator_Element,
355 Aspect_Machine_Radix => Name_Machine_Radix,
356 Aspect_No_Return => Name_No_Return,
357 Aspect_Object_Size => Name_Object_Size,
358 Aspect_Output => Name_Output,
359 Aspect_Pack => Name_Pack,
360 Aspect_Persistent_BSS => Name_Persistent_BSS,
361 Aspect_Post => Name_Post,
362 Aspect_Postcondition => Name_Postcondition,
363 Aspect_Pre => Name_Pre,
364 Aspect_Precondition => Name_Precondition,
365 Aspect_Predicate => Name_Predicate,
366 Aspect_Preelaborable_Initialization => Name_Preelaborable_Initialization,
367 Aspect_Preelaborate => Name_Preelaborate,
368 Aspect_Preelaborate_05 => Name_Preelaborate_05,
369 Aspect_Priority => Name_Priority,
370 Aspect_Pure => Name_Pure,
371 Aspect_Pure_05 => Name_Pure_05,
372 Aspect_Pure_12 => Name_Pure_12,
373 Aspect_Pure_Function => Name_Pure_Function,
374 Aspect_Read => Name_Read,
375 Aspect_Remote_Access_Type => Name_Remote_Access_Type,
376 Aspect_Remote_Call_Interface => Name_Remote_Call_Interface,
377 Aspect_Remote_Types => Name_Remote_Types,
378 Aspect_Scalar_Storage_Order => Name_Scalar_Storage_Order,
379 Aspect_Shared => Name_Shared,
380 Aspect_Shared_Passive => Name_Shared_Passive,
381 Aspect_Simple_Storage_Pool => Name_Simple_Storage_Pool,
382 Aspect_Simple_Storage_Pool_Type => Name_Simple_Storage_Pool_Type,
383 Aspect_Size => Name_Size,
384 Aspect_Small => Name_Small,
385 Aspect_Static_Predicate => Name_Static_Predicate,
386 Aspect_Storage_Pool => Name_Storage_Pool,
387 Aspect_Storage_Size => Name_Storage_Size,
388 Aspect_Stream_Size => Name_Stream_Size,
389 Aspect_Suppress => Name_Suppress,
390 Aspect_Suppress_Debug_Info => Name_Suppress_Debug_Info,
391 Aspect_Synchronization => Name_Synchronization,
392 Aspect_Test_Case => Name_Test_Case,
393 Aspect_Type_Invariant => Name_Type_Invariant,
394 Aspect_Unchecked_Union => Name_Unchecked_Union,
395 Aspect_Universal_Aliasing => Name_Universal_Aliasing,
396 Aspect_Universal_Data => Name_Universal_Data,
397 Aspect_Unmodified => Name_Unmodified,
398 Aspect_Unreferenced => Name_Unreferenced,
399 Aspect_Unreferenced_Objects => Name_Unreferenced_Objects,
400 Aspect_Unsuppress => Name_Unsuppress,
401 Aspect_Value_Size => Name_Value_Size,
402 Aspect_Variable_Indexing => Name_Variable_Indexing,
403 Aspect_Volatile => Name_Volatile,
404 Aspect_Volatile_Components => Name_Volatile_Components,
405 Aspect_Warnings => Name_Warnings,
406 Aspect_Write => Name_Write);
407
408 function Get_Aspect_Id (Name : Name_Id) return Aspect_Id;
409 pragma Inline (Get_Aspect_Id);
410 -- Given a name Nam, returns the corresponding aspect id value. If the name
411 -- does not match any aspect, then No_Aspect is returned as the result.
412
413 ---------------------------------------------------
414 -- Handling of Aspect Specifications in the Tree --
415 ---------------------------------------------------
416
417 -- Several kinds of declaration node permit aspect specifications in Ada
418 -- 2012 mode. If there was room in all the corresponding declaration nodes,
419 -- we could just have a field Aspect_Specifications pointing to a list of
420 -- nodes for the aspects (N_Aspect_Specification nodes). But there isn't
421 -- room, so we adopt a different approach.
422
423 -- The following subprograms provide access to a specialized interface
424 -- implemented internally with a hash table in the body, that provides
425 -- access to aspect specifications.
426
427 function Permits_Aspect_Specifications (N : Node_Id) return Boolean;
428 -- Returns True if the node N is a declaration node that permits aspect
429 -- specifications in the grammar. It is possible for other nodes to have
430 -- aspect specifications as a result of Rewrite or Replace calls.
431
432 function Aspect_Specifications (N : Node_Id) return List_Id;
433 -- Given a node N, returns the list of N_Aspect_Specification nodes that
434 -- are attached to this declaration node. If the node is in the class of
435 -- declaration nodes that permit aspect specifications, as defined by the
436 -- predicate above, and if their Has_Aspects flag is set to True, then this
437 -- will always be a non-empty list. If this flag is set to False, then
438 -- No_List is returned. Normally, the only nodes that have Has_Aspects set
439 -- True are the nodes for which Permits_Aspect_Specifications would return
440 -- True (i.e. the declaration nodes defined in the RM as permitting the
441 -- presence of Aspect_Specifications). However, it is possible for the
442 -- flag Has_Aspects to be set on other nodes as a result of Rewrite and
443 -- Replace calls, and this function may be used to retrieve the aspect
444 -- specifications for the original rewritten node in such cases.
445
446 procedure Set_Aspect_Specifications (N : Node_Id; L : List_Id);
447 -- The node N must be in the class of declaration nodes that permit aspect
448 -- specifications and the Has_Aspects flag must be False on entry. L must
449 -- be a non-empty list of N_Aspect_Specification nodes. This procedure sets
450 -- the Has_Aspects flag to True, and makes an entry that can be retrieved
451 -- by a subsequent Aspect_Specifications call. It is an error to call this
452 -- procedure with a node that does not permit aspect specifications, or a
453 -- node that has its Has_Aspects flag set True on entry, or with L being an
454 -- empty list or No_List.
455
456 function Find_Aspect (Ent : Entity_Id; A : Aspect_Id) return Node_Id;
457 -- Find value of a given aspect from aspect list of entity
458
459 procedure Move_Aspects (From : Node_Id; To : Node_Id);
460 -- Moves aspects from 'From' node to 'To' node. Has_Aspects (To) must be
461 -- False on entry. If Has_Aspects (From) is False, the call has no effect.
462 -- Otherwise the aspects are moved and on return Has_Aspects (To) is True,
463 -- and Has_Aspects (From) is False.
464
465 function Same_Aspect (A1 : Aspect_Id; A2 : Aspect_Id) return Boolean;
466 -- Returns True if A1 and A2 are (essentially) the same aspect. This is not
467 -- a simple equality test because e.g. Post and Postcondition are the same.
468 -- This is used for detecting duplicate aspects.
469
470 procedure Tree_Write;
471 -- Writes contents of Aspect_Specifications hash table to the tree file
472
473 procedure Tree_Read;
474 -- Reads contents of Aspect_Specifications hash table from the tree file
475
476 end Aspects;