%{ 
/*****************************************************************/
/**                                                             **/
/**             (C) Copyright 1992 the Regents of the           **/
/**        University of California.  All Rights Reserved.      **/
/**                                                             **/
/**        This work was produced under the sponsorship of      **/
/**         the U.S. Department of Energy.  The Government      **/
/**                retains certain rights therein.              **/
/**                                                             **/
/**                         Written by                          **/
/**         Distributed Programming Environments Project        **/
/**           Computer Software and Networking Division,        **/
/**                   Livermore Computer Center,                **/
/**            Lawrence Livermore National Laboratory           **/
/**                                                             **/
/*****************************************************************/

#define _NO_EXTERN    /* see decls.h */ 
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "abs.h"
#include "decls.h"
#include "keytab.h"
#include "pnode.h"
#include "misc.h"
#include "gen_code.h"
#include "symtab.h"
#include "argument.h"

#define IS_PRIMITIVE(teptr) \
      (teptr->abstr_type_ptr->get_kind() != AKIND_RECORD && \
      teptr->abstr_type_ptr->get_kind() != AKIND_UNION &&  \
      teptr->abstr_type_ptr->get_kind() != AKIND_ARRAY)

#define STMTNOEXCEPT(stmt)\
	      active_instance_element *active_inst;						\
	      active_inst = active_instances_ptr->get_active_instance();			\
	      gen_exception_header(out,								\
				   active_inst->get_exception_label(),				\
				   active_inst->get_ok_label());				\
	      gen_default_handlers(out,MASK_ZERO,						\
				   active_inst->get_ok_label());				\
	      if (global.gen_log)								\
		 gen_log_statement(out,stmt,active_inst->get_inst_element_ptr()->get_name(),	\
				   active_inst->get_exception_label());				\
	      GEN_LINEDIR									\
	      fprintf(out,"}   /* End of stmt statement */");

%}

%union 
{

#ifndef HASHTEST

  /* Non-structure types, first */

  argument_list      *arg_list_ptr;
  enum arg_mode       arg_mode;
  argument	     *argument;
  int		      bufoffset;
  decl_element       *decl_eptr;
  list               *decl_list;
  enum arraykind      dynorstat;
  encoding_rules     *e_rules;
  boolean             explicit_tagged;
  boolean             has_func;
  enum implicitness   i_or_e_or_empty;
  int                 integer;
  instance_element   *instance_eptr;
  interface_element  *interface_eptr;
  list               *list_ptr;
  enum Handler_Masks  mask;
  name_element       *name_eptr;
  boolean             optional_seen;
  enum op_kind        op_kind;
  operation_element  *operation_eptr;
  parameter_list     *param_list_ptr;
  rules_element      *rules_eptr;
  boolean            *seen;
  enum paradigm       setorseq;
  char               *string;
  symbol_list        *symbol_list_ptr;
  type_element       *type_eptr;
  boolean             iswrapped;
  int		      free_seen;
  boolean             indirect_seen;

  /* structures */


  struct {
    list *list_ptr;
    int free_flag;
  } listptr_free;

  struct {
    enum abstr_kind 	abstr_kind;
    char		*len1;
    char		*len2;
    int			bufoffset;
  } 
  ak_len1_len2_bufoffset;

  struct {
    abstr_type_element  *ateptr;
    list		*lptr;
    boolean		optional_present;
    int                 free_flag;
  } 
  pres_ateptr_lptr_optional;

  struct {
    boolean 	 has_func;
    decl_element *decl_eptr;
  } 
  has_func_decl_eptr;

  struct {
    interface_element   *ieptr;
    int			bufoffset;
  } 
  ieptr_bufoffset;

  struct {
    interface_element   *ieptr;
    int                 is_control;
    int                 is_data;
    int                 is_typedef;
    int			bufoffset;
  } 
  ieptr_cdt_bufoffset;

  struct {
    boolean		is_typeid;
    type_element        *teptr;
    int			bufoffset;
  } 
  istypeid_teptr_bufoffset;

  struct {
    modal_list     *modals;
    parameter_list *ins;
    parameter_list *outs;
  } 
  modals_ins_outs;

  struct {
    operation_element   *oeptr;
    instance_element	*insteptr;
  } 
  oeptr_insteptr;

  struct {
    boolean auto_present;
    boolean autotagged;
  } 
  pres_auto;

  struct {
    boolean          mods_present;
    boolean          auto_present;
    boolean          autotagged;
    encoding_rules  *e_rules;
    paradigm         setorseq;
    boolean          optional_present;
    int              free_flag;
  } 
  pres_auto_erules_setorseq_optional;

  struct {
    boolean auto_present;
    boolean autotagged;
    boolean optional_present;
    int     free_flag;
  } 
  pres_auto_optional;

  struct {
    symbol_element      *septr;
    int			bufoffset;
    link		*lptr;
  } 
  septr_bufoffset_lptr;
  
  struct {
    int size;
    int index;
  } 
  size_index;

  struct {
    char *string1;
    char *string2;
  } 
  string1_2;

  struct {
    char *string1;
    char *string2;
    int bufoffset;
  } 
  string1_2_bufoffset;

  struct {
    char               *string;
    int			bufoffset;
  } 
  string_bufoffset;

  struct {
    char		*string;
    int			bufoffset;
    SymKind		sym;
    void		*ont;
  } 
  string_bufoffset_sym_ont;


  struct {
    boolean   optional_flag;
    boolean   default_flag;
    list     *lptr;
    char     *optionalv;
    char     *defaultv;
    int      free_flag;
  } 
  tag_attrib;

  struct {
    type_element        *teptr;
    int			bufoffset;
  } 
  teptr_bufoffset;

  struct {
    char		*val;
    char		*len;
  } 
  val_len;

  struct {
    char		*val;
    char		*len1;
    char		*len2;
  } 
  val_len1_len2;

#else

  int dummy;

#endif
}


/*
 *        ==========================================================
 *                            T  O  K  E  N  S 
 *        ==========================================================
 */

/*
 *      -----------------------
 *  	Params File tokens
 *      -----------------------
 */

%token	 BOOLEAN
%token	 INTEGER
%token	 REAL
%token	 SENDBUFFERSIZE
%token	 RECEIVEBUFFERSIZE
%token	 BIG_ENDIAN
%token	 LITTLE_ENDIAN
%token	 BIND
%token	 CONFIG_COMMENT

/*
 *          -----------------------
 *           elros-specific tokens
 *          -----------------------     
 */

%token	 <ieptr_bufoffset>	CONTROL_DECL
%token	 <ieptr_bufoffset>	DATA_DECL
%token	 <string>	        BIND_TYPE
%token	 <septr_bufoffset_lptr> INSTANCE_ID
%token	 			UNBIND
%token	 			ABORTINST
%token	 			FLUSHINST
%token	 			ENCODE
%token	 			DECODE
%token	 <oeptr_insteptr>	OPERATION_AT_INSTANCE
%token	 <name_eptr> 		PARAMETER_NAME
%token	 			GIVE
%token	 <operation_eptr> 	OPERATION_NAME
%token	 			ACCEPT
%token	 			ON
%token   <bufoffset>		EXCEPTION
%token	  			ONCOM_ERROR
%token	  			ONINTERNAL_ERROR
%token	  			ONPROTOCOL_ERROR
%token	  			ONMISSING_OP
%token	  			ONMISSING_ARG
%token	  			ONNAME_ERROR
%token	  			ONDONE
%token    			ONBAD_OP_ID


/*
 *         ----------------
 *          I-Spec tokens
 *         ----------------
 */

%token	  INVOKE
%token	  RESULT
%token	  ERROR_KEYWORD
%token	  REJECT_KEYWORD
%token	  CALL
%token	  NAMES

%token	 <ak_len1_len2_bufoffset> ELROS_BASE_TYPE
%token	  BITSTRING
%token	  ENUMERATED
%token	  GENERALSTRING
%token	  GRAPHICSTRING
%token	  IA5STRING
%token	  NULLTYPE
%token	  NUMERICSTRING
%token	  OBJECTIDENTIFIER
%token	  OCTETSTRING
%token	  PRINTABLESTRING
%token	  TELETEXSTRING
%token	  VIDEOTEXSTRING
%token	  VISIBLESTRING
%token	  ANY

%token	 <teptr_bufoffset>  TYPE_ID

%token	  INTERFACE
%token	  OPTIONAL
%token	  DEFAULT_KEYWORD

%token	  UNIVERSAL
%token	  APPLICATION
%token	  CONTEXT
%token	  PRIVATE
%token	  IMPLICIT
%token	  IMPLICIT_TAGS
%token	  EXPLICIT
%token	  EXPLICIT_TAGS


%token	  IDAT
%token	  IN
%token	  OUT
%token	  INOUT
%token	  RECORD
%token	  <dynorstat>	ARRAY
%token	  <dynorstat>	DYNAMICARRAY
%token	  UNION_KEYWORD
%token	  SET
%token	  SEQUENCE
%token	  AUTOTAG
%token	  NOAUTOTAG
%token    FREEABLE
%token    UNFREEABLE
%token	  END



/*
 *         ----------------
 *          C/elros tokens
 *         ----------------
 */

%token   END_CONFIG
%token <bufoffset>	 ELLIPSIS 

%token	 <string_bufoffset_sym_ont> IDENTIFIER

%token	 <string_bufoffset> STRING_CONST
%token   <string_bufoffset> CHAR_CONST
%token	 <string_bufoffset> BOOLEAN_CONST
%token	 <string_bufoffset> INTEGER_CONST
%token	 <string_bufoffset> REAL_CONST
%token	 <string_bufoffset> OBJ_ID_CONST
%token	 <string_bufoffset> HEX_CONST
%token	 <string_bufoffset> NATNUM_CONST

%token <bufoffset> 	 TYPEDEF_NAME

%token <bufoffset>	 LPAR
%token <bufoffset>	 RPAR
%token <bufoffset>	 LBRACE
%token <bufoffset>	 RBRACE
%token <bufoffset>	 LANGLE
%token <bufoffset>	 RANGLE
%token <bufoffset>	 LBRACK
%token <bufoffset>	 RBRACK
%token <bufoffset>	 COMMA
%token <bufoffset>	 SEMI
%token <bufoffset>	 EQUALS
%token <bufoffset>	 DOT
%token <bufoffset>	 AMPER
%token <bufoffset>	 BANG
%token <bufoffset>	 TILDE
%token <bufoffset>	 MINUS
%token <bufoffset>	 PLUS
%token <bufoffset>	 STAR
%token <bufoffset>	 SLASH
%token <bufoffset>	 PERCENT
%token <bufoffset>	 COMP
%token <bufoffset>	 BITOR
%token <bufoffset>	 QUES
%token <bufoffset>	 COLON
%token <bufoffset>	 SIZEOF
%token <bufoffset>	 PTR_OP 
%token <bufoffset>	 INC_OP 
%token <bufoffset>	 DEC_OP 
%token <bufoffset>	 LEFT_OP 
%token <bufoffset>	 RIGHT_OP 
%token <bufoffset>	 LE_OP 
%token <bufoffset>	 GE_OP 
%token <bufoffset>	 EQ_OP 
%token <bufoffset>	 NE_OP
%token <bufoffset>	 AND_OP 
%token <bufoffset>	 OR_OP 
%token <bufoffset>	 MUL_ASSIGN 
%token <bufoffset>	 DIV_ASSIGN 
%token <bufoffset>	 MOD_ASSIGN 
%token <bufoffset>	 ADD_ASSIGN
%token <bufoffset>	 SUB_ASSIGN 
%token <bufoffset>	 LEFT_ASSIGN 
%token <bufoffset>	 RIGHT_ASSIGN 
%token <bufoffset>	 AND_ASSIGN
%token <bufoffset>	 XOR_ASSIGN 
%token <bufoffset>	 OR_ASSIGN 
%token <bufoffset>	 ARROW

%token <bufoffset>	 TYPE_NAME

%token <bufoffset>	 TYPEDEF 
%token <bufoffset>	 EXTERN 
%token <bufoffset>	 STATIC 
%token <bufoffset>	 AUTO 
%token <bufoffset>	 REGISTER
%token <bufoffset>	 CHAR 
%token <bufoffset>	 SHORT 
%token <bufoffset>	 INT 
%token <bufoffset>	 LONG 
%token <bufoffset>	 SIGNED 
%token <bufoffset>	 UNSIGNED 
%token <bufoffset>	 FLOAT 
%token <bufoffset>	 DOUBLE 
%token <bufoffset>	 CONST 
%token <bufoffset>	 VOLATILE 
%token <bufoffset>	 VOID
%token <bufoffset>	 STRUCT 
%token <bufoffset>	 UNION 
%token <bufoffset>	 ENUM 

%token <bufoffset>	 STMT_LABEL

%token <bufoffset>	 CASE 
%token <bufoffset>	 DEFAULT 
%token <bufoffset>	 IF 
%token <bufoffset>	 ELSE 
%token <bufoffset>	 SWITCH 
%token <bufoffset>	 WHILE 
%token <bufoffset>	 DO 
%token <bufoffset>	 FOR 
%token <bufoffset>	 GOTO 
%token <bufoffset>	 CONTINUE 
%token <bufoffset>	 BREAK 
%token <bufoffset>	 RETURN


/*
 *        ==========================================================
 *                      N O N  -  T E R M I N A L S
 *        ==========================================================
 */


/*
 *  Params File Non-terminals
 */

%type <integer>    long_specs
%type <size_index> unsigned_type
%type <size_index> signed_type
%type <size_index> real_type


/*
 *  I-Spec Non-terminals
 */

%type <operation_eptr>             op_def

%type <setorseq>                   set_or_sequence
%type <explicit_tagged>            e_or_i_tagging_opt
%type <optional_seen>              optional_opt

%type <pres_auto_erules_setorseq_optional>  constructed_mod
%type <pres_auto_erules_setorseq_optional>  constr_mod_opt

%type <pres_auto>                  autotagging_opt
%type <pres_auto_optional>         union_spec_opt

%type <param_list_ptr>             param_name_list
%type <param_list_ptr>             param_type_list
%type <param_list_ptr>             op_param_list
%type <modals_ins_outs>            modal_names
%type <modals_ins_outs>            modal_types
%type <modals_ins_outs>            inout_list

%type <integer>                    nonuniv_class_name

%type <string_bufoffset>           op_value
%type <string_bufoffset>           constant
%type <string>                     interface_header
%type <arg_mode>                   mode

%type <tag_attrib>                 rec_elem2
%type <tag_attrib>                 rec_elem1
%type <listptr_free>               un_elem1
%type <tag_attrib>                 attributes
%type <tag_attrib>                 optional_attributes
%type <tag_attrib>                 default_attributes

%type <i_or_e_or_empty>            implicit_explicit_opt

%type <type_eptr>                  rec_def_prefix
%type <type_eptr>                  array_def_prefix
%type <pres_ateptr_lptr_optional>  array_constr
%type <dynorstat>                  array_d_or_s
%type <type_eptr>                  union_def_prefix
%type <type_eptr>                  type_spec
%type <type_eptr>                  rec_elem
%type <type_eptr>                  recun_elem
%type <type_eptr>                  un_elem
%type <type_eptr>                  rec_def
%type <type_eptr>                  var_def
%type <type_eptr>                  array_def
%type <type_eptr>                  union_def

%type <name_eptr>                  name_decl

%type <rules_eptr>                 nonuniv_modifier

%type <list_ptr>                   nonuniv_modifier_list
%type <list_ptr>                   tag_modifier_list
%type <listptr_free>               type_modifier_opt

%type <e_rules>                    tag_modifier_list_opt

%type <op_kind>                    res1

%type <symbol_list_ptr>            rec_list
%type <symbol_list_ptr>            un_list

%type <free_seen>		   free_mod_opt
%type <free_seen>		   free_mod
%type <indirect_seen>		   indirect_opt

/*
 *  ELROS  Non-terminals
 */

%type <string>			bind_stmt1
%type <string>			bind_stmt
%type <type_eptr>       	arrow_phrase
%type <val_len>			exp_with_optlen1
%type <val_len1_len2>		exp_with_optlen_1_or_2
%type <bufoffset>		lvaluep
%type <string_bufoffset>	len_1exp_opt
%type <string1_2_bufoffset>	len_2exp_opt
%type <mask>			on_stmts
%type <mask>			on_stmt
%type <string>			exception_stmt_arg_opt
%type <string1_2>		bracketed_expr_opt
%type <seen>			onop_stmts
%type <integer>			onop_stmt
%type <iswrapped>		ontype_stmt
%type <iswrapped>		ontype_stmts
%type <arg_list_ptr>		argument_list
%type <arg_list_ptr>		empty_arg_list
%type <arg_list_ptr>		ellipsis_arg_list
%type <arg_list_ptr>		positional_arg_list
%type <arg_list_ptr>		named_arg_list
%type <argument>		positional_arg
%type <argument>		named_arg

/*
 *  ELROS and I-Spec Non-terminals
 */

%type <istypeid_teptr_bufoffset>            elros_base_type

/*
 *  C Non-terminals
 */

%type <ieptr_cdt_bufoffset> decl_specs
%type <ieptr_cdt_bufoffset> storage_spec
%type <ieptr_cdt_bufoffset> qsm_specs
%type <ieptr_cdt_bufoffset> qs_specs
%type <ieptr_cdt_bufoffset> type_qual
%type <ieptr_cdt_bufoffset> lone_type_spec
%type <ieptr_cdt_bufoffset> multi_type_spec
%type <ieptr_cdt_bufoffset> base_type_spec
%type <ieptr_cdt_bufoffset> elros_type_spec

%type <string_bufoffset_sym_ont>identifier 
%type <has_func> 		struct_declarator_list 
%type <has_func> 		struct_declarator
%type <has_func_decl_eptr> 	declarator 
%type <has_func_decl_eptr> 	declarator2
%type <decl_eptr> 		init_declarator
%type <decl_list> 		init_declarator_list

%type <bufoffset> record_specifier
%type <bufoffset> record
%type <bufoffset> rec_spec_start
%type <bufoffset> rec_spec_body
%type <bufoffset> enum_specifier
%type <bufoffset> abstract_declarator2
%type <bufoffset> pointer
%type <bufoffset> labeled_statement
%type <bufoffset> compound_statement
%type <bufoffset> compound_statement1
%type <bufoffset> jump_statement
%type <bufoffset> selection_statement
%type <bufoffset> selection_statement1

%type <bufoffset> primary_expr
%type <bufoffset> postfix_expr
%type <bufoffset> argument_expr_list
%type <bufoffset> unary_expr
%type <bufoffset> unary_operator
%type <bufoffset> cast_expr
%type <bufoffset> multiplicative_expr
%type <bufoffset> additive_expr
%type <bufoffset> shift_expr
%type <bufoffset> relational_expr
%type <bufoffset> equality_expr
%type <bufoffset> and_expr
%type <bufoffset> exclusive_or_expr
%type <bufoffset> inclusive_or_expr
%type <bufoffset> log_and_expr
%type <bufoffset> log_or_expr
%type <bufoffset> cond_expr
%type <bufoffset> assignment_expr

%start everything
%%
