1 |
281 |
jeremybenn |
------------------------------------------------------------------------------
|
2 |
|
|
-- --
|
3 |
|
|
-- GNAT COMPILER COMPONENTS --
|
4 |
|
|
-- --
|
5 |
|
|
-- P R J . A T T R --
|
6 |
|
|
-- --
|
7 |
|
|
-- S p e c --
|
8 |
|
|
-- --
|
9 |
|
|
-- Copyright (C) 2001-2009, 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. See the GNU General Public License --
|
17 |
|
|
-- for more details. You should have received a copy of the GNU General --
|
18 |
|
|
-- Public License distributed with GNAT; see file COPYING3. If not, go to --
|
19 |
|
|
-- http://www.gnu.org/licenses for a complete copy of the license. --
|
20 |
|
|
-- --
|
21 |
|
|
-- GNAT was originally developed by the GNAT team at New York University. --
|
22 |
|
|
-- Extensive contributions were provided by Ada Core Technologies Inc. --
|
23 |
|
|
-- --
|
24 |
|
|
------------------------------------------------------------------------------
|
25 |
|
|
|
26 |
|
|
-- This package defines packages and attributes in GNAT project files.
|
27 |
|
|
-- There are predefined packages and attributes.
|
28 |
|
|
|
29 |
|
|
-- It is also possible to define new packages with their attributes
|
30 |
|
|
|
31 |
|
|
with Table;
|
32 |
|
|
|
33 |
|
|
with GNAT.Strings;
|
34 |
|
|
|
35 |
|
|
package Prj.Attr is
|
36 |
|
|
|
37 |
|
|
function Package_Name_List return GNAT.Strings.String_List;
|
38 |
|
|
-- Returns the list of valid package names, including those added by
|
39 |
|
|
-- procedures Register_New_Package below. The String_Access components of
|
40 |
|
|
-- the returned String_List should never be freed.
|
41 |
|
|
|
42 |
|
|
procedure Initialize;
|
43 |
|
|
-- Initialize the predefined project level attributes and the predefined
|
44 |
|
|
-- packages and their attribute. This procedure should be called by
|
45 |
|
|
-- Prj.Initialize.
|
46 |
|
|
|
47 |
|
|
type Attribute_Kind is
|
48 |
|
|
(Unknown,
|
49 |
|
|
-- The attribute does not exist
|
50 |
|
|
|
51 |
|
|
Single,
|
52 |
|
|
-- Single variable attribute (not an associative array)
|
53 |
|
|
|
54 |
|
|
Associative_Array,
|
55 |
|
|
-- Associative array attribute with a case sensitive index
|
56 |
|
|
|
57 |
|
|
Optional_Index_Associative_Array,
|
58 |
|
|
-- Associative array attribute with a case sensitive index and an
|
59 |
|
|
-- optional source index.
|
60 |
|
|
|
61 |
|
|
Case_Insensitive_Associative_Array,
|
62 |
|
|
-- Associative array attribute with a case insensitive index
|
63 |
|
|
|
64 |
|
|
Optional_Index_Case_Insensitive_Associative_Array);
|
65 |
|
|
-- Associative array attribute with a case insensitive index and an
|
66 |
|
|
-- optional source index.
|
67 |
|
|
-- Characteristics of an attribute. Optional_Index indicates that there
|
68 |
|
|
-- may be an optional index in the index of the associative array, as in
|
69 |
|
|
-- for Switches ("files.ada" at 2) use ...
|
70 |
|
|
|
71 |
|
|
subtype Defined_Attribute_Kind is Attribute_Kind
|
72 |
|
|
range Single .. Optional_Index_Case_Insensitive_Associative_Array;
|
73 |
|
|
-- Subset of Attribute_Kinds that may be used for the attributes that is
|
74 |
|
|
-- used when defining a new package.
|
75 |
|
|
|
76 |
|
|
Max_Attribute_Name_Length : constant := 64;
|
77 |
|
|
-- The maximum length of attribute names
|
78 |
|
|
|
79 |
|
|
subtype Attribute_Name_Length is
|
80 |
|
|
Positive range 1 .. Max_Attribute_Name_Length;
|
81 |
|
|
|
82 |
|
|
type Attribute_Data (Name_Length : Attribute_Name_Length := 1) is record
|
83 |
|
|
Name : String (1 .. Name_Length);
|
84 |
|
|
-- The name of the attribute
|
85 |
|
|
|
86 |
|
|
Attr_Kind : Defined_Attribute_Kind;
|
87 |
|
|
-- The type of the attribute
|
88 |
|
|
|
89 |
|
|
Index_Is_File_Name : Boolean;
|
90 |
|
|
-- For associative arrays, indicate if the index is a file name, so
|
91 |
|
|
-- that the attribute kind may be modified depending on the case
|
92 |
|
|
-- sensitivity of file names. This is only taken into account when
|
93 |
|
|
-- Attr_Kind is Associative_Array or Optional_Index_Associative_Array.
|
94 |
|
|
|
95 |
|
|
Opt_Index : Boolean;
|
96 |
|
|
-- True if there may be an optional index in the value of the index,
|
97 |
|
|
-- as in:
|
98 |
|
|
-- "file.ada" at 2
|
99 |
|
|
-- ("main.adb", "file.ada" at 1)
|
100 |
|
|
|
101 |
|
|
Var_Kind : Defined_Variable_Kind;
|
102 |
|
|
-- The attribute value kind: single or list
|
103 |
|
|
|
104 |
|
|
end record;
|
105 |
|
|
-- Name and characteristics of an attribute in a package registered
|
106 |
|
|
-- explicitly with Register_New_Package (see below).
|
107 |
|
|
|
108 |
|
|
type Attribute_Data_Array is array (Positive range <>) of Attribute_Data;
|
109 |
|
|
-- A list of attribute name/characteristics to be used as parameter of
|
110 |
|
|
-- procedure Register_New_Package below.
|
111 |
|
|
|
112 |
|
|
-- In the subprograms below, when it is specified that the subprogram
|
113 |
|
|
-- "fails", procedure Prj.Com.Fail is called. Unless it is specified
|
114 |
|
|
-- otherwise, if Prj.Com.Fail returns, exception Prj.Prj_Error is raised.
|
115 |
|
|
|
116 |
|
|
procedure Register_New_Package
|
117 |
|
|
(Name : String;
|
118 |
|
|
Attributes : Attribute_Data_Array);
|
119 |
|
|
-- Add a new package with its attributes. This procedure can only be
|
120 |
|
|
-- called after Initialize, but before any other call to a service of
|
121 |
|
|
-- the Project Manager. Fail if the name of the package is empty or not
|
122 |
|
|
-- unique, or if the names of the attributes are not different.
|
123 |
|
|
|
124 |
|
|
----------------
|
125 |
|
|
-- Attributes --
|
126 |
|
|
----------------
|
127 |
|
|
|
128 |
|
|
type Attribute_Node_Id is private;
|
129 |
|
|
-- The type to refers to an attribute, self-initialized
|
130 |
|
|
|
131 |
|
|
Empty_Attribute : constant Attribute_Node_Id;
|
132 |
|
|
-- Indicates no attribute. Default value of Attribute_Node_Id objects
|
133 |
|
|
|
134 |
|
|
Attribute_First : constant Attribute_Node_Id;
|
135 |
|
|
-- First attribute node id of project level attributes
|
136 |
|
|
|
137 |
|
|
function Attribute_Node_Id_Of
|
138 |
|
|
(Name : Name_Id;
|
139 |
|
|
Starting_At : Attribute_Node_Id) return Attribute_Node_Id;
|
140 |
|
|
-- Returns the node id of an attribute at the project level or in
|
141 |
|
|
-- a package. Starting_At indicates the first known attribute node where
|
142 |
|
|
-- to start the search. Returns Empty_Attribute if the attribute cannot
|
143 |
|
|
-- be found.
|
144 |
|
|
|
145 |
|
|
function Attribute_Kind_Of
|
146 |
|
|
(Attribute : Attribute_Node_Id) return Attribute_Kind;
|
147 |
|
|
-- Returns the attribute kind of a known attribute. Returns Unknown if
|
148 |
|
|
-- Attribute is Empty_Attribute.
|
149 |
|
|
|
150 |
|
|
procedure Set_Attribute_Kind_Of
|
151 |
|
|
(Attribute : Attribute_Node_Id;
|
152 |
|
|
To : Attribute_Kind);
|
153 |
|
|
-- Set the attribute kind of a known attribute. Does nothing if
|
154 |
|
|
-- Attribute is Empty_Attribute.
|
155 |
|
|
|
156 |
|
|
function Attribute_Name_Of (Attribute : Attribute_Node_Id) return Name_Id;
|
157 |
|
|
-- Returns the name of a known attribute. Returns No_Name if Attribute is
|
158 |
|
|
-- Empty_Attribute.
|
159 |
|
|
|
160 |
|
|
function Variable_Kind_Of
|
161 |
|
|
(Attribute : Attribute_Node_Id) return Variable_Kind;
|
162 |
|
|
-- Returns the variable kind of a known attribute. Returns Undefined if
|
163 |
|
|
-- Attribute is Empty_Attribute.
|
164 |
|
|
|
165 |
|
|
procedure Set_Variable_Kind_Of
|
166 |
|
|
(Attribute : Attribute_Node_Id;
|
167 |
|
|
To : Variable_Kind);
|
168 |
|
|
-- Set the variable kind of a known attribute. Does nothing if Attribute is
|
169 |
|
|
-- Empty_Attribute.
|
170 |
|
|
|
171 |
|
|
function Optional_Index_Of (Attribute : Attribute_Node_Id) return Boolean;
|
172 |
|
|
-- Returns True if Attribute is a known attribute and may have an
|
173 |
|
|
-- optional index. Returns False otherwise.
|
174 |
|
|
|
175 |
|
|
function Is_Read_Only (Attribute : Attribute_Node_Id) return Boolean;
|
176 |
|
|
|
177 |
|
|
function Next_Attribute
|
178 |
|
|
(After : Attribute_Node_Id) return Attribute_Node_Id;
|
179 |
|
|
-- Returns the attribute that follow After in the list of project level
|
180 |
|
|
-- attributes or the list of attributes in a package.
|
181 |
|
|
-- Returns Empty_Attribute if After is either Empty_Attribute or is the
|
182 |
|
|
-- last of the list.
|
183 |
|
|
|
184 |
|
|
function Others_Allowed_For (Attribute : Attribute_Node_Id) return Boolean;
|
185 |
|
|
-- True iff the index for an associative array attributes may be others
|
186 |
|
|
|
187 |
|
|
--------------
|
188 |
|
|
-- Packages --
|
189 |
|
|
--------------
|
190 |
|
|
|
191 |
|
|
type Package_Node_Id is private;
|
192 |
|
|
-- Type to refer to a package, self initialized
|
193 |
|
|
|
194 |
|
|
Empty_Package : constant Package_Node_Id;
|
195 |
|
|
-- Default value of Package_Node_Id objects
|
196 |
|
|
|
197 |
|
|
Unknown_Package : constant Package_Node_Id;
|
198 |
|
|
-- Value of an unknown package that has been found but is unknown
|
199 |
|
|
|
200 |
|
|
procedure Register_New_Package (Name : String; Id : out Package_Node_Id);
|
201 |
|
|
-- Add a new package. Fails if Name (the package name) is empty or is
|
202 |
|
|
-- already the name of a package, and set Id to Empty_Package,
|
203 |
|
|
-- if Prj.Com.Fail returns. Initially, the new package has no attributes.
|
204 |
|
|
-- Id may be used to add attributes using procedure Register_New_Attribute
|
205 |
|
|
-- below.
|
206 |
|
|
|
207 |
|
|
procedure Register_New_Attribute
|
208 |
|
|
(Name : String;
|
209 |
|
|
In_Package : Package_Node_Id;
|
210 |
|
|
Attr_Kind : Defined_Attribute_Kind;
|
211 |
|
|
Var_Kind : Defined_Variable_Kind;
|
212 |
|
|
Index_Is_File_Name : Boolean := False;
|
213 |
|
|
Opt_Index : Boolean := False);
|
214 |
|
|
-- Add a new attribute to registered package In_Package. Fails if Name
|
215 |
|
|
-- (the attribute name) is empty, if In_Package is Empty_Package or if
|
216 |
|
|
-- the attribute name has a duplicate name. See definition of type
|
217 |
|
|
-- Attribute_Data above for the meaning of parameters Attr_Kind, Var_Kind,
|
218 |
|
|
-- Index_Is_File_Name and Opt_Index.
|
219 |
|
|
|
220 |
|
|
function Package_Node_Id_Of (Name : Name_Id) return Package_Node_Id;
|
221 |
|
|
-- Returns the package node id of the package with name Name. Returns
|
222 |
|
|
-- Empty_Package if there is no package with this name.
|
223 |
|
|
|
224 |
|
|
function First_Attribute_Of
|
225 |
|
|
(Pkg : Package_Node_Id) return Attribute_Node_Id;
|
226 |
|
|
-- Returns the first attribute in the list of attributes of package Pkg.
|
227 |
|
|
-- Returns Empty_Attribute if Pkg is Empty_Package.
|
228 |
|
|
|
229 |
|
|
private
|
230 |
|
|
----------------
|
231 |
|
|
-- Attributes --
|
232 |
|
|
----------------
|
233 |
|
|
|
234 |
|
|
Attributes_Initial : constant := 50;
|
235 |
|
|
Attributes_Increment : constant := 100;
|
236 |
|
|
|
237 |
|
|
Attribute_Node_Low_Bound : constant := 0;
|
238 |
|
|
Attribute_Node_High_Bound : constant := 099_999_999;
|
239 |
|
|
|
240 |
|
|
type Attr_Node_Id is
|
241 |
|
|
range Attribute_Node_Low_Bound .. Attribute_Node_High_Bound;
|
242 |
|
|
-- Index type for table Attrs in the body
|
243 |
|
|
|
244 |
|
|
type Attribute_Node_Id is record
|
245 |
|
|
Value : Attr_Node_Id := Attribute_Node_Low_Bound;
|
246 |
|
|
end record;
|
247 |
|
|
-- Full declaration of self-initialized private type
|
248 |
|
|
|
249 |
|
|
Empty_Attr : constant Attr_Node_Id := Attribute_Node_Low_Bound;
|
250 |
|
|
|
251 |
|
|
Empty_Attribute : constant Attribute_Node_Id := (Value => Empty_Attr);
|
252 |
|
|
|
253 |
|
|
First_Attribute : constant Attr_Node_Id := Attribute_Node_Low_Bound + 1;
|
254 |
|
|
|
255 |
|
|
First_Attribute_Node_Id : constant Attribute_Node_Id :=
|
256 |
|
|
(Value => First_Attribute);
|
257 |
|
|
|
258 |
|
|
Attribute_First : constant Attribute_Node_Id := First_Attribute_Node_Id;
|
259 |
|
|
|
260 |
|
|
--------------
|
261 |
|
|
-- Packages --
|
262 |
|
|
--------------
|
263 |
|
|
|
264 |
|
|
Packages_Initial : constant := 10;
|
265 |
|
|
Packages_Increment : constant := 100;
|
266 |
|
|
|
267 |
|
|
Package_Node_Low_Bound : constant := 0;
|
268 |
|
|
Package_Node_High_Bound : constant := 099_999_999;
|
269 |
|
|
|
270 |
|
|
type Pkg_Node_Id is
|
271 |
|
|
range Package_Node_Low_Bound .. Package_Node_High_Bound;
|
272 |
|
|
-- Index type for table Package_Attributes in the body
|
273 |
|
|
|
274 |
|
|
type Package_Node_Id is record
|
275 |
|
|
Value : Pkg_Node_Id := Package_Node_Low_Bound;
|
276 |
|
|
end record;
|
277 |
|
|
-- Full declaration of self-initialized private type
|
278 |
|
|
|
279 |
|
|
Empty_Pkg : constant Pkg_Node_Id := Package_Node_Low_Bound;
|
280 |
|
|
Empty_Package : constant Package_Node_Id := (Value => Empty_Pkg);
|
281 |
|
|
Unknown_Pkg : constant Pkg_Node_Id := Package_Node_High_Bound;
|
282 |
|
|
Unknown_Package : constant Package_Node_Id := (Value => Unknown_Pkg);
|
283 |
|
|
First_Package : constant Pkg_Node_Id := Package_Node_Low_Bound + 1;
|
284 |
|
|
|
285 |
|
|
First_Package_Node_Id : constant Package_Node_Id :=
|
286 |
|
|
(Value => First_Package);
|
287 |
|
|
|
288 |
|
|
Package_First : constant Package_Node_Id := First_Package_Node_Id;
|
289 |
|
|
|
290 |
|
|
----------------
|
291 |
|
|
-- Attributes --
|
292 |
|
|
----------------
|
293 |
|
|
|
294 |
|
|
type Attribute_Record is record
|
295 |
|
|
Name : Name_Id;
|
296 |
|
|
Var_Kind : Variable_Kind;
|
297 |
|
|
Optional_Index : Boolean;
|
298 |
|
|
Attr_Kind : Attribute_Kind;
|
299 |
|
|
Read_Only : Boolean;
|
300 |
|
|
Others_Allowed : Boolean;
|
301 |
|
|
Next : Attr_Node_Id;
|
302 |
|
|
end record;
|
303 |
|
|
-- Data for an attribute
|
304 |
|
|
|
305 |
|
|
package Attrs is
|
306 |
|
|
new Table.Table (Table_Component_Type => Attribute_Record,
|
307 |
|
|
Table_Index_Type => Attr_Node_Id,
|
308 |
|
|
Table_Low_Bound => First_Attribute,
|
309 |
|
|
Table_Initial => Attributes_Initial,
|
310 |
|
|
Table_Increment => Attributes_Increment,
|
311 |
|
|
Table_Name => "Prj.Attr.Attrs");
|
312 |
|
|
-- The table of the attributes
|
313 |
|
|
|
314 |
|
|
--------------
|
315 |
|
|
-- Packages --
|
316 |
|
|
--------------
|
317 |
|
|
|
318 |
|
|
type Package_Record is record
|
319 |
|
|
Name : Name_Id;
|
320 |
|
|
Known : Boolean := True;
|
321 |
|
|
First_Attribute : Attr_Node_Id;
|
322 |
|
|
end record;
|
323 |
|
|
-- Data for a package
|
324 |
|
|
|
325 |
|
|
package Package_Attributes is
|
326 |
|
|
new Table.Table (Table_Component_Type => Package_Record,
|
327 |
|
|
Table_Index_Type => Pkg_Node_Id,
|
328 |
|
|
Table_Low_Bound => First_Package,
|
329 |
|
|
Table_Initial => Packages_Initial,
|
330 |
|
|
Table_Increment => Packages_Increment,
|
331 |
|
|
Table_Name => "Prj.Attr.Packages");
|
332 |
|
|
-- The table of the packages
|
333 |
|
|
|
334 |
|
|
end Prj.Attr;
|