* gcc-interface/decl.c (gnat_to_gnu_entity) <E_Array_Type>: Do not make
[official-gcc.git] / gcc / ada / prj-attr.ads
bloba16e6f3d181f5d8beb6da59d8b59519c3874d857
1 ------------------------------------------------------------------------------
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-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. 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 ------------------------------------------------------------------------------
26 -- This package defines packages and attributes in GNAT project files.
27 -- There are predefined packages and attributes.
29 -- It is also possible to define new packages with their attributes
31 with Table;
33 with GNAT.Strings;
35 package Prj.Attr is
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.
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.
47 type Attribute_Kind is (
48 Unknown,
49 -- The attribute does not exist
51 Single,
52 -- Single variable attribute (not an associative array)
54 Associative_Array,
55 -- Associative array attribute with a case sensitive index
57 Optional_Index_Associative_Array,
58 -- Associative array attribute with a case sensitive index and an
59 -- optional source index.
61 Case_Insensitive_Associative_Array,
62 -- Associative array attribute with a case insensitive index
64 Optional_Index_Case_Insensitive_Associative_Array
65 -- Associative array attribute with a case insensitive index and an
66 -- optional source index.
68 -- Characteristics of an attribute. Optional_Index indicates that there
69 -- may be an optional index in the index of the associative array, as in
70 -- for Switches ("files.ada" at 2) use ...
72 subtype Defined_Attribute_Kind is Attribute_Kind
73 range Single .. Optional_Index_Case_Insensitive_Associative_Array;
74 -- Subset of Attribute_Kinds that may be used for the attributes that is
75 -- used when defining a new package.
77 subtype All_Case_Insensitive_Associative_Array is Attribute_Kind range
78 Case_Insensitive_Associative_Array ..
79 Optional_Index_Case_Insensitive_Associative_Array;
80 -- Subtype including both cases of Case_Insensitive_Associative_Array
82 Max_Attribute_Name_Length : constant := 64;
83 -- The maximum length of attribute names
85 subtype Attribute_Name_Length is
86 Positive range 1 .. Max_Attribute_Name_Length;
88 type Attribute_Data (Name_Length : Attribute_Name_Length := 1) is record
89 Name : String (1 .. Name_Length);
90 -- The name of the attribute
92 Attr_Kind : Defined_Attribute_Kind;
93 -- The type of the attribute
95 Index_Is_File_Name : Boolean;
96 -- For associative arrays, indicate if the index is a file name, so
97 -- that the attribute kind may be modified depending on the case
98 -- sensitivity of file names. This is only taken into account when
99 -- Attr_Kind is Associative_Array or Optional_Index_Associative_Array.
101 Opt_Index : Boolean;
102 -- True if there may be an optional index in the value of the index,
103 -- as in:
104 -- "file.ada" at 2
105 -- ("main.adb", "file.ada" at 1)
107 Var_Kind : Defined_Variable_Kind;
108 -- The attribute value kind: single or list
110 end record;
111 -- Name and characteristics of an attribute in a package registered
112 -- explicitly with Register_New_Package (see below).
114 type Attribute_Data_Array is array (Positive range <>) of Attribute_Data;
115 -- A list of attribute name/characteristics to be used as parameter of
116 -- procedure Register_New_Package below.
118 -- In the subprograms below, when it is specified that the subprogram
119 -- "fails", procedure Prj.Com.Fail is called. Unless it is specified
120 -- otherwise, if Prj.Com.Fail returns, exception Prj.Prj_Error is raised.
122 procedure Register_New_Package
123 (Name : String;
124 Attributes : Attribute_Data_Array);
125 -- Add a new package with its attributes. This procedure can only be
126 -- called after Initialize, but before any other call to a service of
127 -- the Project Manager. Fail if the name of the package is empty or not
128 -- unique, or if the names of the attributes are not different.
130 ----------------
131 -- Attributes --
132 ----------------
134 type Attribute_Node_Id is private;
135 -- The type to refers to an attribute, self-initialized
137 Empty_Attribute : constant Attribute_Node_Id;
138 -- Indicates no attribute. Default value of Attribute_Node_Id objects
140 Attribute_First : constant Attribute_Node_Id;
141 -- First attribute node id of project level attributes
143 function Attribute_Node_Id_Of
144 (Name : Name_Id;
145 Starting_At : Attribute_Node_Id) return Attribute_Node_Id;
146 -- Returns the node id of an attribute at the project level or in
147 -- a package. Starting_At indicates the first known attribute node where
148 -- to start the search. Returns Empty_Attribute if the attribute cannot
149 -- be found.
151 function Attribute_Kind_Of
152 (Attribute : Attribute_Node_Id) return Attribute_Kind;
153 -- Returns the attribute kind of a known attribute. Returns Unknown if
154 -- Attribute is Empty_Attribute.
156 procedure Set_Attribute_Kind_Of
157 (Attribute : Attribute_Node_Id;
158 To : Attribute_Kind);
159 -- Set the attribute kind of a known attribute. Does nothing if
160 -- Attribute is Empty_Attribute.
162 function Attribute_Name_Of (Attribute : Attribute_Node_Id) return Name_Id;
163 -- Returns the name of a known attribute. Returns No_Name if Attribute is
164 -- Empty_Attribute.
166 function Variable_Kind_Of
167 (Attribute : Attribute_Node_Id) return Variable_Kind;
168 -- Returns the variable kind of a known attribute. Returns Undefined if
169 -- Attribute is Empty_Attribute.
171 procedure Set_Variable_Kind_Of
172 (Attribute : Attribute_Node_Id;
173 To : Variable_Kind);
174 -- Set the variable kind of a known attribute. Does nothing if Attribute is
175 -- Empty_Attribute.
177 function Optional_Index_Of (Attribute : Attribute_Node_Id) return Boolean;
178 -- Returns True if Attribute is a known attribute and may have an
179 -- optional index. Returns False otherwise.
181 function Is_Read_Only (Attribute : Attribute_Node_Id) return Boolean;
183 function Next_Attribute
184 (After : Attribute_Node_Id) return Attribute_Node_Id;
185 -- Returns the attribute that follow After in the list of project level
186 -- attributes or the list of attributes in a package.
187 -- Returns Empty_Attribute if After is either Empty_Attribute or is the
188 -- last of the list.
190 function Others_Allowed_For (Attribute : Attribute_Node_Id) return Boolean;
191 -- True iff the index for an associative array attributes may be others
193 --------------
194 -- Packages --
195 --------------
197 type Package_Node_Id is private;
198 -- Type to refer to a package, self initialized
200 Empty_Package : constant Package_Node_Id;
201 -- Default value of Package_Node_Id objects
203 Unknown_Package : constant Package_Node_Id;
204 -- Value of an unknown package that has been found but is unknown
206 procedure Register_New_Package (Name : String; Id : out Package_Node_Id);
207 -- Add a new package. Fails if Name (the package name) is empty or is
208 -- already the name of a package, and set Id to Empty_Package,
209 -- if Prj.Com.Fail returns. Initially, the new package has no attributes.
210 -- Id may be used to add attributes using procedure Register_New_Attribute
211 -- below.
213 procedure Register_New_Attribute
214 (Name : String;
215 In_Package : Package_Node_Id;
216 Attr_Kind : Defined_Attribute_Kind;
217 Var_Kind : Defined_Variable_Kind;
218 Index_Is_File_Name : Boolean := False;
219 Opt_Index : Boolean := False);
220 -- Add a new attribute to registered package In_Package. Fails if Name
221 -- (the attribute name) is empty, if In_Package is Empty_Package or if
222 -- the attribute name has a duplicate name. See definition of type
223 -- Attribute_Data above for the meaning of parameters Attr_Kind, Var_Kind,
224 -- Index_Is_File_Name and Opt_Index.
226 function Package_Node_Id_Of (Name : Name_Id) return Package_Node_Id;
227 -- Returns the package node id of the package with name Name. Returns
228 -- Empty_Package if there is no package with this name.
230 function First_Attribute_Of
231 (Pkg : Package_Node_Id) return Attribute_Node_Id;
232 -- Returns the first attribute in the list of attributes of package Pkg.
233 -- Returns Empty_Attribute if Pkg is Empty_Package.
235 private
236 ----------------
237 -- Attributes --
238 ----------------
240 Attributes_Initial : constant := 50;
241 Attributes_Increment : constant := 100;
243 Attribute_Node_Low_Bound : constant := 0;
244 Attribute_Node_High_Bound : constant := 099_999_999;
246 type Attr_Node_Id is
247 range Attribute_Node_Low_Bound .. Attribute_Node_High_Bound;
248 -- Index type for table Attrs in the body
250 type Attribute_Node_Id is record
251 Value : Attr_Node_Id := Attribute_Node_Low_Bound;
252 end record;
253 -- Full declaration of self-initialized private type
255 Empty_Attr : constant Attr_Node_Id := Attribute_Node_Low_Bound;
257 Empty_Attribute : constant Attribute_Node_Id := (Value => Empty_Attr);
259 First_Attribute : constant Attr_Node_Id := Attribute_Node_Low_Bound + 1;
261 First_Attribute_Node_Id : constant Attribute_Node_Id :=
262 (Value => First_Attribute);
264 Attribute_First : constant Attribute_Node_Id := First_Attribute_Node_Id;
266 --------------
267 -- Packages --
268 --------------
270 Packages_Initial : constant := 10;
271 Packages_Increment : constant := 100;
273 Package_Node_Low_Bound : constant := 0;
274 Package_Node_High_Bound : constant := 099_999_999;
276 type Pkg_Node_Id is
277 range Package_Node_Low_Bound .. Package_Node_High_Bound;
278 -- Index type for table Package_Attributes in the body
280 type Package_Node_Id is record
281 Value : Pkg_Node_Id := Package_Node_Low_Bound;
282 end record;
283 -- Full declaration of self-initialized private type
285 Empty_Pkg : constant Pkg_Node_Id := Package_Node_Low_Bound;
286 Empty_Package : constant Package_Node_Id := (Value => Empty_Pkg);
287 Unknown_Pkg : constant Pkg_Node_Id := Package_Node_High_Bound;
288 Unknown_Package : constant Package_Node_Id := (Value => Unknown_Pkg);
289 First_Package : constant Pkg_Node_Id := Package_Node_Low_Bound + 1;
291 First_Package_Node_Id : constant Package_Node_Id :=
292 (Value => First_Package);
294 Package_First : constant Package_Node_Id := First_Package_Node_Id;
296 ----------------
297 -- Attributes --
298 ----------------
300 type Attribute_Record is record
301 Name : Name_Id;
302 Var_Kind : Variable_Kind;
303 Optional_Index : Boolean;
304 Attr_Kind : Attribute_Kind;
305 Read_Only : Boolean;
306 Others_Allowed : Boolean;
307 Next : Attr_Node_Id;
308 end record;
309 -- Data for an attribute
311 package Attrs is
312 new Table.Table (Table_Component_Type => Attribute_Record,
313 Table_Index_Type => Attr_Node_Id,
314 Table_Low_Bound => First_Attribute,
315 Table_Initial => Attributes_Initial,
316 Table_Increment => Attributes_Increment,
317 Table_Name => "Prj.Attr.Attrs");
318 -- The table of the attributes
320 --------------
321 -- Packages --
322 --------------
324 type Package_Record is record
325 Name : Name_Id;
326 Known : Boolean := True;
327 First_Attribute : Attr_Node_Id;
328 end record;
329 -- Data for a package
331 package Package_Attributes is
332 new Table.Table (Table_Component_Type => Package_Record,
333 Table_Index_Type => Pkg_Node_Id,
334 Table_Low_Bound => First_Package,
335 Table_Initial => Packages_Initial,
336 Table_Increment => Packages_Increment,
337 Table_Name => "Prj.Attr.Packages");
338 -- The table of the packages
340 end Prj.Attr;