/*****************************************************************/
/**                                                             **/
/**             (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           **/
/**                                                             **/
/*****************************************************************/

#ifndef ABS_H
#define ABS_H

/* This typedef appears first so that if HASHTEST is defined, it is the
 * only thing from this file that is included. HASHTEST is defined when
 * building the program to search for a perfect hash for the keyword
 * table. To compile keytab.c, this typedef is needed, but nothing else */

typedef enum {
	  AKIND_REAL,			/* 0 */
	  AKIND_BITSTRING,		/* 1 */
	  AKIND_OBJECTIDENTIFIER,	/* 2 */
	  AKIND_BOOLEAN,		/* 3 */
	  AKIND_INTEGER,		/* 4 */
	  AKIND_OCTETSTRING,		/* 5 */
	  AKIND_ENUMERATED,		/* 6 */
	  AKIND_NULL,			/* 7 */
	  AKIND_NUMERICSTRING,		/* 8 */
	  AKIND_PRINTABLESTRING,	/* 9 */
	  AKIND_TELETEXSTRING,		/* 10 */
	  AKIND_VIDEOTEXSTRING,		/* 11 */
	  AKIND_VISIBLESTRING,		/* 12 */
	  AKIND_IA5STRING,		/* 13 */
	  AKIND_GRAPHICSTRING,		/* 14 */
	  AKIND_GENERALSTRING,		/* 15 */
	  AKIND_ANY,			/* 16 */
	  AKIND_RECORD, 		/* 17 */
	  AKIND_ARRAY,			/* 18 */
	  AKIND_UNION,			/* 19 */
	  AKIND_UNKNOWN		        /* 20 - used as an initial value */
      } abstr_kind;

typedef enum {
	  NOVEC,INTVEC,REALVEC
      } kindofvec;

#ifndef HASHTEST

#include "decls.h"
#include "list.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

extern FILE *yyout;          /* file where dumps are put */

extern __RO_type_lengths __ROc_Real_lengths[3];
extern __RO_type_lengths __ROc_Integer_lengths[5];
extern __RO_type_lengths __ROc_SignedInteger_lengths[5];
extern __RO_type_lengths __ROc_NaturalNumber_lengths[5];
extern __RO_type_lengths __ROc_LogicalVector_lengths[5];
extern __RO_type_lengths __ROc_Boolean_lengths[5];

#ifndef TRUE
#define TRUE (0==0)
#endif
#ifndef FALSE
#define FALSE (0==1)
#endif

#define CLASS_UNIVERSAL   0
#define CLASS_APPLICATION 1
#define CLASS_CONTEXT     2
#define CLASS_PRIVATE     3

#define FORM_PRIMITIVE   0
#define FORM_CONSTRUCTED 1

#define NO_PARAM_LIST    0
#define NAMED_PARAM_LIST 1
#define TYPE_PARAM_LIST  2

#define GETACTIVEINST \
	 (active_instances_ptr->get_active_instance())
#define GETOKLAB 					\
	 (GETACTIVEINST 				\
	      ? GETACTIVEINST->get_ok_label()		\
	      : NULL)
#define GETEXCEPTIONLAB 				\
	 (GETACTIVEINST 			 	\
	   ? GETACTIVEINST->get_exception_label()	\
	   : NULL)
#define GETINSTELE					\
	 (GETACTIVEINST					\
	   ? GETACTIVEINST->get_inst_element_ptr()	\
	   : NULL)
#define GETINTERF					\
	 (GETINSTELE					\
	   ? GETINSTELE->get_interf()			\
	   : NULL)
#define GETCONSTNAME					\
	 (GETINTERF					\
	   ? GETINTERF->constant_table_name		\
	   : NULL)
#define GETIID						\
	 (GETACTIVEINST					\
	   ? GETACTIVEINST->get_iidvar()		\
	   : NULL)
#define GETLID						\
	 (GETACTIVEINST					\
	   ? GETACTIVEINST->get_lidvar()		\
	   : NULL)
#define GETINSTNAME					\
	 (GETINSTELE					\
	   ? GETINSTELE->get_name()			\
	   : NULL)

static char *primitive_name[] =  {
"Real",
"BitString",
"ObjectIdentifier",
"Boolean",
"Integer",
"OctetString",
"Enumerated",
"Null",
"NumericString",
"PrintableString",
"TeletexString",
"VideotexString",
"VisibleString",
"IA5String",
"GraphicString",
"GeneralString",
"Any",
"",
"",
""

// We don't need "Array", "Record", "Union", and "Unknown"
// since names above are only for primitive types.

};


void dump_interfaces(interface_list *);
void dump_instances(symbol_list *);
void dump_primitive_types(list *);
void dumpnamebuf();

/* A symbol_element contains the basic info about a symbol: its name, what
 * kind it is, and what interface it's from, if applicable. It is derived
 * from tree_link to provide a two-way linking mechanism; one for grouping
 * these things into lists, and another used by the symbol_table to chain
 * together multiply defined symbols with the same name */


class tree_link: public link {

   friend class symbol_table;

   protected:
      tree_link *tlptr;
   public:
      tree_link() {tlptr = NULL;}
      inline void set_tlptr(tree_link *t)
	{tlptr = t;}
      inline tree_link *get_tlptr()
	{return tlptr;}
};

class symbol_element: public tree_link {
   protected:
      char* name;
      SymKind kind;
      interface_element* interf;
   public:
      symbol_element();
      ~symbol_element(){}
      void set_name(char*);
      inline char* get_name()
	{return name;}
      inline void set_kind(SymKind k)
	{kind = k;}
      inline SymKind get_kind()
	{return kind;}
      inline void set_interf(interface_element* i)
	{interf = i;}
      inline interface_element* get_interf()
	{return interf;}
};

class symbol_list: public list {
   public:
      int search(char*,link *&);
};

class interface_list: public symbol_list {
   public:
      int srch_dcls(char*,link *&);
      int srch_ops(char*,link *&);
};

class instance_list: public symbol_list {
   public:
      void delete_instances(int bracedepth);
};

class primitive_list: public list {
   public:
      abstr_type_element* append_primitive(abstr_type_element*);
};

class type_element_ptr: public link {
   public:
      type_element *ptr;
      inline type_element_ptr(type_element *p) 
      { ptr = p; }
};

class type_element_list: public list {
/* used for lists of type_element_ptr's */
   public:
      void update_incomplete_types(type_element *teptr);
      void gen_encode_decode_routines(FILE*);
      void gen_free_routines(FILE*);
};

class printer_list: public list {
   public:
      void append_printer_element(printer_element*);
      void gen_print_routines(FILE*);
};

class printer_element: public link {
   protected:
      abstr_type_element *abstr_type_element_ptr;
   public:
      inline void set_abstr_type_element_ptr(abstr_type_element *ateptr)
	{abstr_type_element_ptr = ateptr;}
      inline abstr_type_element* get_abstr_type_element_ptr()
	{return abstr_type_element_ptr;}
      printer_element(abstr_type_element *ateptr);
      ~printer_element()
      {}
};

class interface_element: public symbol_element {
   public:
      symbol_list* operations_ptr;
      symbol_list* types_ptr;
      symbol_list* names_ptr;
      symbol_list* variables_ptr;
      char *constant_table_name;     /* name of constant table */
      char *information_name;        /* name of information table */

      optable_generator *optable_gen;
      constant_generator *constant_gen;  

      interface_element();
      interface_element(char *name);
      ~interface_element(){}
      void append_op(operation_element*);
      void dump_ops(int);
      void append_type(type_element*);
      void append_name(name_element*);
      void dump_types(int);
      void dump_names();
      void dump_variables();
      symbol_element *lookup_op(char * name);
      symbol_element *lookup_type(char * name);
      symbol_element *lookup_name(char * name);
      symbol_element *lookup_var(char * name);
      void free_recur_containers(FILE*out);
};

class operation_element: public symbol_element {

      friend class optable_generator;

      op_kind kind_op; 
      parameter_list* params_ptr;
      int internal_number;
      operation_element *inv_part;
      operation_element *res_part;
      modal_list *modal_list_ptr;
   public:
      char* op_num;
      operation_element();
      operation_element(op_kind,char*,char*,parameter_list*);
      operation_element
		  (op_kind k,
		  char* nam,
		  char* num,
		  modal_list* mlptr,
		  operation_element* oe_i,
		  operation_element* oe_r);
      operation_element(op_kind,char*,char*);
      ~operation_element(){}
      void process_call_arguments(
			  argument_list *callarglist,
			  argument_list *&inarglist,
			  argument_list *&outarglist);
      void set_op_num(char*);
      inline parameter_list *get_params_ptr()
      { return params_ptr;}
      inline op_kind get_kind_op()
      { return kind_op;}
      inline int get_internal_number()
      { return internal_number;}
      inline operation_element *get_inv_part()
      { return inv_part;}
      inline operation_element *get_res_part()
      { return res_part;}

      void process_arguments(argument_list *actual_arguments);
      void gen_give(FILE *output_file,
		    char *operation_identifier_expression,
		    char *link_identifier_expression,
		    argument_list *actual_arguments,
		    char *exception_label, 
		    boolean dont_V_semaphore=FALSE);

      void gen_accept_on(FILE *out,
			 argument_list *arglist,
			 boolean ellipses_present,
			 char *e_label,
			 boolean on_callop);
      void get_args_and_eoc(argument_list *al,
			    boolean ellipses_present,
			    char *e_label);
      void get_set_and_eoc(argument_list *al,
			   boolean ellipses_present,
			   char *e_label);
      void get_NULL_arg(char *e_label);
      void p_operation(int);
      void dump_params();
};

class encoding_rules {
   protected:
      list* rules_ptr;
   public:
      encoding_rules();
      encoding_rules(list*);
      ~encoding_rules() {}
      inline list *get_rules_ptr()
      { return rules_ptr;}
      void reconcile();
      int eoc_count();
      __RO_int32 tag_value(int which);
};

class conc_part_element: public encoding_rules {
   protected:
      int encoded_offset;
      int encoded_length;
      boolean optional_flag;
      char* optional_value;
      char* optional_name;
      boolean default_flag;
      char* default_value;
      char* default_name;
   public:
      conc_part_element();
      virtual ~conc_part_element(){}
      void encode(bytearray &,char *);
      void gen_name(char *& default_or_optional_name);

      inline void set_optional_flag(boolean b)
      { optional_flag = b; }
      inline boolean get_optional_flag()
      { return optional_flag; }

      inline void set_optional_value(char* nv)
      { optional_value = nv; }
      inline char* get_optional_value()
      { return optional_value; }

      inline void set_default_flag(boolean b)
      {default_flag = b;}
      inline boolean get_default_flag()
      {return default_flag;}

      inline void set_default_value(char* dv)
      {default_value = dv;}
      inline char* get_default_value()
      {return default_value;}

      inline int get_encoded_offset()
      {return encoded_offset;}

      inline int get_encoded_length()
      {return encoded_length;}
};

class type_element: public symbol_element, public conc_part_element{
   public:
      int element_number; /* for records and unions */
      abstr_type_element* abstr_type_ptr;
      char *type_name;
      boolean indirect; 
      int freeable;  /* -1 if not defined; 0 if not freeable; 1 if freeable */

      type_element();
      type_element(char*,char*);
      type_element(char*,char*,list*,int,boolean);
      type_element(abstr_type_element*,list*,boolean,int);
      type_element(char*,abstr_type_element*,list*,int,int,boolean);
      type_element(char*,abstr_type_element*,rules_element*);
      type_element(type_element*,list*,int,boolean);
      ~type_element(){}

      void p_type_element(int);
      void dump_rules(int);
      list *leading_tags;
      list *get_leading_tags();
      void gen_leadingTAG_cases(FILE *out, int indent); 
      void gen_leadingTAG_iftest(FILE *out, int indent);
      void gen_consts(FILE *output_file);
      char *gen_val_const(char *value,unsigned long*nelems);
      void gen_copy_default(FILE*,int,char*);
      void set_type_name(char *);


      void gen_sendP
		   (FILE *out, 
		    int indent, 
		    char *source, 
		    char *source_len,
		    char *instname,
		    char *const_tab_name, 
		    char *e_label, 
		    boolean toplevel = TRUE,
		    boolean gen_for_ROn = FALSE);
      void gen_sendP_PRIMITIVE
		   (FILE *out, 
		    int indent, 
		    char *source, 
		    char *e_label, 
		    boolean toplevel, 
		    char *valuevar, 
		    char *instname,
		    char *const_tab_name);
      void gen_sendP_RECORD
		   (FILE *out, 
		    int indent, 
		    char *source, 
		    char *e_label, 
		    boolean toplevel, 
		    char *valuevar, 
		    char *instname,
		    char *const_tab_name,
		    boolean gen_for_ROn = FALSE);
      void gen_sendP_UNION
		   (FILE *out, 
		    int indent, 
		    char *source, 
		    char *e_label, 
		    boolean toplevel, 
		    char *valuevar, 
		    char *instname,
		    char *const_tab_name,
		    boolean gen_for_ROn = FALSE);
      void gen_sendP_ARRAY
		   (FILE *out, 
		    int indent, 
		    char *source, 
		    char *source_len, 
		    char *e_label, 
		    boolean toplevel, 
		    char *valuevar, 
		    char *instname,
		    char *const_tab_name,
		    boolean gen_for_ROn = FALSE);
      void gen_sendP_Vector
		   (FILE *out,
		    int z,
		    char *source,
		    char *source_len,
		    char *e_label,
		    boolean toplevel,
		    char *valuevar,
		    char *instname,
		    char *const_tab_name,
		    type_element* component,
		    char *int_or_real);
      void gen_getP
		   (FILE *output_file,
		    int indentation_level,
		    char *target_expression,
		    char *target_length_expression,
		    char *exception_label,
		    char *instname,
		    boolean top_level_expression = TRUE,
		    boolean gen_for_ROd = FALSE);
      void gen_getP_PRIMITIVE
		   (FILE *output_file,
		    int indentation_level,
		    char *target_expression,
		    char *exception_label,
		    char *instname,
		    boolean top_level_expression,
		    char *target_expression_workspace);
      void gen_getP_RECORD_Set
		   (FILE *output_file,
		    int indentation_level,
		    char *target_expression,
		    char *exception_label,
		    char *instname,
		    boolean top_level_expression,
		    char *target_expression_workspace);
      void gen_getP_RECORD_Sequence
		   (FILE *output_file,
		    int indentation_level,
		    char *target_expression,
		    char *exception_label,
		    char *instname,
		    boolean top_level_expression,
		    char *target_expression_workspace);
      void gen_getP_UNION
		  (FILE *output_file,
		   int indentation_level,
		   char *target_expression,
		   char *exception_label,
		   char *instname,
		   boolean top_level_expression,
		   char *target_expression_workspace);
      void gen_getP_ARRAY
		   (FILE *output_file,
		    int indentation_level,
		    char *target_expression,
		    char *target_length_expression,
		    char *exception_label,
		    char *instname,
		    boolean top_level_expression,
		    char *target_expression_workspace);
      void type_element::gen_getP_Vector
		   (FILE *out,
		    int z,
		    char *target,
		    char *target_len,
		    char *e_label,
		    char *instname,
		    boolean toplevel,
		    char *variable,
		    type_element *component,
		    char *int_or_real);
      void dump_val_const
       (FILE*out,char *name,char *value,unsigned long nelems);
      void dump_value
       (FILE *out,char *value,char *name,unsigned long nelems);
      void dump_list
       (FILE *output_file,void *charptr,unsigned long bytes);
      void type_element::gen_encode_decode
       (FILE *out, int n_or_d);
      void gen_free_routine(FILE*);
};

class name_element: public symbol_element {

      friend class param_element;

      type_element* type_element_ptr;
      int usage;
   public:
      name_element();
      ~name_element(){}
      inline type_element *get_type_element_ptr()
      { return type_element_ptr; }
      inline void set_type_element_ptr(type_element *tep)
      { type_element_ptr = tep; }
      inline void set_usage(int u)
      { usage = u; }
      void p_name_element(int);
};

class instance_element: public symbol_element {

      friend class active_instance_list;
      friend class instance_list;

      inst_type type;
      int bracedepth;
   public:
      instance_element();
      instance_element(char* name, int bracedepth, 
		       interface_element* ieptr,inst_type t);
      ~instance_element(){}
      inline interface_element *get_interf()
      { return interf; }
      inline inst_type get_type()
      { return type; }
      void p_instance(int indent);
};

class abstr_type_element: public link {

      friend class type_element;
      friend class type_element_list;
      friend class optable_generator;
      friend class argument;

   protected:
      abstr_kind kind;
      int length;
      int length2;
      char* typedef_name;
      unsigned long element_count;  /* for arrays */
      paradigm setorseq;  /* records and arrays */
      boolean autotagged; /* record and union */
      symbol_list* components;
      char *print_name;
      char *free_name;    /* for records,arrays,unions */
      char *encode_name;
      char *decode_name;
      boolean pointer_already;
      arraykind dynorstat;
      kindofvec veckind;

   public:
      abstr_type_element();
      abstr_type_element(abstr_kind,symbol_list*);
      abstr_type_element(abstr_kind,symbol_list*,boolean);
      abstr_type_element(abstr_kind,
			 symbol_list*,
			 boolean,
			 paradigm);
      abstr_type_element(abstr_kind,
			 boolean,
			 paradigm,
			 arraykind);
      abstr_type_element(abstr_kind,int,int);
      ~abstr_type_element(){}
      void p_abstr_type(int);
      void dump_components(int);
      void gen_typedef(FILE*,char*);
      void gen_type(FILE*, int, char*);
      void putout_type(FILE*,char*,char*,__RO_type_lengths*);
      void gen_print_decl(FILE*);
      void gen_print(FILE*);

      inline void set_length(int l)
      { length = l; }
      inline abstr_kind get_kind()
      { return (kind); }
      inline int get_length()
      { return (length); }
      inline int get_length2()
      { return (length2); }
      inline void set_typedef_name(char* name)
      { typedef_name = name; }
      inline char* get_typedef_name()
      { return (typedef_name); }
      inline void set_components(symbol_list *l)
      { components = l; }
      inline symbol_list* get_components()
      { return (components); }
      inline void set_count(int ec)
      {element_count = ec;}
      inline boolean get_autotagged()
      {return autotagged;}
      inline paradigm get_setorseq()
      {return setorseq;}
      inline arraykind get_dynorstat()
      {return dynorstat;}
      inline void set_veckind(kindofvec k)
      {veckind = k;}
      void tag_elements(boolean);
};

class tag_element: public link {
      __RO_int32 tag_bytes;
   public:
      tag_element(__RO_int32);
      ~tag_element() {}
      inline __RO_int32 get_tag_bytes()
      { return tag_bytes; }
};
      
class rules_element: public link {
      int tag_class;
      int tag_form;
      unsigned int tag_value;
      boolean implicit_flag;
   public:
      rules_element();
      ~rules_element(){}
      rules_element(abstr_kind,paradigm);            /* records and arrays */
      rules_element(abstr_kind);                     /* all other kinds    */
      rules_element(int,int,int,implicitness);
      rules_element(rules_element*);
      inline void set_form(int f)
      { tag_form = f; }
      inline int get_form()
      { return tag_form; }
      void p_rule(int);
      __RO_int32 class_and_value();
      void encode(bytearray &);
      inline void set_implicit_flag(boolean i)
      { implicit_flag = i; }
      inline boolean get_implicit_flag()
      { return implicit_flag; }

};

class param_element: public link {
      type_element* type_element_ptr;
      name_element* name_ptr;
      arg_mode mode;
      int list_position;
      char *num_id;
   public:
      param_element(name_element *ne,
		    arg_mode m,
		    int position);
      param_element(type_element *te,
		    arg_mode m,
		    int position);
      ~param_element(){}
      inline void set_type_element_ptr(type_element* te)
      { type_element_ptr = te;}
      inline type_element *get_type_element_ptr()
      { return type_element_ptr;}
      inline void set_name_ptr(name_element* ne)
      { name_ptr = ne;}
      inline name_element *get_name_ptr()
      { return name_ptr;}
      inline void set_mode(arg_mode am)
      { mode = am;}
      inline arg_mode get_mode()
      { return mode;}
      inline int get_list_position()
      { return list_position;}
      void p_param();
      inline void set_num_id(char* c)
      { num_id = c;}
      inline char *get_num_id()
      { return num_id;}
};

class parameter_list: public list {
      int pos_or_named;
      boolean wrapping;
      boolean unwrapped_Any_present;
   public:
      parameter_list();
      parameter_list(int);
      ~parameter_list(){}
      inline void set_wrapping(boolean b)
      { wrapping = b;}
      inline boolean get_wrapping()
      { return wrapping;}
      inline void set_pos_or_named(int porn)
      { pos_or_named = porn;}
      inline int get_pos_or_named()
      { return pos_or_named;}
      inline void set_unwrapped_Any_present(boolean b)
      { unwrapped_Any_present = b;}
      inline boolean get_unwrapped_Any_present()
      { return unwrapped_Any_present;}
      void dump_parameter_list();
      void auto_tag();
      void resolve(argument_list *actual_arguments);
};

class modal_param: public link {
      friend class modal_list;
   protected:
      param_element *in;
      param_element *out;
   public:
      modal_param(param_element *in, param_element *out);
      ~modal_param() {}
      char *get_name();
};

class modal_list: public list {
      int pos_or_named;
   public:
      modal_list(int);
      ~modal_list() {}
      inline int get_pos_or_named()
      { return pos_or_named;}
      void resolve(argument_list*,
		   argument_list*,
		   argument_list*);
      char* get_name();
};

class active_instance_element: public link {

      friend class active_instance_list;

      instance_element* inst_element_ptr;
      char *exception_label;
      char *ok_label;
      char *iidvar;
      char *lidvar;
   public:
      active_instance_element();
      active_instance_element(instance_element*,
			      char *el,
			      char *ol);
      active_instance_element(instance_element*,
			      char *el,
			      char *ol,
			      char *iid,
			      char *lid);
      ~active_instance_element(){}
      inline instance_element* get_inst_element_ptr()
	{return inst_element_ptr;}
      inline char* get_exception_label()
	{return exception_label;}
      inline char* get_ok_label()
	{return ok_label;}
      inline char* get_iidvar()
	{return iidvar;}
      inline char* get_lidvar()
	{return lidvar;}
};

class active_instance_list: public list {
   public:
      inline void delete_active_instance()
      {
	 link *tmplinkptr;
	 reset();
	 getnext(tmplinkptr);
      }
      active_instance_element *get_active_instance();
};


/************************************ dmatrix.h *******************************/
#define DMATRIX_ELEMENT long

class dmatrix
{
protected:
   int rows,cols;
   DMATRIX_ELEMENT *values;

   boolean lesscol(int l, int r);
   void range_check(const int r, const int c)
   {
      if (r<0 || r>rows-1 || c<0 || c>cols-1)
      {
         printf("dmatrix range error\n");
         exit(1);
      }
   }

public:
   dmatrix(int r,int c);
   ~dmatrix();

   DMATRIX_ELEMENT get(int r,int c)
   { range_check(r,c); return(values[r*cols+c]); }

   void put(int r,int c,DMATRIX_ELEMENT val)
   { range_check(r,c); values[r*cols+c] = val; }

   void sort();

   void print(FILE *,char *);

};

/***************************** end of dmatrix.h *******************************/

/************************************** bytes.h *******************************/

class singlebyte: public link
{
protected:
   unsigned char value;
   char *comment;

public:

   singlebyte(unsigned char v)
   {value = v; comment=NULL; }
   ~singlebyte()
   {}

   void set_comment(char *c)
   { comment = (char*)malloc(strlen(c)+1); strcpy(comment,c); }

   void print(FILE *,int);

};

class bytearray: public list
{
public:

   int offset()
   { return (length());}
   void generate(FILE *,char *);

};
/******************************* end of bytes.h *******************************/

/**********************************  gen_optables.h ***************************/

struct opoid_skeleton
{
   int size;
   long comp[1];
};

void encode_op_Integer(bytearray &blist, long *);
void encode_op_ObjectIdentifier(bytearray &blist, struct opoid_skeleton *);
void encode_op_length(bytearray &blist, int *);

class operation_link: public link
{
   friend class optable_generator;

   operation_element *op;
   struct opoid_skeleton *opoid;
   int give_offset,give_length;
   int arg_offset;


   operation_link()
   {}
   operation_link(operation_link *opl)
   {
      op = opl->op;
      opoid = opl->opoid;
   }
   ~operation_link()
   {}

	/* Convert the operation's 'operation_number' string into 'opoid';
	   Return the size of the OID (Integers = 1, Rejects = 2) */
   int convert();
};

class optable_generator
{
protected:
   list all;
   bytearray give_encodes;
   char printtable_name[64];
   char freetable_name[64];
   char give_encodes_name[64];
   char arg_table_name[64];
   char givetable_name[64];
   char accepttables_name[64];
   int maxoidsize;
   int maxnest;

   void gen_printtable(FILE *output_file);
   void gen_freetable(FILE *output_file, type_element_list *freelist);
   void gen_argtable(FILE *output_file);
   void gen_givetable(FILE *output_file);
   void gen_accepttable(FILE *output_file,
			list *operation_list,
			op_kind kind_op,
			char operation_character);

	/* Builds an oid-tree from a matrix of oid's */
   int accept_descend(dmatrix & opoid_matrix,
			int row,
			int column_to_begin_descent,
			int column_to_end_descent,
			struct acceptnum **oid_subtree_ptr);
			/* RETURNs total number of nodes */

	/* Numbers the nodes and fills in childlow and childhigh values */
   int accept_number(struct acceptnum *oid_tree,
			int &total_descent_depth);
			/* RETURNs 1-level descent depth */

	/* generates an accept_table */
   void accept_gen(FILE *output_file,
			struct acceptnum *oid_tree);


public:
   optable_generator()
      { maxoidsize = 0; }
   ~optable_generator()
   {}

   void add_operation(operation_element *operation_to_be_added);
   void generate(FILE *output_file);

   int operation_count()
   { return(all.length()); }

};


/**************************** end of gen_optables.h ***************************/
/*******************************  gen_consts.h ********************************/
class constant_generator
{
   protected:
   bytearray constant_bytes;

   public:
      constant_generator() {}
      ~constant_generator() {}

      void add_encoding(type_element *);
      void add_encoding(name_element *);
      void generate(FILE *);
};

/****************************** end of gen_consts.h ***************************/

/* The first #endif is for #ifndef HASHTEST at the top of the file */

#endif 

#endif
