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