test_000.adb 4.72 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
------------------------------------------------------------------------------
--                                                                          --
--                           OCARINA COMPONENTS                             --
--                                                                          --
--                             T E S T _ 0 0 0                              --
--                                                                          --
--                                 B o d y                                  --
--                                                                          --
--                     Copyright (C) 2016 ESA & ISAE.                       --
--                                                                          --
-- Ocarina  is free software; you can redistribute it and/or modify under   --
-- terms of the  GNU General Public License as published  by the Free Soft- --
-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
-- sion. Ocarina 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.                     --
--                                                                          --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception,   --
-- version 3.1, as published by the Free Software Foundation.               --
--                                                                          --
-- You should have received a copy of the GNU General Public License and    --
-- a copy of the GCC Runtime Library Exception along with this program;     --
-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
-- <http://www.gnu.org/licenses/>.                                          --
--                                                                          --
--                 Ocarina is maintained by the TASTE project               --
--                      (taste-users@lists.tuxfamily.org)                   --
--                                                                          --
------------------------------------------------------------------------------

with Ocarina.Types;
with Ocarina.Namet;
with Locations;
with Ocarina.Output;

with Ocarina.Configuration;
with Ocarina.ME_AADL.Tokens;
with Ocarina.FE_AADL.Lexer;
with Ocarina.ME_AO4AADL.Tokens;
with Ocarina.FE_AO4AADL.Lexer;

with Ada.Command_Line;

procedure test_000 is
   use Ocarina.Types;
   use Ocarina.Namet;
   use Locations;
   use Ocarina.Output;
   use Ocarina;
   use Ada.Command_Line;

   package AADL_T renames Ocarina.ME_AADL.Tokens;
   package AADL_L renames Ocarina.FE_AADL.Lexer;
   package AO4AADL_T renames Ocarina.ME_AO4AADL.Tokens;
   package AO4AADL_L renames Ocarina.FE_AO4AADL.Lexer;

   use type AADL_T.Token_Type;
   use type AO4AADL_T.Token_Type;

   AO4AADL_Name    : Name_Id;
   AO4AADL_Present : Boolean := False;

   L : Location;

begin
   if Argument_Count /= 1 then
      Write_Line ("Usage test_000 <ocarina_source_dir>");
      return;
   end if;

   Ocarina.Initialize;
   Default_AADL_Version := AADL_V1;
   AADL_Version         := Default_AADL_Version;
   Ocarina.Configuration.Init_Modules;

   AO4AADL_Name := Get_String_Name ("ao4aadl");

   declare
      AADL_File  : constant String
        := Argument (1) & "/tests/ao4aadl/Test_Example.aadl";
   begin
      L := AADL_L.Load_File (Get_String_Name (AADL_File));
   end;

   --  We skip the AADL tokens until we find the AO4AADL annex

   AADL_L.Restore_Lexer (L);

   AADL_L.Scan_Token;

   while  AADL_L.Token /= AADL_T.T_EOF loop
      --  We exit the loop if the current token is T_Annex and the
      --  next is AO4AADL

      if AADL_L.Token = AADL_T.T_Annex then
         declare
            S : Location;
         begin
            AADL_L.Save_Lexer (S);
            AADL_L.Scan_Token;

            if AADL_L.Token = AADL_T.T_Identifier
              and then AADL_L.Token_Name = AO4AADL_Name
            then
               AO4AADL_Present := True;
               exit;
            end if;

            AADL_L.Restore_Lexer (S);
         end;
      end if;

      AADL_L.Scan_Token;
   end loop;

   if AO4AADL_Present then

      --  Skip {**
      AADL_L.Scan_Token;

      L := AADL_L.Token_Location;

      AO4AADL_L.Restore_Lexer (L);

      AO4AADL_L.Scan_Token;
      Write_Line (AO4AADL_L.Current_Token_Image);

      while AO4AADL_T.Token /= AO4AADL_T.T_EOF loop
         AO4AADL_L.Scan_Token;
         Write_Line (AO4AADL_L.Current_Token_Image);
      end loop;
   end if;

   Ocarina.Configuration.Reset_Modules;
   Ocarina.Reset;
end test_000;