OSDN Git Service

2011-08-05 Hristian Kirtchev <kirtchev@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / switch.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                               S W I T C H                                --
6 --                                                                          --
7 --                                 S p e c                                  --
8 --                                                                          --
9 --          Copyright (C) 1992-2011, 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 together with a child package appropriate to the client tool
27 --  scans switches. Note that the body of the appropriate Usage package must be
28 --  coordinated with the switches that are recognized by this package. These
29 --  Usage packages also act as the official documentation for the switches
30 --  that are recognized. In addition, package Debug documents the otherwise
31 --  undocumented debug switches that are also recognized.
32
33 with Gnatvsn;
34 with Types; use Types;
35
36 ------------
37 -- Switch --
38 ------------
39
40 package Switch is
41
42    --  Common switches for GNU tools
43
44    Version_Switch : constant String := "--version";
45    Help_Switch    : constant String := "--help";
46
47    -----------------
48    -- Subprograms --
49    -----------------
50
51    generic
52       with procedure Usage;
53       --  Print tool-specific part of --help message
54    procedure Check_Version_And_Help_G
55      (Tool_Name      : String;
56       Initial_Year   : String;
57       Version_String : String := Gnatvsn.Gnat_Version_String);
58    --  Check if switches --version or --help is used. If one of this switch is
59    --  used, issue the proper messages and end the process.
60
61    procedure Display_Version
62      (Tool_Name      : String;
63       Initial_Year   : String;
64       Version_String : String := Gnatvsn.Gnat_Version_String);
65    --  Display version of a tool when switch --version is used
66
67    function Is_Switch (Switch_Chars : String) return Boolean;
68    --  Returns True iff Switch_Chars is at least two characters long, and the
69    --  first character is an hyphen ('-').
70
71    function Is_Front_End_Switch (Switch_Chars : String) return Boolean;
72    --  Returns True iff Switch_Chars represents a front-end switch, i.e. it
73    --  starts with -I, -gnat or -?RTS.
74
75    function Is_Language_Switch (Switch_Chars : String) return Boolean;
76    --  Returns True iff Switch_Chars represents a language switch, i.e. it
77    --  specifies -gnat83/95/2005/2012.
78
79    function Is_Internal_GCC_Switch (Switch_Chars : String) return Boolean;
80    --  Returns True iff Switch_Chars represents an internal GCC switch to be
81    --  followed by a single argument, such as -dumpbase, --param or -auxbase.
82    --  Even though passed by the "gcc" driver, these need not be stored in ALI
83    --  files and may safely be ignored by non GCC back-ends.
84
85    function Switch_Last (Switch_Chars : String) return Natural;
86    --  Index in Switch_Chars of the last relevant character for later string
87    --  comparison purposes. This is typically 'Last, minus one if there is a
88    --  terminating ASCII.NUL.
89
90 private
91    --  This section contains some common routines used by the tool dependent
92    --  child packages (there is one such child package for each tool that uses
93    --  Switches to scan switches - Compiler/gnatbind/gnatmake/.
94
95    Switch_Max_Value : constant := 999_999;
96    --  Maximum value permitted in switches that take a value
97
98    function Nat_Present
99      (Switch_Chars : String;
100       Max          : Integer;
101       Ptr          : Integer) return Boolean;
102    --  Returns True if an integer is at the current scan location or an equal
103    --  sign. This is used as a guard for calling Scan_Nat. Switch_Chars is the
104    --  string containing the switch, and Ptr points just past the switch
105    --  character. Max is the maximum allowed value of Ptr.
106
107    procedure Scan_Nat
108      (Switch_Chars : String;
109       Max          : Integer;
110       Ptr          : in out Integer;
111       Result       : out Nat;
112       Switch       : Character);
113    --  Scan natural integer parameter for switch. On entry, Ptr points just
114    --  past the switch character, on exit it points past the last digit of the
115    --  integer value. Max is the maximum allowed value of Ptr, so the scan is
116    --  restricted to Switch_Chars (Ptr .. Max). It is possible for Ptr to be
117    --  one greater than Max on return if the entire string is digits. Scan_Nat
118    --  will skip an optional equal sign if it is present. Nat_Present must be
119    --  True, or an error will be signalled.
120
121    procedure Scan_Pos
122      (Switch_Chars : String;
123       Max          : Integer;
124       Ptr          : in out Integer;
125       Result       : out Pos;
126       Switch       : Character);
127    --  Scan positive integer parameter for switch. On entry, Ptr points just
128    --  past the switch character, on exit it points past the last digit of the
129    --  integer value.
130
131    procedure Bad_Switch (Switch : Character);
132    procedure Bad_Switch (Switch : String);
133    --  Fail with an appropriate message when a switch is not recognized
134
135 end Switch;