1------------------------------------------------------------------------------
2--                                                                          --
3--                            GNATPP COMPONENTS                             --
4--                                                                          --
5--     A S I S _ U L . S O U R C E _ T A B L E . P R O C E S S I N G .      --
6--                      A S I S _ P R O C E S S I N G                       --
7--                                                                          --
8--              (adapted for gnatpp from ASIS Utility Library)              --
9--                                                                          --
10--                                 B o d y                                  --
11--                                                                          --
12--                    Copyright (C) 2013-2016, AdaCore                      --
13--                                                                          --
14-- GNATPP is free software; you can redistribute it  and/or modify it under --
15-- terms of the  GNU General Public License as published  by the Free Soft- --
16-- ware  Foundation;  either version 2,  or (at your option) any later ver- --
17-- sion.  GNATPP is  distributed in the  hope that it will  be  useful, but --
18-- WITHOUT ANY WARRANTY; without even the implied warranty of  MERCHANTABI- --
19-- LITY or  FITNESS  FOR A  PARTICULAR  PURPOSE. See the GNU General Public --
20-- License  for more details. You  should  have  received a copy of the GNU --
21-- General Public License  distributed with GNAT; see file COPYING. If not, --
22-- write to the Free Software Foundation,  51 Franklin Street, Fifth Floor, --
23-- Boston,                                                                  --
24--                                                                          --
25-- GNATPP is maintained by AdaCore (http://www.adacore.com)                 --
26--                                                                          --
27------------------------------------------------------------------------------
28
29pragma Ada_2012;
30
31with Ada.Directories;       use Ada.Directories;
32with Ada.Text_IO;           use Ada.Text_IO;
33
34with Gnat2xml.Xml;          use Gnat2xml;
35
36separate (ASIS_UL.Source_Table.Processing)
37procedure ASIS_Processing (CU : Asis.Compilation_Unit; SF : SF_Id) is
38
39   procedure Process (XML_File : File_Access);
40   --  Helper routine that does all the work once the output file is opened
41
42   procedure Process (XML_File : File_Access) is
43      The_Node_Information : constant Xml.Info_Node :=
44        (XML_File  => XML_File,
45         Krunch    => False,
46         Xml_Style => False,
47         Verbose   => Verbose_Mode);
48   begin
49      Xml.Start_Representation (The_Node_Information);
50      Xml.Process_Unit (CU, The_Node_Information);
51   end Process;
52
53--  Start of processing for ASIS_Processing
54
55begin
56   if Out_Dir = null then
57      Process (Standard_Output); -- pipe output to standard output
58   else
59      declare
60         XML_Name : constant String :=
61           Compose
62             (Containing_Directory => Out_Dir.all,
63              Name                 => Short_Source_Name (SF),
64              Extension            => "xml");
65         XML_Out_File : aliased File_Type;
66      begin
67         if Verbose_Mode then
68            Put_Line ("creating " & XML_Name);
69         elsif Debug_Flag_V then
70            Put_Line ("creating " & Short_Source_Name (SF) & ".xml");
71         end if;
72
73         Create (XML_Out_File, Out_File, Name => XML_Name);
74         Process (XML_Out_File'Unchecked_Access);
75         Close (XML_Out_File);
76      end;
77   end if;
78
79   Set_Source_Status (SF, Processed);
80end ASIS_Processing;
81