1 ------------------------------------------------------------------------------
3 -- GNAT SYSTEM UTILITIES --
11 -- Copyright (C) 1992-2000 Free Software Foundation, Inc. --
13 -- GNAT is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNAT; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
24 -- GNAT was originally developed by the GNAT team at New York University. --
25 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
27 ------------------------------------------------------------------------------
29 -- Program to construct C header file a-sinfo.h (C version of sinfo.ads spec,
30 -- for use by Gigi, contains all definitions and access functions, but does
31 -- not contain set procedures, since Gigi never modifies the GNAT tree)
35 -- sinfo.ads Spec of Sinfo package
39 -- a-sinfo.h Corresponding c header file
41 -- Note: this program assumes that sinfo.ads has passed the error checks
42 -- which are carried out by the CSinfo utility, so it does not duplicate
43 -- these checks and assumes the soruce is correct.
45 -- An optional argument allows the specification of an output file name to
46 -- override the default a-sinfo.h file name for the generated output file.
48 with Ada.Command_Line; use Ada.Command_Line;
49 with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
50 with Ada.Strings.Unbounded.Text_IO; use Ada.Strings.Unbounded.Text_IO;
51 with Ada.Text_IO; use Ada.Text_IO;
53 with GNAT.Spitbol; use GNAT.Spitbol;
54 with GNAT.Spitbol.Patterns; use GNAT.Spitbol.Patterns;
63 Comment : VString := Nul;
64 Line : VString := Nul;
66 N1, N2 : VString := Nul;
69 Sinforev : VString := Nul;
70 Term : VString := Nul;
71 XSinforev : VString := Nul;
76 wsp : Pattern := Span (' ' & ASCII.HT);
77 Get_Vsn : Pattern := BreakX ('$') & "$Rev" & "ision: "
78 & Break (' ') * Sinforev;
79 Wsp_For : Pattern := wsp & "for";
80 Is_Cmnt : Pattern := wsp & "--";
81 Typ_Nod : Pattern := wsp * A & "type Node_Kind is";
82 Get_Nam : Pattern := wsp * A & "N_" & Break (",)") * Nam
84 Sub_Typ : Pattern := wsp * A & "subtype " & Break (' ') * N;
85 No_Cont : Pattern := wsp & Break (' ') * N1 & " .. " & Break (';') * N2;
86 Cont_N1 : Pattern := wsp & Break (' ') * N1 & " .." & Rpos (0);
87 Cont_N2 : Pattern := Span (' ') & Break (';') * N2;
88 Is_Func : Pattern := wsp * A & "function " & Rest * Nam;
89 Get_Arg : Pattern := wsp & "(N : " & Break (')') * Arg
90 & ") return " & Break (';') * Rtn
91 & ';' & wsp & "--" & wsp & Rest * Comment;
99 -- Get non-comment, non-blank line. Also skips "for " rep clauses.
104 Line := Get_Line (InS);
107 and then not Match (Line, Wsp_For)
108 and then not Match (Line, Is_Cmnt)
112 elsif Match (Line, " -- End functions (note") then
118 -- Start of processing for XSinfo
122 Anchored_Mode := True;
123 Match ("$Revision: 1.19 $", "$Rev" & "ision: " & Break (' ') * XSinforev);
125 if Argument_Count > 0 then
126 Create (Ofile, Out_File, Argument (1));
128 Create (Ofile, Out_File, "a-sinfo.h");
131 Open (InS, In_File, "sinfo.ads");
133 -- Get Sinfo rev and write header to output file
136 Line := Get_Line (InS);
139 if Match (Line, Get_Vsn) then
141 (Ofile, "/* Generated by xsinfo revision "
142 & XSinforev & " using */");
144 (Ofile, "/* sinfo.ads revision "
151 "-- C Header File ");
153 Match (Line, "--", "/*");
154 Match (Line, Rtab (2) * A & "--", M);
155 Replace (M, A & "*/");
156 Put_Line (Ofile, Line);
160 -- Skip to package line
164 exit when Match (Line, "package");
167 -- Skip to first node kind line
171 exit when Match (Line, Typ_Nod);
172 Put_Line (Ofile, Line);
175 Put_Line (Ofile, "");
178 -- Loop through node kind codes
183 if Match (Line, Get_Nam) then
184 Put_Line (Ofile, A & "#define N_" & Nam & ' ' & NKV);
186 exit when not Match (Term, ",");
189 Put_Line (Ofile, Line);
193 Put_Line (Ofile, "");
194 Put_Line (Ofile, A & "#define Number_Node_Kinds " & NKV);
196 -- Loop through subtype declarations
201 if not Match (Line, Sub_Typ) then
202 exit when Match (Line, " function");
203 Put_Line (Ofile, Line);
206 Put_Line (Ofile, A & "SUBTYPE (" & N & ", Node_Kind, ");
211 if Match (Line, No_Cont) then
212 Put_Line (Ofile, A & " " & N1 & ", " & N2 & ')');
217 if not Match (Line, Cont_N1) then
223 if not Match (Line, Cont_N2) then
227 Put_Line (Ofile, A & " " & N1 & ',');
228 Put_Line (Ofile, A & " " & N2 & ')');
233 -- Loop through functions. Note that this loop is terminated by
234 -- the call to Getfile encountering the end of functions sentinel
237 if Match (Line, Is_Func) then
239 if not Match (Line, Get_Arg) then
244 A & "INLINE " & Rpad (Rtn, 9)
245 & ' ' & Rpad (Nam, 30) & " (" & Arg & " N)");
247 Put_Line (Ofile, A & " { return " & Comment & " (N); }");
250 Put_Line (Ofile, Line);
258 Put_Line (Ofile, "");