1 ------------------------------------------------------------------------------
3 -- GNAT SYSTEM UTILITIES --
10 -- Copyright (C) 1992-2000 Free Software Foundation, Inc. --
12 -- GNAT is free software; you can redistribute it and/or modify it under --
13 -- terms of the GNU General Public License as published by the Free Soft- --
14 -- ware Foundation; either version 2, or (at your option) any later ver- --
15 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
18 -- for more details. You should have received a copy of the GNU General --
19 -- Public License distributed with GNAT; see file COPYING. If not, write --
20 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
21 -- MA 02111-1307, USA. --
23 -- GNAT was originally developed by the GNAT team at New York University. --
24 -- Extensive contributions were provided by Ada Core Technologies Inc. --
26 ------------------------------------------------------------------------------
28 -- Program to construct C header file a-sinfo.h (C version of sinfo.ads spec,
29 -- for use by Gigi, contains all definitions and access functions, but does
30 -- not contain set procedures, since Gigi never modifies the GNAT tree)
34 -- sinfo.ads Spec of Sinfo package
38 -- a-sinfo.h Corresponding c header file
40 -- Note: this program assumes that sinfo.ads has passed the error checks
41 -- which are carried out by the CSinfo utility, so it does not duplicate
42 -- these checks and assumes the soruce is correct.
44 -- An optional argument allows the specification of an output file name to
45 -- override the default a-sinfo.h file name for the generated output file.
47 with Ada
.Command_Line
; use Ada
.Command_Line
;
48 with Ada
.Strings
.Unbounded
; use Ada
.Strings
.Unbounded
;
49 with Ada
.Strings
.Unbounded
.Text_IO
; use Ada
.Strings
.Unbounded
.Text_IO
;
50 with Ada
.Text_IO
; use Ada
.Text_IO
;
52 with GNAT
.Spitbol
; use GNAT
.Spitbol
;
53 with GNAT
.Spitbol
.Patterns
; use GNAT
.Spitbol
.Patterns
;
62 Comment
: VString
:= Nul
;
63 Line
: VString
:= Nul
;
65 N1
, N2
: VString
:= Nul
;
68 Term
: VString
:= Nul
;
73 wsp
: Pattern
:= Span
(' ' & ASCII
.HT
);
74 Wsp_For
: Pattern
:= wsp
& "for";
75 Is_Cmnt
: Pattern
:= wsp
& "--";
76 Typ_Nod
: Pattern
:= wsp
* A
& "type Node_Kind is";
77 Get_Nam
: Pattern
:= wsp
* A
& "N_" & Break
(",)") * Nam
79 Sub_Typ
: Pattern
:= wsp
* A
& "subtype " & Break
(' ') * N
;
80 No_Cont
: Pattern
:= wsp
& Break
(' ') * N1
& " .. " & Break
(';') * N2
;
81 Cont_N1
: Pattern
:= wsp
& Break
(' ') * N1
& " .." & Rpos
(0);
82 Cont_N2
: Pattern
:= Span
(' ') & Break
(';') * N2
;
83 Is_Func
: Pattern
:= wsp
* A
& "function " & Rest
* Nam
;
84 Get_Arg
: Pattern
:= wsp
& "(N : " & Break
(')') * Arg
85 & ") return " & Break
(';') * Rtn
86 & ';' & wsp
& "--" & wsp
& Rest
* Comment
;
94 -- Get non-comment, non-blank line. Also skips "for " rep clauses.
99 Line
:= Get_Line
(InS
);
102 and then not Match
(Line
, Wsp_For
)
103 and then not Match
(Line
, Is_Cmnt
)
107 elsif Match
(Line
, " -- End functions (note") then
113 -- Start of processing for XSinfo
117 Anchored_Mode
:= True;
119 if Argument_Count
> 0 then
120 Create
(Ofile
, Out_File
, Argument
(1));
122 Create
(Ofile
, Out_File
, "a-sinfo.h");
125 Open
(InS
, In_File
, "sinfo.ads");
127 -- Write header to output file
130 Line
:= Get_Line
(InS
);
136 "-- C Header File ");
138 Match
(Line
, "--", "/*");
139 Match
(Line
, Rtab
(2) * A
& "--", M
);
140 Replace
(M
, A
& "*/");
141 Put_Line
(Ofile
, Line
);
144 -- Skip to package line
148 exit when Match
(Line
, "package");
151 -- Skip to first node kind line
155 exit when Match
(Line
, Typ_Nod
);
156 Put_Line
(Ofile
, Line
);
159 Put_Line
(Ofile
, "");
162 -- Loop through node kind codes
167 if Match
(Line
, Get_Nam
) then
168 Put_Line
(Ofile
, A
& "#define N_" & Nam
& ' ' & NKV
);
170 exit when not Match
(Term
, ",");
173 Put_Line
(Ofile
, Line
);
177 Put_Line
(Ofile
, "");
178 Put_Line
(Ofile
, A
& "#define Number_Node_Kinds " & NKV
);
180 -- Loop through subtype declarations
185 if not Match
(Line
, Sub_Typ
) then
186 exit when Match
(Line
, " function");
187 Put_Line
(Ofile
, Line
);
190 Put_Line
(Ofile
, A
& "SUBTYPE (" & N
& ", Node_Kind, ");
195 if Match
(Line
, No_Cont
) then
196 Put_Line
(Ofile
, A
& " " & N1
& ", " & N2
& ')');
201 if not Match
(Line
, Cont_N1
) then
207 if not Match
(Line
, Cont_N2
) then
211 Put_Line
(Ofile
, A
& " " & N1
& ',');
212 Put_Line
(Ofile
, A
& " " & N2
& ')');
217 -- Loop through functions. Note that this loop is terminated by
218 -- the call to Getfile encountering the end of functions sentinel
221 if Match
(Line
, Is_Func
) then
223 if not Match
(Line
, Get_Arg
) then
228 A
& "INLINE " & Rpad
(Rtn
, 9)
229 & ' ' & Rpad
(Nam
, 30) & " (" & Arg
& " N)");
231 Put_Line
(Ofile
, A
& " { return " & Comment
& " (N); }");
234 Put_Line
(Ofile
, Line
);
242 Put_Line
(Ofile
, "");