X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fcc65%2Fexpr.h;h=efd1777e66bf2a2be7161ebd67dd20ed72956aa8;hb=98da4b581175232d89630f5c19f22e37a7588c7b;hp=7768d3540dea0ccb6f1a94824ccb347fc1d89e5d;hpb=53dd513176425872128ef26031d00952ef7a0628;p=cc65 diff --git a/src/cc65/expr.h b/src/cc65/expr.h index 7768d3540..efd1777e6 100644 --- a/src/cc65/expr.h +++ b/src/cc65/expr.h @@ -11,109 +11,96 @@ +/* cc65 */ #include "datatype.h" +#include "exprdesc.h" /*****************************************************************************/ -/* data */ +/* code */ /*****************************************************************************/ -/* Defines for the flags field of the expression descriptor */ -#define E_MREG 0x0110 /* Special: Expression is primary register */ -#define E_MGLOBAL 0x0080 /* Reference to static variable */ -#define E_MLOCAL 0x0040 /* Reference to local variable (stack offset) */ -#define E_MCONST 0x0020 /* Constant value */ -#define E_MEXPR 0x0010 /* Result is in primary register */ -#define E_MEOFFS 0x0011 /* Offset is in primary register, base on stack */ - -#define E_MCTYPE 0x0007 /* Type of a constant */ -#define E_TCONST 0x0000 /* Constant */ -#define E_TGLAB 0x0001 /* Global label */ -#define E_TLIT 0x0002 /* Literal of some kind */ -#define E_TLOFFS 0x0003 /* Constant stack offset */ -#define E_TLLAB 0x0004 /* Local label */ -#define E_TREGISTER 0x0005 /* Register variable */ - -/* Defines for the test field of the expression descriptor */ -#define E_CC 0x0001 /* expr has set cond codes apropos result value */ -#define E_FORCETEST 0x0002 /* if expr has NOT set CC, force a test */ -#define E_LOGL 0x0004 /* expr has left a logical value (1 or 0) in AX */ -#define E_XINV 0x0008 /* flip this bit to invert sense of test */ -#define E_TEST 0x0010 /* We're evaluating a test */ - -/* Describe the result of an expression */ -struct expent { - struct SymEntry* Sym; /* Symbol table entry if known */ - type* e_tptr; /* Type array of expression */ - long e_const; /* Value if expression constant */ - unsigned e_flags; - unsigned e_test; /* */ - unsigned long e_name; /* Name or label number */ -}; - - - -/*****************************************************************************/ -/* code */ -/*****************************************************************************/ - +void PushAddr (ExprDesc* lval); +/* 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 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. + */ -void doasm (void); -/* This function parses ASM statements. The syntax of the ASM directive - * looks like the one defined for C++ (C has no ASM directive), that is, - * a string literal in parenthesis. +void CheckBoolExpr (ExprDesc* lval); +/* Check if the given expression is a boolean expression, output a diagnostic + * if not. */ -unsigned assignadjust (type* lhst, struct expent* rhs); +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 exprhs (unsigned flags, int k, struct expent *lval); +void exprhs (unsigned flags, int k, ExprDesc *lval); /* Put the result of an expression into the primary register */ -void expression1 (struct expent* lval); +void Store (ExprDesc* lval, 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 expression1 (ExprDesc* lval); /* Evaluate an expression on level 1 (no comma operator) and put it into * the primary register */ -void expression (struct expent* lval); +void expression (ExprDesc* lval); /* Evaluate an expression and put it into the primary register */ -int evalexpr (unsigned flags, int (*f) (struct expent*), struct expent* lval); +int evalexpr (unsigned flags, int (*f) (ExprDesc*), ExprDesc* lval); /* 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. */ -void constexpr (struct expent* lval); +void ConstExpr (ExprDesc* lval); /* Get a constant value */ -void intexpr (struct expent* lval); -/* Get an integer expression */ +void ConstIntExpr (ExprDesc* Val); +/* Get a constant int value */ -void boolexpr (struct expent* lval); -/* Get a boolean expression */ +void intexpr (ExprDesc* lval); +/* Get an integer expression */ -void test (unsigned label, int cond); -/* Generate code to perform test and jump if false. */ +int hie10 (ExprDesc* lval); +/* Handle ++, --, !, unary - etc. */ -int hie1 (struct expent* lval); +int hie1 (ExprDesc* lval); /* Parse first level of expression hierarchy. */ -int hie0 (struct expent* lval); -/* Parse comma operator (highest level of expression hierarchy) */ - -void DefineData (struct expent* lval); +void DefineData (ExprDesc* lval); /* Output a data definition for the given expression */ +void Test (unsigned Label, int Invert); +/* Evaluate a boolean test expression and jump depending on the result of + * the test and on Invert. + */ + +void TestInParens (unsigned Label, int Invert); +/* Evaluate a boolean test expression in parenthesis and jump depending on + * the result of the test * and on Invert. + */ + /* End of expr.h */