X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fcc65%2Fexpr.h;h=acf442986c576b91379c7be6beae399773a7aab1;hb=763a35911411adbe46e07b57b6161205a51e16b6;hp=7933a7f4d697f2999168ec09d66d26c7a904bec7;hpb=5548b6fd56c8dc5a203804ce63db9649aab37abb;p=cc65 diff --git a/src/cc65/expr.h b/src/cc65/expr.h index 7933a7f4d..acf442986 100644 --- a/src/cc65/expr.h +++ b/src/cc65/expr.h @@ -11,111 +11,74 @@ +/* cc65 */ #include "datatype.h" +#include "exprdesc.h" /*****************************************************************************/ -/* data */ +/* code */ /*****************************************************************************/ -/* Defines for the flags field of the expression descriptor */ -#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 */ - -/* Defines for the test field of the expression descriptor */ -#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 */ - -/* Describe the result of an expression */ -typedef struct ExprDesc ExprDesc; -struct ExprDesc { - struct SymEntry* Sym; /* Symbol table entry if known */ - type* Type; /* Type array of expression */ - long ConstVal;/* Value if expression constant */ - unsigned short Flags; - unsigned short Test; /* */ - unsigned long Name; /* Name or label number */ -}; - - - -/*****************************************************************************/ -/* code */ -/*****************************************************************************/ - - - -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. - */ - -unsigned assignadjust (type* lhst, ExprDesc* rhs); -/* 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. +void PushAddr (const ExprDesc* Expr); +/* If the expression contains an address that was somehow evaluated, + * push this address on the stack. This is a helper function for all + * sorts of implicit or explicit assignment functions where the lvalue + * must be saved if it's not constant, before evaluating the rhs. */ -void exprhs (unsigned flags, int k, ExprDesc *lval); +void ExprLoad (unsigned flags, ExprDesc* Expr); /* Put the result of an expression into the primary register */ -void expression1 (ExprDesc* lval); -/* Evaluate an expression on level 1 (no comma operator) and put it into - * the primary register +void Store (ExprDesc* Expr, const type* StoreType); +/* Store the primary register into the location denoted by lval. If StoreType + * is given, use this type when storing instead of lval->Type. If StoreType + * is NULL, use lval->Type instead. */ -void expression (ExprDesc* lval); -/* Evaluate an expression and put it into the primary register */ +void hie0 (ExprDesc* Expr); +/* Parse comma operator. */ -int evalexpr (unsigned flags, int (*f) (ExprDesc*), ExprDesc* lval); +int evalexpr (unsigned flags, void (*Func) (ExprDesc*), ExprDesc* Expr); /* 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 + * result is not constant, ExprLoad is called to bring the value into the * primary register and 1 is returned. */ -void ConstExpr (ExprDesc* lval); -/* Get a constant value */ +void Expression0 (ExprDesc* Expr); +/* Evaluate an expression via hie0 and put the result into the primary register */ -void ConstIntExpr (ExprDesc* Val); -/* Get a constant int value */ - -void intexpr (ExprDesc* lval); -/* Get an integer expression */ +void ConstExpr (void (*Func) (ExprDesc*), ExprDesc* Expr); +/* Will evaluate an expression via the given function. If the result is not + * a constant of some sort, 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. + */ -void boolexpr (ExprDesc* lval); -/* Get a boolean expression */ +void BoolExpr (void (*Func) (ExprDesc*), ExprDesc* Expr); +/* Will evaluate an expression via the given function. If the result is not + * something that may be evaluated in a boolean context, 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. + */ -void test (unsigned label, int cond); -/* Generate code to perform test and jump if false. */ +void ConstAbsIntExpr (void (*Func) (ExprDesc*), ExprDesc* Expr); +/* Will evaluate an expression via the given function. If the result is not + * a constant numeric integer value, 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. + */ -int hie10 (ExprDesc* lval); +void hie10 (ExprDesc* lval); /* Handle ++, --, !, unary - etc. */ -int hie1 (ExprDesc* lval); +void hie1 (ExprDesc* lval); /* Parse first level of expression hierarchy. */ -int hie0 (ExprDesc* lval); -/* Parse comma operator (highest level of expression hierarchy) */ - void DefineData (ExprDesc* lval); /* Output a data definition for the given expression */