OSDN Git Service

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