-----------------------------------------------------------------------
--                 Odd - The Other Display Debugger                  --
--                                                                   --
--                         Copyright (C) 2000                        --
--                 Emmanuel Briot and Arnaud Charlet                 --
--                                                                   --
-- Odd is free  software;  you can redistribute it and/or modify  it --
-- under the terms of the GNU General Public License as published by --
-- the Free Software Foundation; either version 2 of the License, or --
-- (at your option) any later version.                               --
--                                                                   --
-- This program is  distributed in the hope that it will be  useful, --
-- but  WITHOUT ANY WARRANTY;  without even the  implied warranty of --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU --
-- General Public License for more details. You should have received --
-- a copy of the GNU General Public License along with this library; --
-- if not,  write to the  Free Software Foundation, Inc.,  59 Temple --
-- Place - Suite 330, Boston, MA 02111-1307, USA.                    --
-----------------------------------------------------------------------

with Items;            use Items;
with Debugger.Gdb;     use Debugger.Gdb;
with Debugger.Gdb.Cpp;   use Debugger.Gdb.Cpp;
pragma Warnings (Off);
with GNAT.Expect;      use GNAT.Expect;
pragma Warnings (On);
with GNAT.IO;          use GNAT.IO;
with Ada.Calendar;     use Ada.Calendar;
with Process_Proxies;  use Process_Proxies;
with GNAT.OS_Lib;      use GNAT.OS_Lib;
with Debugger;         use Debugger;
with GVD.Types;        use GVD.Types;
with Gtk.Main;         use Gtk.Main;
with GVD.Preferences;  use GVD.Preferences;

procedure Test_Parse_Cpp is

   Gdb_Record : aliased Gdb_Debugger;
   Gdb        : Debugger_Access := Gdb_Record'Unchecked_Access;
   Language   : aliased Gdb_Cpp_Language;

   ---------------
   -- Print_Var --
   ---------------

   procedure Print_Var (Var : String) is
      V : Generic_Type_Access;
      T     : Time;
      Durat : Duration;
      Found : Boolean;
   begin
      Put_Line ("------------------------------");
      Put_Line ("PRINT " & Var);
      T := Clock;
      V := Parse_Type (Gdb, Var);
      Durat := Clock - T;
--      Put_Line ("Parsing type, time=" & Durat'Img);
      if V /= null then
         T := Clock;
         Parse_Value (Gdb, Var, V, Default_Format, Found);
         Durat := Clock - T;
--         Put_Line ("Parsing value, time=" & Durat'Img);
         Print (V.all);
      end if;

      New_Line;
   end Print_Var;

   List : Argument_List (1 .. 0);
   B    : Breakpoint_Identifier;

begin
   Init;
   GVD_Prefs := new GVD_Preferences_Manager;
   Register_Default_Preferences (GVD_Prefs, Page_Prefix => "General:");
   Load_Preferences (GVD_Prefs, "./preferences");

   Set_Language (Gdb, Language'Unchecked_Access);
   Set_Debugger (Language'Access, Gdb);

   Spawn (Gdb, "", List, "", new Process_Proxy, null);
   Initialize (Gdb);
   Set_Executable (Gdb, "parse_cpp");
   B := Break_Subprogram (Gdb, "foo");

   Run (Gdb);

   Print_Var ("Parse::Non_Existant_Variable");
   --  Check there is no error in that case.

   Print_Var ("main::A");
   Print_Var ("main::B");
   Print_Var ("main::C");
   Print_Var ("main::Sh");
   Print_Var ("main::L");
   Print_Var ("main::Uns");
   Print_Var ("main::UL");
   Print_Var ("main::S");
   Print_Var ("main::S2");
   Print_Var ("main::S3");
   Print_Var ("main::Act");
   Print_Var ("main::My_Enum_Variable");
   Print_Var ("main::T");
   Print_Var ("main::Ea");
   Print_Var ("main::Aoa");
   Print_Var ("main::U");
   Print_Var ("main::A3d");
   Print_Var ("main::Iaa");
   Print_Var ("main::V");
   Print_Var ("main::Anonymous_Var");
   Print_Var ("main::V2");
   Print_Var ("main::cl1");
   Print_Var ("main::cl2");
   Print_Var ("main::cl3");
   Print_Var ("main::cl4");
   Print_Var ("main::Mror");
   Print_Var ("main::Mrora");
   Print_Var ("main::Mrorpa");
   Print_Var ("main::Uni");
   Print_Var ("main::Uni2");
   Print_Var ("main::Uni3");
   Print_Var ("main::Mrwu");
   Print_Var ("main::as");
   Print_Var ("main::asa");
   Print_Var ("main::Mrws");
   Print_Var ("main::Mrws2");
   Print_Var ("main::tv");
   Print_Var ("main::list");
   Print_Var ("main::FC");
   Print_Var ("main::SC");
   Print_Var ("main::SAC");
   Print_Var ("main::MI");
   Print_Var ("main::NF");
   Close (Gdb);

exception
   when others =>
      Close (Gdb);
      raise;

end Test_Parse_Cpp;
