Some renaming and restructuring
git-svn-id: svn://svn.cc65.org/cc65/trunk@3050 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
4f024ca81b
commit
fedb566ff1
3 changed files with 78 additions and 52 deletions
|
@ -84,7 +84,7 @@ static unsigned ParseInitInternal (type* T, int AllowFlexibleMembers);
|
||||||
static type OptionalQualifiers (type Q)
|
static type OptionalQualifiers (type Q)
|
||||||
/* Read type qualifiers if we have any */
|
/* Read type qualifiers if we have any */
|
||||||
{
|
{
|
||||||
while (CurTok.Tok == TOK_CONST || CurTok.Tok == TOK_VOLATILE) {
|
while (TokIsTypeQual (&CurTok)) {
|
||||||
|
|
||||||
switch (CurTok.Tok) {
|
switch (CurTok.Tok) {
|
||||||
|
|
||||||
|
@ -103,8 +103,7 @@ static type OptionalQualifiers (type Q)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
/* Keep gcc silent */
|
Internal ("Unexpected type qualifier token: %d", CurTok.Tok);
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
/*
|
/* expr.c
|
||||||
* expr.c
|
|
||||||
*
|
*
|
||||||
* Ullrich von Bassewitz, 21.06.1998
|
* Ullrich von Bassewitz, 21.06.1998
|
||||||
*/
|
*/
|
||||||
|
@ -325,25 +324,31 @@ static const GenDesc* FindGen (token_t Tok, const GenDesc* Table)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static int istypeexpr (void)
|
static int TypeSpecAhead (void)
|
||||||
/* Return true if some sort of variable or type is waiting (helper for cast
|
/* Return true if some sort of type is waiting (helper for cast and sizeof()
|
||||||
* and sizeof() in hie10).
|
* in hie10).
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
SymEntry* Entry;
|
SymEntry* Entry;
|
||||||
|
|
||||||
|
/* There's a type waiting if:
|
||||||
|
*
|
||||||
|
* 1. We have an opening paren, and
|
||||||
|
* a. the next token is a type, or
|
||||||
|
* b. the next token is a type qualifier, or
|
||||||
|
* c. the next token is a typedef'd type
|
||||||
|
*/
|
||||||
return CurTok.Tok == TOK_LPAREN && (
|
return CurTok.Tok == TOK_LPAREN && (
|
||||||
(NextTok.Tok >= TOK_FIRSTTYPE && NextTok.Tok <= TOK_LASTTYPE) ||
|
TokIsType (&NextTok) ||
|
||||||
(NextTok.Tok == TOK_CONST) ||
|
TokIsTypeQual (&NextTok) ||
|
||||||
(NextTok.Tok == TOK_VOLATILE) ||
|
(NextTok.Tok == TOK_IDENT &&
|
||||||
(NextTok.Tok == TOK_IDENT &&
|
(Entry = FindSym (NextTok.Ident)) != 0 &&
|
||||||
(Entry = FindSym (NextTok.Ident)) != 0 &&
|
|
||||||
SymIsTypeDef (Entry)));
|
SymIsTypeDef (Entry)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void PushAddr (ExprDesc* lval)
|
void PushAddr (ExprDesc* Expr)
|
||||||
/* If the expression contains an address that was somehow evaluated,
|
/* If the expression contains an address that was somehow evaluated,
|
||||||
* push this address on the stack. This is a helper function for all
|
* push this address on the stack. This is a helper function for all
|
||||||
* sorts of implicit or explicit assignment functions where the lvalue
|
* sorts of implicit or explicit assignment functions where the lvalue
|
||||||
|
@ -351,7 +356,7 @@ void PushAddr (ExprDesc* lval)
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
/* Get the address on stack if needed */
|
/* Get the address on stack if needed */
|
||||||
if (lval->Flags != E_MREG && (lval->Flags & E_MEXPR)) {
|
if (Expr->Flags != E_MREG && (Expr->Flags & E_MEXPR)) {
|
||||||
/* Push the address (always a pointer) */
|
/* Push the address (always a pointer) */
|
||||||
g_push (CF_PTR, 0);
|
g_push (CF_PTR, 0);
|
||||||
}
|
}
|
||||||
|
@ -376,7 +381,7 @@ void ConstSubExpr (void (*Func) (ExprDesc*), ExprDesc* Expr)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void CheckBoolExpr (ExprDesc* lval)
|
void CheckBoolExpr (ExprDesc* Expr)
|
||||||
/* Check if the given expression is a boolean expression, output a diagnostic
|
/* Check if the given expression is a boolean expression, output a diagnostic
|
||||||
* if not.
|
* if not.
|
||||||
*/
|
*/
|
||||||
|
@ -384,10 +389,10 @@ void CheckBoolExpr (ExprDesc* lval)
|
||||||
/* If it's an integer, it's ok. If it's not an integer, but a pointer,
|
/* If it's an integer, it's ok. If it's not an integer, but a pointer,
|
||||||
* the pointer used in a boolean context is also ok
|
* the pointer used in a boolean context is also ok
|
||||||
*/
|
*/
|
||||||
if (!IsClassInt (lval->Type) && !IsClassPtr (lval->Type)) {
|
if (!IsClassInt (Expr->Type) && !IsClassPtr (Expr->Type)) {
|
||||||
Error ("Boolean expression expected");
|
Error ("Boolean expression expected");
|
||||||
/* To avoid any compiler errors, make the expression a valid int */
|
/* To avoid any compiler errors, make the expression a valid int */
|
||||||
ED_MakeConstInt (lval, 1);
|
ED_MakeConstInt (Expr, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1284,51 +1289,51 @@ static void hie11 (ExprDesc *Expr)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Store (ExprDesc* lval, const type* StoreType)
|
void Store (ExprDesc* Expr, const type* StoreType)
|
||||||
/* Store the primary register into the location denoted by lval. If StoreType
|
/* Store the primary register into the location denoted by Expr. If StoreType
|
||||||
* is given, use this type when storing instead of lval->Type. If StoreType
|
* is given, use this type when storing instead of Expr->Type. If StoreType
|
||||||
* is NULL, use lval->Type instead.
|
* is NULL, use Expr->Type instead.
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
unsigned Flags;
|
unsigned Flags;
|
||||||
|
|
||||||
unsigned f = lval->Flags;
|
unsigned f = Expr->Flags;
|
||||||
|
|
||||||
/* If StoreType was not given, use lval->Type instead */
|
/* If StoreType was not given, use Expr->Type instead */
|
||||||
if (StoreType == 0) {
|
if (StoreType == 0) {
|
||||||
StoreType = lval->Type;
|
StoreType = Expr->Type;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the code generator flags */
|
/* Get the code generator flags */
|
||||||
Flags = TypeOf (StoreType);
|
Flags = TypeOf (StoreType);
|
||||||
if (f & E_MGLOBAL) {
|
if (f & E_MGLOBAL) {
|
||||||
Flags |= GlobalModeFlags (f);
|
Flags |= GlobalModeFlags (f);
|
||||||
if (lval->Test) {
|
if (Expr->Test) {
|
||||||
/* Just testing */
|
/* Just testing */
|
||||||
Flags |= CF_TEST;
|
Flags |= CF_TEST;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Generate code */
|
/* Generate code */
|
||||||
g_putstatic (Flags, lval->Name, lval->ConstVal);
|
g_putstatic (Flags, Expr->Name, Expr->ConstVal);
|
||||||
|
|
||||||
} else if (f & E_MLOCAL) {
|
} else if (f & E_MLOCAL) {
|
||||||
/* Store an auto variable */
|
/* Store an auto variable */
|
||||||
g_putlocal (Flags, lval->ConstVal, 0);
|
g_putlocal (Flags, Expr->ConstVal, 0);
|
||||||
} else if (f == E_MEOFFS) {
|
} else if (f == E_MEOFFS) {
|
||||||
/* Store indirect with offset */
|
/* Store indirect with offset */
|
||||||
g_putind (Flags, lval->ConstVal);
|
g_putind (Flags, Expr->ConstVal);
|
||||||
} else if (f != E_MREG) {
|
} else if (f != E_MREG) {
|
||||||
if (f & E_MEXPR) {
|
if (f & E_MEXPR) {
|
||||||
/* Indirect without offset */
|
/* Indirect without offset */
|
||||||
g_putind (Flags, 0);
|
g_putind (Flags, 0);
|
||||||
} else {
|
} else {
|
||||||
/* Store into absolute address */
|
/* Store into absolute address */
|
||||||
g_putstatic (Flags | CF_ABSOLUTE, lval->ConstVal, 0);
|
g_putstatic (Flags | CF_ABSOLUTE, Expr->ConstVal, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Assume that each one of the stores will invalidate CC */
|
/* Assume that each one of the stores will invalidate CC */
|
||||||
lval->Test &= ~E_CC;
|
Expr->Test &= ~E_CC;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1567,7 +1572,7 @@ void hie10 (ExprDesc* Expr)
|
||||||
|
|
||||||
case TOK_SIZEOF:
|
case TOK_SIZEOF:
|
||||||
NextToken ();
|
NextToken ();
|
||||||
if (istypeexpr ()) {
|
if (TypeSpecAhead ()) {
|
||||||
type Type[MAXTYPELEN];
|
type Type[MAXTYPELEN];
|
||||||
NextToken ();
|
NextToken ();
|
||||||
Expr->ConstVal = CheckedSizeOf (ParseType (Type));
|
Expr->ConstVal = CheckedSizeOf (ParseType (Type));
|
||||||
|
@ -1581,12 +1586,12 @@ void hie10 (ExprDesc* Expr)
|
||||||
RemoveCode (Mark);
|
RemoveCode (Mark);
|
||||||
}
|
}
|
||||||
Expr->Flags = E_MCONST | E_TCONST | E_RVAL;
|
Expr->Flags = E_MCONST | E_TCONST | E_RVAL;
|
||||||
Expr->Type = type_uint;
|
Expr->Type = type_size_t;
|
||||||
Expr->Test &= ~E_CC;
|
Expr->Test &= ~E_CC;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (istypeexpr ()) {
|
if (TypeSpecAhead ()) {
|
||||||
|
|
||||||
/* A typecast */
|
/* A typecast */
|
||||||
TypeCast (Expr);
|
TypeCast (Expr);
|
||||||
|
@ -1611,9 +1616,9 @@ void hie10 (ExprDesc* Expr)
|
||||||
|
|
||||||
|
|
||||||
static void hie_internal (const GenDesc* Ops, /* List of generators */
|
static void hie_internal (const GenDesc* Ops, /* List of generators */
|
||||||
ExprDesc* Expr, /* parent expr's lval */
|
ExprDesc* Expr,
|
||||||
void (*hienext) (ExprDesc*),
|
void (*hienext) (ExprDesc*),
|
||||||
int* UsedGen) /* next higher level */
|
int* UsedGen)
|
||||||
/* Helper function */
|
/* Helper function */
|
||||||
{
|
{
|
||||||
ExprDesc lval2;
|
ExprDesc lval2;
|
||||||
|
@ -1717,7 +1722,7 @@ static void hie_internal (const GenDesc* Ops, /* List of generators */
|
||||||
|
|
||||||
|
|
||||||
static void hie_compare (const GenDesc* Ops, /* List of generators */
|
static void hie_compare (const GenDesc* Ops, /* List of generators */
|
||||||
ExprDesc* Expr, /* parent expr's lval */
|
ExprDesc* Expr,
|
||||||
void (*hienext) (ExprDesc*))
|
void (*hienext) (ExprDesc*))
|
||||||
/* Helper function for the compare operators */
|
/* Helper function for the compare operators */
|
||||||
{
|
{
|
||||||
|
@ -2930,7 +2935,7 @@ void hie0 (ExprDesc *Expr)
|
||||||
|
|
||||||
int evalexpr (unsigned Flags, void (*Func) (ExprDesc*), ExprDesc* Expr)
|
int evalexpr (unsigned Flags, void (*Func) (ExprDesc*), ExprDesc* Expr)
|
||||||
/* Will evaluate an expression via the given function. If the result is a
|
/* 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
|
* constant, 0 is returned and the value is put in the Expr struct. If the
|
||||||
* result is not constant, ExprLoad 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.
|
* primary register and 1 is returned.
|
||||||
*/
|
*/
|
||||||
|
@ -2992,29 +2997,27 @@ void expression0 (ExprDesc* Expr)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void ConstExpr (ExprDesc* lval)
|
void ConstExpr (ExprDesc* Expr)
|
||||||
/* Get a constant value */
|
/* Get a constant value */
|
||||||
{
|
{
|
||||||
expr (hie1, InitExprDesc (lval));
|
expr (hie1, InitExprDesc (Expr));
|
||||||
if (ED_IsLVal (lval) || (lval->Flags & E_MCONST) == 0) {
|
if (ED_IsLVal (Expr) || (Expr->Flags & E_MCONST) == 0) {
|
||||||
Error ("Constant expression expected");
|
Error ("Constant expression expected");
|
||||||
/* To avoid any compiler errors, make the expression a valid const */
|
/* To avoid any compiler errors, make the expression a valid const */
|
||||||
ED_MakeConstInt (lval, 1);
|
ED_MakeConstInt (Expr, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void ConstIntExpr (ExprDesc* Val)
|
void ConstIntExpr (ExprDesc* Expr)
|
||||||
/* Get a constant int value */
|
/* Get a constant int value */
|
||||||
{
|
{
|
||||||
expr (hie1, InitExprDesc (Val));
|
expr (hie1, InitExprDesc (Expr));
|
||||||
if (ED_IsLVal (Val) ||
|
if (ED_IsLVal (Expr) || (Expr->Flags & E_MCONST) == 0 || !IsClassInt (Expr->Type)) {
|
||||||
(Val->Flags & E_MCONST) == 0 ||
|
|
||||||
!IsClassInt (Val->Type)) {
|
|
||||||
Error ("Constant integer expression expected");
|
Error ("Constant integer expression expected");
|
||||||
/* To avoid any compiler errors, make the expression a valid const */
|
/* To avoid any compiler errors, make the expression a valid const */
|
||||||
ED_MakeConstInt (Val, 1);
|
ED_MakeConstInt (Expr, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -61,12 +61,16 @@ typedef enum token_t {
|
||||||
TOK_RESTRICT,
|
TOK_RESTRICT,
|
||||||
TOK_STATIC,
|
TOK_STATIC,
|
||||||
TOK_TYPEDEF,
|
TOK_TYPEDEF,
|
||||||
TOK_CONST,
|
|
||||||
|
/* Tokens denoting type qualifiers */
|
||||||
|
TOK_FIRST_TYPEQUAL,
|
||||||
|
TOK_CONST = TOK_FIRST_TYPEQUAL,
|
||||||
TOK_VOLATILE,
|
TOK_VOLATILE,
|
||||||
|
TOK_LAST_TYPEQUAL = TOK_VOLATILE,
|
||||||
|
|
||||||
/* Tokens denoting types */
|
/* Tokens denoting types */
|
||||||
TOK_FIRSTTYPE,
|
TOK_FIRST_TYPE,
|
||||||
TOK_ENUM = TOK_FIRSTTYPE,
|
TOK_ENUM = TOK_FIRST_TYPE,
|
||||||
TOK_CHAR,
|
TOK_CHAR,
|
||||||
TOK_INT,
|
TOK_INT,
|
||||||
TOK_DOUBLE,
|
TOK_DOUBLE,
|
||||||
|
@ -78,7 +82,7 @@ typedef enum token_t {
|
||||||
TOK_STRUCT,
|
TOK_STRUCT,
|
||||||
TOK_UNION,
|
TOK_UNION,
|
||||||
TOK_VOID,
|
TOK_VOID,
|
||||||
TOK_LASTTYPE = TOK_VOID,
|
TOK_LAST_TYPE = TOK_VOID,
|
||||||
|
|
||||||
/* Control statements */
|
/* Control statements */
|
||||||
TOK_DO,
|
TOK_DO,
|
||||||
|
@ -199,6 +203,26 @@ extern Token NextTok; /* The next token */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(HAVE_INLINE)
|
||||||
|
INLINE int TokIsType (const Token* T)
|
||||||
|
/* Return true if the token is a type */
|
||||||
|
{
|
||||||
|
return (T->Tok >= TOK_FIRST_TYPE && T->Tok <= TOK_LAST_TYPE);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
# define TokIsType(T) ((T)->Tok >= TOK_FIRST_TYPE && (T)->Tok <= TOK_LAST_TYPE)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(HAVE_INLINE)
|
||||||
|
INLINE int TokIsTypeQual (const Token* T)
|
||||||
|
/* Return true if the token is a type qualifier */
|
||||||
|
{
|
||||||
|
return (T->Tok >= TOK_FIRST_TYPEQUAL && T->Tok <= TOK_LAST_TYPEQUAL);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
# define TokIsTypeQual(T) ((T)->Tok >= TOK_FIRST_TYPEQUAL && (T)->Tok <= TOK_LAST_TYPEQUAL)
|
||||||
|
#endif
|
||||||
|
|
||||||
void SymName (char* s);
|
void SymName (char* s);
|
||||||
/* Get symbol from input stream */
|
/* Get symbol from input stream */
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue