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
;
36 with Tree_IO
; use Tree_IO
;
38 with GNAT
.HTable
; use GNAT
.HTable
;
40 package body Aspects
is
42 ------------------------------------------
43 -- Hash Table for Aspect Specifications --
44 ------------------------------------------
46 type AS_Hash_Range
is range 0 .. 510;
47 -- Size of hash table headers
49 function AS_Hash
(F
: Node_Id
) return AS_Hash_Range
;
50 -- Hash function for hash table
52 function AS_Hash
(F
: Node_Id
) return AS_Hash_Range
is
54 return AS_Hash_Range
(F
mod 511);
57 package Aspect_Specifications_Hash_Table
is new
58 GNAT
.HTable
.Simple_HTable
59 (Header_Num
=> AS_Hash_Range
,
61 No_Element
=> No_List
,
66 -----------------------------------------
67 -- Table Linking Names and Aspect_Id's --
68 -----------------------------------------
70 type Aspect_Entry
is record
75 Aspect_Names
: constant array (Integer range <>) of Aspect_Entry
:= (
76 (Name_Ada_2005
, Aspect_Ada_2005
),
77 (Name_Ada_2012
, Aspect_Ada_2012
),
78 (Name_Address
, Aspect_Address
),
79 (Name_Alignment
, Aspect_Alignment
),
80 (Name_Atomic
, Aspect_Atomic
),
81 (Name_Atomic_Components
, Aspect_Atomic_Components
),
82 (Name_Bit_Order
, Aspect_Bit_Order
),
83 (Name_Component_Size
, Aspect_Component_Size
),
84 (Name_Discard_Names
, Aspect_Discard_Names
),
85 (Name_External_Tag
, Aspect_External_Tag
),
86 (Name_Favor_Top_Level
, Aspect_Favor_Top_Level
),
87 (Name_Inline
, Aspect_Inline
),
88 (Name_Inline_Always
, Aspect_Inline_Always
),
89 (Name_Input
, Aspect_Input
),
90 (Name_Invariant
, Aspect_Invariant
),
91 (Name_Machine_Radix
, Aspect_Machine_Radix
),
92 (Name_Object_Size
, Aspect_Object_Size
),
93 (Name_Output
, Aspect_Output
),
94 (Name_Pack
, Aspect_Pack
),
95 (Name_Persistent_BSS
, Aspect_Persistent_BSS
),
96 (Name_Post
, Aspect_Post
),
97 (Name_Pre
, Aspect_Pre
),
98 (Name_Predicate
, Aspect_Predicate
),
99 (Name_Preelaborable_Initialization
, Aspect_Preelaborable_Initialization
),
100 (Name_Pure_Function
, Aspect_Pure_Function
),
101 (Name_Read
, Aspect_Read
),
102 (Name_Shared
, Aspect_Shared
),
103 (Name_Size
, Aspect_Size
),
104 (Name_Storage_Pool
, Aspect_Storage_Pool
),
105 (Name_Storage_Size
, Aspect_Storage_Size
),
106 (Name_Stream_Size
, Aspect_Stream_Size
),
107 (Name_Suppress
, Aspect_Suppress
),
108 (Name_Suppress_Debug_Info
, Aspect_Suppress_Debug_Info
),
109 (Name_Unchecked_Union
, Aspect_Unchecked_Union
),
110 (Name_Universal_Aliasing
, Aspect_Universal_Aliasing
),
111 (Name_Unmodified
, Aspect_Unmodified
),
112 (Name_Unreferenced
, Aspect_Unreferenced
),
113 (Name_Unreferenced_Objects
, Aspect_Unreferenced_Objects
),
114 (Name_Unsuppress
, Aspect_Unsuppress
),
115 (Name_Value_Size
, Aspect_Value_Size
),
116 (Name_Volatile
, Aspect_Volatile
),
117 (Name_Volatile_Components
, Aspect_Volatile_Components
),
118 (Name_Warnings
, Aspect_Warnings
),
119 (Name_Write
, Aspect_Write
));
121 -------------------------------------
122 -- Hash Table for Aspect Id Values --
123 -------------------------------------
125 type AI_Hash_Range
is range 0 .. 112;
126 -- Size of hash table headers
128 function AI_Hash
(F
: Name_Id
) return AI_Hash_Range
;
129 -- Hash function for hash table
131 function AI_Hash
(F
: Name_Id
) return AI_Hash_Range
is
133 return AI_Hash_Range
(F
mod 113);
136 package Aspect_Id_Hash_Table
is new
137 GNAT
.HTable
.Simple_HTable
138 (Header_Num
=> AI_Hash_Range
,
139 Element
=> Aspect_Id
,
140 No_Element
=> No_Aspect
,
149 function Get_Aspect_Id
(Name
: Name_Id
) return Aspect_Id
is
151 return Aspect_Id_Hash_Table
.Get
(Name
);
154 ---------------------------
155 -- Aspect_Specifications --
156 ---------------------------
158 function Aspect_Specifications
(N
: Node_Id
) return List_Id
is
160 if Has_Aspects
(N
) then
161 return Aspect_Specifications_Hash_Table
.Get
(N
);
165 end Aspect_Specifications
;
171 procedure Move_Aspects
(From
: Node_Id
; To
: Node_Id
) is
172 pragma Assert
(not Has_Aspects
(To
));
174 if Has_Aspects
(From
) then
175 Set_Aspect_Specifications
(To
, Aspect_Specifications
(From
));
176 Aspect_Specifications_Hash_Table
.Remove
(From
);
177 Set_Has_Aspects
(From
, False);
181 -----------------------------------
182 -- Permits_Aspect_Specifications --
183 -----------------------------------
185 Has_Aspect_Specifications_Flag
: constant array (Node_Kind
) of Boolean :=
186 (N_Abstract_Subprogram_Declaration
=> True,
187 N_Component_Declaration
=> True,
188 N_Entry_Declaration
=> True,
189 N_Exception_Declaration
=> True,
190 N_Formal_Abstract_Subprogram_Declaration
=> True,
191 N_Formal_Concrete_Subprogram_Declaration
=> True,
192 N_Formal_Object_Declaration
=> True,
193 N_Formal_Package_Declaration
=> True,
194 N_Formal_Type_Declaration
=> True,
195 N_Full_Type_Declaration
=> True,
196 N_Function_Instantiation
=> True,
197 N_Generic_Package_Declaration
=> True,
198 N_Generic_Subprogram_Declaration
=> True,
199 N_Object_Declaration
=> True,
200 N_Package_Declaration
=> True,
201 N_Package_Instantiation
=> True,
202 N_Private_Extension_Declaration
=> True,
203 N_Private_Type_Declaration
=> True,
204 N_Procedure_Instantiation
=> True,
205 N_Protected_Type_Declaration
=> True,
206 N_Single_Protected_Declaration
=> True,
207 N_Single_Task_Declaration
=> True,
208 N_Subprogram_Declaration
=> True,
209 N_Subtype_Declaration
=> True,
210 N_Task_Type_Declaration
=> True,
213 function Permits_Aspect_Specifications
(N
: Node_Id
) return Boolean is
215 return Has_Aspect_Specifications_Flag
(Nkind
(N
));
216 end Permits_Aspect_Specifications
;
218 -------------------------------
219 -- Set_Aspect_Specifications --
220 -------------------------------
222 procedure Set_Aspect_Specifications
(N
: Node_Id
; L
: List_Id
) is
224 pragma Assert
(Permits_Aspect_Specifications
(N
));
225 pragma Assert
(not Has_Aspects
(N
));
226 pragma Assert
(L
/= No_List
);
230 Aspect_Specifications_Hash_Table
.Set
(N
, L
);
231 end Set_Aspect_Specifications
;
237 procedure Tree_Read
is
242 Tree_Read_Int
(Int
(Node
));
243 Tree_Read_Int
(Int
(List
));
244 exit when List
= No_List
;
245 Set_Aspect_Specifications
(Node
, List
);
253 procedure Tree_Write
is
254 Node
: Node_Id
:= Empty
;
257 Aspect_Specifications_Hash_Table
.Get_First
(Node
, List
);
259 Tree_Write_Int
(Int
(Node
));
260 Tree_Write_Int
(Int
(List
));
261 exit when List
= No_List
;
262 Aspect_Specifications_Hash_Table
.Get_Next
(Node
, List
);
266 -- Package initialization sets up Aspect Id hash table
269 for J
in Aspect_Names
'Range loop
270 Aspect_Id_Hash_Table
.Set
(Aspect_Names
(J
).Nam
, Aspect_Names
(J
).Asp
);