2000-05-28 13:40:48 +00:00
|
|
|
/*
|
|
|
|
* expr.h
|
|
|
|
*
|
|
|
|
* Ullrich von Bassewitz, 21.06.1998
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef EXPR_H
|
|
|
|
#define EXPR_H
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "datatype.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* data */
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Defines for the flags field of the expression descriptor */
|
2001-08-03 06:45:22 +00:00
|
|
|
#define E_MREG 0x0110U /* Special: Expression is primary register */
|
|
|
|
#define E_MGLOBAL 0x0080U /* Reference to static variable */
|
|
|
|
#define E_MLOCAL 0x0040U /* Reference to local variable (stack offset) */
|
|
|
|
#define E_MCONST 0x0020U /* Constant value */
|
|
|
|
#define E_MEXPR 0x0010U /* Result is in primary register */
|
|
|
|
#define E_MEOFFS 0x0011U /* Base is in primary register, const offset */
|
|
|
|
|
|
|
|
#define E_MCTYPE 0x0007U /* Type of a constant */
|
|
|
|
#define E_TCONST 0x0000U /* Constant */
|
|
|
|
#define E_TGLAB 0x0001U /* Global label */
|
|
|
|
#define E_TLIT 0x0002U /* Literal of some kind */
|
|
|
|
#define E_TLOFFS 0x0003U /* Constant stack offset */
|
|
|
|
#define E_TLLAB 0x0004U /* Local label */
|
|
|
|
#define E_TREGISTER 0x0005U /* Register variable */
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
/* Defines for the test field of the expression descriptor */
|
2001-08-03 06:45:22 +00:00
|
|
|
#define E_CC 0x0001U /* expr has set cond codes apropos result value */
|
|
|
|
#define E_FORCETEST 0x0002U /* if expr has NOT set CC, force a test */
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
/* Describe the result of an expression */
|
2001-07-17 21:24:19 +00:00
|
|
|
typedef struct ExprDesc ExprDesc;
|
|
|
|
struct ExprDesc {
|
2000-05-28 13:40:48 +00:00
|
|
|
struct SymEntry* Sym; /* Symbol table entry if known */
|
2001-07-17 21:29:21 +00:00
|
|
|
type* Type; /* Type array of expression */
|
2001-07-17 21:53:17 +00:00
|
|
|
long ConstVal;/* Value if expression constant */
|
|
|
|
unsigned short Flags;
|
|
|
|
unsigned short Test; /* */
|
|
|
|
unsigned long Name; /* Name or label number */
|
2000-05-28 13:40:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* code */
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-09-09 20:49:20 +00:00
|
|
|
void ConstSubExpr (int (*F) (ExprDesc*), ExprDesc* Expr);
|
|
|
|
/* Will evaluate an expression via the given function. If the result is not
|
|
|
|
* a constant, a diagnostic will be printed, and the value is replaced by
|
|
|
|
* a constant one to make sure there are no internal errors that result
|
|
|
|
* from this input error.
|
2000-05-28 13:40:48 +00:00
|
|
|
*/
|
2001-07-17 21:53:17 +00:00
|
|
|
|
2001-07-17 21:24:19 +00:00
|
|
|
unsigned assignadjust (type* lhst, ExprDesc* rhs);
|
2000-05-28 13:40:48 +00:00
|
|
|
/* Adjust the type of the right hand expression so that it can be assigned to
|
|
|
|
* the type on the left hand side. This function is used for assignment and
|
|
|
|
* for converting parameters in a function call. It returns the code generator
|
|
|
|
* flags for the operation.
|
|
|
|
*/
|
|
|
|
|
2001-07-17 21:24:19 +00:00
|
|
|
void exprhs (unsigned flags, int k, ExprDesc *lval);
|
2000-05-28 13:40:48 +00:00
|
|
|
/* Put the result of an expression into the primary register */
|
|
|
|
|
2001-07-17 21:24:19 +00:00
|
|
|
void expression1 (ExprDesc* lval);
|
2000-05-28 13:40:48 +00:00
|
|
|
/* Evaluate an expression on level 1 (no comma operator) and put it into
|
|
|
|
* the primary register
|
|
|
|
*/
|
|
|
|
|
2001-07-17 21:24:19 +00:00
|
|
|
void expression (ExprDesc* lval);
|
2000-05-28 13:40:48 +00:00
|
|
|
/* Evaluate an expression and put it into the primary register */
|
|
|
|
|
2001-07-17 21:24:19 +00:00
|
|
|
int evalexpr (unsigned flags, int (*f) (ExprDesc*), ExprDesc* lval);
|
2000-05-28 13:40:48 +00:00
|
|
|
/* Will evaluate an expression via the given function. If the result is a
|
|
|
|
* constant, 0 is returned and the value is put in the lval struct. If the
|
|
|
|
* result is not constant, exprhs is called to bring the value into the
|
|
|
|
* primary register and 1 is returned.
|
|
|
|
*/
|
|
|
|
|
2002-02-18 08:40:11 +00:00
|
|
|
void ConstExpr (ExprDesc* lval);
|
2000-05-28 13:40:48 +00:00
|
|
|
/* Get a constant value */
|
|
|
|
|
2002-02-18 08:40:11 +00:00
|
|
|
void ConstIntExpr (ExprDesc* Val);
|
|
|
|
/* Get a constant int value */
|
|
|
|
|
2001-07-17 21:24:19 +00:00
|
|
|
void intexpr (ExprDesc* lval);
|
2000-05-28 13:40:48 +00:00
|
|
|
/* Get an integer expression */
|
|
|
|
|
2001-07-17 21:24:19 +00:00
|
|
|
void boolexpr (ExprDesc* lval);
|
2000-05-28 13:40:48 +00:00
|
|
|
/* Get a boolean expression */
|
|
|
|
|
|
|
|
void test (unsigned label, int cond);
|
|
|
|
/* Generate code to perform test and jump if false. */
|
|
|
|
|
2002-11-01 15:16:16 +00:00
|
|
|
int hie10 (ExprDesc* lval);
|
|
|
|
/* Handle ++, --, !, unary - etc. */
|
|
|
|
|
2001-07-17 21:24:19 +00:00
|
|
|
int hie1 (ExprDesc* lval);
|
2000-05-28 13:40:48 +00:00
|
|
|
/* Parse first level of expression hierarchy. */
|
|
|
|
|
2001-07-17 21:24:19 +00:00
|
|
|
int hie0 (ExprDesc* lval);
|
2000-05-28 13:40:48 +00:00
|
|
|
/* Parse comma operator (highest level of expression hierarchy) */
|
|
|
|
|
2001-07-17 21:24:19 +00:00
|
|
|
void DefineData (ExprDesc* lval);
|
2000-05-28 13:40:48 +00:00
|
|
|
/* Output a data definition for the given expression */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* End of expr.h */
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|