/* This is the lowest level of the expression parser. */
{
SymEntry* Sym;
- Literal* L;
/* Initialize fields in the expression stucture */
ED_Init (E);
case TOK_SCONST:
case TOK_WCSCONST:
/* String literal */
- L = UseLiteral (CurTok.SVal);
+ E->LVal = UseLiteral (CurTok.SVal);
E->Type = GetCharArrayType (GetLiteralSize (CurTok.SVal));
E->Flags = E_LOC_LITERAL | E_RTYPE_RVAL;
E->IVal = 0;
- E->Name = GetLiteralLabel (CurTok.SVal);
+ E->Name = GetLiteralLabel (CurTok.SVal);
NextToken ();
break;
/* */
/* */
/* */
-/* (C) 2002-2009, Ullrich von Bassewitz */
+/* (C) 2002-2010, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
Expr->Name = 0;
Expr->IVal = 0;
Expr->FVal = FP_D_Make (0.0);
+ Expr->LVal = 0;
Expr->BitOffs = 0;
Expr->BitWidth = 0;
return Expr;
/* */
/* */
/* */
-/* (C) 2002-2009, Ullrich von Bassewitz */
+/* (C) 2002-2010, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
};
+/* Forward */
+struct Literal;
+
/* Describe the result of an expression */
typedef struct ExprDesc ExprDesc;
struct ExprDesc {
unsigned long Name; /* Name or label number */
long IVal; /* Integer value if expression constant */
Double FVal; /* Floating point value */
+ struct Literal* LVal; /* Literal value */
/* Bit field stuff */
unsigned BitOffs; /* Bit offset for bit fields */
#if defined(HAVE_INLINE)
INLINE int ED_IsLocLiteral (const ExprDesc* Expr)
/* Return true if the expression is a string from the literal pool */
-{
+{
return (Expr->Flags & E_MASK_LOC) == E_LOC_LITERAL;
}
#else
/* Do type conversion */
TypeConversion (&Arg, ArgType);
-
-#if 0
+
/* If the expression is a literal, and if string literals are read
* only, we can calculate the length of the string and remove it
* from the literal pool. Otherwise we have to calculate the length
if (ED_IsLocLiteral (&Arg) && IS_Get (&WritableStrings) == 0) {
/* Constant string literal */
- ED_MakeConstAbs (Expr, GetLiteralSize (GetLiteral (Arg.IVal)), type_size_t);
+ ED_MakeConstAbs (Expr, GetLiteralSize (Arg.LVal) - 1, type_size_t);
+
+ /* We don't need the literal any longer */
+ ReleaseLiteral (Arg.LVal);
/* We will inline strlen for arrays with constant addresses, if either the
* inlining was forced on the command line, or the array is smaller than
* 256, so the inlining is considered safe.
*/
- } else
-#endif
- if (ED_IsLocConst (&Arg) && IsArray &&
+ } else if (ED_IsLocConst (&Arg) && IsArray &&
(IS_Get (&InlineStdFuncs) || IsByteIndex)) {
/* Generate the strlen code */