annotate gcc/ada/libgnat/a-comlin.ads @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 84e7813d76e9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT RUN-TIME COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- A D A . C O M M A N D _ L I N E --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- S p e c --
kono
parents:
diff changeset
8 -- --
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
9 -- Copyright (C) 1992-2019, Free Software Foundation, Inc. --
111
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- This specification is derived from the Ada Reference Manual for use with --
kono
parents:
diff changeset
12 -- GNAT. The copyright notice above, and the license provisions that follow --
kono
parents:
diff changeset
13 -- apply solely to the contents of the part following the private keyword. --
kono
parents:
diff changeset
14 -- --
kono
parents:
diff changeset
15 -- GNAT is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
16 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
17 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
18 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
19 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
20 -- or FITNESS FOR A PARTICULAR PURPOSE. --
kono
parents:
diff changeset
21 -- --
kono
parents:
diff changeset
22 -- As a special exception under Section 7 of GPL version 3, you are granted --
kono
parents:
diff changeset
23 -- additional permissions described in the GCC Runtime Library Exception, --
kono
parents:
diff changeset
24 -- version 3.1, as published by the Free Software Foundation. --
kono
parents:
diff changeset
25 -- --
kono
parents:
diff changeset
26 -- You should have received a copy of the GNU General Public License and --
kono
parents:
diff changeset
27 -- a copy of the GCC Runtime Library Exception along with this program; --
kono
parents:
diff changeset
28 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
kono
parents:
diff changeset
29 -- <http://www.gnu.org/licenses/>. --
kono
parents:
diff changeset
30 -- --
kono
parents:
diff changeset
31 -- GNAT was originally developed by the GNAT team at New York University. --
kono
parents:
diff changeset
32 -- Extensive contributions were provided by Ada Core Technologies Inc. --
kono
parents:
diff changeset
33 -- --
kono
parents:
diff changeset
34 ------------------------------------------------------------------------------
kono
parents:
diff changeset
35
kono
parents:
diff changeset
36 package Ada.Command_Line is
kono
parents:
diff changeset
37 pragma Preelaborate;
kono
parents:
diff changeset
38
kono
parents:
diff changeset
39 function Argument_Count return Natural;
kono
parents:
diff changeset
40 -- If the external execution environment supports passing arguments to a
kono
parents:
diff changeset
41 -- program, then Argument_Count returns the number of arguments passed to
kono
parents:
diff changeset
42 -- the program invoking the function. Otherwise it return 0.
kono
parents:
diff changeset
43 --
kono
parents:
diff changeset
44 -- In GNAT: Corresponds to (argc - 1) in C.
kono
parents:
diff changeset
45
kono
parents:
diff changeset
46 pragma Assertion_Policy (Pre => Ignore);
kono
parents:
diff changeset
47 -- We need to ignore the precondition of Argument, below, so that we don't
kono
parents:
diff changeset
48 -- raise Assertion_Error. The body raises Constraint_Error. It would be
kono
parents:
diff changeset
49 -- cleaner to add "or else raise Constraint_Error" to the precondition, but
kono
parents:
diff changeset
50 -- SPARK does not yet support raise expressions.
kono
parents:
diff changeset
51
kono
parents:
diff changeset
52 function Argument (Number : Positive) return String with
kono
parents:
diff changeset
53 Pre => Number <= Argument_Count;
kono
parents:
diff changeset
54 -- If the external execution environment supports passing arguments to
kono
parents:
diff changeset
55 -- a program, then Argument returns an implementation-defined value
kono
parents:
diff changeset
56 -- corresponding to the argument at relative position Number. If Number
kono
parents:
diff changeset
57 -- is outside the range 1 .. Argument_Count, then Constraint_Error is
kono
parents:
diff changeset
58 -- propagated.
kono
parents:
diff changeset
59 --
kono
parents:
diff changeset
60 -- in GNAT: Corresponds to argv [n] (for n > 0) in C.
kono
parents:
diff changeset
61
kono
parents:
diff changeset
62 function Command_Name return String;
kono
parents:
diff changeset
63 -- If the external execution environment supports passing arguments to
kono
parents:
diff changeset
64 -- a program, then Command_Name returns an implementation-defined value
kono
parents:
diff changeset
65 -- corresponding to the name of the command invoking the program.
kono
parents:
diff changeset
66 -- Otherwise Command_Name returns the null string.
kono
parents:
diff changeset
67 --
kono
parents:
diff changeset
68 -- in GNAT: Corresponds to argv [0] in C.
kono
parents:
diff changeset
69
kono
parents:
diff changeset
70 type Exit_Status is new Integer;
kono
parents:
diff changeset
71
kono
parents:
diff changeset
72 Success : constant Exit_Status;
kono
parents:
diff changeset
73 Failure : constant Exit_Status;
kono
parents:
diff changeset
74
kono
parents:
diff changeset
75 procedure Set_Exit_Status (Code : Exit_Status);
kono
parents:
diff changeset
76
kono
parents:
diff changeset
77 ------------------------------------
kono
parents:
diff changeset
78 -- Note on Interface Requirements --
kono
parents:
diff changeset
79 ------------------------------------
kono
parents:
diff changeset
80
kono
parents:
diff changeset
81 -- Services in this package are not supported during the elaboration of an
kono
parents:
diff changeset
82 -- auto-initialized Stand-Alone Library.
kono
parents:
diff changeset
83
kono
parents:
diff changeset
84 -- If the main program is in Ada, this package works as specified without
kono
parents:
diff changeset
85 -- any other work than the normal steps of WITH'ing the package and then
kono
parents:
diff changeset
86 -- calling the desired routines.
kono
parents:
diff changeset
87
kono
parents:
diff changeset
88 -- If the main program is not in Ada, then the information must be made
kono
parents:
diff changeset
89 -- available for this package to work correctly. In particular, it is
kono
parents:
diff changeset
90 -- required that the global variable "gnat_argc" contain the number of
kono
parents:
diff changeset
91 -- arguments, and that the global variable "gnat_argv" points to an
kono
parents:
diff changeset
92 -- array of null-terminated strings, the first entry being the command
kono
parents:
diff changeset
93 -- name, and the remaining entries being the command arguments.
kono
parents:
diff changeset
94
kono
parents:
diff changeset
95 -- These correspond to the normal argc/argv variables passed to a C
kono
parents:
diff changeset
96 -- main program, and the following is an example of a complete C main
kono
parents:
diff changeset
97 -- program that stores the required information:
kono
parents:
diff changeset
98
kono
parents:
diff changeset
99 -- main(int argc, char **argv, char **envp)
kono
parents:
diff changeset
100 -- {
kono
parents:
diff changeset
101 -- extern int gnat_argc;
kono
parents:
diff changeset
102 -- extern char **gnat_argv;
kono
parents:
diff changeset
103 -- extern char **gnat_envp;
kono
parents:
diff changeset
104 -- gnat_argc = argc;
kono
parents:
diff changeset
105 -- gnat_argv = argv;
kono
parents:
diff changeset
106 -- gnat_envp = envp;
kono
parents:
diff changeset
107
kono
parents:
diff changeset
108 -- adainit();
kono
parents:
diff changeset
109 -- adamain();
kono
parents:
diff changeset
110 -- adafinal();
kono
parents:
diff changeset
111 -- }
kono
parents:
diff changeset
112
kono
parents:
diff changeset
113 -- The assignment statements ensure that the necessary information is
kono
parents:
diff changeset
114 -- available for finding the command name and command line arguments.
kono
parents:
diff changeset
115
kono
parents:
diff changeset
116 private
kono
parents:
diff changeset
117 Success : constant Exit_Status := 0;
kono
parents:
diff changeset
118 Failure : constant Exit_Status := 1;
kono
parents:
diff changeset
119
kono
parents:
diff changeset
120 -- The following locations support the operation of the package
kono
parents:
diff changeset
121 -- Ada.Command_Line.Remove, which provides facilities for logically
kono
parents:
diff changeset
122 -- removing arguments from the command line. If one of the remove
kono
parents:
diff changeset
123 -- procedures is called in this unit, then Remove_Args/Remove_Count
kono
parents:
diff changeset
124 -- are set to indicate which arguments are removed. If no such calls
kono
parents:
diff changeset
125 -- have been made, then Remove_Args is null.
kono
parents:
diff changeset
126
kono
parents:
diff changeset
127 Remove_Count : Natural;
kono
parents:
diff changeset
128 -- Number of arguments reflecting removals. Not defined unless
kono
parents:
diff changeset
129 -- Remove_Args is non-null.
kono
parents:
diff changeset
130
kono
parents:
diff changeset
131 type Arg_Nums is array (Positive range <>) of Positive;
kono
parents:
diff changeset
132 type Arg_Nums_Ptr is access Arg_Nums;
kono
parents:
diff changeset
133 -- An array that maps logical argument numbers (reflecting removal)
kono
parents:
diff changeset
134 -- to physical argument numbers (e.g. if the first argument has been
kono
parents:
diff changeset
135 -- removed, but not the second, then Arg_Nums (1) will be set to 2.
kono
parents:
diff changeset
136
kono
parents:
diff changeset
137 Remove_Args : Arg_Nums_Ptr := null;
kono
parents:
diff changeset
138 -- Left set to null if no remove calls have been made, otherwise set
kono
parents:
diff changeset
139 -- to point to an appropriate mapping array. Only the first Remove_Count
kono
parents:
diff changeset
140 -- elements are relevant.
kono
parents:
diff changeset
141
kono
parents:
diff changeset
142 pragma Import (C, Set_Exit_Status, "__gnat_set_exit_status");
kono
parents:
diff changeset
143
kono
parents:
diff changeset
144 end Ada.Command_Line;