------------------------------------------------------------------------------
--                                                                          --
--                           ASIStint COMPONENTS                            --
--                                                                          --
--                       A S I S T I N T . T A B L E                        --
--                                                                          --
--                                 S p e c                                  --
--                                                                          --
--            Copyright (c) 1997, Free Software Foundation, Inc.            --
--                                                                          --
-- ASIStint is free software; you can redistribute  it  and/or  modify  it  --
-- under terms of the GNU General Public License  as published by the  Free --
-- Software Foundation;  either version 2,  or  (at your option)  any later --
-- version.  ASIStint  is distributed  in the hope  that it will be useful, --
-- but  WITHOUT  ANY  WARRANTY;  without even the implied warranty of  MER- --
-- CHANTABILITY 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  distributed with ASIStint; see file COPYING. --
-- If not, write to the  Free  Software  Foundation,  59 Temple Place Suite --
-- 330, Boston, MA 02111-1307, USA.                                         --
--                                                                          --
-- ASIStint  was  originally  developed  by  the  ASIS-for-GNAT team at the --
-- Software Engineering  Laboratory  of  the  Swiss  Federal  Institute  of --
-- Technology (LGL-EPFL) in Lausanne, Switzerland, in cooperation with  the --
-- Scientific  Research  Computer  Center  of Moscow State University (SRCC --
-- MSU), Russia.                                                            --
--                                                                          --
-- This work was supported by a  grant  from  the  Swiss  National  Science --
-- Foundation, no 7SUPJ048247, funding a project entitled  "Development  of --
-- ASIS for GNAT with industry quality".                                    --
------------------------------------------------------------------------------

with ASIS;
with ASIS.Text;
with ASIStint.Common; use ASIStint.Common;
with ASIStint.XTable; use ASIStint.XTable;

package ASIStint.Table is

------------------------------------------------------------------------------
-- This package provides handling of ASIStint language variable tables
------------------------------------------------------------------------------

  subtype Var_Name is Name_String;

  type Var_Type is
  (
    Par_Absent,

    Par_ATime,
    Par_Boolean,
    Par_Context,
    Par_CUnit,
    Par_CUnitList,
    Par_ElemList,
    Par_Element,
    Par_Integer,
    Par_Line,
    Par_String,
    Par_Span,
    Par_XXXXX -- for not implemented types
  );
  -- Type to represent variable types


  Type Query_Result ( RType: Var_Type := Par_Absent ) is
    record
      case RType is
        when Par_Absent    => null;
        when Par_String    => S:  String_Ptr;
        when Par_Boolean   => B:  Boolean;
        when Par_CUnit     => C:  ASIS.Compilation_Unit;
        when Par_CUnitList => CL: CUnitList_Ptr;
        when Par_Element   => E:  ASIS.Element;
        when Par_ElemList  => EL: ElemList_Ptr;
        when Par_Context | Par_Integer
                           => I:  Integer;
        when Par_Line      => L:  ASIS.Text.Line;
        when Par_Span      => Sp: ASIS.Text.Span;
        when others        => null;
      end case;
    end record;
  -- Universal ASIStint expression representation


  type Var_Info is
    record
      Name:    Var_Name;
      VType:   Var_Type;
      IValue:  Integer;
      SValue:  String_Ptr;
    end record;

  Var_Unknown: constant Var_Info :=
    ((1..MAX_ID_LENGTH => ' '), Par_Absent, 0, null);

  type V_Table is array (Positive range <>) of Var_Info;
  type V_TablePtr is access all V_Table;

  type Var_Table is
    record
      Free:  Positive;
      Max:   Positive;
      Table: V_TablePtr;
    end record;

  CurTable: Var_Table := (1, MAX_VARIABLES, new V_Table(1..MAX_VARIABLES));

  function  Get_Var    (T: Var_Table; N: Wide_String) return Var_Info;
  -- Scans for the variable in table T. Returns Var_Unknown if fails.

  function Get_Var_Value ( VI : Var_Info ) return Query_Result;
  -- Returns variable value information

  function Store_Var_Value ( QR : Query_Result ) return Var_Info;
  -- Stores value information in variable

  procedure Modify_Var (T: in out Var_Table; V: Var_Info);
  -- Adds/changes variable

end ASIStint.Table;