OSDN Git Service

optimize
[pf3gnuchains/gcc-fork.git] / gcc / ada / vms_conv.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                            V M S _ C O N V                               --
6 --                                                                          --
7 --                                 S p e c                                  --
8 --                                                                          --
9 --          Copyright (C) 2003-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 is part of the GNAT driver. It contains a procedure
28 --  VMS_Conversion to convert the command line in VMS form to the equivalent
29 --  command line with switches for the GNAT tools that the GNAT driver will
30 --  invoke.
31 --
32 --  The qualifier declarations are contained in package VMS_Data.
33
34 with Table;
35 with VMS_Data; use VMS_Data;
36
37 with GNAT.OS_Lib; use GNAT.OS_Lib;
38
39 package VMS_Conv is
40
41    --  A table to keep the switches on the command line
42
43    package Last_Switches is new Table.Table
44      (Table_Component_Type => String_Access,
45       Table_Index_Type     => Integer,
46       Table_Low_Bound      => 1,
47       Table_Initial        => 20,
48       Table_Increment      => 100,
49       Table_Name           => "Gnatcmd.Last_Switches");
50
51    Normal_Exit : exception;
52    --  Raise this exception for normal program termination
53
54    Error_Exit : exception;
55    --  Raise this exception if error detected
56
57    Errors : Natural := 0;
58    --  Count errors detected
59
60    Display_Command : Boolean := False;
61    --  Set true if /? switch causes display of generated command (on VMS)
62
63    -------------------
64    -- COMMAND TABLE --
65    -------------------
66
67    --  The command table contains an entry for each command recognized by
68    --  GNATCmd. The entries are represented by an array of records.
69
70    type Parameter_Type is
71    --  A parameter is defined as a whitespace bounded string, not begining
72    --   with a slash. (But see note under FILES_OR_WILDCARD).
73      (File,
74       --  A required file or directory parameter.
75
76       Optional_File,
77       --  An optional file or directory parameter.
78
79       Other_As_Is,
80       --  A parameter that's passed through as is (not canonicalized)
81
82       Unlimited_Files,
83       --  An unlimited number of whitespace separate file or directory
84       --  parameters including wildcard specifications.
85
86       Unlimited_As_Is,
87       --  Un unlimited number of whitespace separated paameters that are
88       --  passed through as is (not canonicalized).
89
90       Files_Or_Wildcard);
91       --  A comma separated list of files and/or wildcard file specifications.
92       --  A comma preceded by or followed by whitespace is considered as a
93       --  single comma character w/o whitespace.
94
95    type Parameter_Array is array (Natural range <>) of Parameter_Type;
96    type Parameter_Ref is access all Parameter_Array;
97
98    type Command_Type is
99      (Bind, Chop, Clean, Compile, Elim, Find, Krunch, Library, Link, List,
100       Make, Metric, Name, Preprocess, Pretty, Shared, Stub, Xref, Undefined);
101
102    type Alternate_Command is (Comp, Ls, Kr, Pp, Prep);
103    --  Alternate command libel for non VMS system
104
105    Corresponding_To : constant array (Alternate_Command) of Command_Type :=
106      (Comp  => Compile,
107       Ls    => List,
108       Kr    => Krunch,
109       Prep  => Preprocess,
110       Pp    => Pretty);
111    --  Mapping of alternate commands to commands
112
113    subtype Real_Command_Type is Command_Type range Bind .. Xref;
114
115    type Command_Entry is record
116       Cname : String_Ptr;
117       --  Command name for GNAT xxx command
118
119       Usage : String_Ptr;
120       --  A usage string, used for error messages
121
122       Unixcmd : String_Ptr;
123       --  Corresponding Unix command
124
125       Unixsws : Argument_List_Access;
126       --  Switches for the Unix command
127
128       VMS_Only : Boolean;
129       --  When True, the command can only be used on VMS
130
131       Switches : Switches_Ptr;
132       --  Pointer to array of switch strings
133
134       Params : Parameter_Ref;
135       --  Describes the allowable types of parameters.
136       --  Params (1) is the type of the first parameter, etc.
137       --  An empty parameter array means this command takes no parameters.
138
139       Defext : String (1 .. 3);
140       --  Default extension. If non-blank, then this extension is supplied by
141       --  default as the extension for any file parameter which does not have
142       --  an extension already.
143    end record;
144
145    -------------------------
146    -- INTERNAL STRUCTURES --
147    -------------------------
148
149    --  The switches and commands are defined by strings in the previous
150    --  section so that they are easy to modify, but internally, they are
151    --  kept in a more conveniently accessible form described in this
152    --  section.
153
154    --  Commands, command qualifers and options have a similar common format
155    --  so that searching for matching names can be done in a common manner.
156
157    type Item_Id is (Id_Command, Id_Switch, Id_Option);
158
159    type Translation_Type is
160      (
161       T_Direct,
162       --  A qualifier with no options.
163       --  Example: GNAT MAKE /VERBOSE
164
165       T_Directories,
166       --  A qualifier followed by a list of directories
167       --  Example: GNAT COMPILE /SEARCH=([], [.FOO], [.BAR])
168
169       T_Directory,
170       --  A qualifier followed by one directory
171       --  Example: GNAT LIBRARY /SET=[.VAXFLOATLIB]
172
173       T_File,
174       --  A qualifier followed by a filename
175       --  Example: GNAT LINK /EXECUTABLE=FOO.EXE
176
177       T_No_Space_File,
178       --  A qualifier followed by a filename
179       --  Example: GNAT MAKE /PROJECT_FILE=PRJ.GPR
180
181       T_Numeric,
182       --  A qualifier followed by a numeric value.
183       --  Example: GNAT CHOP /FILE_NAME_MAX_LENGTH=39
184
185       T_String,
186       --  A qualifier followed by a quoted string. Only used by
187       --  /IDENTIFICATION qualifier.
188       --  Example: GNAT LINK /IDENTIFICATION="3.14a1 version"
189
190       T_Options,
191       --  A qualifier followed by a list of options.
192       --  Example: GNAT COMPILE /REPRESENTATION_INFO=(ARRAYS,OBJECTS)
193
194       T_Commands,
195       --  A qualifier followed by a list. Only used for
196       --  MAKE /COMPILER_QUALIFIERS /BINDER_QUALIFIERS /LINKER_QUALIFIERS
197       --  (gnatmake -cargs -bargs -largs )
198       --  Example: GNAT MAKE ... /LINKER_QUALIFIERS /VERBOSE FOOBAR.OBJ
199
200       T_Other,
201       --  A qualifier passed directly to the linker. Only used
202       --  for LINK and SHARED if no other match is found.
203       --  Example: GNAT LINK FOO.ALI /SYSSHR
204
205       T_Alphanumplus
206       --  A qualifier followed by a legal linker symbol prefix. Only used
207       --  for BIND /BUILD_LIBRARY (gnatbind -Lxyz).
208       --  Example: GNAT BIND /BUILD_LIBRARY=foobar
209       );
210
211    type Item (Id : Item_Id);
212    type Item_Ptr is access all Item;
213
214    type Item (Id : Item_Id) is record
215       Name : String_Ptr;
216       --  Name of the command, switch (with slash) or option
217
218       Next : Item_Ptr;
219       --  Pointer to next item on list, always has the same Id value
220
221       Command : Command_Type := Undefined;
222
223       Unix_String : String_Ptr := null;
224       --  Corresponding Unix string. For a command, this is the unix command
225       --  name and possible default switches. For a switch or option it is
226       --  the unix switch string.
227
228       case Id is
229
230          when Id_Command =>
231
232             Switches : Item_Ptr;
233             --  Pointer to list of switch items for the command, linked
234             --  through the Next fields with null terminating the list.
235
236             Usage : String_Ptr;
237             --  Usage information, used only for errors and the default
238             --  list of commands output.
239
240             Params : Parameter_Ref;
241             --  Array of parameters
242
243             Defext : String (1 .. 3);
244             --  Default extension. If non-blank, then this extension is
245             --  supplied by default as the extension for any file parameter
246             --  which does not have an extension already.
247
248          when Id_Switch =>
249
250             Translation : Translation_Type;
251             --  Type of switch translation. For all cases, except Options,
252             --  this is the only field needed, since the Unix translation
253             --  is found in Unix_String.
254
255             Options : Item_Ptr;
256             --  For the Options case, this field is set to point to a list
257             --  of options item (for this case Unix_String is null in the
258             --  main switch item). The end of the list is marked by null.
259
260          when Id_Option =>
261
262             null;
263             --  No special fields needed, since Name and Unix_String are
264             --  sufficient to completely described an option.
265
266       end case;
267    end record;
268
269    subtype Command_Item is Item (Id_Command);
270    subtype Switch_Item  is Item (Id_Switch);
271    subtype Option_Item  is Item (Id_Option);
272
273    ------------------
274    -- SWITCH TABLE --
275    ------------------
276
277    --  The switch tables contain an entry for each switch recognized by the
278    --  command processor. It is initialized by procedure Initialize.
279
280    Command_List : array (Real_Command_Type) of Command_Entry;
281
282    ----------------
283    -- Procedures --
284    ----------------
285
286    procedure Initialize;
287    --  Initialized the switch table Command_List
288
289    procedure Output_Version;
290    --  Output the version of this program
291
292    procedure VMS_Conversion (The_Command : out Command_Type);
293    --  Converts VMS command line to equivalent Unix command line
294
295 end VMS_Conv;