2011-05-31 Gabriel Charette <gchare@google.com>
[official-gcc.git] / gcc / ada / aspects.ads
blob9f44197dd42c3402168989a54804e683b399cd73
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, 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 ------------------------------------------------------------------------------
32 -- This package defines the aspects that are recognized by GNAT in aspect
33 -- specifications. It also contains the subprograms for storing/retrieving
34 -- aspect specifications from the tree. The semantic processing for aspect
35 -- specifications is found in Sem_Ch13.Analyze_Aspect_Specifications.
37 with Namet; use Namet;
38 with Types; use Types;
40 package Aspects is
42 -- Type defining recognized aspects
44 type Aspect_Id is
45 (No_Aspect, -- Dummy entry for no aspect
46 Aspect_Ada_2005, -- GNAT
47 Aspect_Ada_2012, -- GNAT
48 Aspect_Address,
49 Aspect_Alignment,
50 Aspect_Atomic,
51 Aspect_Atomic_Components,
52 Aspect_Bit_Order,
53 Aspect_Component_Size,
54 Aspect_Discard_Names,
55 Aspect_External_Tag,
56 Aspect_Favor_Top_Level, -- GNAT
57 Aspect_Inline,
58 Aspect_Inline_Always, -- GNAT
59 Aspect_Input,
60 Aspect_Invariant,
61 Aspect_Machine_Radix,
62 Aspect_No_Return,
63 Aspect_Object_Size, -- GNAT
64 Aspect_Output,
65 Aspect_Pack,
66 Aspect_Persistent_BSS, -- GNAT
67 Aspect_Post,
68 Aspect_Pre,
69 Aspect_Predicate, -- GNAT???
70 Aspect_Preelaborable_Initialization,
71 Aspect_Pure_Function, -- GNAT
72 Aspect_Read,
73 Aspect_Shared, -- GNAT (equivalent to Atomic)
74 Aspect_Size,
75 Aspect_Storage_Pool,
76 Aspect_Storage_Size,
77 Aspect_Stream_Size,
78 Aspect_Suppress,
79 Aspect_Suppress_Debug_Info, -- GNAT
80 Aspect_Unchecked_Union,
81 Aspect_Universal_Aliasing, -- GNAT
82 Aspect_Unmodified, -- GNAT
83 Aspect_Unreferenced, -- GNAT
84 Aspect_Unreferenced_Objects, -- GNAT
85 Aspect_Unsuppress,
86 Aspect_Value_Size, -- GNAT
87 Aspect_Volatile,
88 Aspect_Volatile_Components,
89 Aspect_Warnings,
90 Aspect_Write); -- GNAT
92 -- The following array indicates aspects that accept 'Class
94 Class_Aspect_OK : constant array (Aspect_Id) of Boolean :=
95 (Aspect_Invariant => True,
96 Aspect_Pre => True,
97 Aspect_Predicate => True,
98 Aspect_Post => True,
99 others => False);
101 -- The following type is used for indicating allowed expression forms
103 type Aspect_Expression is
104 (Optional, -- Optional boolean expression
105 Expression, -- Required non-boolean expression
106 Name); -- Required name
108 -- The following array indicates what argument type is required
110 Aspect_Argument : constant array (Aspect_Id) of Aspect_Expression :=
111 (No_Aspect => Optional,
112 Aspect_Ada_2005 => Optional,
113 Aspect_Ada_2012 => Optional,
114 Aspect_Address => Expression,
115 Aspect_Alignment => Expression,
116 Aspect_Atomic => Optional,
117 Aspect_Atomic_Components => Optional,
118 Aspect_Bit_Order => Expression,
119 Aspect_Component_Size => Expression,
120 Aspect_Discard_Names => Optional,
121 Aspect_External_Tag => Expression,
122 Aspect_Favor_Top_Level => Optional,
123 Aspect_Inline => Optional,
124 Aspect_Inline_Always => Optional,
125 Aspect_Input => Name,
126 Aspect_Invariant => Expression,
127 Aspect_Machine_Radix => Expression,
128 Aspect_No_Return => Optional,
129 Aspect_Object_Size => Expression,
130 Aspect_Output => Name,
131 Aspect_Persistent_BSS => Optional,
132 Aspect_Pack => Optional,
133 Aspect_Post => Expression,
134 Aspect_Pre => Expression,
135 Aspect_Predicate => Expression,
136 Aspect_Preelaborable_Initialization => Optional,
137 Aspect_Pure_Function => Optional,
138 Aspect_Read => Name,
139 Aspect_Shared => Optional,
140 Aspect_Size => Expression,
141 Aspect_Storage_Pool => Name,
142 Aspect_Storage_Size => Expression,
143 Aspect_Stream_Size => Expression,
144 Aspect_Suppress => Name,
145 Aspect_Suppress_Debug_Info => Optional,
146 Aspect_Unchecked_Union => Optional,
147 Aspect_Universal_Aliasing => Optional,
148 Aspect_Unmodified => Optional,
149 Aspect_Unreferenced => Optional,
150 Aspect_Unreferenced_Objects => Optional,
151 Aspect_Unsuppress => Name,
152 Aspect_Value_Size => Expression,
153 Aspect_Volatile => Optional,
154 Aspect_Volatile_Components => Optional,
155 Aspect_Warnings => Name,
156 Aspect_Write => Name);
158 function Get_Aspect_Id (Name : Name_Id) return Aspect_Id;
159 pragma Inline (Get_Aspect_Id);
160 -- Given a name Nam, returns the corresponding aspect id value. If the name
161 -- does not match any aspect, then No_Aspect is returned as the result.
163 ---------------------------------------------------
164 -- Handling of Aspect Specifications in the Tree --
165 ---------------------------------------------------
167 -- Several kinds of declaration node permit aspect specifications in Ada
168 -- 2012 mode. If there was room in all the corresponding declaration nodes,
169 -- we could just have a field Aspect_Specifications pointing to a list of
170 -- nodes for the aspects (N_Aspect_Specification nodes). But there isn't
171 -- room, so we adopt a different approach.
173 -- The following subprograms provide access to a specialized interface
174 -- implemented internally with a hash table in the body, that provides
175 -- access to aspect specifications.
177 function Permits_Aspect_Specifications (N : Node_Id) return Boolean;
178 -- Returns True if the node N is a declaration node that permits aspect
179 -- specifications in the grammar. It is possible for other nodes to have
180 -- aspect specifications as a result of Rewrite or Replace calls.
182 function Aspect_Specifications (N : Node_Id) return List_Id;
183 -- Given a node N, returns the list of N_Aspect_Specification nodes that
184 -- are attached to this declaration node. If the node is in the class of
185 -- declaration nodes that permit aspect specifications, as defined by the
186 -- predicate above, and if their Has_Aspects flag is set to True, then this
187 -- will always be a non-empty list. If this flag is set to False, then
188 -- No_List is returned. Normally, the only nodes that have Has_Aspects set
189 -- True are the nodes for which Permits_Aspect_Specifications would return
190 -- True (i.e. the declaration nodes defined in the RM as permitting the
191 -- presence of Aspect_Specifications). However, it is possible for the
192 -- flag Has_Aspects to be set on other nodes as a result of Rewrite and
193 -- Replace calls, and this function may be used to retrieve the aspect
194 -- specifications for the original rewritten node in such cases.
196 procedure Set_Aspect_Specifications (N : Node_Id; L : List_Id);
197 -- The node N must be in the class of declaration nodes that permit aspect
198 -- specifications and the Has_Aspects flag must be False on entry. L must
199 -- be a non-empty list of N_Aspect_Specification nodes. This procedure sets
200 -- the Has_Aspects flag to True, and makes an entry that can be retrieved
201 -- by a subsequent Aspect_Specifications call. It is an error to call this
202 -- procedure with a node that does not permit aspect specifications, or a
203 -- node that has its Has_Aspects flag set True on entry, or with L being an
204 -- empty list or No_List.
206 procedure Move_Aspects (From : Node_Id; To : Node_Id);
207 -- Moves aspects from 'From' node to 'To' node. Has_Aspects (To) must be
208 -- False on entry. If Has_Aspects (From) is False, the call has no effect.
209 -- Otherwise the aspects are moved and on return Has_Aspects (To) is True,
210 -- and Has_Aspects (From) is False.
212 procedure Tree_Write;
213 -- Writes contents of Aspect_Specifications hash table to the tree file
215 procedure Tree_Read;
216 -- Reads contents of Aspect_Specifications hash table from the tree file
218 end Aspects;