1 /*****************************************************************************/
5 /* Expression descriptor structure */
9 /* (C) 2002-2004 Ullrich von Bassewitz */
11 /* D-70794 Filderstadt */
12 /* EMail: uz@cc65.org */
15 /* This software is provided 'as-is', without any expressed or implied */
16 /* warranty. In no event will the authors be held liable for any damages */
17 /* arising from the use of this software. */
19 /* Permission is granted to anyone to use this software for any purpose, */
20 /* including commercial applications, and to alter it and redistribute it */
21 /* freely, subject to the following restrictions: */
23 /* 1. The origin of this software must not be misrepresented; you must not */
24 /* claim that you wrote the original software. If you use this software */
25 /* in a product, an acknowledgment in the product documentation would be */
26 /* appreciated but is not required. */
27 /* 2. Altered source versions must be plainly marked as such, and must not */
28 /* be misrepresented as being the original software. */
29 /* 3. This notice may not be removed or altered from any source */
32 /*****************************************************************************/
51 /*****************************************************************************/
53 /*****************************************************************************/
57 /* Defines for the flags field of the expression descriptor */
58 #define E_MREG 0x0110U /* Special: Expression is primary register */
59 #define E_MGLOBAL 0x0080U /* Reference to static variable */
60 #define E_MLOCAL 0x0040U /* Reference to local variable (stack offset) */
61 #define E_MCONST 0x0020U /* Constant value */
62 #define E_MEXPR 0x0010U /* Result is in primary register */
63 #define E_MEOFFS 0x0011U /* Base is in primary register, const offset */
65 #define E_MCTYPE 0x0007U /* Type of a constant */
66 #define E_TCONST 0x0000U /* Constant */
67 #define E_TGLAB 0x0001U /* Global label */
68 #define E_TLIT 0x0002U /* Literal of some kind */
69 #define E_TLOFFS 0x0003U /* Constant stack offset */
70 #define E_TLLAB 0x0004U /* Local label */
71 #define E_TREGISTER 0x0005U /* Register variable */
73 #define E_RVAL 0x0000U /* Expression node is a value */
74 #define E_LVAL 0x1000U /* Expression node is a reference */
76 /* Defines for the test field of the expression descriptor */
77 #define E_CC 0x0001U /* expr has set cond codes apropos result value */
78 #define E_FORCETEST 0x0002U /* if expr has NOT set CC, force a test */
80 /* Describe the result of an expression */
81 typedef struct ExprDesc ExprDesc;
83 struct SymEntry* Sym; /* Symbol table entry if known */
84 type* Type; /* Type array of expression */
85 long ConstVal;/* Value if expression constant */
87 unsigned short Test; /* */
88 unsigned long Name; /* Name or label number */
93 /*****************************************************************************/
95 /*****************************************************************************/
99 #if defined(HAVE_INLINE)
100 INLINE ExprDesc* InitExprDesc (ExprDesc* Expr)
101 /* Initialize an ExprDesc */
103 return memset (Expr, 0, sizeof (*Expr));
106 # define InitExprDesc(E) memset ((E), 0, sizeof (*(E)))
109 #if defined(HAVE_INLINE)
110 INLINE int ED_IsLVal (const ExprDesc* Expr)
111 /* Return true if the expression is a reference */
113 return (Expr->Flags & E_LVAL) != 0;
116 # define ED_IsLVal(Expr) (((Expr)->Flags & E_LVAL) != 0)
119 #if defined(HAVE_INLINE)
120 INLINE int ED_IsRVal (const ExprDesc* Expr)
121 /* Return true if the expression is a rvalue */
123 return (Expr->Flags & E_LVAL) == 0;
126 # define ED_IsRVal(Expr) (((Expr)->Flags & E_LVAL) == 0)
129 #if defined(HAVE_INLINE)
130 INLINE int ED_SetValType (ExprDesc* Expr, int Ref)
131 /* Set the reference flag for an expression and return it (the flag) */
133 Expr->Flags = Ref? (Expr->Flags | E_LVAL) : (Expr->Flags & ~E_LVAL);
137 /* Beware: Just one occurance of R below, since it may have side effects! */
138 # define ED_SetValType(E, R) \
139 (((E)->Flags = (R)? ((E)->Flags | E_LVAL) : ((E)->Flags & ~E_LVAL)), \
143 #if defined(HAVE_INLINE)
144 INLINE int ED_MakeLVal (ExprDesc* Expr)
145 /* Make the expression a lvalue and return true */
147 return ED_SetValType (Expr, 1);
150 # define ED_MakeLVal(Expr) ED_SetValType (Expr, 1)
153 #if defined(HAVE_INLINE)
154 INLINE int ED_MakeRVal (ExprDesc* Expr)
155 /* Make the expression a rvalue and return false */
157 return ED_SetValType (Expr, 0);
160 # define ED_MakeRVal(Expr) ED_SetValType (Expr, 0)
163 ExprDesc* ED_MakeConstInt (ExprDesc* Expr, long Value);
164 /* Make Expr a constant integer expression with the given value */
166 void PrintExprDesc (FILE* F, ExprDesc* Expr);
167 /* Print an ExprDesc */
169 type* ReplaceType (ExprDesc* Expr, const type* NewType);
170 /* Replace the type of Expr by a copy of Newtype and return the old type string */
174 /* End of exprdesc.h */