------------------------->  GNU Sather - sourcefile  <-------------------------
-- Copyright (C) 1995 by International Computer Science Institute            --
-- This file is part of the GNU Sather package. It is free software; you may --
-- redistribute  and/or modify it under the terms of the  GNU General Public --
-- License (GPL)  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 Doc/GPL for more details.        --
-- The license text is also available from:  Free Software Foundation, Inc., --
-- 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA                     --
-------------->  Please email comments to <bug-sather@gnu.org>  <--------------

-- as.sa: The Abstract Syntax tree representation for the Sather compiler.
-------------------------------------------------------------------
-- $AS_NODE: Supertype of all abstract syntax tree nodes.
-- AS_NODE: Implementation to be included by $AS_NODE nodes.
-- 
-- AS_CLASS_DEF: Class definitions. 
-- 
-- Other tree components: AS_PARAM_DEC, AS_TYPE_SPEC,
-- AS_ARG_DEC, AS_FEAT_MOD, AS_CASE_WHEN, AS_TYPECASE_WHEN, 
-- AS_PROTECT_WHEN
--
-- Each tree node class descends from $AS_NODE and has a name starting
-- with AS_. The rest of the name is the name of the corresponding 
-- grammar production from the 1.0 spec using the suffixes:
-- "_DEC" for declarations, "_DEF" for definitions, "_ELT" for elements,
-- "_EXPR" for expressions, "_LIST" for lists, "_SPEC" for 
-- specifications, "_STMT" for statements
--
-- Single classes sometimes represent several productions.
-- Whenever a comment says "if any" that means that "void" is a possible
-- value and it indicates the the component was not present.
-- 
-------------------------------------------------------------------
abstract class $AS_NODE < $PROG_ERR is
   -- A supertype of all nodes in the tree representation.
   source:SFILE_ID;
   source(s:SFILE_ID);
   --am_node(a:$AM);        -- MP
   --am_node:$AM;
end;
   
-------------------------------------------------------------------
class AS_NODE is
   -- A supertype of all nodes in the tree representation.
   
   attr source:SFILE_ID; -- The origin of a node in a Sather 
      -- source file.
      
   --attr am_node:$AM;   -- MP
   
   create: SAME is
      -- A new object with default initialization.
      return new end;
   
end; -- class AS_NODE

-------------------------------------------------------------------
class AS_CLASS_DEF < $AS_NODE is
   -- The definition of a class.
   include AS_NODE;
   include NEXT{SAME};		-- Next class in the list.
   
   const unused:INT:=0;
   const imm:INT:=1;		-- Value class.
   const ref:INT:=2;		-- Reference class.
   const abs:INT:=3;		-- Abstract class.
   const part:INT:=4;           -- Partial class.
   
   const c_ext:INT:=5;		-- External C class.
   const fortran_ext:INT:=6;    -- External Fortran class
   const spr:INT:=7;		-- Spread class (pSather).

   attr kind:INT;		-- One of imm, ref, abs, ext.
   attr name:IDENT;		-- Name of the class.
   attr params:AS_PARAM_DEC;	-- List of parameter declarations, 
      -- if any.
   attr under:AS_TYPE_SPEC;	-- List of parents in the type graph.
   attr over:AS_TYPE_SPEC;	-- List of over children in the type graph.
   attr body:$AS_CLASS_ELT;	-- The body of the class.
end;

-------------------------------------------------------------------
class AS_PARAM_DEC < $AS_NODE is
   -- The declaration of a parameter for a class.
   include AS_NODE;
   include NEXT{SAME};		-- Next parameter, if any.
   
   attr name:IDENT;		-- Index of parameter name.
   attr type_constraint:AS_TYPE_SPEC; -- Type constraint for type, 
      -- if any.
end;

-------------------------------------------------------------------
class AS_TYPE_SPEC < $AS_NODE is
   -- A type specifier.
   include AS_NODE;
   include NEXT{SAME};		-- Next parameter, if any.   
   
   const ord:INT:=0;		-- Abstract, immutable, reference, partial 
                                -- or external.
   const rt:INT:=1;		-- Bound routine type.
   const it:INT:=2;		-- Bound iter type.
   const same:INT:=3;		-- "SAME".
   const f_rt:INT:=4;           -- Bound fortran routine

   attr kind:INT;		-- One of ord, rt, it, f_rt, or same.
   attr is_hot:BOOL;			-- True if this is a specifier
    -- for a hot bound iter argument type.
   attr name:IDENT;		-- Name of the type, void for bound types.
   attr params:AS_TYPE_SPEC;	-- For ordinary types, these are the
      -- parameters specifiers, if any. For bound types, these are the 
      -- argument type specifiers.
   attr mode:AS_ARG_MODE;       -- Argument mode for bound types
   attr ret:AS_TYPE_SPEC;	-- Return type spec for bound types.
end;

-------------------------------------------------------------------

class AS_ARG_MODE is
-- argument modes
    include NEXT{SAME}; -- mode of the next arg
 
    readonly shared in_mode:INT := 1;
    readonly shared out_mode:INT := 2;
    readonly shared inout_mode:INT := 3;
    readonly shared once_mode:INT := 4;

    attr mod:INT;

    create(m: INT): SAME is
	res ::= new;
	res.mod := m;
	return res;
   end;
   
   is_out_inout : BOOL is
      if mod = out_mode or mod = inout_mode then
	 return true;
      else
	 return false;
      end;
   end;
end;
