OSDN Git Service

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