1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2010-2011, Free Software Foundation, Inc. --
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. --
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. --
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/>. --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
30 ------------------------------------------------------------------------------
32 with Atree; use Atree;
33 with Einfo; use Einfo;
34 with Nlists; use Nlists;
35 with Sinfo; use Sinfo;
36 with Tree_IO; use Tree_IO;
38 with GNAT.HTable; use GNAT.HTable;
40 package body Aspects is
42 procedure Set_Aspect_Specifications_No_Check (N : Node_Id; L : List_Id);
43 -- Same as Set_Aspect_Specifications, but does not contain the assertion
44 -- that checks that N does not already have aspect specifications. This
45 -- subprogram is supposed to be used as a part of Tree_Read. When reading
46 -- tree, first read nodes with their basic properties (as Atree.Tree_Read),
47 -- this includes reading the Has_Aspects flag for each node, then we reed
48 -- all the list tables and only after that we call Tree_Read for Aspects.
49 -- That is, when reading the tree, the list of aspects is attached to the
50 -- node that already has Has_Aspects flag set ON.
52 ------------------------------------------
53 -- Hash Table for Aspect Specifications --
54 ------------------------------------------
56 type AS_Hash_Range is range 0 .. 510;
57 -- Size of hash table headers
59 function AS_Hash (F : Node_Id) return AS_Hash_Range;
60 -- Hash function for hash table
62 function AS_Hash (F : Node_Id) return AS_Hash_Range is
64 return AS_Hash_Range (F mod 511);
67 package Aspect_Specifications_Hash_Table is new
68 GNAT.HTable.Simple_HTable
69 (Header_Num => AS_Hash_Range,
71 No_Element => No_List,
76 -------------------------------------
77 -- Hash Table for Aspect Id Values --
78 -------------------------------------
80 type AI_Hash_Range is range 0 .. 112;
81 -- Size of hash table headers
83 function AI_Hash (F : Name_Id) return AI_Hash_Range;
84 -- Hash function for hash table
86 function AI_Hash (F : Name_Id) return AI_Hash_Range is
88 return AI_Hash_Range (F mod 113);
91 package Aspect_Id_Hash_Table is new
92 GNAT.HTable.Simple_HTable
93 (Header_Num => AI_Hash_Range,
95 No_Element => No_Aspect,
100 ---------------------------
101 -- Aspect_Specifications --
102 ---------------------------
104 function Aspect_Specifications (N : Node_Id) return List_Id is
106 if Has_Aspects (N) then
107 return Aspect_Specifications_Hash_Table.Get (N);
111 end Aspect_Specifications;
117 function Get_Aspect_Id (Name : Name_Id) return Aspect_Id is
119 return Aspect_Id_Hash_Table.Get (Name);
126 function Find_Aspect (Ent : Entity_Id; A : Aspect_Id) return Node_Id is
130 Ritem := First_Rep_Item (Ent);
131 while Present (Ritem) loop
132 if Nkind (Ritem) = N_Aspect_Specification
133 and then Get_Aspect_Id (Chars (Identifier (Ritem))) = A
135 if A = Aspect_Default_Iterator then
136 return Expression (Aspect_Rep_Item (Ritem));
138 return Expression (Ritem);
142 Next_Rep_Item (Ritem);
152 procedure Move_Aspects (From : Node_Id; To : Node_Id) is
153 pragma Assert (not Has_Aspects (To));
155 if Has_Aspects (From) then
156 Set_Aspect_Specifications (To, Aspect_Specifications (From));
157 Aspect_Specifications_Hash_Table.Remove (From);
158 Set_Has_Aspects (From, False);
162 -----------------------------------
163 -- Permits_Aspect_Specifications --
164 -----------------------------------
166 Has_Aspect_Specifications_Flag : constant array (Node_Kind) of Boolean :=
167 (N_Abstract_Subprogram_Declaration => True,
168 N_Component_Declaration => True,
169 N_Entry_Declaration => True,
170 N_Exception_Declaration => True,
171 N_Formal_Abstract_Subprogram_Declaration => True,
172 N_Formal_Concrete_Subprogram_Declaration => True,
173 N_Formal_Object_Declaration => True,
174 N_Formal_Package_Declaration => True,
175 N_Formal_Type_Declaration => True,
176 N_Full_Type_Declaration => True,
177 N_Function_Instantiation => True,
178 N_Generic_Package_Declaration => True,
179 N_Generic_Subprogram_Declaration => True,
180 N_Object_Declaration => True,
181 N_Package_Declaration => True,
182 N_Package_Instantiation => True,
183 N_Package_Specification => True,
184 N_Private_Extension_Declaration => True,
185 N_Private_Type_Declaration => True,
186 N_Procedure_Instantiation => True,
187 N_Protected_Body => True,
188 N_Protected_Type_Declaration => True,
189 N_Single_Protected_Declaration => True,
190 N_Single_Task_Declaration => True,
191 N_Subprogram_Body => True,
192 N_Subprogram_Declaration => True,
193 N_Subtype_Declaration => True,
195 N_Task_Type_Declaration => True,
198 function Permits_Aspect_Specifications (N : Node_Id) return Boolean is
200 return Has_Aspect_Specifications_Flag (Nkind (N));
201 end Permits_Aspect_Specifications;
207 -- Table used for Same_Aspect, maps aspect to canonical aspect
209 Canonical_Aspect : constant array (Aspect_Id) of Aspect_Id :=
210 (No_Aspect => No_Aspect,
211 Aspect_Ada_2005 => Aspect_Ada_2005,
212 Aspect_Ada_2012 => Aspect_Ada_2005,
213 Aspect_Address => Aspect_Address,
214 Aspect_Alignment => Aspect_Alignment,
215 Aspect_Asynchronous => Aspect_Asynchronous,
216 Aspect_Atomic => Aspect_Atomic,
217 Aspect_Atomic_Components => Aspect_Atomic_Components,
218 Aspect_Attach_Handler => Aspect_Attach_Handler,
219 Aspect_Bit_Order => Aspect_Bit_Order,
220 Aspect_Component_Size => Aspect_Component_Size,
221 Aspect_Constant_Indexing => Aspect_Constant_Indexing,
222 Aspect_CPU => Aspect_CPU,
223 Aspect_Default_Component_Value => Aspect_Default_Component_Value,
224 Aspect_Default_Iterator => Aspect_Default_Iterator,
225 Aspect_Default_Value => Aspect_Default_Value,
226 Aspect_Discard_Names => Aspect_Discard_Names,
227 Aspect_Dispatching_Domain => Aspect_Dispatching_Domain,
228 Aspect_Dynamic_Predicate => Aspect_Predicate,
229 Aspect_External_Tag => Aspect_External_Tag,
230 Aspect_Favor_Top_Level => Aspect_Favor_Top_Level,
231 Aspect_Implicit_Dereference => Aspect_Implicit_Dereference,
232 Aspect_Independent => Aspect_Independent,
233 Aspect_Independent_Components => Aspect_Independent_Components,
234 Aspect_Inline => Aspect_Inline,
235 Aspect_Inline_Always => Aspect_Inline,
236 Aspect_Interrupt_Handler => Aspect_Interrupt_Handler,
237 Aspect_Interrupt_Priority => Aspect_Interrupt_Priority,
238 Aspect_Iterator_Element => Aspect_Iterator_Element,
239 Aspect_All_Calls_Remote => Aspect_All_Calls_Remote,
240 Aspect_Compiler_Unit => Aspect_Compiler_Unit,
241 Aspect_Elaborate_Body => Aspect_Elaborate_Body,
242 Aspect_Preelaborate => Aspect_Preelaborate,
243 Aspect_Preelaborate_05 => Aspect_Preelaborate_05,
244 Aspect_Pure => Aspect_Pure,
245 Aspect_Pure_05 => Aspect_Pure_05,
246 Aspect_Remote_Call_Interface => Aspect_Remote_Call_Interface,
247 Aspect_Remote_Types => Aspect_Remote_Types,
248 Aspect_Shared_Passive => Aspect_Shared_Passive,
249 Aspect_Universal_Data => Aspect_Universal_Data,
250 Aspect_Input => Aspect_Input,
251 Aspect_Invariant => Aspect_Invariant,
252 Aspect_Machine_Radix => Aspect_Machine_Radix,
253 Aspect_No_Return => Aspect_No_Return,
254 Aspect_Object_Size => Aspect_Object_Size,
255 Aspect_Output => Aspect_Output,
256 Aspect_Pack => Aspect_Pack,
257 Aspect_Persistent_BSS => Aspect_Persistent_BSS,
258 Aspect_Post => Aspect_Post,
259 Aspect_Postcondition => Aspect_Post,
260 Aspect_Pre => Aspect_Pre,
261 Aspect_Precondition => Aspect_Pre,
262 Aspect_Predicate => Aspect_Predicate,
263 Aspect_Preelaborable_Initialization => Aspect_Preelaborable_Initialization,
264 Aspect_Priority => Aspect_Priority,
265 Aspect_Pure_Function => Aspect_Pure_Function,
266 Aspect_Read => Aspect_Read,
267 Aspect_Shared => Aspect_Atomic,
268 Aspect_Size => Aspect_Size,
269 Aspect_Small => Aspect_Small,
270 Aspect_Static_Predicate => Aspect_Predicate,
271 Aspect_Storage_Pool => Aspect_Storage_Pool,
272 Aspect_Storage_Size => Aspect_Storage_Size,
273 Aspect_Stream_Size => Aspect_Stream_Size,
274 Aspect_Suppress => Aspect_Suppress,
275 Aspect_Suppress_Debug_Info => Aspect_Suppress_Debug_Info,
276 Aspect_Test_Case => Aspect_Test_Case,
277 Aspect_Type_Invariant => Aspect_Invariant,
278 Aspect_Unchecked_Union => Aspect_Unchecked_Union,
279 Aspect_Universal_Aliasing => Aspect_Universal_Aliasing,
280 Aspect_Unmodified => Aspect_Unmodified,
281 Aspect_Unreferenced => Aspect_Unreferenced,
282 Aspect_Unreferenced_Objects => Aspect_Unreferenced_Objects,
283 Aspect_Unsuppress => Aspect_Unsuppress,
284 Aspect_Variable_Indexing => Aspect_Variable_Indexing,
285 Aspect_Value_Size => Aspect_Value_Size,
286 Aspect_Volatile => Aspect_Volatile,
287 Aspect_Volatile_Components => Aspect_Volatile_Components,
288 Aspect_Warnings => Aspect_Warnings,
289 Aspect_Write => Aspect_Write);
291 function Same_Aspect (A1 : Aspect_Id; A2 : Aspect_Id) return Boolean is
293 return Canonical_Aspect (A1) = Canonical_Aspect (A2);
296 -------------------------------
297 -- Set_Aspect_Specifications --
298 -------------------------------
300 procedure Set_Aspect_Specifications (N : Node_Id; L : List_Id) is
302 pragma Assert (Permits_Aspect_Specifications (N));
303 pragma Assert (not Has_Aspects (N));
304 pragma Assert (L /= No_List);
308 Aspect_Specifications_Hash_Table.Set (N, L);
309 end Set_Aspect_Specifications;
311 ----------------------------------------
312 -- Set_Aspect_Specifications_No_Check --
313 ----------------------------------------
315 procedure Set_Aspect_Specifications_No_Check (N : Node_Id; L : List_Id) is
317 pragma Assert (Permits_Aspect_Specifications (N));
318 pragma Assert (L /= No_List);
322 Aspect_Specifications_Hash_Table.Set (N, L);
323 end Set_Aspect_Specifications_No_Check;
329 procedure Tree_Read is
334 Tree_Read_Int (Int (Node));
335 Tree_Read_Int (Int (List));
336 exit when List = No_List;
337 Set_Aspect_Specifications_No_Check (Node, List);
345 procedure Tree_Write is
346 Node : Node_Id := Empty;
349 Aspect_Specifications_Hash_Table.Get_First (Node, List);
351 Tree_Write_Int (Int (Node));
352 Tree_Write_Int (Int (List));
353 exit when List = No_List;
354 Aspect_Specifications_Hash_Table.Get_Next (Node, List);
358 -- Package initialization sets up Aspect Id hash table
361 for J in Aspect_Id loop
362 Aspect_Id_Hash_Table.Set (Aspect_Names (J), J);