]> git.sur5r.net Git - cc65/blobdiff - src/cc65/expr.h
Better code for compares
[cc65] / src / cc65 / expr.h
index fa5430fced6e8de3bddc9bfc769e691f46899488..1a6d18a8f4c486055a4fee08415271a3d2788f84 100644 (file)
 
 
 /* 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  /* Base is in primary register, const offset */
-
-#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 */
+#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           0x0001  /* expr has set cond codes apropos result value */
-#define E_FORCETEST            0x0002  /* if expr has NOT set CC, force a test */
+#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 */
-struct expent {
+typedef struct ExprDesc ExprDesc;
+struct ExprDesc {
     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 */
+    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 */
 };
 
 
@@ -59,56 +60,57 @@ struct expent {
 
 
 
-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 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, 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 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);
+void intexpr (ExprDesc* lval);
 /* Get an integer expression */
 
-void boolexpr (struct expent* lval);
+void boolexpr (ExprDesc* lval);
 /* Get a boolean expression */
 
 void test (unsigned label, int cond);
 /* Generate code to perform test and jump if false. */
 
-int hie1 (struct expent* lval);
+int hie1 (ExprDesc* lval);
 /* Parse first level of expression hierarchy. */
 
-int hie0 (struct expent* lval);
+int hie0 (ExprDesc* 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 */