1 ------------------------------------------------------------------------------
3 -- GNAT SYSTEM UTILITIES --
9 -- Copyright (C) 1992-2005, Free Software Foundation, Inc. --
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. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 -- Program to construct C header file sinfo.h (C version of sinfo.ads spec,
28 -- for use by Gigi, contains all definitions and access functions, but does
29 -- not contain set procedures, since Gigi never modifies the GNAT tree)
33 -- sinfo.ads Spec of Sinfo package
37 -- sinfo.h Corresponding c header file
39 -- Note: this program assumes that sinfo.ads has passed the error checks
40 -- which are carried out by the CSinfo utility, so it does not duplicate
41 -- these checks and assumes the soruce is correct.
43 -- An optional argument allows the specification of an output file name to
44 -- override the default sinfo.h file name for the generated output file.
46 with Ada
.Command_Line
; use Ada
.Command_Line
;
47 with Ada
.Strings
.Unbounded
; use Ada
.Strings
.Unbounded
;
48 with Ada
.Strings
.Unbounded
.Text_IO
; use Ada
.Strings
.Unbounded
.Text_IO
;
49 with Ada
.Text_IO
; use Ada
.Text_IO
;
51 with GNAT
.Spitbol
; use GNAT
.Spitbol
;
52 with GNAT
.Spitbol
.Patterns
; use GNAT
.Spitbol
.Patterns
;
61 Comment
: VString
:= Nul
;
62 Line
: VString
:= Nul
;
64 N1
, N2
: VString
:= Nul
;
67 Term
: VString
:= Nul
;
72 wsp
: Pattern
:= Span
(' ' & ASCII
.HT
);
73 Wsp_For
: Pattern
:= wsp
& "for";
74 Is_Cmnt
: Pattern
:= wsp
& "--";
75 Typ_Nod
: Pattern
:= wsp
* A
& "type Node_Kind is";
76 Get_Nam
: Pattern
:= wsp
* A
& "N_" & Break
(",)") * Nam
78 Sub_Typ
: Pattern
:= wsp
* A
& "subtype " & Break
(' ') * N
;
79 No_Cont
: Pattern
:= wsp
& Break
(' ') * N1
& " .. " & Break
(';') * N2
;
80 Cont_N1
: Pattern
:= wsp
& Break
(' ') * N1
& " .." & Rpos
(0);
81 Cont_N2
: Pattern
:= Span
(' ') & Break
(';') * N2
;
82 Is_Func
: Pattern
:= wsp
* A
& "function " & Rest
* Nam
;
83 Get_Arg
: Pattern
:= wsp
& "(N : " & Break
(')') * Arg
84 & ") return " & Break
(';') * Rtn
85 & ';' & wsp
& "--" & wsp
& Rest
* Comment
;
92 -- Get non-comment, non-blank line. Also skips "for " rep clauses
101 Line
:= Get_Line
(InS
);
104 and then not Match
(Line
, Wsp_For
)
105 and then not Match
(Line
, Is_Cmnt
)
109 elsif Match
(Line
, " -- End functions (note") then
115 -- Start of processing for XSinfo
119 Anchored_Mode
:= True;
121 if Argument_Count
> 0 then
122 Create
(Ofile
, Out_File
, Argument
(1));
124 Create
(Ofile
, Out_File
, "sinfo.h");
127 Open
(InS
, In_File
, "sinfo.ads");
129 -- Write header to output file
132 Line
:= Get_Line
(InS
);
138 "-- C Header File ");
140 Match
(Line
, "--", "/*");
141 Match
(Line
, Rtab
(2) * A
& "--", M
);
142 Replace
(M
, A
& "*/");
143 Put_Line
(Ofile
, Line
);
146 -- Skip to package line
150 exit when Match
(Line
, "package");
153 -- Skip to first node kind line
157 exit when Match
(Line
, Typ_Nod
);
158 Put_Line
(Ofile
, Line
);
161 Put_Line
(Ofile
, "");
164 -- Loop through node kind codes
169 if Match
(Line
, Get_Nam
) then
170 Put_Line
(Ofile
, A
& "#define N_" & Nam
& ' ' & NKV
);
172 exit when not Match
(Term
, ",");
175 Put_Line
(Ofile
, Line
);
179 Put_Line
(Ofile
, "");
180 Put_Line
(Ofile
, A
& "#define Number_Node_Kinds " & NKV
);
182 -- Loop through subtype declarations
187 if not Match
(Line
, Sub_Typ
) then
188 exit when Match
(Line
, " function");
189 Put_Line
(Ofile
, Line
);
192 Put_Line
(Ofile
, A
& "SUBTYPE (" & N
& ", Node_Kind, ");
197 if Match
(Line
, No_Cont
) then
198 Put_Line
(Ofile
, A
& " " & N1
& ", " & N2
& ')');
203 if not Match
(Line
, Cont_N1
) then
209 if not Match
(Line
, Cont_N2
) then
213 Put_Line
(Ofile
, A
& " " & N1
& ',');
214 Put_Line
(Ofile
, A
& " " & N2
& ')');
219 -- Loop through functions. Note that this loop is terminated by
220 -- the call to Getfile encountering the end of functions sentinel
223 if Match
(Line
, Is_Func
) then
225 if not Match
(Line
, Get_Arg
) then
230 A
& "INLINE " & Rpad
(Rtn
, 9)
231 & ' ' & Rpad
(Nam
, 30) & " (" & Arg
& " N)");
233 Put_Line
(Ofile
, A
& " { return " & Comment
& " (N); }");
236 Put_Line
(Ofile
, Line
);
244 Put_Line
(Ofile
, "");