
/* contains the type declarations for expression handling information  
 *
 * $Header: c:\\cygwin\\cvsroot/Vert03/vertlib/expression.h,v 1.1.1.1 2003/11/04 23:34:57 mjames Exp $ 
 *
 * $Log: expression.h,v $
 * Revision 1.1.1.1  2003/11/04 23:34:57  mjames
 * Imported into local repositrory
 *
 * Revision 1.8  2002/10/02 19:37:30  MJAMES
 * Moved dummy functions to a separate support file.
 *
 * Used correct number of arguments to define_pin
 *
 * Revision 1.7  2002/09/30 13:22:38  MJAMES
 * Altered the use and creation of partition
 * generics (at evaluation time of expressions within the partition )
 * This still needs checking, as evaluation of the expression may well be
 * delayed until after when the partition generics need to be defined.
 *
 * Revision 1.6  2002/09/09 10:15:54  mjames
 * Modified expression parser to match CC as previous one was
 * broken
 *
 * Revision 1.5  2002/08/14 12:04:42  mjames
 * Added declaration for eval_expression
 *
 * Revision 1.5  2002/04/04 14:53:05  mjames
 * Added mentor board station reader to the portfolio
 *
 * Revision 1.4  2001/10/31 22:20:04  mjames
 * Tidying up problematical comments caused by CVS
 * 'intelligent' comment guessing
 *
 * Revision 1.3  2001/06/06 12:10:23  mjames
 * Move from HPUX
 *
 * Revision 1.2  2000/11/29 21:51:18  mjames
 * Fine tuning of software
 *
 * Revision 1.1.1.1  2000/10/19 21:58:37  mjames
 * Mike put it here
 *
 *
 * Revision 1.19  2000/10/04  10:37:15  10:37:15  mjames (Mike James)
 * Modified for Vertical2 : support COMPONENTS and SIGNALS
 * 
 * Revision 1.19  2000/10/04  10:37:15  10:37:15  mjames (Mike James)
 * Part of Release PSAVAT01
 * 
 * Revision 1.18  2000/10/02  11:04:12  11:04:12  mjames (Mike James)
 * new_vhdl
 * 
 * Revision 1.17  2000/09/27  14:42:30  14:42:30  mjames (Mike James)
 * Part of Release Sep_27_ST_2000
 * 
 * Revision 1.16  2000/09/21  10:16:00  10:16:00  mjames (Mike James)
 * Part of Release Sep21Alpha
 * 
 * Revision 1.15  2000/08/25  09:57:23  09:57:23  mjames (Mike James)
 * Part of Release Aug25_alpha
 * 
 * Revision 1.14  2000/08/16  08:57:40  08:57:40  mjames (Mike James)
 * Part of Release CD01_Aug2000
 * 
 * Revision 1.13  2000/08/14  14:45:19  14:45:19  mjames (Mike James)
 * Part of Release Aug_14_2000
 * 
 * Revision 1.12  2000/08/11  08:30:40  08:30:40  mjames (Mike James)
 * Part of Release Aug_11_2000
 * 
 * Revision 1.11  2000/08/09  10:31:57  10:31:57  mjames (Mike James)
 * Part of Release Aug__9_2000
 * 
 * Revision 1.10  2000/05/31  11:43:11  11:43:11  mjames (Mike James)
 * Part of Release May_31_2000
 * 
 * Revision 1.9  2000/05/08  17:01:46  17:01:46  mjames (Mike James)
 * Part of Release May__8_2000
 * 
 * Revision 1.8  2000/05/08  16:59:40  16:59:40  mjames (Mike James)
 * Part of Release May__8_2000
 * 
 * Revision 1.7  2000/05/08  16:57:16  16:57:16  mjames (Mike James)
 * Part of Release May__8_2000
 * 
 * Revision 1.6  2000/03/08  16:18:57  16:18:57  mjames (Mike James)
 * New version including PC
 * 
 * Revision 1.3  2000/01/20  15:58:58  15:58:58  mjames (Mike James)
 * Part of Release R22
 * 
 * Revision 1.2  99/12/22  11:15:39  11:15:39  mjames (Mike James)
 * Part of Release Dec_22_1999
 * 
 * Revision 1.1  99/06/25  14:36:23  14:36:23  mjames (Mike James)
 * Initial revision
 * 
 *  */
#if !defined _EXPRESSION
#define _EXPRESSION


/* constants for object types found at bottom of expressions */
#define EXP_CONSTANT   'C'
#define EXP_VAR_REF    'I'
#define EXP_BOOLEAN    'B'
#define EXP_VARIABLE   'V'
#define EXP_STRING     'S'
#define EXP_UNDEF_VAR  'U'
#define EXP_CHAR       'H'



/* decoding  recurse_generics 
 * 0: NO_RECURSE stop expanding generics when a constant encountered
 * 1: RECURSE_CONST expand generics until one found which does not contain an expression
 * 2: RECURSE_NUMBER: expand generics until all constants are exposed
 
 constant a : integer := 3;
 constant b : integer := a + 3;
 constant c : integer := b + a;
 
 for values of expand generics :
 value 0: 
 constant a : integer := 3;
 constant b : integer := a + 3;
 constant c : integer := b + a;
 
 value 1: 
 constant a : integer := 3;
 constant b : integer := a + 3;
 constant c : integer := (a+3) + a;
 
 value 2: 
 constant a : integer := 3;
 constant b : integer := (3) + 3;
 constant c : integer := ((3)+3) + (3);
 
 
  */

typedef enum { NO_RECURSE=0,RECURSE_CONST,RECURSE_NUMBER } generic_print_style;

struct generic_info;
/* see database.h for the description of expression_t */
/* expression data structures .. see expression.h for handler fns */
typedef struct exp {
  int opcode;
  union {
    char * s; /* pointer to string value */ 
    struct generic_info  * g; /* pointer to generic value */
    int    i;  /* integer part of expression */
    struct exp * e;
    int * ip; /* pointer to an integer somewhere */
    } left; /* values */
  union {
    char * s;  /* pointer to name */
    struct exp * e;
    } right;  /* name or expression */
  
  } expression_t;

/* place reference to a 'C' variable at the end of the tree branch */
extern expression_t * compile_variable_reference(int *v,char * s );

/* compiles a variable. When printing expression stop descent of the evaluation tree here */
extern expression_t * compile_variable(struct generic_info * gen , char * valname);

extern expression_t * compile_string(char * s);

extern expression_t * compile_char(char c);

/* an unelaborated variable reference (link at evaluation time */
extern expression_t * compile_reference(char * s);

/* compiles an integer constant */
extern expression_t * compile_constant(int k );  

extern expression_t * compile_constant_string(int k,char * s ) ;

/* compiles an boolean constant */
extern expression_t * compile_bool_constant(int k );  

extern expression_t * compile_bool_constant_string(int k,char * s ) ;


extern expression_t * compile_expression(int opcode, 
       expression_t * left,
       expression_t * right );  

extern void print_expression(FILE * f,expression_t * e,generic_print_style recurse_generics ) ;

extern void print_range_expression(FILE * f,expression_t * e,generic_print_style recurse_generics);

extern void print_msg_expression(FILE * f,char * s,expression_t * e );


/* this is actually returning the type of the generic */
extern int eval_gen_expression(
       struct generic_info * gen); 

extern int eval_vhdl_expression(expression_t * expr,
                         int * high,
                         int * low );

/*******************************************/
struct socket;/* pulled in from database.h */
struct vhdl;
/*******************************************/
extern expression_t * copy_expression(expression_t * src,struct socket  * skt);


extern struct vhdl * copy_vhdl(struct vhdl * vhdl,struct socket * skt); 

extern void free_expression(expression_t * expr);

extern int eval_expression(expression_t * e,struct generic_info ** generic_list);

#endif
