OSDN Git Service

2007-04-20 Vincent Celier <celier@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / prj-util.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                              P R J . U T I L                             --
6 --                                                                          --
7 --                                 S p e c                                  --
8 --                                                                          --
9 --          Copyright (C) 2001-2007, 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,  51  Franklin  Street,  Fifth  Floor, --
20 -- Boston, MA 02110-1301, 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 --  Utilities for use in processing project files
28
29 package Prj.Util is
30
31    function Executable_Of
32      (Project  : Project_Id;
33       In_Tree  : Project_Tree_Ref;
34       Main     : File_Name_Type;
35       Index    : Int;
36       Ada_Main : Boolean := True) return File_Name_Type;
37    --  Return the value of the attribute Builder'Executable for file Main in
38    --  the project Project, if it exists. If there is no attribute Executable
39    --  for Main, remove the suffix from Main; then, if the attribute
40    --  Executable_Suffix is specified, add this suffix, otherwise add the
41    --  standard executable suffix for the platform.
42
43    function Value_Of
44      (Variable : Variable_Value;
45       Default  : String) return String;
46    --  Get the value of a single string variable. If Variable is
47    --  Nil_Variable_Value, is a string list or is defaulted, return Default.
48
49    function Value_Of
50      (Index    : Name_Id;
51       In_Array : Array_Element_Id;
52       In_Tree  : Project_Tree_Ref) return Name_Id;
53    --  Get a single string array component. Returns No_Name if there is no
54    --  component Index, if In_Array is null, or if the component is a String
55    --  list. Depending on the attribute (only attributes may be associative
56    --  arrays) the index may or may not be case sensitive. If the index is not
57    --  case sensitive, it is first set to lower case before the search in the
58    --  associative array.
59
60    function Value_Of
61      (Index     : Name_Id;
62       Src_Index : Int := 0;
63       In_Array  : Array_Element_Id;
64       In_Tree   : Project_Tree_Ref) return Variable_Value;
65    --  Get a string array component (single String or String list). Returns
66    --  Nil_Variable_Value if no component Index or if In_Array is null.
67    --
68    --  Depending on the attribute (only attributes may be associative arrays)
69    --  the index may or may not be case sensitive. If the index is not case
70    --  sensitive, it is first set to lower case before the search in the
71    --  associative array.
72
73    function Value_Of
74      (Name                    : Name_Id;
75       Index                   : Int := 0;
76       Attribute_Or_Array_Name : Name_Id;
77       In_Package              : Package_Id;
78       In_Tree                 : Project_Tree_Ref) return Variable_Value;
79    --  In a specific package,
80    --   - if there exists an array Attribute_Or_Array_Name with an index Name,
81    --     returns the corresponding component (depending on the attribute, the
82    --     index may or may not be case sensitive, see previous function),
83    --   - otherwise if there is a single attribute Attribute_Or_Array_Name,
84    --     returns this attribute,
85    --   - otherwise, returns Nil_Variable_Value.
86    --  If In_Package is null, returns Nil_Variable_Value.
87
88    function Value_Of
89      (Index     : Name_Id;
90       In_Array  : Name_Id;
91       In_Arrays : Array_Id;
92       In_Tree   : Project_Tree_Ref) return Name_Id;
93    --  Get a string array component in an array of an array list. Returns
94    --  No_Name if there is no component Index, if In_Arrays is null, if
95    --  In_Array is not found in In_Arrays or if the component is a String list.
96
97    function Value_Of
98      (Name      : Name_Id;
99       In_Arrays : Array_Id;
100       In_Tree   : Project_Tree_Ref) return Array_Element_Id;
101    --  Returns a specified array in an array list. Returns No_Array_Element
102    --  if In_Arrays is null or if Name is not the name of an array in
103    --  In_Arrays. The caller must ensure that Name is in lower case.
104
105    function Value_Of
106      (Name        : Name_Id;
107       In_Packages : Package_Id;
108       In_Tree     : Project_Tree_Ref) return Package_Id;
109    --  Returns a specified package in a package list. Returns No_Package if
110    --  In_Packages is null or if Name is not the name of a package in
111    --  Package_List. The caller must ensure that Name is in lower case.
112
113    function Value_Of
114      (Variable_Name : Name_Id;
115       In_Variables  : Variable_Id;
116       In_Tree       : Project_Tree_Ref) return Variable_Value;
117    --  Returns a specified variable in a variable list. Returns null if
118    --  In_Variables is null or if Variable_Name is not the name of a
119    --  variable in In_Variables. Caller must ensure that Name is lower case.
120
121    procedure Write_Str
122      (S          : String;
123       Max_Length : Positive;
124       Separator  : Character);
125    --  Output string S using Output.Write_Str. If S is too long to fit in
126    --  one line of Max_Length, cut it in several lines, using Separator as
127    --  the last character of each line, if possible.
128
129    type Text_File is limited private;
130    --  Represents a text file. Default is invalid text file
131
132    function Is_Valid (File : Text_File) return Boolean;
133    --  Returns True if File designates an open text file that
134    --  has not yet been closed.
135
136    procedure Open (File : out Text_File; Name : String);
137    --  Open a text file. If this procedure fails, File is invalid
138
139    function End_Of_File (File : Text_File) return Boolean;
140    --  Returns True if the end of the text file File has been reached. Fails if
141    --  File is invalid.
142
143    procedure Get_Line
144      (File : Text_File;
145       Line : out String;
146       Last : out Natural);
147    --  Reads a line from an open text file. Fails if File is invalid
148
149    procedure Close (File : in out Text_File);
150    --  Close an open text file. File becomes invalid. Fails if File is already
151    --  invalid.
152
153 private
154
155    type Text_File_Data is record
156       FD                  : File_Descriptor := Invalid_FD;
157       Buffer              : String (1 .. 1_000);
158       Buffer_Len          : Natural;
159       Cursor              : Natural := 0;
160       End_Of_File_Reached : Boolean := False;
161    end record;
162
163    type Text_File is access Text_File_Data;
164
165 end Prj.Util;