1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2010, 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 Nlists; use Nlists;
34 with Sinfo; use Sinfo;
35 with Snames; use Snames;
37 with GNAT.HTable; use GNAT.HTable;
39 package body Aspects is
41 ------------------------------------------
42 -- Hash Table for Aspect Specifications --
43 ------------------------------------------
45 type AS_Hash_Range is range 0 .. 510;
46 -- Size of hash table headers
48 function AS_Hash (F : Node_Id) return AS_Hash_Range;
49 -- Hash function for hash table
51 function AS_Hash (F : Node_Id) return AS_Hash_Range is
53 return AS_Hash_Range (F mod 511);
56 package Aspect_Specifications_Hash_Table is new
57 GNAT.HTable.Simple_HTable
58 (Header_Num => AS_Hash_Range,
60 No_Element => No_List,
65 -----------------------------------------
66 -- Table Linking Names and Aspect_Id's --
67 -----------------------------------------
69 type Aspect_Entry is record
74 Aspect_Names : constant array (Integer range <>) of Aspect_Entry := (
75 (Name_Ada_2005, Aspect_Ada_2005),
76 (Name_Ada_2012, Aspect_Ada_2012),
77 (Name_Address, Aspect_Address),
78 (Name_Alignment, Aspect_Alignment),
79 (Name_Atomic, Aspect_Atomic),
80 (Name_Atomic_Components, Aspect_Atomic_Components),
81 (Name_Bit_Order, Aspect_Bit_Order),
82 (Name_Component_Size, Aspect_Component_Size),
83 (Name_Discard_Names, Aspect_Discard_Names),
84 (Name_External_Tag, Aspect_External_Tag),
85 (Name_Favor_Top_Level, Aspect_Favor_Top_Level),
86 (Name_Inline, Aspect_Inline),
87 (Name_Inline_Always, Aspect_Inline_Always),
88 (Name_Invariant, Aspect_Invariant),
89 (Name_Machine_Radix, Aspect_Machine_Radix),
90 (Name_Object_Size, Aspect_Object_Size),
91 (Name_Pack, Aspect_Pack),
92 (Name_Persistent_BSS, Aspect_Persistent_BSS),
93 (Name_Post, Aspect_Post),
94 (Name_Pre, Aspect_Pre),
95 (Name_Predicate, Aspect_Predicate),
96 (Name_Preelaborable_Initialization, Aspect_Preelaborable_Initialization),
97 (Name_Pure_Function, Aspect_Pure_Function),
98 (Name_Shared, Aspect_Shared),
99 (Name_Size, Aspect_Size),
100 (Name_Storage_Pool, Aspect_Storage_Pool),
101 (Name_Storage_Size, Aspect_Storage_Size),
102 (Name_Stream_Size, Aspect_Stream_Size),
103 (Name_Suppress, Aspect_Suppress),
104 (Name_Suppress_Debug_Info, Aspect_Suppress_Debug_Info),
105 (Name_Unchecked_Union, Aspect_Unchecked_Union),
106 (Name_Universal_Aliasing, Aspect_Universal_Aliasing),
107 (Name_Unmodified, Aspect_Unmodified),
108 (Name_Unreferenced, Aspect_Unreferenced),
109 (Name_Unreferenced_Objects, Aspect_Unreferenced_Objects),
110 (Name_Unsuppress, Aspect_Unsuppress),
111 (Name_Value_Size, Aspect_Value_Size),
112 (Name_Volatile, Aspect_Volatile),
113 (Name_Volatile_Components, Aspect_Volatile_Components),
114 (Name_Warnings, Aspect_Warnings));
116 -------------------------------------
117 -- Hash Table for Aspect Id Values --
118 -------------------------------------
120 type AI_Hash_Range is range 0 .. 112;
121 -- Size of hash table headers
123 function AI_Hash (F : Name_Id) return AI_Hash_Range;
124 -- Hash function for hash table
126 function AI_Hash (F : Name_Id) return AI_Hash_Range is
128 return AI_Hash_Range (F mod 113);
131 package Aspect_Id_Hash_Table is new
132 GNAT.HTable.Simple_HTable
133 (Header_Num => AI_Hash_Range,
134 Element => Aspect_Id,
135 No_Element => No_Aspect,
144 function Get_Aspect_Id (Name : Name_Id) return Aspect_Id is
146 return Aspect_Id_Hash_Table.Get (Name);
149 ---------------------------
150 -- Aspect_Specifications --
151 ---------------------------
153 function Aspect_Specifications (N : Node_Id) return List_Id is
155 return Aspect_Specifications_Hash_Table.Get (N);
156 end Aspect_Specifications;
158 -----------------------------------
159 -- Permits_Aspect_Specifications --
160 -----------------------------------
162 Has_Aspect_Specifications_Flag : constant array (Node_Kind) of Boolean :=
163 (N_Abstract_Subprogram_Declaration => True,
164 N_Component_Declaration => True,
165 N_Entry_Declaration => True,
166 N_Exception_Declaration => True,
167 N_Formal_Abstract_Subprogram_Declaration => True,
168 N_Formal_Concrete_Subprogram_Declaration => True,
169 N_Formal_Object_Declaration => True,
170 N_Formal_Package_Declaration => True,
171 N_Formal_Type_Declaration => True,
172 N_Full_Type_Declaration => True,
173 N_Function_Instantiation => True,
174 N_Generic_Package_Declaration => True,
175 N_Generic_Subprogram_Declaration => True,
176 N_Object_Declaration => True,
177 N_Package_Declaration => True,
178 N_Package_Instantiation => True,
179 N_Private_Extension_Declaration => True,
180 N_Private_Type_Declaration => True,
181 N_Procedure_Instantiation => True,
182 N_Protected_Type_Declaration => True,
183 N_Single_Protected_Declaration => True,
184 N_Single_Task_Declaration => True,
185 N_Subprogram_Declaration => True,
186 N_Subtype_Declaration => True,
187 N_Task_Type_Declaration => True,
190 function Permits_Aspect_Specifications (N : Node_Id) return Boolean is
192 return Has_Aspect_Specifications_Flag (Nkind (N));
193 end Permits_Aspect_Specifications;
195 -------------------------------
196 -- Set_Aspect_Specifications --
197 -------------------------------
199 procedure Set_Aspect_Specifications (N : Node_Id; L : List_Id) is
201 pragma Assert (Permits_Aspect_Specifications (N));
202 pragma Assert (not Has_Aspect_Specifications (N));
203 pragma Assert (L /= No_List);
205 Set_Has_Aspect_Specifications (N);
207 Aspect_Specifications_Hash_Table.Set (N, L);
208 end Set_Aspect_Specifications;
210 -- Package initialization sets up Aspect Id hash table
213 for J in Aspect_Names'Range loop
214 Aspect_Id_Hash_Table.Set (Aspect_Names (J).Nam, Aspect_Names (J).Asp);