1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-28 03:29:39 +00:00

Move all attributes and other information that is attached to a token into a

structure named Token.


git-svn-id: svn://svn.cc65.org/cc65/trunk@4910 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
uz 2011-01-16 16:05:43 +00:00
parent dbfae85f54
commit ddb7296b6c
23 changed files with 526 additions and 496 deletions

View File

@ -6,7 +6,7 @@
/* */ /* */
/* */ /* */
/* */ /* */
/* (C) 2003-2008, Ullrich von Bassewitz */ /* (C) 2003-2011, Ullrich von Bassewitz */
/* Roemerstrasse 52 */ /* Roemerstrasse 52 */
/* D-70794 Filderstadt */ /* D-70794 Filderstadt */
/* EMail: uz@cc65.org */ /* EMail: uz@cc65.org */
@ -83,7 +83,7 @@ static Assertion* NewAssertion (ExprNode* Expr, AssertAction Action, unsigned Ms
A->Expr = Expr; A->Expr = Expr;
A->Action = Action; A->Action = Action;
A->Msg = Msg; A->Msg = Msg;
A->Pos = CurPos; A->Pos = CurTok.Pos;
/* Return the new struct */ /* Return the new struct */
return A; return A;
@ -179,3 +179,4 @@ void WriteAssertions (void)

View File

@ -98,7 +98,7 @@ static IfDesc* AllocIf (const char* Directive, int NeedTerm)
/* Initialize elements */ /* Initialize elements */
ID->Flags = NeedTerm? ifNeedTerm : ifNone; ID->Flags = NeedTerm? ifNeedTerm : ifNone;
ID->Pos = CurPos; ID->Pos = CurTok.Pos;
ID->Name = Directive; ID->Name = Directive;
/* Return the result */ /* Return the result */
@ -192,7 +192,7 @@ static void SetElse (IfDesc* ID, int E)
/*****************************************************************************/ /*****************************************************************************/
/* Code */ /* Code */
/*****************************************************************************/ /*****************************************************************************/
@ -205,7 +205,7 @@ void DoConditionals (void)
int IfCond = GetCurrentIfCond (); int IfCond = GetCurrentIfCond ();
do { do {
switch (Tok) { switch (CurTok.Tok) {
case TOK_ELSE: case TOK_ELSE:
D = GetCurrentIf (); D = GetCurrentIf ();
@ -218,7 +218,7 @@ void DoConditionals (void)
/* Allow an .ELSE */ /* Allow an .ELSE */
InvertIfCond (D); InvertIfCond (D);
SetElse (D, 1); SetElse (D, 1);
D->Pos = CurPos; D->Pos = CurTok.Pos;
D->Name = ".ELSE"; D->Name = ".ELSE";
IfCond = GetCurrentIfCond (); IfCond = GetCurrentIfCond ();
} }
@ -284,7 +284,7 @@ void DoConditionals (void)
D = AllocIf (".IFBLANK", 1); D = AllocIf (".IFBLANK", 1);
NextTok (); NextTok ();
if (IfCond) { if (IfCond) {
if (TokIsSep (Tok)) { if (TokIsSep (CurTok.Tok)) {
SetIfCond (D, 1); SetIfCond (D, 1);
} else { } else {
SetIfCond (D, 0); SetIfCond (D, 0);
@ -320,7 +320,7 @@ void DoConditionals (void)
D = AllocIf (".IFNBLANK", 1); D = AllocIf (".IFNBLANK", 1);
NextTok (); NextTok ();
if (IfCond) { if (IfCond) {
if (TokIsSep (Tok)) { if (TokIsSep (CurTok.Tok)) {
SetIfCond (D, 0); SetIfCond (D, 0);
} else { } else {
SetIfCond (D, 1); SetIfCond (D, 1);
@ -421,7 +421,7 @@ void DoConditionals (void)
} }
} while (IfCond == 0 && Tok != TOK_EOF); } while (IfCond == 0 && CurTok.Tok != TOK_EOF);
} }
@ -432,7 +432,7 @@ int CheckConditionals (void)
* return false otherwise. * return false otherwise.
*/ */
{ {
switch (Tok) { switch (CurTok.Tok) {
case TOK_ELSE: case TOK_ELSE:
case TOK_ELSEIF: case TOK_ELSEIF:
case TOK_ENDIF: case TOK_ENDIF:
@ -474,7 +474,7 @@ void CheckOpenIfs (void)
break; break;
} }
if (D->Pos.Name != CurPos.Name) { if (D->Pos.Name != CurTok.Pos.Name) {
/* The .if is from another file, bail out */ /* The .if is from another file, bail out */
break; break;
} }
@ -505,3 +505,4 @@ void CleanupIfStack (unsigned SP)

View File

@ -6,7 +6,7 @@
/* */ /* */
/* */ /* */
/* */ /* */
/* (C) 2000-2010, Ullrich von Bassewitz */ /* (C) 2000-2011, Ullrich von Bassewitz */
/* Roemerstrasse 52 */ /* Roemerstrasse 52 */
/* D-70794 Filderstadt */ /* D-70794 Filderstadt */
/* EMail: uz@cc65.org */ /* EMail: uz@cc65.org */
@ -65,11 +65,11 @@ void DbgInfoFile (void)
ConsumeComma (); ConsumeComma ();
/* Name */ /* Name */
if (Tok != TOK_STRCON) { if (CurTok.Tok != TOK_STRCON) {
ErrorSkip ("String constant expected"); ErrorSkip ("String constant expected");
return; return;
} }
SB_Copy (&Name, &SVal); SB_Copy (&Name, &CurTok.SVal);
NextTok (); NextTok ();
/* Comma expected */ /* Comma expected */
@ -102,7 +102,7 @@ void DbgInfoLine (void)
/* If a parameters follow, this is actual line info. If no parameters /* If a parameters follow, this is actual line info. If no parameters
* follow, the last line info is terminated. * follow, the last line info is terminated.
*/ */
if (Tok == TOK_SEP) { if (CurTok.Tok == TOK_SEP) {
ClearLineInfo (); ClearLineInfo ();
return; return;
} }
@ -111,13 +111,13 @@ void DbgInfoLine (void)
ConsumeComma (); ConsumeComma ();
/* The name of the file follows */ /* The name of the file follows */
if (Tok != TOK_STRCON) { if (CurTok.Tok != TOK_STRCON) {
ErrorSkip ("String constant expected"); ErrorSkip ("String constant expected");
return; return;
} }
/* Get the index in the file table for the name */ /* Get the index in the file table for the name */
Index = GetFileIndex (&SVal); Index = GetFileIndex (&CurTok.SVal);
/* Skip the name */ /* Skip the name */
NextTok (); NextTok ();
@ -146,3 +146,5 @@ void DbgInfoSym (void)

View File

@ -6,10 +6,10 @@
/* */ /* */
/* */ /* */
/* */ /* */
/* (C) 1998-2004 Ullrich von Bassewitz */ /* (C) 1998-2011, Ullrich von Bassewitz */
/* Römerstrasse 52 */ /* Roemerstrasse 52 */
/* D-70794 Filderstadt */ /* D-70794 Filderstadt */
/* EMail: uz@cc65.org */ /* EMail: uz@cc65.org */
/* */ /* */
/* */ /* */
/* This software is provided 'as-is', without any expressed or implied */ /* This software is provided 'as-is', without any expressed or implied */
@ -59,7 +59,7 @@ void GetEA (EffAddr* A)
A->Expr = 0; A->Expr = 0;
/* Handle an addressing size override */ /* Handle an addressing size override */
switch (Tok) { switch (CurTok.Tok) {
case TOK_OVERRIDE_ZP: case TOK_OVERRIDE_ZP:
Restrictions = AM65_DIR | AM65_DIR_X | AM65_DIR_Y; Restrictions = AM65_DIR | AM65_DIR_X | AM65_DIR_Y;
NextTok (); NextTok ();
@ -81,29 +81,29 @@ void GetEA (EffAddr* A)
} }
/* Parse the effective address */ /* Parse the effective address */
if (TokIsSep (Tok)) { if (TokIsSep (CurTok.Tok)) {
A->AddrModeSet = AM65_IMPLICIT; A->AddrModeSet = AM65_IMPLICIT;
} else if (Tok == TOK_HASH) { } else if (CurTok.Tok == TOK_HASH) {
/* #val */ /* #val */
NextTok (); NextTok ();
A->Expr = Expression (); A->Expr = Expression ();
A->AddrModeSet = AM65_IMM; A->AddrModeSet = AM65_IMM;
} else if (Tok == TOK_A) { } else if (CurTok.Tok == TOK_A) {
NextTok (); NextTok ();
A->AddrModeSet = AM65_ACCU; A->AddrModeSet = AM65_ACCU;
} else if (Tok == TOK_LBRACK) { } else if (CurTok.Tok == TOK_LBRACK) {
/* [dir] or [dir],y */ /* [dir] or [dir],y */
NextTok (); NextTok ();
A->Expr = Expression (); A->Expr = Expression ();
Consume (TOK_RBRACK, "']' expected"); Consume (TOK_RBRACK, "']' expected");
if (Tok == TOK_COMMA) { if (CurTok.Tok == TOK_COMMA) {
/* [dir],y */ /* [dir],y */
NextTok (); NextTok ();
Consume (TOK_Y, "`Y' expected"); Consume (TOK_Y, "`Y' expected");
@ -113,22 +113,22 @@ void GetEA (EffAddr* A)
A->AddrModeSet = AM65_DIR_IND_LONG; A->AddrModeSet = AM65_DIR_IND_LONG;
} }
} else if (Tok == TOK_LPAREN) { } else if (CurTok.Tok == TOK_LPAREN) {
/* One of the indirect modes */ /* One of the indirect modes */
NextTok (); NextTok ();
A->Expr = Expression (); A->Expr = Expression ();
if (Tok == TOK_COMMA) { if (CurTok.Tok == TOK_COMMA) {
/* (expr,X) or (rel,S),y */ /* (expr,X) or (rel,S),y */
NextTok (); NextTok ();
if (Tok == TOK_X) { if (CurTok.Tok == TOK_X) {
/* (adr,x) */ /* (adr,x) */
NextTok (); NextTok ();
A->AddrModeSet = AM65_ABS_X_IND | AM65_DIR_X_IND; A->AddrModeSet = AM65_ABS_X_IND | AM65_DIR_X_IND;
ConsumeRParen (); ConsumeRParen ();
} else if (Tok == TOK_S) { } else if (CurTok.Tok == TOK_S) {
/* (rel,s),y */ /* (rel,s),y */
NextTok (); NextTok ();
A->AddrModeSet = AM65_STACK_REL_IND_Y; A->AddrModeSet = AM65_STACK_REL_IND_Y;
@ -143,7 +143,7 @@ void GetEA (EffAddr* A)
/* (adr) or (adr),y */ /* (adr) or (adr),y */
ConsumeRParen (); ConsumeRParen ();
if (Tok == TOK_COMMA) { if (CurTok.Tok == TOK_COMMA) {
/* (adr),y */ /* (adr),y */
NextTok (); NextTok ();
Consume (TOK_Y, "`Y' expected"); Consume (TOK_Y, "`Y' expected");
@ -165,10 +165,10 @@ void GetEA (EffAddr* A)
*/ */
A->Expr = Expression (); A->Expr = Expression ();
if (Tok == TOK_COMMA) { if (CurTok.Tok == TOK_COMMA) {
NextTok (); NextTok ();
switch (Tok) { switch (CurTok.Tok) {
case TOK_X: case TOK_X:
A->AddrModeSet = AM65_ABS_LONG_X | AM65_ABS_X | AM65_DIR_X; A->AddrModeSet = AM65_ABS_LONG_X | AM65_ABS_X | AM65_DIR_X;
@ -203,3 +203,4 @@ void GetEA (EffAddr* A)

View File

@ -6,10 +6,10 @@
/* */ /* */
/* */ /* */
/* */ /* */
/* (C) 2004 Ullrich von Bassewitz */ /* (C) 2004-2011, Ullrich von Bassewitz */
/* Römerstrasse 52 */ /* Roemerstrasse 52 */
/* D-70794 Filderstadt */ /* D-70794 Filderstadt */
/* EMail: uz@cc65.org */ /* EMail: uz@cc65.org */
/* */ /* */
/* */ /* */
/* This software is provided 'as-is', without any expressed or implied */ /* This software is provided 'as-is', without any expressed or implied */
@ -80,17 +80,17 @@ void GetSweet16EA (EffAddr* A)
A->Reg = 0; A->Reg = 0;
/* Parse the effective address */ /* Parse the effective address */
if (TokIsSep (Tok)) { if (TokIsSep (CurTok.Tok)) {
A->AddrModeSet = AMSW16_IMP; A->AddrModeSet = AMSW16_IMP;
} else if (Tok == TOK_AT) { } else if (CurTok.Tok == TOK_AT) {
/* @reg or @regnumber */ /* @reg or @regnumber */
A->AddrModeSet = AMSW16_IND; A->AddrModeSet = AMSW16_IND;
NextTok (); NextTok ();
if (Tok == TOK_REG) { if (CurTok.Tok == TOK_REG) {
A->Reg = (unsigned) IVal; A->Reg = (unsigned) CurTok.IVal;
NextTok (); NextTok ();
} else if ((Reg = RegNum ()) >= 0) { } else if ((Reg = RegNum ()) >= 0) {
/* Register number */ /* Register number */
@ -100,12 +100,12 @@ void GetSweet16EA (EffAddr* A)
A->Reg = 0; A->Reg = 0;
} }
} else if (Tok == TOK_REG) { } else if (CurTok.Tok == TOK_REG) {
A->Reg = (unsigned) IVal; A->Reg = (unsigned) CurTok.IVal;
NextTok (); NextTok ();
if (Tok == TOK_COMMA) { if (CurTok.Tok == TOK_COMMA) {
/* Rx, constant */ /* Rx, constant */
NextTok (); NextTok ();
@ -133,7 +133,7 @@ void GetSweet16EA (EffAddr* A)
A->Reg = (unsigned) Reg; A->Reg = (unsigned) Reg;
/* If a comma follows, it is: OPC Rx, constant */ /* If a comma follows, it is: OPC Rx, constant */
if (Tok == TOK_COMMA) { if (CurTok.Tok == TOK_COMMA) {
NextTok (); NextTok ();
A->Expr = Expression (); A->Expr = Expression ();
A->AddrModeSet = AMSW16_IMM; A->AddrModeSet = AMSW16_IMM;
@ -147,4 +147,4 @@ void GetSweet16EA (EffAddr* A)
} }

View File

@ -6,10 +6,10 @@
/* */ /* */
/* */ /* */
/* */ /* */
/* (C) 2003-2008 Ullrich von Bassewitz */ /* (C) 2003-2011, Ullrich von Bassewitz */
/* Roemerstrasse 52 */ /* Roemerstrasse 52 */
/* D-70794 Filderstadt */ /* D-70794 Filderstadt */
/* EMail: uz@cc65.org */ /* EMail: uz@cc65.org */
/* */ /* */
/* */ /* */
/* This software is provided 'as-is', without any expressed or implied */ /* This software is provided 'as-is', without any expressed or implied */
@ -62,10 +62,10 @@ void DoEnum (void)
ExprNode* BaseExpr = GenLiteral0 (); ExprNode* BaseExpr = GenLiteral0 ();
/* Check for a name */ /* Check for a name */
int Anon = (Tok != TOK_IDENT); int Anon = (CurTok.Tok != TOK_IDENT);
if (!Anon) { if (!Anon) {
/* Enter a new scope, then skip the name */ /* Enter a new scope, then skip the name */
SymEnterLevel (&SVal, ST_ENUM, ADDR_SIZE_ABS); SymEnterLevel (&CurTok.SVal, ST_ENUM, ADDR_SIZE_ABS);
NextTok (); NextTok ();
} }
@ -73,19 +73,19 @@ void DoEnum (void)
ConsumeSep (); ConsumeSep ();
/* Read until end of struct */ /* Read until end of struct */
while (Tok != TOK_ENDENUM && Tok != TOK_EOF) { while (CurTok.Tok != TOK_ENDENUM && CurTok.Tok != TOK_EOF) {
SymEntry* Sym; SymEntry* Sym;
ExprNode* EnumExpr; ExprNode* EnumExpr;
/* Skip empty lines */ /* Skip empty lines */
if (Tok == TOK_SEP) { if (CurTok.Tok == TOK_SEP) {
NextTok (); NextTok ();
continue; continue;
} }
/* The format is "identifier [ = value ]" */ /* The format is "identifier [ = value ]" */
if (Tok != TOK_IDENT) { if (CurTok.Tok != TOK_IDENT) {
/* Maybe it's a conditional? */ /* Maybe it's a conditional? */
if (!CheckConditionals ()) { if (!CheckConditionals ()) {
ErrorSkip ("Identifier expected"); ErrorSkip ("Identifier expected");
@ -94,13 +94,13 @@ void DoEnum (void)
} }
/* We have an identifier, generate a symbol */ /* We have an identifier, generate a symbol */
Sym = SymFind (CurrentScope, &SVal, SYM_ALLOC_NEW); Sym = SymFind (CurrentScope, &CurTok.SVal, SYM_ALLOC_NEW);
/* Skip the member name */ /* Skip the member name */
NextTok (); NextTok ();
/* Check for an assignment */ /* Check for an assignment */
if (Tok == TOK_EQ) { if (CurTok.Tok == TOK_EQ) {
/* Skip the equal sign */ /* Skip the equal sign */
NextTok (); NextTok ();
@ -145,3 +145,4 @@ void DoEnum (void)

View File

@ -6,10 +6,10 @@
/* */ /* */
/* */ /* */
/* */ /* */
/* (C) 1998-2008 Ullrich von Bassewitz */ /* (C) 1998-2011, Ullrich von Bassewitz */
/* Roemerstrasse 52 */ /* Roemerstrasse 52 */
/* D-70794 Filderstadt */ /* D-70794 Filderstadt */
/* EMail: uz@cc65.org */ /* EMail: uz@cc65.org */
/* */ /* */
/* */ /* */
/* This software is provided 'as-is', without any expressed or implied */ /* This software is provided 'as-is', without any expressed or implied */
@ -94,7 +94,7 @@ void Warning (unsigned Level, const char* Format, ...)
{ {
va_list ap; va_list ap;
va_start (ap, Format); va_start (ap, Format);
WarningMsg (&CurPos, Level, Format, ap); WarningMsg (&CurTok.Pos, Level, Format, ap);
va_end (ap); va_end (ap);
} }
@ -140,7 +140,7 @@ void Error (const char* Format, ...)
{ {
va_list ap; va_list ap;
va_start (ap, Format); va_start (ap, Format);
ErrorMsg (&CurPos, Format, ap); ErrorMsg (&CurTok.Pos, Format, ap);
va_end (ap); va_end (ap);
} }
@ -162,7 +162,7 @@ void ErrorSkip (const char* Format, ...)
{ {
va_list ap; va_list ap;
va_start (ap, Format); va_start (ap, Format);
ErrorMsg (&CurPos, Format, ap); ErrorMsg (&CurTok.Pos, Format, ap);
va_end (ap); va_end (ap);
SkipUntilSep (); SkipUntilSep ();

View File

@ -335,13 +335,13 @@ static ExprNode* FuncBlank (void)
*/ */
token_t Term = GetTokListTerm (TOK_RPAREN); token_t Term = GetTokListTerm (TOK_RPAREN);
unsigned Count = 0; unsigned Count = 0;
while (Tok != Term) { while (CurTok.Tok != Term) {
/* Check for end of line or end of input. Since the calling function /* Check for end of line or end of input. Since the calling function
* will check for the closing paren, we don't need to print an error * will check for the closing paren, we don't need to print an error
* here, just bail out. * here, just bail out.
*/ */
if (TokIsSep (Tok)) { if (TokIsSep (CurTok.Tok)) {
break; break;
} }
@ -353,7 +353,7 @@ static ExprNode* FuncBlank (void)
} }
/* If the list was enclosed in curly braces, skip the closing brace */ /* If the list was enclosed in curly braces, skip the closing brace */
if (Term == TOK_RCURLY && Tok == TOK_RCURLY) { if (Term == TOK_RCURLY && CurTok.Tok == TOK_RCURLY) {
NextTok (); NextTok ();
} }
@ -438,10 +438,10 @@ static ExprNode* DoMatch (enum TC EqualityLevel)
* either enclosed in curly braces, or terminated by a comma. * either enclosed in curly braces, or terminated by a comma.
*/ */
token_t Term = GetTokListTerm (TOK_COMMA); token_t Term = GetTokListTerm (TOK_COMMA);
while (Tok != Term) { while (CurTok.Tok != Term) {
/* We may not end-of-line of end-of-file here */ /* We may not end-of-line of end-of-file here */
if (TokIsSep (Tok)) { if (TokIsSep (CurTok.Tok)) {
Error ("Unexpected end of line"); Error ("Unexpected end of line");
return GenLiteral0 (); return GenLiteral0 ();
} }
@ -476,10 +476,10 @@ static ExprNode* DoMatch (enum TC EqualityLevel)
Term = GetTokListTerm (TOK_RPAREN); Term = GetTokListTerm (TOK_RPAREN);
Result = 1; Result = 1;
Node = Root; Node = Root;
while (Tok != Term) { while (CurTok.Tok != Term) {
/* We may not end-of-line of end-of-file here */ /* We may not end-of-line of end-of-file here */
if (TokIsSep (Tok)) { if (TokIsSep (CurTok.Tok)) {
Error ("Unexpected end of line"); Error ("Unexpected end of line");
return GenLiteral0 (); return GenLiteral0 ();
} }
@ -621,18 +621,18 @@ static ExprNode* FuncSizeOf (void)
SizeSym = 0; SizeSym = 0;
/* Check for a cheap local which needs special handling */ /* Check for a cheap local which needs special handling */
if (Tok == TOK_LOCAL_IDENT) { if (CurTok.Tok == TOK_LOCAL_IDENT) {
/* Cheap local symbol */ /* Cheap local symbol */
Sym = SymFindLocal (SymLast, &SVal, SYM_FIND_EXISTING); Sym = SymFindLocal (SymLast, &CurTok.SVal, SYM_FIND_EXISTING);
if (Sym == 0) { if (Sym == 0) {
Error ("Unknown symbol or scope: `%m%p'", &SVal); Error ("Unknown symbol or scope: `%m%p'", &CurTok.SVal);
} else { } else {
SizeSym = GetSizeOfSymbol (Sym); SizeSym = GetSizeOfSymbol (Sym);
} }
/* Remember and skip SVal, terminate ScopeName so it is empty */ /* Remember and skip SVal, terminate ScopeName so it is empty */
SB_Copy (&Name, &SVal); SB_Copy (&Name, &CurTok.SVal);
NextTok (); NextTok ();
SB_Terminate (&ScopeName); SB_Terminate (&ScopeName);
@ -708,14 +708,14 @@ static ExprNode* FuncStrAt (void)
unsigned char C = 0; unsigned char C = 0;
/* String constant expected */ /* String constant expected */
if (Tok != TOK_STRCON) { if (CurTok.Tok != TOK_STRCON) {
Error ("String constant expected"); Error ("String constant expected");
NextTok (); NextTok ();
goto ExitPoint; goto ExitPoint;
} }
/* Remember the string and skip it */ /* Remember the string and skip it */
SB_Copy (&Str, &SVal); SB_Copy (&Str, &CurTok.SVal);
NextTok (); NextTok ();
/* Comma must follow */ /* Comma must follow */
@ -751,11 +751,11 @@ static ExprNode* FuncStrLen (void)
int Len; int Len;
/* String constant expected */ /* String constant expected */
if (Tok != TOK_STRCON) { if (CurTok.Tok != TOK_STRCON) {
Error ("String constant expected"); Error ("String constant expected");
/* Smart error recovery */ /* Smart error recovery */
if (Tok != TOK_RPAREN) { if (CurTok.Tok != TOK_RPAREN) {
NextTok (); NextTok ();
} }
Len = 0; Len = 0;
@ -763,7 +763,7 @@ static ExprNode* FuncStrLen (void)
} else { } else {
/* Get the length of the string */ /* Get the length of the string */
Len = SB_GetLen (&SVal); Len = SB_GetLen (&CurTok.SVal);
/* Skip the string */ /* Skip the string */
NextTok (); NextTok ();
@ -783,13 +783,13 @@ static ExprNode* FuncTCount (void)
*/ */
token_t Term = GetTokListTerm (TOK_RPAREN); token_t Term = GetTokListTerm (TOK_RPAREN);
int Count = 0; int Count = 0;
while (Tok != Term) { while (CurTok.Tok != Term) {
/* Check for end of line or end of input. Since the calling function /* Check for end of line or end of input. Since the calling function
* will check for the closing paren, we don't need to print an error * will check for the closing paren, we don't need to print an error
* here, just bail out. * here, just bail out.
*/ */
if (TokIsSep (Tok)) { if (TokIsSep (CurTok.Tok)) {
break; break;
} }
@ -801,7 +801,7 @@ static ExprNode* FuncTCount (void)
} }
/* If the list was enclosed in curly braces, skip the closing brace */ /* If the list was enclosed in curly braces, skip the closing brace */
if (Term == TOK_RCURLY && Tok == TOK_RCURLY) { if (Term == TOK_RCURLY && CurTok.Tok == TOK_RCURLY) {
NextTok (); NextTok ();
} }
@ -828,7 +828,7 @@ static ExprNode* Function (ExprNode* (*F) (void))
NextTok (); NextTok ();
/* Expression must be enclosed in braces */ /* Expression must be enclosed in braces */
if (Tok != TOK_LPAREN) { if (CurTok.Tok != TOK_LPAREN) {
Error ("'(' expected"); Error ("'(' expected");
SkipUntilSep (); SkipUntilSep ();
return GenLiteral0 (); return GenLiteral0 ();
@ -853,15 +853,15 @@ static ExprNode* Factor (void)
ExprNode* N; ExprNode* N;
long Val; long Val;
switch (Tok) { switch (CurTok.Tok) {
case TOK_INTCON: case TOK_INTCON:
N = GenLiteralExpr (IVal); N = GenLiteralExpr (CurTok.IVal);
NextTok (); NextTok ();
break; break;
case TOK_CHARCON: case TOK_CHARCON:
N = GenLiteralExpr (TgtTranslateChar (IVal)); N = GenLiteralExpr (TgtTranslateChar (CurTok.IVal));
NextTok (); NextTok ();
break; break;
@ -872,7 +872,7 @@ static ExprNode* Factor (void)
break; break;
case TOK_ULABEL: case TOK_ULABEL:
N = ULabRef (IVal); N = ULabRef (CurTok.IVal);
NextTok (); NextTok ();
break; break;
@ -1016,9 +1016,10 @@ static ExprNode* Factor (void)
break; break;
default: default:
if (LooseCharTerm && Tok == TOK_STRCON && SB_GetLen (&SVal) == 1) { if (LooseCharTerm && CurTok.Tok == TOK_STRCON &&
SB_GetLen (&CurTok.SVal) == 1) {
/* A character constant */ /* A character constant */
N = GenLiteralExpr (TgtTranslateChar (SB_At (&SVal, 0))); N = GenLiteralExpr (TgtTranslateChar (SB_At (&CurTok.SVal, 0)));
} else { } else {
N = GenLiteral0 (); /* Dummy */ N = GenLiteral0 (); /* Dummy */
Error ("Syntax error"); Error ("Syntax error");
@ -1037,16 +1038,17 @@ static ExprNode* Term (void)
ExprNode* Root = Factor (); ExprNode* Root = Factor ();
/* Handle multiplicative operations */ /* Handle multiplicative operations */
while (Tok == TOK_MUL || Tok == TOK_DIV || Tok == TOK_MOD || while (CurTok.Tok == TOK_MUL || CurTok.Tok == TOK_DIV ||
Tok == TOK_AND || Tok == TOK_XOR || Tok == TOK_SHL || CurTok.Tok == TOK_MOD || CurTok.Tok == TOK_AND ||
Tok == TOK_SHR) { CurTok.Tok == TOK_XOR || CurTok.Tok == TOK_SHL ||
CurTok.Tok == TOK_SHR) {
long LVal, RVal, Val; long LVal, RVal, Val;
ExprNode* Left; ExprNode* Left;
ExprNode* Right; ExprNode* Right;
/* Remember the token and skip it */ /* Remember the token and skip it */
token_t T = Tok; token_t T = CurTok.Tok;
NextTok (); NextTok ();
/* Move root to left side and read the right side */ /* Move root to left side and read the right side */
@ -1140,14 +1142,16 @@ static ExprNode* SimpleExpr (void)
ExprNode* Root = Term (); ExprNode* Root = Term ();
/* Handle additive operations */ /* Handle additive operations */
while (Tok == TOK_PLUS || Tok == TOK_MINUS || Tok == TOK_OR) { while (CurTok.Tok == TOK_PLUS ||
CurTok.Tok == TOK_MINUS ||
CurTok.Tok == TOK_OR) {
long LVal, RVal, Val; long LVal, RVal, Val;
ExprNode* Left; ExprNode* Left;
ExprNode* Right; ExprNode* Right;
/* Remember the token and skip it */ /* Remember the token and skip it */
token_t T = Tok; token_t T = CurTok.Tok;
NextTok (); NextTok ();
/* Move root to left side and read the right side */ /* Move root to left side and read the right side */
@ -1201,15 +1205,16 @@ static ExprNode* BoolExpr (void)
ExprNode* Root = SimpleExpr (); ExprNode* Root = SimpleExpr ();
/* Handle booleans */ /* Handle booleans */
while (Tok == TOK_EQ || Tok == TOK_NE || Tok == TOK_LT || while (CurTok.Tok == TOK_EQ || CurTok.Tok == TOK_NE ||
Tok == TOK_GT || Tok == TOK_LE || Tok == TOK_GE) { CurTok.Tok == TOK_LT || CurTok.Tok == TOK_GT ||
CurTok.Tok == TOK_LE || CurTok.Tok == TOK_GE) {
long LVal, RVal, Val; long LVal, RVal, Val;
ExprNode* Left; ExprNode* Left;
ExprNode* Right; ExprNode* Right;
/* Remember the token and skip it */ /* Remember the token and skip it */
token_t T = Tok; token_t T = CurTok.Tok;
NextTok (); NextTok ();
/* Move root to left side and read the right side */ /* Move root to left side and read the right side */
@ -1269,14 +1274,14 @@ static ExprNode* Expr2 (void)
ExprNode* Root = BoolExpr (); ExprNode* Root = BoolExpr ();
/* Handle booleans */ /* Handle booleans */
while (Tok == TOK_BOOLAND || Tok == TOK_BOOLXOR) { while (CurTok.Tok == TOK_BOOLAND || CurTok.Tok == TOK_BOOLXOR) {
long LVal, RVal, Val; long LVal, RVal, Val;
ExprNode* Left; ExprNode* Left;
ExprNode* Right; ExprNode* Right;
/* Remember the token and skip it */ /* Remember the token and skip it */
token_t T = Tok; token_t T = CurTok.Tok;
NextTok (); NextTok ();
/* Move root to left side and read the right side */ /* Move root to left side and read the right side */
@ -1328,14 +1333,14 @@ static ExprNode* Expr1 (void)
ExprNode* Root = Expr2 (); ExprNode* Root = Expr2 ();
/* Handle booleans */ /* Handle booleans */
while (Tok == TOK_BOOLOR) { while (CurTok.Tok == TOK_BOOLOR) {
long LVal, RVal, Val; long LVal, RVal, Val;
ExprNode* Left; ExprNode* Left;
ExprNode* Right; ExprNode* Right;
/* Remember the token and skip it */ /* Remember the token and skip it */
token_t T = Tok; token_t T = CurTok.Tok;
NextTok (); NextTok ();
/* Move root to left side and read the right side */ /* Move root to left side and read the right side */
@ -1384,7 +1389,7 @@ static ExprNode* Expr0 (void)
ExprNode* Root; ExprNode* Root;
/* Handle booleans */ /* Handle booleans */
if (Tok == TOK_BOOLNOT) { if (CurTok.Tok == TOK_BOOLNOT) {
long Val; long Val;
ExprNode* Left; ExprNode* Left;

View File

@ -6,10 +6,10 @@
/* */ /* */
/* */ /* */
/* */ /* */
/* (C) 1998-2003 Ullrich von Bassewitz */ /* (C) 1998-2011, Ullrich von Bassewitz */
/* Römerstrasse 52 */ /* Roemerstrasse 52 */
/* D-70794 Filderstadt */ /* D-70794 Filderstadt */
/* EMail: uz@cc65.org */ /* EMail: uz@cc65.org */
/* */ /* */
/* */ /* */
/* This software is provided 'as-is', without any expressed or implied */ /* This software is provided 'as-is', without any expressed or implied */
@ -60,7 +60,7 @@ Fragment* NewFragment (unsigned char Type, unsigned short Len)
/* Initialize it */ /* Initialize it */
F->Next = 0; F->Next = 0;
F->LineList = 0; F->LineList = 0;
F->Pos = CurPos; F->Pos = CurTok.Pos;
F->LI = UseLineInfo (CurLineInfo); F->LI = UseLineInfo (CurLineInfo);
F->Len = Len; F->Len = Len;
F->Type = Type; F->Type = Type;

View File

@ -6,7 +6,7 @@
/* */ /* */
/* */ /* */
/* */ /* */
/* (C) 1998-2009, Ullrich von Bassewitz */ /* (C) 1998-2011, Ullrich von Bassewitz */
/* Roemerstrasse 52 */ /* Roemerstrasse 52 */
/* D-70794 Filderstadt */ /* D-70794 Filderstadt */
/* EMail: uz@cc65.org */ /* EMail: uz@cc65.org */
@ -1255,7 +1255,7 @@ static void PutTST (const InsDesc* Ins)
EffAddr A; EffAddr A;
/* The first argument is always an immediate byte */ /* The first argument is always an immediate byte */
if (Tok != TOK_HASH) { if (CurTok.Tok != TOK_HASH) {
ErrorSkip ("Invalid addressing mode"); ErrorSkip ("Invalid addressing mode");
return; return;
} }

View File

@ -6,10 +6,10 @@
/* */ /* */
/* */ /* */
/* */ /* */
/* (C) 1998-2008 Ullrich von Bassewitz */ /* (C) 1998-2011, Ullrich von Bassewitz */
/* Roemerstrasse 52 */ /* Roemerstrasse 52 */
/* D-70794 Filderstadt */ /* D-70794 Filderstadt */
/* EMail: uz@cc65.org */ /* EMail: uz@cc65.org */
/* */ /* */
/* */ /* */
/* This software is provided 'as-is', without any expressed or implied */ /* This software is provided 'as-is', without any expressed or implied */
@ -311,10 +311,10 @@ static void MacSkipDef (unsigned Style)
{ {
if (Style == MAC_STYLE_CLASSIC) { if (Style == MAC_STYLE_CLASSIC) {
/* Skip tokens until we reach the final .endmacro */ /* Skip tokens until we reach the final .endmacro */
while (Tok != TOK_ENDMACRO && Tok != TOK_EOF) { while (CurTok.Tok != TOK_ENDMACRO && CurTok.Tok != TOK_EOF) {
NextTok (); NextTok ();
} }
if (Tok != TOK_EOF) { if (CurTok.Tok != TOK_EOF) {
SkipUntilSep (); SkipUntilSep ();
} else { } else {
Error ("`.ENDMACRO' expected"); Error ("`.ENDMACRO' expected");
@ -335,11 +335,11 @@ void MacDef (unsigned Style)
int HaveParams; int HaveParams;
/* We expect a macro name here */ /* We expect a macro name here */
if (Tok != TOK_IDENT) { if (CurTok.Tok != TOK_IDENT) {
Error ("Identifier expected"); Error ("Identifier expected");
MacSkipDef (Style); MacSkipDef (Style);
return; return;
} else if (!UbiquitousIdents && FindInstruction (&SVal) >= 0) { } else if (!UbiquitousIdents && FindInstruction (&CurTok.SVal) >= 0) {
/* The identifier is a name of a 6502 instruction, which is not /* The identifier is a name of a 6502 instruction, which is not
* allowed if not explicitly enabled. * allowed if not explicitly enabled.
*/ */
@ -349,16 +349,16 @@ void MacDef (unsigned Style)
} }
/* Did we already define that macro? */ /* Did we already define that macro? */
if (HT_Find (&MacroTab, &SVal) != 0) { if (HT_Find (&MacroTab, &CurTok.SVal) != 0) {
/* Macro is already defined */ /* Macro is already defined */
Error ("A macro named `%m%p' is already defined", &SVal); Error ("A macro named `%m%p' is already defined", &CurTok.SVal);
/* Skip tokens until we reach the final .endmacro */ /* Skip tokens until we reach the final .endmacro */
MacSkipDef (Style); MacSkipDef (Style);
return; return;
} }
/* Define the macro */ /* Define the macro */
M = NewMacro (&SVal, Style); M = NewMacro (&CurTok.SVal, Style);
/* Switch to raw token mode and skip the macro name */ /* Switch to raw token mode and skip the macro name */
EnterRawTokenMode (); EnterRawTokenMode ();
@ -370,7 +370,7 @@ void MacDef (unsigned Style)
if (Style == MAC_STYLE_CLASSIC) { if (Style == MAC_STYLE_CLASSIC) {
HaveParams = 1; HaveParams = 1;
} else { } else {
if (Tok == TOK_LPAREN) { if (CurTok.Tok == TOK_LPAREN) {
HaveParams = 1; HaveParams = 1;
NextTok (); NextTok ();
} else { } else {
@ -381,10 +381,10 @@ void MacDef (unsigned Style)
/* Parse the parameter list */ /* Parse the parameter list */
if (HaveParams) { if (HaveParams) {
while (Tok == TOK_IDENT) { while (CurTok.Tok == TOK_IDENT) {
/* Create a struct holding the identifier */ /* Create a struct holding the identifier */
IdDesc* I = NewIdDesc (&SVal); IdDesc* I = NewIdDesc (&CurTok.SVal);
/* Insert the struct into the list, checking for duplicate idents */ /* Insert the struct into the list, checking for duplicate idents */
if (M->ParamCount == 0) { if (M->ParamCount == 0) {
@ -392,8 +392,8 @@ void MacDef (unsigned Style)
} else { } else {
IdDesc* List = M->Params; IdDesc* List = M->Params;
while (1) { while (1) {
if (SB_Compare (&List->Id, &SVal) == 0) { if (SB_Compare (&List->Id, &CurTok.SVal) == 0) {
Error ("Duplicate symbol `%m%p'", &SVal); Error ("Duplicate symbol `%m%p'", &CurTok.SVal);
} }
if (List->Next == 0) { if (List->Next == 0) {
break; break;
@ -409,7 +409,7 @@ void MacDef (unsigned Style)
NextTok (); NextTok ();
/* Maybe there are more params... */ /* Maybe there are more params... */
if (Tok == TOK_COMMA) { if (CurTok.Tok == TOK_COMMA) {
NextTok (); NextTok ();
} else { } else {
break; break;
@ -436,24 +436,24 @@ void MacDef (unsigned Style)
/* Check for end of macro */ /* Check for end of macro */
if (Style == MAC_STYLE_CLASSIC) { if (Style == MAC_STYLE_CLASSIC) {
/* In classic macros, only .endmacro is allowed */ /* In classic macros, only .endmacro is allowed */
if (Tok == TOK_ENDMACRO) { if (CurTok.Tok == TOK_ENDMACRO) {
/* Done */ /* Done */
break; break;
} }
/* May not have end of file in a macro definition */ /* May not have end of file in a macro definition */
if (Tok == TOK_EOF) { if (CurTok.Tok == TOK_EOF) {
Error ("`.ENDMACRO' expected"); Error ("`.ENDMACRO' expected");
goto Done; goto Done;
} }
} else { } else {
/* Accept a newline or end of file for new style macros */ /* Accept a newline or end of file for new style macros */
if (TokIsSep (Tok)) { if (TokIsSep (CurTok.Tok)) {
break; break;
} }
} }
/* Check for a .LOCAL declaration */ /* Check for a .LOCAL declaration */
if (Tok == TOK_LOCAL && Style == MAC_STYLE_CLASSIC) { if (CurTok.Tok == TOK_LOCAL && Style == MAC_STYLE_CLASSIC) {
while (1) { while (1) {
@ -463,21 +463,21 @@ void MacDef (unsigned Style)
NextTok (); NextTok ();
/* Need an identifer */ /* Need an identifer */
if (Tok != TOK_IDENT && Tok != TOK_LOCAL_IDENT) { if (CurTok.Tok != TOK_IDENT && CurTok.Tok != TOK_LOCAL_IDENT) {
Error ("Identifier expected"); Error ("Identifier expected");
SkipUntilSep (); SkipUntilSep ();
break; break;
} }
/* Put the identifier into the locals list and skip it */ /* Put the identifier into the locals list and skip it */
I = NewIdDesc (&SVal); I = NewIdDesc (&CurTok.SVal);
I->Next = M->Locals; I->Next = M->Locals;
M->Locals = I; M->Locals = I;
++M->LocalCount; ++M->LocalCount;
NextTok (); NextTok ();
/* Check for end of list */ /* Check for end of list */
if (Tok != TOK_COMMA) { if (CurTok.Tok != TOK_COMMA) {
break; break;
} }
@ -492,11 +492,11 @@ void MacDef (unsigned Style)
T = NewTokNode (); T = NewTokNode ();
/* If the token is an ident, check if it is a local parameter */ /* If the token is an ident, check if it is a local parameter */
if (Tok == TOK_IDENT) { if (CurTok.Tok == TOK_IDENT) {
unsigned Count = 0; unsigned Count = 0;
IdDesc* I = M->Params; IdDesc* I = M->Params;
while (I) { while (I) {
if (SB_Compare (&I->Id, &SVal) == 0) { if (SB_Compare (&I->Id, &CurTok.SVal) == 0) {
/* Local param name, replace it */ /* Local param name, replace it */
T->Tok = TOK_MACPARAM; T->Tok = TOK_MACPARAM;
T->IVal = Count; T->IVal = Count;
@ -584,29 +584,30 @@ static int MacExpand (void* Data)
Mac->Exp = Mac->Exp->Next; Mac->Exp = Mac->Exp->Next;
/* Is it a request for actual parameter count? */ /* Is it a request for actual parameter count? */
if (Tok == TOK_PARAMCOUNT) { if (CurTok.Tok == TOK_PARAMCOUNT) {
Tok = TOK_INTCON; CurTok.Tok = TOK_INTCON;
IVal = Mac->ParamCount; CurTok.IVal = Mac->ParamCount;
return 1; return 1;
} }
/* Is it the name of a macro parameter? */ /* Is it the name of a macro parameter? */
if (Tok == TOK_MACPARAM) { if (CurTok.Tok == TOK_MACPARAM) {
/* Start to expand the parameter token list */ /* Start to expand the parameter token list */
Mac->ParamExp = Mac->Params [IVal]; Mac->ParamExp = Mac->Params [CurTok.IVal];
/* Recursive call to expand the parameter */ /* Recursive call to expand the parameter */
return MacExpand (Mac); return MacExpand (Mac);
} }
/* If it's an identifier, it may in fact be a local symbol */ /* If it's an identifier, it may in fact be a local symbol */
if ((Tok == TOK_IDENT || Tok == TOK_LOCAL_IDENT) && Mac->M->LocalCount) { if ((CurTok.Tok == TOK_IDENT || CurTok.Tok == TOK_LOCAL_IDENT) &&
Mac->M->LocalCount) {
/* Search for the local symbol in the list */ /* Search for the local symbol in the list */
unsigned Index = 0; unsigned Index = 0;
IdDesc* I = Mac->M->Locals; IdDesc* I = Mac->M->Locals;
while (I) { while (I) {
if (SB_Compare (&SVal, &I->Id) == 0) { if (SB_Compare (&CurTok.SVal, &I->Id) == 0) {
/* This is in fact a local symbol, change the name. Be sure /* This is in fact a local symbol, change the name. Be sure
* to generate a local label name if the original name was * to generate a local label name if the original name was
* a local label, and also generate a name that cannot be * a local label, and also generate a name that cannot be
@ -614,11 +615,11 @@ static int MacExpand (void* Data)
*/ */
if (SB_At (&I->Id, 0) == LocalStart) { if (SB_At (&I->Id, 0) == LocalStart) {
/* Must generate a local symbol */ /* Must generate a local symbol */
SB_Printf (&SVal, "%cLOCAL-MACRO_SYMBOL-%04X", SB_Printf (&CurTok.SVal, "%cLOCAL-MACRO_SYMBOL-%04X",
LocalStart, Mac->LocalStart + Index); LocalStart, Mac->LocalStart + Index);
} else { } else {
/* Global symbol */ /* Global symbol */
SB_Printf (&SVal, "LOCAL-MACRO_SYMBOL-%04X", SB_Printf (&CurTok.SVal, "LOCAL-MACRO_SYMBOL-%04X",
Mac->LocalStart + Index); Mac->LocalStart + Index);
} }
break; break;
@ -677,7 +678,7 @@ static void StartExpClassic (Macro* M)
E = NewMacExp (M); E = NewMacExp (M);
/* Read the actual parameters */ /* Read the actual parameters */
while (!TokIsSep (Tok)) { while (!TokIsSep (CurTok.Tok)) {
TokNode* Last; TokNode* Last;
@ -692,12 +693,12 @@ static void StartExpClassic (Macro* M)
/* Read tokens for one parameter, accept empty params */ /* Read tokens for one parameter, accept empty params */
Last = 0; Last = 0;
while (Tok != Term && Tok != TOK_SEP) { while (CurTok.Tok != Term && CurTok.Tok != TOK_SEP) {
TokNode* T; TokNode* T;
/* Check for end of file */ /* Check for end of file */
if (Tok == TOK_EOF) { if (CurTok.Tok == TOK_EOF) {
Error ("Unexpected end of file"); Error ("Unexpected end of file");
FreeMacExp (E); FreeMacExp (E);
return; return;
@ -725,7 +726,7 @@ static void StartExpClassic (Macro* M)
* is an error. Skip the closing curly brace. * is an error. Skip the closing curly brace.
*/ */
if (Term == TOK_RCURLY) { if (Term == TOK_RCURLY) {
if (Tok == TOK_SEP) { if (CurTok.Tok == TOK_SEP) {
Error ("End of line encountered within macro argument"); Error ("End of line encountered within macro argument");
break; break;
} }
@ -733,7 +734,7 @@ static void StartExpClassic (Macro* M)
} }
/* Check for a comma */ /* Check for a comma */
if (Tok == TOK_COMMA) { if (CurTok.Tok == TOK_COMMA) {
NextTok (); NextTok ();
} else { } else {
break; break;
@ -772,7 +773,7 @@ static void StartExpDefine (Macro* M)
token_t Term = GetTokListTerm (TOK_COMMA); token_t Term = GetTokListTerm (TOK_COMMA);
/* Check if there is really a parameter */ /* Check if there is really a parameter */
if (TokIsSep (Tok) || Tok == Term) { if (TokIsSep (CurTok.Tok) || CurTok.Tok == Term) {
ErrorSkip ("Macro parameter #%u is empty", E->ParamCount+1); ErrorSkip ("Macro parameter #%u is empty", E->ParamCount+1);
FreeMacExp (E); FreeMacExp (E);
return; return;
@ -798,7 +799,7 @@ static void StartExpDefine (Macro* M)
/* And skip it... */ /* And skip it... */
NextTok (); NextTok ();
} while (Tok != Term && !TokIsSep (Tok)); } while (CurTok.Tok != Term && !TokIsSep (CurTok.Tok));
/* One parameter more */ /* One parameter more */
++E->ParamCount; ++E->ParamCount;
@ -807,7 +808,7 @@ static void StartExpDefine (Macro* M)
* is an error. Skip the closing curly brace. * is an error. Skip the closing curly brace.
*/ */
if (Term == TOK_RCURLY) { if (Term == TOK_RCURLY) {
if (TokIsSep (Tok)) { if (TokIsSep (CurTok.Tok)) {
Error ("End of line encountered within macro argument"); Error ("End of line encountered within macro argument");
break; break;
} }
@ -816,7 +817,7 @@ static void StartExpDefine (Macro* M)
/* Check for a comma */ /* Check for a comma */
if (Count > 0) { if (Count > 0) {
if (Tok == TOK_COMMA) { if (CurTok.Tok == TOK_COMMA) {
NextTok (); NextTok ();
} else { } else {
Error ("`,' expected"); Error ("`,' expected");
@ -841,14 +842,14 @@ void MacExpandStart (void)
/* Start expanding the macro in SVal */ /* Start expanding the macro in SVal */
{ {
/* Search for the macro */ /* Search for the macro */
Macro* M = HT_FindEntry (&MacroTab, &SVal); Macro* M = HT_FindEntry (&MacroTab, &CurTok.SVal);
CHECK (M != 0); CHECK (M != 0);
/* Call the apropriate subroutine */ /* Call the apropriate subroutine */
switch (M->Style) { switch (M->Style) {
case MAC_STYLE_CLASSIC: StartExpClassic (M); break; case MAC_STYLE_CLASSIC: StartExpClassic (M); break;
case MAC_STYLE_DEFINE: StartExpDefine (M); break; case MAC_STYLE_DEFINE: StartExpDefine (M); break;
default: Internal ("Invalid macro style: %d", M->Style); default: Internal ("Invalid macro style: %d", M->Style);
} }
} }
@ -891,3 +892,4 @@ int InMacExpansion (void)

View File

@ -6,7 +6,7 @@
/* */ /* */
/* */ /* */
/* */ /* */
/* (C) 1998-2010, Ullrich von Bassewitz */ /* (C) 1998-2011, Ullrich von Bassewitz */
/* Roemerstrasse 52 */ /* Roemerstrasse 52 */
/* D-70794 Filderstadt */ /* D-70794 Filderstadt */
/* EMail: uz@cc65.org */ /* EMail: uz@cc65.org */
@ -598,7 +598,7 @@ static void OneLine (void)
InitListingLine (); InitListingLine ();
} }
if (Tok == TOK_COLON) { if (CurTok.Tok == TOK_COLON) {
/* An unnamed label */ /* An unnamed label */
ULabDef (); ULabDef ();
NextTok (); NextTok ();
@ -607,16 +607,16 @@ static void OneLine (void)
/* If the first token on the line is an identifier, check for a macro or /* If the first token on the line is an identifier, check for a macro or
* an instruction. * an instruction.
*/ */
if (Tok == TOK_IDENT) { if (CurTok.Tok == TOK_IDENT) {
if (!UbiquitousIdents) { if (!UbiquitousIdents) {
/* Macros and symbols cannot use instruction names */ /* Macros and symbols cannot use instruction names */
Instr = FindInstruction (&SVal); Instr = FindInstruction (&CurTok.SVal);
if (Instr < 0) { if (Instr < 0) {
Macro = IsMacro (&SVal); Macro = IsMacro (&CurTok.SVal);
} }
} else { } else {
/* Macros and symbols may use the names of instructions */ /* Macros and symbols may use the names of instructions */
Macro = IsMacro (&SVal); Macro = IsMacro (&CurTok.SVal);
} }
} }
@ -624,12 +624,12 @@ static void OneLine (void)
* scoped identifier which may start with a namespace token (for global * scoped identifier which may start with a namespace token (for global
* namespace) * namespace)
*/ */
if (Tok == TOK_LOCAL_IDENT || if (CurTok.Tok == TOK_LOCAL_IDENT ||
Tok == TOK_NAMESPACE || CurTok.Tok == TOK_NAMESPACE ||
(Tok == TOK_IDENT && Instr < 0 && !Macro)) { (CurTok.Tok == TOK_IDENT && Instr < 0 && !Macro)) {
/* Did we have whitespace before the ident? */ /* Did we have whitespace before the ident? */
int HadWS = WS; int HadWS = CurTok.WS;
/* Generate the symbol table entry, then skip the name */ /* Generate the symbol table entry, then skip the name */
Sym = ParseAnySymName (SYM_ALLOC_NEW); Sym = ParseAnySymName (SYM_ALLOC_NEW);
@ -637,10 +637,10 @@ static void OneLine (void)
/* If a colon follows, this is a label definition. If there /* If a colon follows, this is a label definition. If there
* is no colon, it's an assignment. * is no colon, it's an assignment.
*/ */
if (Tok == TOK_EQ || Tok == TOK_ASSIGN) { if (CurTok.Tok == TOK_EQ || CurTok.Tok == TOK_ASSIGN) {
/* Determine the symbol flags from the assignment token */ /* Determine the symbol flags from the assignment token */
unsigned Flags = (Tok == TOK_ASSIGN)? SF_LABEL : SF_NONE; unsigned Flags = (CurTok.Tok == TOK_ASSIGN)? SF_LABEL : SF_NONE;
/* Skip the '=' */ /* Skip the '=' */
NextTok (); NextTok ();
@ -652,7 +652,7 @@ static void OneLine (void)
ConsumeSep (); ConsumeSep ();
return; return;
} else if (Tok == TOK_SET) { } else if (CurTok.Tok == TOK_SET) {
ExprNode* Expr; ExprNode* Expr;
@ -686,11 +686,11 @@ static void OneLine (void)
* without a colon if there is no whitespace before the * without a colon if there is no whitespace before the
* identifier. * identifier.
*/ */
if (Tok != TOK_COLON) { if (CurTok.Tok != TOK_COLON) {
if (HadWS || !NoColonLabels) { if (HadWS || !NoColonLabels) {
Error ("`:' expected"); Error ("`:' expected");
/* Try some smart error recovery */ /* Try some smart error recovery */
if (Tok == TOK_NAMESPACE) { if (CurTok.Tok == TOK_NAMESPACE) {
NextTok (); NextTok ();
} }
} }
@ -702,35 +702,35 @@ static void OneLine (void)
/* If we come here, a new identifier may be waiting, which may /* If we come here, a new identifier may be waiting, which may
* be a macro or instruction. * be a macro or instruction.
*/ */
if (Tok == TOK_IDENT) { if (CurTok.Tok == TOK_IDENT) {
if (!UbiquitousIdents) { if (!UbiquitousIdents) {
/* Macros and symbols cannot use instruction names */ /* Macros and symbols cannot use instruction names */
Instr = FindInstruction (&SVal); Instr = FindInstruction (&CurTok.SVal);
if (Instr < 0) { if (Instr < 0) {
Macro = IsMacro (&SVal); Macro = IsMacro (&CurTok.SVal);
} }
} else { } else {
/* Macros and symbols may use the names of instructions */ /* Macros and symbols may use the names of instructions */
Macro = IsMacro (&SVal); Macro = IsMacro (&CurTok.SVal);
} }
} }
} }
} }
/* We've handled a possible label, now handle the remainder of the line */ /* We've handled a possible label, now handle the remainder of the line */
if (Tok >= TOK_FIRSTPSEUDO && Tok <= TOK_LASTPSEUDO) { if (CurTok.Tok >= TOK_FIRSTPSEUDO && CurTok.Tok <= TOK_LASTPSEUDO) {
/* A control command */ /* A control command */
HandlePseudo (); HandlePseudo ();
} else if (Macro) { } else if (Macro) {
/* A macro expansion */ /* A macro expansion */
MacExpandStart (); MacExpandStart ();
} else if (Instr >= 0 || } else if (Instr >= 0 ||
(UbiquitousIdents && ((Instr = FindInstruction (&SVal)) >= 0))) { (UbiquitousIdents && ((Instr = FindInstruction (&CurTok.SVal)) >= 0))) {
/* A mnemonic - assemble one instruction */ /* A mnemonic - assemble one instruction */
HandleInstruction (Instr); HandleInstruction (Instr);
} else if (PCAssignment && (Tok == TOK_STAR || Tok == TOK_PC)) { } else if (PCAssignment && (CurTok.Tok == TOK_STAR || CurTok.Tok == TOK_PC)) {
NextTok (); NextTok ();
if (Tok != TOK_EQ) { if (CurTok.Tok != TOK_EQ) {
Error ("`=' expected"); Error ("`=' expected");
SkipUntilSep (); SkipUntilSep ();
} else { } else {
@ -770,7 +770,7 @@ static void Assemble (void)
NextTok (); NextTok ();
/* Assemble lines until end of file */ /* Assemble lines until end of file */
while (Tok != TOK_EOF) { while (CurTok.Tok != TOK_EOF) {
OneLine (); OneLine ();
} }
} }

View File

@ -73,7 +73,7 @@ static int LookAtStrCon (void)
* true. * true.
*/ */
{ {
if (Tok != TOK_STRCON) { if (CurTok.Tok != TOK_STRCON) {
Error ("String constant expected"); Error ("String constant expected");
SkipUntilSep (); SkipUntilSep ();
return 0; return 0;
@ -106,10 +106,10 @@ static TokList* CollectTokens (unsigned Start, unsigned Count)
/* Read the token list */ /* Read the token list */
unsigned Current = 0; unsigned Current = 0;
while (Tok != Term) { while (CurTok.Tok != Term) {
/* Check for end of line or end of input */ /* Check for end of line or end of input */
if (TokIsSep (Tok)) { if (TokIsSep (CurTok.Tok)) {
Error ("Unexpected end of line"); Error ("Unexpected end of line");
return List; return List;
} }
@ -160,13 +160,13 @@ static void FuncConcat (void)
} }
/* Append the string */ /* Append the string */
SB_Append (&Buf, &SVal); SB_Append (&Buf, &CurTok.SVal);
/* Skip the string token */ /* Skip the string token */
NextTok (); NextTok ();
/* Comma means another argument */ /* Comma means another argument */
if (Tok == TOK_COMMA) { if (CurTok.Tok == TOK_COMMA) {
NextTok (); NextTok ();
} else { } else {
/* Done */ /* Done */
@ -177,11 +177,11 @@ static void FuncConcat (void)
/* We expect a closing parenthesis, but will not skip it but replace it /* We expect a closing parenthesis, but will not skip it but replace it
* by the string token just created. * by the string token just created.
*/ */
if (Tok != TOK_RPAREN) { if (CurTok.Tok != TOK_RPAREN) {
Error ("`)' expected"); Error ("`)' expected");
} else { } else {
Tok = TOK_STRCON; CurTok.Tok = TOK_STRCON;
SB_Copy (&SVal, &Buf); SB_Copy (&CurTok.SVal, &Buf);
} }
/* Free the string buffer */ /* Free the string buffer */
@ -203,7 +203,7 @@ static void FuncIdent (void)
/* Handle the .IDENT function */ /* Handle the .IDENT function */
{ {
StrBuf Buf = STATIC_STRBUF_INITIALIZER; StrBuf Buf = STATIC_STRBUF_INITIALIZER;
token_t Id; token_t Id;
unsigned I; unsigned I;
/* Skip it */ /* Skip it */
@ -220,23 +220,23 @@ static void FuncIdent (void)
/* Check that the string contains a valid identifier. While doing so, /* Check that the string contains a valid identifier. While doing so,
* determine if it is a cheap local, or global one. * determine if it is a cheap local, or global one.
*/ */
SB_Reset (&SVal); SB_Reset (&CurTok.SVal);
/* Check for a cheap local symbol */ /* Check for a cheap local symbol */
if (SB_Peek (&SVal) == LocalStart) { if (SB_Peek (&CurTok.SVal) == LocalStart) {
SB_Skip (&SVal); SB_Skip (&CurTok.SVal);
Id = TOK_LOCAL_IDENT; Id = TOK_LOCAL_IDENT;
} else { } else {
Id = TOK_IDENT; Id = TOK_IDENT;
} }
/* Next character must be a valid identifier start */ /* Next character must be a valid identifier start */
if (!IsIdStart (SB_Get (&SVal))) { if (!IsIdStart (SB_Get (&CurTok.SVal))) {
NoIdent (); NoIdent ();
return; return;
} }
for (I = SB_GetIndex (&SVal); I < SB_GetLen (&SVal); ++I) { for (I = SB_GetIndex (&CurTok.SVal); I < SB_GetLen (&CurTok.SVal); ++I) {
if (!IsIdChar (SB_AtUnchecked (&SVal, I))) { if (!IsIdChar (SB_AtUnchecked (&CurTok.SVal, I))) {
NoIdent (); NoIdent ();
return; return;
} }
@ -248,13 +248,13 @@ static void FuncIdent (void)
/* If anything is ok, save and skip the string. Check that the next token /* If anything is ok, save and skip the string. Check that the next token
* is a right paren, then replace the token by an identifier token. * is a right paren, then replace the token by an identifier token.
*/ */
SB_Copy (&Buf, &SVal); SB_Copy (&Buf, &CurTok.SVal);
NextTok (); NextTok ();
if (Tok != TOK_RPAREN) { if (CurTok.Tok != TOK_RPAREN) {
Error ("`)' expected"); Error ("`)' expected");
} else { } else {
Tok = Id; CurTok.Tok = Id;
SB_Copy (&SVal, &Buf); SB_Copy (&CurTok.SVal, &Buf);
} }
/* Free buffer memory */ /* Free buffer memory */
@ -442,7 +442,7 @@ static void FuncSPrintF (void)
if (!LookAtStrCon ()) { if (!LookAtStrCon ()) {
return; return;
} }
SB_Copy (&Format, &SVal); SB_Copy (&Format, &CurTok.SVal);
NextTok (); NextTok ();
/* Walk over the format string, generating the function result in R */ /* Walk over the format string, generating the function result in R */
@ -544,11 +544,11 @@ static void FuncSPrintF (void)
/* The argument must be a string constant */ /* The argument must be a string constant */
if (!LookAtStrCon ()) { if (!LookAtStrCon ()) {
/* Make it one */ /* Make it one */
SB_CopyStr (&SVal, "**undefined**"); SB_CopyStr (&CurTok.SVal, "**undefined**");
} }
/* Format this argument according to the spec */ /* Format this argument according to the spec */
SB_Printf (&R1, SB_GetConstBuf (&F1), SVal); SB_Printf (&R1, SB_GetConstBuf (&F1), CurTok.SVal);
/* Skip the string constant */ /* Skip the string constant */
NextTok (); NextTok ();
@ -596,11 +596,11 @@ static void FuncSPrintF (void)
/* We expect a closing parenthesis, but will not skip it but replace it /* We expect a closing parenthesis, but will not skip it but replace it
* by the string token just created. * by the string token just created.
*/ */
if (Tok != TOK_RPAREN) { if (CurTok.Tok != TOK_RPAREN) {
Error ("`)' expected"); Error ("`)' expected");
} else { } else {
Tok = TOK_STRCON; CurTok.Tok = TOK_STRCON;
SB_Copy (&SVal, &R); SB_Copy (&CurTok.SVal, &R);
} }
@ -612,7 +612,7 @@ static void FuncSPrintF (void)
} }
static void FuncString (void) static void FuncString (void)
/* Handle the .STRING function */ /* Handle the .STRING function */
{ {
@ -625,9 +625,9 @@ static void FuncString (void)
ConsumeLParen (); ConsumeLParen ();
/* Accept identifiers or numeric expressions */ /* Accept identifiers or numeric expressions */
if (Tok == TOK_IDENT || Tok == TOK_LOCAL_IDENT) { if (CurTok.Tok == TOK_IDENT || CurTok.Tok == TOK_LOCAL_IDENT) {
/* Save the identifier, then skip it */ /* Save the identifier, then skip it */
SB_Copy (&Buf, &SVal); SB_Copy (&Buf, &CurTok.SVal);
NextTok (); NextTok ();
} else { } else {
/* Numeric expression */ /* Numeric expression */
@ -638,11 +638,11 @@ static void FuncString (void)
/* We expect a closing parenthesis, but will not skip it but replace it /* We expect a closing parenthesis, but will not skip it but replace it
* by the string token just created. * by the string token just created.
*/ */
if (Tok != TOK_RPAREN) { if (CurTok.Tok != TOK_RPAREN) {
Error ("`)' expected"); Error ("`)' expected");
} else { } else {
Tok = TOK_STRCON; CurTok.Tok = TOK_STRCON;
SB_Copy (&SVal, &Buf); SB_Copy (&CurTok.SVal, &Buf);
} }
/* Free string memory */ /* Free string memory */
@ -661,7 +661,7 @@ void NextTok (void)
if (RawMode == 0) { if (RawMode == 0) {
/* Execute token handling functions */ /* Execute token handling functions */
switch (Tok) { switch (CurTok.Tok) {
case TOK_CONCAT: case TOK_CONCAT:
FuncConcat (); FuncConcat ();
@ -704,7 +704,7 @@ void NextTok (void)
void Consume (token_t Expected, const char* ErrMsg) void Consume (token_t Expected, const char* ErrMsg)
/* Consume Expected, print an error if we don't find it */ /* Consume Expected, print an error if we don't find it */
{ {
if (Tok == Expected) { if (CurTok.Tok == Expected) {
NextTok (); NextTok ();
} else { } else {
Error ("%s", ErrMsg); Error ("%s", ErrMsg);
@ -720,7 +720,7 @@ void ConsumeSep (void)
ExpectSep (); ExpectSep ();
/* If we are at end of line, skip it */ /* If we are at end of line, skip it */
if (Tok == TOK_SEP) { if (CurTok.Tok == TOK_SEP) {
NextTok (); NextTok ();
} }
} }
@ -754,7 +754,7 @@ void ConsumeComma (void)
void SkipUntilSep (void) void SkipUntilSep (void)
/* Skip tokens until we reach a line separator or end of file */ /* Skip tokens until we reach a line separator or end of file */
{ {
while (!TokIsSep (Tok)) { while (!TokIsSep (CurTok.Tok)) {
NextTok (); NextTok ();
} }
} }
@ -766,7 +766,7 @@ void ExpectSep (void)
* not skip the line separator. * not skip the line separator.
*/ */
{ {
if (!TokIsSep (Tok)) { if (!TokIsSep (CurTok.Tok)) {
ErrorSkip ("Unexpected trailing garbage characters"); ErrorSkip ("Unexpected trailing garbage characters");
} }
} }

View File

@ -131,7 +131,7 @@ static unsigned char OptionalAddrSize (void)
*/ */
{ {
unsigned AddrSize = ADDR_SIZE_DEFAULT; unsigned AddrSize = ADDR_SIZE_DEFAULT;
if (Tok == TOK_COLON) { if (CurTok.Tok == TOK_COLON) {
NextTok (); NextTok ();
AddrSize = ParseAddrSize (); AddrSize = ParseAddrSize ();
if (!ValidAddrSizeForCPU (AddrSize)) { if (!ValidAddrSizeForCPU (AddrSize)) {
@ -154,20 +154,20 @@ static void SetBoolOption (unsigned char* Flag)
"ON", "ON",
}; };
if (Tok == TOK_PLUS) { if (CurTok.Tok == TOK_PLUS) {
*Flag = 1; *Flag = 1;
NextTok (); NextTok ();
} else if (Tok == TOK_MINUS) { } else if (CurTok.Tok == TOK_MINUS) {
*Flag = 0; *Flag = 0;
NextTok (); NextTok ();
} else if (Tok == TOK_IDENT) { } else if (CurTok.Tok == TOK_IDENT) {
/* Map the keyword to a number */ /* Map the keyword to a number */
switch (GetSubKey (Keys, sizeof (Keys) / sizeof (Keys [0]))) { switch (GetSubKey (Keys, sizeof (Keys) / sizeof (Keys [0]))) {
case 0: *Flag = 0; NextTok (); break; case 0: *Flag = 0; NextTok (); break;
case 1: *Flag = 1; NextTok (); break; case 1: *Flag = 1; NextTok (); break;
default: ErrorSkip ("`on' or `off' expected"); break; default: ErrorSkip ("`on' or `off' expected"); break;
} }
} else if (TokIsSep (Tok)) { } else if (TokIsSep (CurTok.Tok)) {
/* Without anything assume switch on */ /* Without anything assume switch on */
*Flag = 1; *Flag = 1;
} else { } else {
@ -183,10 +183,10 @@ static void ExportWithAssign (SymEntry* Sym, unsigned char AddrSize, unsigned Fl
/* The name and optional address size spec may be followed by an assignment /* The name and optional address size spec may be followed by an assignment
* or equal token. * or equal token.
*/ */
if (Tok == TOK_ASSIGN || Tok == TOK_EQ) { if (CurTok.Tok == TOK_ASSIGN || CurTok.Tok == TOK_EQ) {
/* Assignment means the symbol is a label */ /* Assignment means the symbol is a label */
if (Tok == TOK_ASSIGN) { if (CurTok.Tok == TOK_ASSIGN) {
Flags |= SF_LABEL; Flags |= SF_LABEL;
} }
@ -214,13 +214,13 @@ static void ExportImport (void (*Func) (SymEntry*, unsigned char, unsigned),
while (1) { while (1) {
/* We need an identifier here */ /* We need an identifier here */
if (Tok != TOK_IDENT) { if (CurTok.Tok != TOK_IDENT) {
ErrorSkip ("Identifier expected"); ErrorSkip ("Identifier expected");
return; return;
} }
/* Find the symbol table entry, allocate a new one if necessary */ /* Find the symbol table entry, allocate a new one if necessary */
Sym = SymFind (CurrentScope, &SVal, SYM_ALLOC_NEW); Sym = SymFind (CurrentScope, &CurTok.SVal, SYM_ALLOC_NEW);
/* Skip the name */ /* Skip the name */
NextTok (); NextTok ();
@ -235,7 +235,7 @@ static void ExportImport (void (*Func) (SymEntry*, unsigned char, unsigned),
Func (Sym, AddrSize, Flags); Func (Sym, AddrSize, Flags);
/* More symbols? */ /* More symbols? */
if (Tok == TOK_COMMA) { if (CurTok.Tok == TOK_COMMA) {
NextTok (); NextTok ();
} else { } else {
break; break;
@ -250,7 +250,7 @@ static long IntArg (long Min, long Max)
* and return -1 in this case. * and return -1 in this case.
*/ */
{ {
if (Tok == TOK_IDENT && SB_CompareStr (&SVal, "unlimited") == 0) { if (CurTok.Tok == TOK_IDENT && SB_CompareStr (&CurTok.SVal, "unlimited") == 0) {
NextTok (); NextTok ();
return -1; return -1;
} else { } else {
@ -275,7 +275,7 @@ static void ConDes (const StrBuf* Name, unsigned Type)
SymEntry* Sym = SymFind (CurrentScope, Name, SYM_ALLOC_NEW); SymEntry* Sym = SymFind (CurrentScope, Name, SYM_ALLOC_NEW);
/* Optional constructor priority */ /* Optional constructor priority */
if (Tok == TOK_COMMA) { if (CurTok.Tok == TOK_COMMA) {
/* Priority value follows */ /* Priority value follows */
NextTok (); NextTok ();
Prio = ConstExpression (); Prio = ConstExpression ();
@ -337,7 +337,7 @@ static void DoAddr (void)
/* Do a range check */ /* Do a range check */
EmitWord (Expression ()); EmitWord (Expression ());
} }
if (Tok != TOK_COMMA) { if (CurTok.Tok != TOK_COMMA) {
break; break;
} else { } else {
NextTok (); NextTok ();
@ -362,7 +362,7 @@ static void DoAlign (void)
} }
/* Optional value follows */ /* Optional value follows */
if (Tok == TOK_COMMA) { if (CurTok.Tok == TOK_COMMA) {
NextTok (); NextTok ();
Val = ConstExpression (); Val = ConstExpression ();
/* We need a byte value here */ /* We need a byte value here */
@ -390,16 +390,16 @@ static void DoASCIIZ (void)
{ {
while (1) { while (1) {
/* Must have a string constant */ /* Must have a string constant */
if (Tok != TOK_STRCON) { if (CurTok.Tok != TOK_STRCON) {
ErrorSkip ("String constant expected"); ErrorSkip ("String constant expected");
return; return;
} }
/* Translate into target charset and emit */ /* Translate into target charset and emit */
TgtTranslateStrBuf (&SVal); TgtTranslateStrBuf (&CurTok.SVal);
EmitStrBuf (&SVal); EmitStrBuf (&CurTok.SVal);
NextTok (); NextTok ();
if (Tok == TOK_COMMA) { if (CurTok.Tok == TOK_COMMA) {
NextTok (); NextTok ();
} else { } else {
break; break;
@ -428,7 +428,7 @@ static void DoAssert (void)
ConsumeComma (); ConsumeComma ();
/* Action follows */ /* Action follows */
if (Tok != TOK_IDENT) { if (CurTok.Tok != TOK_IDENT) {
ErrorSkip ("Identifier expected"); ErrorSkip ("Identifier expected");
return; return;
} }
@ -468,13 +468,13 @@ static void DoAssert (void)
/* We can have an optional message. If no message is present, use /* We can have an optional message. If no message is present, use
* "Assertion failed". * "Assertion failed".
*/ */
if (Tok == TOK_COMMA) { if (CurTok.Tok == TOK_COMMA) {
/* Skip the comma */ /* Skip the comma */
NextTok (); NextTok ();
/* Read the message */ /* Read the message */
if (Tok != TOK_STRCON) { if (CurTok.Tok != TOK_STRCON) {
ErrorSkip ("String constant expected"); ErrorSkip ("String constant expected");
return; return;
} }
@ -482,7 +482,7 @@ static void DoAssert (void)
/* Translate the message into a string id. We can then skip the input /* Translate the message into a string id. We can then skip the input
* string. * string.
*/ */
Msg = GetStrBufId (&SVal); Msg = GetStrBufId (&CurTok.SVal);
NextTok (); NextTok ();
} else { } else {
@ -510,7 +510,7 @@ static void DoBankBytes (void)
{ {
while (1) { while (1) {
EmitByte (FuncBankByte ()); EmitByte (FuncBankByte ());
if (Tok != TOK_COMMA) { if (CurTok.Tok != TOK_COMMA) {
break; break;
} else { } else {
NextTok (); NextTok ();
@ -532,20 +532,20 @@ static void DoByte (void)
/* Define bytes */ /* Define bytes */
{ {
while (1) { while (1) {
if (Tok == TOK_STRCON) { if (CurTok.Tok == TOK_STRCON) {
/* A string, translate into target charset and emit */ /* A string, translate into target charset and emit */
TgtTranslateStrBuf (&SVal); TgtTranslateStrBuf (&CurTok.SVal);
EmitStrBuf (&SVal); EmitStrBuf (&CurTok.SVal);
NextTok (); NextTok ();
} else { } else {
EmitByte (Expression ()); EmitByte (Expression ());
} }
if (Tok != TOK_COMMA) { if (CurTok.Tok != TOK_COMMA) {
break; break;
} else { } else {
NextTok (); NextTok ();
/* Do smart handling of dangling comma */ /* Do smart handling of dangling comma */
if (Tok == TOK_SEP) { if (CurTok.Tok == TOK_SEP) {
Error ("Unexpected end of line"); Error ("Unexpected end of line");
break; break;
} }
@ -615,16 +615,16 @@ static void DoConDes (void)
long Type; long Type;
/* Symbol name follows */ /* Symbol name follows */
if (Tok != TOK_IDENT) { if (CurTok.Tok != TOK_IDENT) {
ErrorSkip ("Identifier expected"); ErrorSkip ("Identifier expected");
return; return;
} }
SB_Copy (&Name, &SVal); SB_Copy (&Name, &CurTok.SVal);
NextTok (); NextTok ();
/* Type follows. May be encoded as identifier or numerical */ /* Type follows. May be encoded as identifier or numerical */
ConsumeComma (); ConsumeComma ();
if (Tok == TOK_IDENT) { if (CurTok.Tok == TOK_IDENT) {
/* Map the following keyword to a number, then skip it */ /* Map the following keyword to a number, then skip it */
Type = GetSubKey (Keys, sizeof (Keys) / sizeof (Keys [0])); Type = GetSubKey (Keys, sizeof (Keys) / sizeof (Keys [0]));
@ -664,11 +664,11 @@ static void DoConstructor (void)
StrBuf Name = STATIC_STRBUF_INITIALIZER; StrBuf Name = STATIC_STRBUF_INITIALIZER;
/* Symbol name follows */ /* Symbol name follows */
if (Tok != TOK_IDENT) { if (CurTok.Tok != TOK_IDENT) {
ErrorSkip ("Identifier expected"); ErrorSkip ("Identifier expected");
return; return;
} }
SB_Copy (&Name, &SVal); SB_Copy (&Name, &CurTok.SVal);
NextTok (); NextTok ();
/* Parse the remainder of the line and export the symbol */ /* Parse the remainder of the line and export the symbol */
@ -700,7 +700,7 @@ static void DoDbg (void)
/* We expect a subkey */ /* We expect a subkey */
if (Tok != TOK_IDENT) { if (CurTok.Tok != TOK_IDENT) {
ErrorSkip ("Identifier expected"); ErrorSkip ("Identifier expected");
return; return;
} }
@ -727,7 +727,7 @@ static void DoDByt (void)
{ {
while (1) { while (1) {
EmitWord (GenSwapExpr (Expression ())); EmitWord (GenSwapExpr (Expression ()));
if (Tok != TOK_COMMA) { if (CurTok.Tok != TOK_COMMA) {
break; break;
} else { } else {
NextTok (); NextTok ();
@ -759,11 +759,11 @@ static void DoDestructor (void)
StrBuf Name = STATIC_STRBUF_INITIALIZER; StrBuf Name = STATIC_STRBUF_INITIALIZER;
/* Symbol name follows */ /* Symbol name follows */
if (Tok != TOK_IDENT) { if (CurTok.Tok != TOK_IDENT) {
ErrorSkip ("Identifier expected"); ErrorSkip ("Identifier expected");
return; return;
} }
SB_Copy (&Name, &SVal); SB_Copy (&Name, &CurTok.SVal);
NextTok (); NextTok ();
/* Parse the remainder of the line and export the symbol */ /* Parse the remainder of the line and export the symbol */
@ -780,7 +780,7 @@ static void DoDWord (void)
{ {
while (1) { while (1) {
EmitDWord (Expression ()); EmitDWord (Expression ());
if (Tok != TOK_COMMA) { if (CurTok.Tok != TOK_COMMA) {
break; break;
} else { } else {
NextTok (); NextTok ();
@ -828,10 +828,10 @@ static void DoEndScope (void)
static void DoError (void) static void DoError (void)
/* User error */ /* User error */
{ {
if (Tok != TOK_STRCON) { if (CurTok.Tok != TOK_STRCON) {
ErrorSkip ("String constant expected"); ErrorSkip ("String constant expected");
} else { } else {
Error ("User error: %m%p", &SVal); Error ("User error: %m%p", &CurTok.SVal);
SkipUntilSep (); SkipUntilSep ();
} }
} }
@ -872,7 +872,7 @@ static void DoFarAddr (void)
{ {
while (1) { while (1) {
EmitFarAddr (Expression ()); EmitFarAddr (Expression ());
if (Tok != TOK_COMMA) { if (CurTok.Tok != TOK_COMMA) {
break; break;
} else { } else {
NextTok (); NextTok ();
@ -885,10 +885,10 @@ static void DoFarAddr (void)
static void DoFatal (void) static void DoFatal (void)
/* Fatal user error */ /* Fatal user error */
{ {
if (Tok != TOK_STRCON) { if (CurTok.Tok != TOK_STRCON) {
ErrorSkip ("String constant expected"); ErrorSkip ("String constant expected");
} else { } else {
Fatal ("User error: %m%p", &SVal); Fatal ("User error: %m%p", &CurTok.SVal);
SkipUntilSep (); SkipUntilSep ();
} }
} }
@ -902,7 +902,7 @@ static void DoFeature (void)
while (1) { while (1) {
/* We expect an identifier */ /* We expect an identifier */
if (Tok != TOK_IDENT) { if (CurTok.Tok != TOK_IDENT) {
ErrorSkip ("Identifier expected"); ErrorSkip ("Identifier expected");
return; return;
} }
@ -911,9 +911,9 @@ static void DoFeature (void)
LocaseSVal (); LocaseSVal ();
/* Set the feature and check for errors */ /* Set the feature and check for errors */
if (SetFeature (&SVal) == FEAT_UNKNOWN) { if (SetFeature (&CurTok.SVal) == FEAT_UNKNOWN) {
/* Not found */ /* Not found */
ErrorSkip ("Invalid feature: `%m%p'", &SVal); ErrorSkip ("Invalid feature: `%m%p'", &CurTok.SVal);
return; return;
} else { } else {
/* Skip the keyword */ /* Skip the keyword */
@ -921,7 +921,7 @@ static void DoFeature (void)
} }
/* Allow more than one keyword */ /* Allow more than one keyword */
if (Tok == TOK_COMMA) { if (CurTok.Tok == TOK_COMMA) {
NextTok (); NextTok ();
} else { } else {
break; break;
@ -937,7 +937,7 @@ static void DoFileOpt (void)
long OptNum; long OptNum;
/* The option type may be given as a keyword or as a number. */ /* The option type may be given as a keyword or as a number. */
if (Tok == TOK_IDENT) { if (CurTok.Tok == TOK_IDENT) {
/* Option given as keyword */ /* Option given as keyword */
static const char* Keys [] = { static const char* Keys [] = {
@ -959,7 +959,7 @@ static void DoFileOpt (void)
ConsumeComma (); ConsumeComma ();
/* We accept only string options for now */ /* We accept only string options for now */
if (Tok != TOK_STRCON) { if (CurTok.Tok != TOK_STRCON) {
ErrorSkip ("String constant expected"); ErrorSkip ("String constant expected");
return; return;
} }
@ -969,17 +969,17 @@ static void DoFileOpt (void)
case 0: case 0:
/* Author */ /* Author */
OptAuthor (&SVal); OptAuthor (&CurTok.SVal);
break; break;
case 1: case 1:
/* Comment */ /* Comment */
OptComment (&SVal); OptComment (&CurTok.SVal);
break; break;
case 2: case 2:
/* Compiler */ /* Compiler */
OptCompiler (&SVal); OptCompiler (&CurTok.SVal);
break; break;
default: default:
@ -1003,13 +1003,13 @@ static void DoFileOpt (void)
ConsumeComma (); ConsumeComma ();
/* We accept only string options for now */ /* We accept only string options for now */
if (Tok != TOK_STRCON) { if (CurTok.Tok != TOK_STRCON) {
ErrorSkip ("String constant expected"); ErrorSkip ("String constant expected");
return; return;
} }
/* Insert the option */ /* Insert the option */
OptStr ((unsigned char) OptNum, &SVal); OptStr ((unsigned char) OptNum, &CurTok.SVal);
/* Done */ /* Done */
NextTok (); NextTok ();
@ -1046,7 +1046,7 @@ static void DoHiBytes (void)
{ {
while (1) { while (1) {
EmitByte (FuncHiByte ()); EmitByte (FuncHiByte ());
if (Tok != TOK_COMMA) { if (CurTok.Tok != TOK_COMMA) {
break; break;
} else { } else {
NextTok (); NextTok ();
@ -1109,21 +1109,21 @@ static void DoIncBin (void)
FILE* F; FILE* F;
/* Name must follow */ /* Name must follow */
if (Tok != TOK_STRCON) { if (CurTok.Tok != TOK_STRCON) {
ErrorSkip ("String constant expected"); ErrorSkip ("String constant expected");
return; return;
} }
SB_Copy (&Name, &SVal); SB_Copy (&Name, &CurTok.SVal);
SB_Terminate (&Name); SB_Terminate (&Name);
NextTok (); NextTok ();
/* A starting offset may follow */ /* A starting offset may follow */
if (Tok == TOK_COMMA) { if (CurTok.Tok == TOK_COMMA) {
NextTok (); NextTok ();
Start = ConstExpression (); Start = ConstExpression ();
/* And a length may follow */ /* And a length may follow */
if (Tok == TOK_COMMA) { if (CurTok.Tok == TOK_COMMA) {
NextTok (); NextTok ();
Count = ConstExpression (); Count = ConstExpression ();
} }
@ -1228,11 +1228,11 @@ static void DoInclude (void)
/* Include another file */ /* Include another file */
{ {
/* Name must follow */ /* Name must follow */
if (Tok != TOK_STRCON) { if (CurTok.Tok != TOK_STRCON) {
ErrorSkip ("String constant expected"); ErrorSkip ("String constant expected");
} else { } else {
SB_Terminate (&SVal); SB_Terminate (&CurTok.SVal);
if (NewInputFile (SB_GetConstBuf (&SVal)) == 0) { if (NewInputFile (SB_GetConstBuf (&CurTok.SVal)) == 0) {
/* Error opening the file, skip remainder of line */ /* Error opening the file, skip remainder of line */
SkipUntilSep (); SkipUntilSep ();
} }
@ -1247,11 +1247,11 @@ static void DoInterruptor (void)
StrBuf Name = STATIC_STRBUF_INITIALIZER; StrBuf Name = STATIC_STRBUF_INITIALIZER;
/* Symbol name follows */ /* Symbol name follows */
if (Tok != TOK_IDENT) { if (CurTok.Tok != TOK_IDENT) {
ErrorSkip ("Identifier expected"); ErrorSkip ("Identifier expected");
return; return;
} }
SB_Copy (&Name, &SVal); SB_Copy (&Name, &CurTok.SVal);
NextTok (); NextTok ();
/* Parse the remainder of the line and export the symbol */ /* Parse the remainder of the line and export the symbol */
@ -1307,7 +1307,7 @@ static void DoLoBytes (void)
{ {
while (1) { while (1) {
EmitByte (FuncLoByte ()); EmitByte (FuncLoByte ());
if (Tok != TOK_COMMA) { if (CurTok.Tok != TOK_COMMA) {
break; break;
} else { } else {
NextTok (); NextTok ();
@ -1327,13 +1327,13 @@ static void DoListBytes (void)
static void DoLocalChar (void) static void DoLocalChar (void)
/* Define the character that starts local labels */ /* Define the character that starts local labels */
{ {
if (Tok != TOK_CHARCON) { if (CurTok.Tok != TOK_CHARCON) {
ErrorSkip ("Character constant expected"); ErrorSkip ("Character constant expected");
} else { } else {
if (IVal != '@' && IVal != '?') { if (CurTok.IVal != '@' && CurTok.IVal != '?') {
Error ("Invalid start character for locals"); Error ("Invalid start character for locals");
} else { } else {
LocalStart = (char) IVal; LocalStart = (char) CurTok.IVal;
} }
NextTok (); NextTok ();
} }
@ -1347,14 +1347,14 @@ static void DoMacPack (void)
int Package; int Package;
/* We expect an identifier */ /* We expect an identifier */
if (Tok != TOK_IDENT) { if (CurTok.Tok != TOK_IDENT) {
ErrorSkip ("Identifier expected"); ErrorSkip ("Identifier expected");
return; return;
} }
/* Search for the macro package name */ /* Search for the macro package name */
LocaseSVal (); LocaseSVal ();
Package = MacPackFind (&SVal); Package = MacPackFind (&CurTok.SVal);
if (Package < 0) { if (Package < 0) {
/* Not found */ /* Not found */
ErrorSkip ("Invalid macro package"); ErrorSkip ("Invalid macro package");
@ -1403,13 +1403,15 @@ static void DoOrg (void)
static void DoOut (void) static void DoOut (void)
/* Output a string */ /* Output a string */
{ {
if (Tok != TOK_STRCON) { if (CurTok.Tok != TOK_STRCON) {
ErrorSkip ("String constant expected"); ErrorSkip ("String constant expected");
} else { } else {
/* Output the string and be sure to flush the output to keep it in /* Output the string and be sure to flush the output to keep it in
* sync with any error messages if the output is redirected to a file. * sync with any error messages if the output is redirected to a file.
*/ */
printf ("%.*s\n", (int) SB_GetLen (&SVal), SB_GetConstBuf (&SVal)); printf ("%.*s\n",
(int) SB_GetLen (&CurTok.SVal),
SB_GetConstBuf (&CurTok.SVal));
fflush (stdout); fflush (stdout);
NextTok (); NextTok ();
} }
@ -1493,12 +1495,12 @@ static void DoProc (void)
StrBuf Name = STATIC_STRBUF_INITIALIZER; StrBuf Name = STATIC_STRBUF_INITIALIZER;
unsigned char AddrSize; unsigned char AddrSize;
if (Tok == TOK_IDENT) { if (CurTok.Tok == TOK_IDENT) {
SymEntry* Sym; SymEntry* Sym;
/* The new scope has a name. Remember it. */ /* The new scope has a name. Remember it. */
SB_Copy (&Name, &SVal); SB_Copy (&Name, &CurTok.SVal);
/* Search for the symbol, generate a new one if needed */ /* Search for the symbol, generate a new one if needed */
Sym = SymFind (CurrentScope, &Name, SYM_ALLOC_NEW); Sym = SymFind (CurrentScope, &Name, SYM_ALLOC_NEW);
@ -1595,7 +1597,7 @@ static void DoRes (void)
ErrorSkip ("Range error"); ErrorSkip ("Range error");
return; return;
} }
if (Tok == TOK_COMMA) { if (CurTok.Tok == TOK_COMMA) {
NextTok (); NextTok ();
Val = ConstExpression (); Val = ConstExpression ();
/* We need a byte value here */ /* We need a byte value here */
@ -1632,10 +1634,10 @@ static void DoScope (void)
unsigned char AddrSize; unsigned char AddrSize;
if (Tok == TOK_IDENT) { if (CurTok.Tok == TOK_IDENT) {
/* The new scope has a name. Remember and skip it. */ /* The new scope has a name. Remember and skip it. */
SB_Copy (&Name, &SVal); SB_Copy (&Name, &CurTok.SVal);
NextTok (); NextTok ();
} else { } else {
@ -1663,12 +1665,12 @@ static void DoSegment (void)
StrBuf Name = STATIC_STRBUF_INITIALIZER; StrBuf Name = STATIC_STRBUF_INITIALIZER;
SegDef Def; SegDef Def;
if (Tok != TOK_STRCON) { if (CurTok.Tok != TOK_STRCON) {
ErrorSkip ("String constant expected"); ErrorSkip ("String constant expected");
} else { } else {
/* Save the name of the segment and skip it */ /* Save the name of the segment and skip it */
SB_Copy (&Name, &SVal); SB_Copy (&Name, &CurTok.SVal);
NextTok (); NextTok ();
/* Use the name for the segment definition */ /* Use the name for the segment definition */
@ -1692,14 +1694,14 @@ static void DoSetCPU (void)
/* Switch the CPU instruction set */ /* Switch the CPU instruction set */
{ {
/* We expect an identifier */ /* We expect an identifier */
if (Tok != TOK_STRCON) { if (CurTok.Tok != TOK_STRCON) {
ErrorSkip ("String constant expected"); ErrorSkip ("String constant expected");
} else { } else {
cpu_t CPU; cpu_t CPU;
/* Try to find the CPU */ /* Try to find the CPU */
SB_Terminate (&SVal); SB_Terminate (&CurTok.SVal);
CPU = FindCPU (SB_GetConstBuf (&SVal)); CPU = FindCPU (SB_GetConstBuf (&CurTok.SVal));
/* Switch to the new CPU */ /* Switch to the new CPU */
SetCPU (CPU); SetCPU (CPU);
@ -1758,7 +1760,7 @@ static void DoTag (void)
} }
/* Optional multiplicator may follow */ /* Optional multiplicator may follow */
if (Tok == TOK_COMMA) { if (CurTok.Tok == TOK_COMMA) {
long Multiplicator; long Multiplicator;
NextTok (); NextTok ();
Multiplicator = ConstExpression (); Multiplicator = ConstExpression ();
@ -1788,10 +1790,10 @@ static void DoUnexpected (void)
static void DoWarning (void) static void DoWarning (void)
/* User warning */ /* User warning */
{ {
if (Tok != TOK_STRCON) { if (CurTok.Tok != TOK_STRCON) {
ErrorSkip ("String constant expected"); ErrorSkip ("String constant expected");
} else { } else {
Warning (0, "User warning: %m%p", &SVal); Warning (0, "User warning: %m%p", &CurTok.SVal);
SkipUntilSep (); SkipUntilSep ();
} }
} }
@ -1803,7 +1805,7 @@ static void DoWord (void)
{ {
while (1) { while (1) {
EmitWord (Expression ()); EmitWord (Expression ());
if (Tok != TOK_COMMA) { if (CurTok.Tok != TOK_COMMA) {
break; break;
} else { } else {
NextTok (); NextTok ();
@ -1990,7 +1992,7 @@ void HandlePseudo (void)
CtrlDesc* D; CtrlDesc* D;
/* Calculate the index into the table */ /* Calculate the index into the table */
unsigned Index = Tok - TOK_FIRSTPSEUDO; unsigned Index = CurTok.Tok - TOK_FIRSTPSEUDO;
/* Safety check */ /* Safety check */
if (PSEUDO_COUNT != (TOK_LASTPSEUDO - TOK_FIRSTPSEUDO + 1)) { if (PSEUDO_COUNT != (TOK_LASTPSEUDO - TOK_FIRSTPSEUDO + 1)) {
@ -2004,7 +2006,7 @@ void HandlePseudo (void)
/* Remember the instruction, then skip it if needed */ /* Remember the instruction, then skip it if needed */
if ((D->Flags & ccKeepToken) == 0) { if ((D->Flags & ccKeepToken) == 0) {
SB_Copy (&Keyword, &SVal); SB_Copy (&Keyword, &CurTok.SVal);
NextTok (); NextTok ();
} }

View File

@ -6,7 +6,7 @@
/* */ /* */
/* */ /* */
/* */ /* */
/* (C) 2000-2008, Ullrich von Bassewitz */ /* (C) 2000-2011, Ullrich von Bassewitz */
/* Roemerstrasse 52 */ /* Roemerstrasse 52 */
/* D-70794 Filderstadt */ /* D-70794 Filderstadt */
/* EMail: uz@cc65.org */ /* EMail: uz@cc65.org */
@ -63,10 +63,10 @@ static TokList* CollectRepeatTokens (void)
/* Read the token list */ /* Read the token list */
unsigned Repeats = 0; unsigned Repeats = 0;
while (Repeats != 0 || Tok != TOK_ENDREP) { while (Repeats != 0 || CurTok.Tok != TOK_ENDREP) {
/* Check for end of input */ /* Check for end of input */
if (Tok == TOK_EOF) { if (CurTok.Tok == TOK_EOF) {
Error ("Unexpected end of file"); Error ("Unexpected end of file");
FreeTokList (List); FreeTokList (List);
return 0; return 0;
@ -76,9 +76,9 @@ static TokList* CollectRepeatTokens (void)
AddCurTok (List); AddCurTok (List);
/* Check for and count nested .REPEATs */ /* Check for and count nested .REPEATs */
if (Tok == TOK_REPEAT) { if (CurTok.Tok == TOK_REPEAT) {
++Repeats; ++Repeats;
} else if (Tok == TOK_ENDREP) { } else if (CurTok.Tok == TOK_ENDREP) {
--Repeats; --Repeats;
} }
@ -100,10 +100,12 @@ static void RepeatTokenCheck (TokList* L)
* for and replace identifiers that are the repeat counter. * for and replace identifiers that are the repeat counter.
*/ */
{ {
if (Tok == TOK_IDENT && L->Data != 0 && SB_CompareStr (&SVal, L->Data) == 0) { if (CurTok.Tok == TOK_IDENT &&
L->Data != 0 &&
SB_CompareStr (&CurTok.SVal, L->Data) == 0) {
/* Must replace by the repeat counter */ /* Must replace by the repeat counter */
Tok = TOK_INTCON; CurTok.Tok = TOK_INTCON;
IVal = L->RepCount; CurTok.IVal = L->RepCount;
} }
} }
@ -124,18 +126,18 @@ void ParseRepeat (void)
/* Optional there is a comma and a counter variable */ /* Optional there is a comma and a counter variable */
Name = 0; Name = 0;
if (Tok == TOK_COMMA) { if (CurTok.Tok == TOK_COMMA) {
/* Skip the comma */ /* Skip the comma */
NextTok (); NextTok ();
/* Check for an identifier */ /* Check for an identifier */
if (Tok != TOK_IDENT) { if (CurTok.Tok != TOK_IDENT) {
ErrorSkip ("Identifier expected"); ErrorSkip ("Identifier expected");
} else { } else {
/* Remember the name and skip it */ /* Remember the name and skip it */
SB_Terminate (&SVal); SB_Terminate (&CurTok.SVal);
Name = xstrdup (SB_GetConstBuf (&SVal)); Name = xstrdup (SB_GetConstBuf (&CurTok.SVal));
NextTok (); NextTok ();
} }
} }

View File

@ -70,14 +70,8 @@
token_t Tok = TOK_NONE; /* Current token */ /* Current input token incl. attributes */
int WS; /* Flag: Whitespace before token */ Token CurTok = STATIC_TOKEN_INITIALIZER;
long IVal; /* Integer token attribute */
StrBuf SVal = STATIC_STRBUF_INITIALIZER;/* String token attribute */
FilePos CurPos = STATIC_FILEPOS_INITIALIZER; /* Name and position in current file */
/* Struct to handle include files. */ /* Struct to handle include files. */
typedef struct InputFile InputFile; typedef struct InputFile InputFile;
@ -305,7 +299,7 @@ static void UseCharSource (CharSource* S)
/* Initialize a new input source and start to use it. */ /* Initialize a new input source and start to use it. */
{ {
/* Remember the current input char and token */ /* Remember the current input char and token */
S->Tok = Tok; S->Tok = CurTok.Tok;
S->C = C; S->C = C;
/* Use the new input source */ /* Use the new input source */
@ -318,7 +312,7 @@ static void UseCharSource (CharSource* S)
/* Setup the next token so it will be skipped on the next call to /* Setup the next token so it will be skipped on the next call to
* NextRawTok(). * NextRawTok().
*/ */
Tok = TOK_SEP; CurTok.Tok = TOK_SEP;
} }
@ -332,7 +326,7 @@ static void DoneCharSource (void)
Source->Func->Done (Source); Source->Func->Done (Source);
/* Restore the old token */ /* Restore the old token */
Tok = Source->Tok; CurTok.Tok = Source->Tok;
C = Source->C; C = Source->C;
/* Remember the last stacked input source */ /* Remember the last stacked input source */
@ -356,7 +350,7 @@ static void DoneCharSource (void)
static void IFMarkStart (CharSource* S) static void IFMarkStart (CharSource* S)
/* Mark the start of the next token */ /* Mark the start of the next token */
{ {
CurPos = S->V.File.Pos; CurTok.Pos = S->V.File.Pos;
} }
@ -657,7 +651,7 @@ static void NextChar (void)
void LocaseSVal (void) void LocaseSVal (void)
/* Make SVal lower case */ /* Make SVal lower case */
{ {
SB_ToLower (&SVal); SB_ToLower (&CurTok.SVal);
} }
@ -665,7 +659,7 @@ void LocaseSVal (void)
void UpcaseSVal (void) void UpcaseSVal (void)
/* Make SVal upper case */ /* Make SVal upper case */
{ {
SB_ToUpper (&SVal); SB_ToUpper (&CurTok.SVal);
} }
@ -678,7 +672,7 @@ static int CmpDotKeyword (const void* K1, const void* K2)
static unsigned char FindDotKeyword (void) static token_t FindDotKeyword (void)
/* Find the dot keyword in SVal. Return the corresponding token if found, /* Find the dot keyword in SVal. Return the corresponding token if found,
* return TOK_NONE if not found. * return TOK_NONE if not found.
*/ */
@ -687,7 +681,7 @@ static unsigned char FindDotKeyword (void)
struct DotKeyword* R; struct DotKeyword* R;
/* Initialize K */ /* Initialize K */
K.Key = SB_GetConstBuf (&SVal); K.Key = SB_GetConstBuf (&CurTok.SVal);
K.Tok = 0; K.Tok = 0;
/* If we aren't in ignore case mode, we have to uppercase the keyword */ /* If we aren't in ignore case mode, we have to uppercase the keyword */
@ -697,7 +691,7 @@ static unsigned char FindDotKeyword (void)
/* Search for the keyword */ /* Search for the keyword */
R = bsearch (&K, DotKeywords, sizeof (DotKeywords) / sizeof (DotKeywords [0]), R = bsearch (&K, DotKeywords, sizeof (DotKeywords) / sizeof (DotKeywords [0]),
sizeof (DotKeywords [0]), CmpDotKeyword); sizeof (DotKeywords [0]), CmpDotKeyword);
if (R != 0) { if (R != 0) {
return R->Tok; return R->Tok;
} else { } else {
@ -716,10 +710,10 @@ static void ReadIdent (void)
{ {
/* Read the identifier */ /* Read the identifier */
do { do {
SB_AppendChar (&SVal, C); SB_AppendChar (&CurTok.SVal, C);
NextChar (); NextChar ();
} while (IsIdChar (C)); } while (IsIdChar (C));
SB_Terminate (&SVal); SB_Terminate (&CurTok.SVal);
/* If we should ignore case, convert the identifier to upper case */ /* If we should ignore case, convert the identifier to upper case */
if (IgnoreCase) { if (IgnoreCase) {
@ -746,7 +740,7 @@ static void ReadStringConst (int StringTerm)
} }
/* Append the char to the string */ /* Append the char to the string */
SB_AppendChar (&SVal, C); SB_AppendChar (&CurTok.SVal, C);
/* Skip the character */ /* Skip the character */
NextChar (); NextChar ();
@ -756,7 +750,7 @@ static void ReadStringConst (int StringTerm)
NextChar (); NextChar ();
/* Terminate the string */ /* Terminate the string */
SB_Terminate (&SVal); SB_Terminate (&CurTok.SVal);
} }
@ -795,7 +789,7 @@ void NextRawTok (void)
{ {
/* If we've a forced end of assembly, don't read further */ /* If we've a forced end of assembly, don't read further */
if (ForcedEnd) { if (ForcedEnd) {
Tok = TOK_EOF; CurTok.Tok = TOK_EOF;
return; return;
} }
@ -807,7 +801,7 @@ Restart:
Again: Again:
/* Skip whitespace, remember if we had some */ /* Skip whitespace, remember if we had some */
if ((WS = IsBlank (C)) != 0) { if ((CurTok.WS = IsBlank (C)) != 0) {
do { do {
NextChar (); NextChar ();
} while (IsBlank (C)); } while (IsBlank (C));
@ -817,7 +811,7 @@ Again:
Source->Func->MarkStart (Source); Source->Func->MarkStart (Source);
/* Clear the string attribute */ /* Clear the string attribute */
SB_Clear (&SVal); SB_Clear (&CurTok.SVal);
/* Hex number or PC symbol? */ /* Hex number or PC symbol? */
if (C == '$') { if (C == '$') {
@ -826,7 +820,7 @@ Again:
/* Hex digit must follow or DollarIsPC must be enabled */ /* Hex digit must follow or DollarIsPC must be enabled */
if (!IsXDigit (C)) { if (!IsXDigit (C)) {
if (DollarIsPC) { if (DollarIsPC) {
Tok = TOK_PC; CurTok.Tok = TOK_PC;
return; return;
} else { } else {
Error ("Hexadecimal digit expected"); Error ("Hexadecimal digit expected");
@ -834,18 +828,18 @@ Again:
} }
/* Read the number */ /* Read the number */
IVal = 0; CurTok.IVal = 0;
while (IsXDigit (C)) { while (IsXDigit (C)) {
if (IVal & 0xF0000000) { if (CurTok.IVal & 0xF0000000) {
Error ("Overflow in hexadecimal number"); Error ("Overflow in hexadecimal number");
IVal = 0; CurTok.IVal = 0;
} }
IVal = (IVal << 4) + DigitVal (C); CurTok.IVal = (CurTok.IVal << 4) + DigitVal (C);
NextChar (); NextChar ();
} }
/* This is an integer constant */ /* This is an integer constant */
Tok = TOK_INTCON; CurTok.Tok = TOK_INTCON;
return; return;
} }
@ -859,18 +853,18 @@ Again:
} }
/* Read the number */ /* Read the number */
IVal = 0; CurTok.IVal = 0;
while (IsBDigit (C)) { while (IsBDigit (C)) {
if (IVal & 0x80000000) { if (CurTok.IVal & 0x80000000) {
Error ("Overflow in binary number"); Error ("Overflow in binary number");
IVal = 0; CurTok.IVal = 0;
} }
IVal = (IVal << 1) + DigitVal (C); CurTok.IVal = (CurTok.IVal << 1) + DigitVal (C);
NextChar (); NextChar ();
} }
/* This is an integer constant */ /* This is an integer constant */
Tok = TOK_INTCON; CurTok.Tok = TOK_INTCON;
return; return;
} }
@ -915,24 +909,24 @@ Again:
} }
/* Convert the number using the given base */ /* Convert the number using the given base */
IVal = 0; CurTok.IVal = 0;
for (I = 0; I < Digits; ++I) { for (I = 0; I < Digits; ++I) {
if (IVal > Max) { if (CurTok.IVal > Max) {
Error ("Number out of range"); Error ("Number out of range");
IVal = 0; CurTok.IVal = 0;
break; break;
} }
DVal = DigitVal (Buf[I]); DVal = DigitVal (Buf[I]);
if (DVal > Base) { if (DVal > Base) {
Error ("Invalid digits in number"); Error ("Invalid digits in number");
IVal = 0; CurTok.IVal = 0;
break; break;
} }
IVal = (IVal * Base) + DVal; CurTok.IVal = (CurTok.IVal * Base) + DVal;
} }
/* This is an integer constant */ /* This is an integer constant */
Tok = TOK_INTCON; CurTok.Tok = TOK_INTCON;
return; return;
} }
@ -946,36 +940,36 @@ Again:
if (!IsIdStart (C)) { if (!IsIdStart (C)) {
/* Just a dot */ /* Just a dot */
Tok = TOK_DOT; CurTok.Tok = TOK_DOT;
} else { } else {
/* Read the remainder of the identifier */ /* Read the remainder of the identifier */
SB_AppendChar (&SVal, '.'); SB_AppendChar (&CurTok.SVal, '.');
ReadIdent (); ReadIdent ();
/* Dot keyword, search for it */ /* Dot keyword, search for it */
Tok = FindDotKeyword (); CurTok.Tok = FindDotKeyword ();
if (Tok == TOK_NONE) { if (CurTok.Tok == TOK_NONE) {
/* Not found */ /* Not found */
if (!LeadingDotInIdents) { if (!LeadingDotInIdents) {
/* Invalid pseudo instruction */ /* Invalid pseudo instruction */
Error ("`%m%p' is not a recognized control command", &SVal); Error ("`%m%p' is not a recognized control command", &CurTok.SVal);
goto Again; goto Again;
} }
/* An identifier with a dot. Check if it's a define style /* An identifier with a dot. Check if it's a define style
* macro. * macro.
*/ */
if (IsDefine (&SVal)) { if (IsDefine (&CurTok.SVal)) {
/* This is a define style macro - expand it */ /* This is a define style macro - expand it */
MacExpandStart (); MacExpandStart ();
goto Restart; goto Restart;
} }
/* Just an identifier with a dot */ /* Just an identifier with a dot */
Tok = TOK_IDENT; CurTok.Tok = TOK_IDENT;
} }
} }
@ -987,7 +981,7 @@ Again:
*/ */
if (CPU == CPU_SWEET16 && C == '@') { if (CPU == CPU_SWEET16 && C == '@') {
NextChar (); NextChar ();
Tok = TOK_AT; CurTok.Tok = TOK_AT;
return; return;
} }
@ -998,13 +992,13 @@ Again:
ReadIdent (); ReadIdent ();
/* Start character alone is not enough */ /* Start character alone is not enough */
if (SB_GetLen (&SVal) == 1) { if (SB_GetLen (&CurTok.SVal) == 1) {
Error ("Invalid cheap local symbol"); Error ("Invalid cheap local symbol");
goto Again; goto Again;
} }
/* A local identifier */ /* A local identifier */
Tok = TOK_LOCAL_IDENT; CurTok.Tok = TOK_LOCAL_IDENT;
return; return;
} }
@ -1018,45 +1012,45 @@ Again:
/* Check for special names. Bail out if we have identified the type of /* Check for special names. Bail out if we have identified the type of
* the token. Go on if the token is an identifier. * the token. Go on if the token is an identifier.
*/ */
if (SB_GetLen (&SVal) == 1) { if (SB_GetLen (&CurTok.SVal) == 1) {
switch (toupper (SB_AtUnchecked (&SVal, 0))) { switch (toupper (SB_AtUnchecked (&CurTok.SVal, 0))) {
case 'A': case 'A':
if (C == ':') { if (C == ':') {
NextChar (); NextChar ();
Tok = TOK_OVERRIDE_ABS; CurTok.Tok = TOK_OVERRIDE_ABS;
} else { } else {
Tok = TOK_A; CurTok.Tok = TOK_A;
} }
return; return;
case 'F': case 'F':
if (C == ':') { if (C == ':') {
NextChar (); NextChar ();
Tok = TOK_OVERRIDE_FAR; CurTok.Tok = TOK_OVERRIDE_FAR;
return; return;
} }
break; break;
case 'S': case 'S':
if (CPU == CPU_65816) { if (CPU == CPU_65816) {
Tok = TOK_S; CurTok.Tok = TOK_S;
return; return;
} }
break; break;
case 'X': case 'X':
Tok = TOK_X; CurTok.Tok = TOK_X;
return; return;
case 'Y': case 'Y':
Tok = TOK_Y; CurTok.Tok = TOK_Y;
return; return;
case 'Z': case 'Z':
if (C == ':') { if (C == ':') {
NextChar (); NextChar ();
Tok = TOK_OVERRIDE_ZP; CurTok.Tok = TOK_OVERRIDE_ZP;
return; return;
} }
break; break;
@ -1065,22 +1059,23 @@ Again:
break; break;
} }
} else if (CPU == CPU_SWEET16 && (IVal = Sweet16Reg (&SVal)) >= 0) { } else if (CPU == CPU_SWEET16 &&
(CurTok.IVal = Sweet16Reg (&CurTok.SVal)) >= 0) {
/* A sweet16 register number in sweet16 mode */ /* A sweet16 register number in sweet16 mode */
Tok = TOK_REG; CurTok.Tok = TOK_REG;
return; return;
} }
/* Check for define style macro */ /* Check for define style macro */
if (IsDefine (&SVal)) { if (IsDefine (&CurTok.SVal)) {
/* Macro - expand it */ /* Macro - expand it */
MacExpandStart (); MacExpandStart ();
goto Restart; goto Restart;
} else { } else {
/* An identifier */ /* An identifier */
Tok = TOK_IDENT; CurTok.Tok = TOK_IDENT;
} }
return; return;
} }
@ -1091,21 +1086,21 @@ CharAgain:
case '+': case '+':
NextChar (); NextChar ();
Tok = TOK_PLUS; CurTok.Tok = TOK_PLUS;
return; return;
case '-': case '-':
NextChar (); NextChar ();
Tok = TOK_MINUS; CurTok.Tok = TOK_MINUS;
return; return;
case '/': case '/':
NextChar (); NextChar ();
if (C != '*') { if (C != '*') {
Tok = TOK_DIV; CurTok.Tok = TOK_DIV;
} else if (CComments) { } else if (CComments) {
/* Remember the position, then skip the '*' */ /* Remember the position, then skip the '*' */
FilePos Pos = CurPos; FilePos Pos = CurTok.Pos;
NextChar (); NextChar ();
do { do {
while (C != '*') { while (C != '*') {
@ -1124,21 +1119,21 @@ CharAgain:
case '*': case '*':
NextChar (); NextChar ();
Tok = TOK_MUL; CurTok.Tok = TOK_MUL;
return; return;
case '^': case '^':
NextChar (); NextChar ();
Tok = TOK_XOR; CurTok.Tok = TOK_XOR;
return; return;
case '&': case '&':
NextChar (); NextChar ();
if (C == '&') { if (C == '&') {
NextChar (); NextChar ();
Tok = TOK_BOOLAND; CurTok.Tok = TOK_BOOLAND;
} else { } else {
Tok = TOK_AND; CurTok.Tok = TOK_AND;
} }
return; return;
@ -1146,9 +1141,9 @@ CharAgain:
NextChar (); NextChar ();
if (C == '|') { if (C == '|') {
NextChar (); NextChar ();
Tok = TOK_BOOLOR; CurTok.Tok = TOK_BOOLOR;
} else { } else {
Tok = TOK_OR; CurTok.Tok = TOK_OR;
} }
return; return;
@ -1158,41 +1153,41 @@ CharAgain:
case ':': case ':':
NextChar (); NextChar ();
Tok = TOK_NAMESPACE; CurTok.Tok = TOK_NAMESPACE;
break; break;
case '-': case '-':
IVal = 0; CurTok.IVal = 0;
do { do {
--IVal; --CurTok.IVal;
NextChar (); NextChar ();
} while (C == '-'); } while (C == '-');
Tok = TOK_ULABEL; CurTok.Tok = TOK_ULABEL;
break; break;
case '+': case '+':
IVal = 0; CurTok.IVal = 0;
do { do {
++IVal; ++CurTok.IVal;
NextChar (); NextChar ();
} while (C == '+'); } while (C == '+');
Tok = TOK_ULABEL; CurTok.Tok = TOK_ULABEL;
break; break;
case '=': case '=':
NextChar (); NextChar ();
Tok = TOK_ASSIGN; CurTok.Tok = TOK_ASSIGN;
break; break;
default: default:
Tok = TOK_COLON; CurTok.Tok = TOK_COLON;
break; break;
} }
return; return;
case ',': case ',':
NextChar (); NextChar ();
Tok = TOK_COMMA; CurTok.Tok = TOK_COMMA;
return; return;
case ';': case ';':
@ -1204,81 +1199,81 @@ CharAgain:
case '#': case '#':
NextChar (); NextChar ();
Tok = TOK_HASH; CurTok.Tok = TOK_HASH;
return; return;
case '(': case '(':
NextChar (); NextChar ();
Tok = TOK_LPAREN; CurTok.Tok = TOK_LPAREN;
return; return;
case ')': case ')':
NextChar (); NextChar ();
Tok = TOK_RPAREN; CurTok.Tok = TOK_RPAREN;
return; return;
case '[': case '[':
NextChar (); NextChar ();
Tok = TOK_LBRACK; CurTok.Tok = TOK_LBRACK;
return; return;
case ']': case ']':
NextChar (); NextChar ();
Tok = TOK_RBRACK; CurTok.Tok = TOK_RBRACK;
return; return;
case '{': case '{':
NextChar (); NextChar ();
Tok = TOK_LCURLY; CurTok.Tok = TOK_LCURLY;
return; return;
case '}': case '}':
NextChar (); NextChar ();
Tok = TOK_RCURLY; CurTok.Tok = TOK_RCURLY;
return; return;
case '<': case '<':
NextChar (); NextChar ();
if (C == '=') { if (C == '=') {
NextChar (); NextChar ();
Tok = TOK_LE; CurTok.Tok = TOK_LE;
} else if (C == '<') { } else if (C == '<') {
NextChar (); NextChar ();
Tok = TOK_SHL; CurTok.Tok = TOK_SHL;
} else if (C == '>') { } else if (C == '>') {
NextChar (); NextChar ();
Tok = TOK_NE; CurTok.Tok = TOK_NE;
} else { } else {
Tok = TOK_LT; CurTok.Tok = TOK_LT;
} }
return; return;
case '=': case '=':
NextChar (); NextChar ();
Tok = TOK_EQ; CurTok.Tok = TOK_EQ;
return; return;
case '!': case '!':
NextChar (); NextChar ();
Tok = TOK_BOOLNOT; CurTok.Tok = TOK_BOOLNOT;
return; return;
case '>': case '>':
NextChar (); NextChar ();
if (C == '=') { if (C == '=') {
NextChar (); NextChar ();
Tok = TOK_GE; CurTok.Tok = TOK_GE;
} else if (C == '>') { } else if (C == '>') {
NextChar (); NextChar ();
Tok = TOK_SHR; CurTok.Tok = TOK_SHR;
} else { } else {
Tok = TOK_GT; CurTok.Tok = TOK_GT;
} }
return; return;
case '~': case '~':
NextChar (); NextChar ();
Tok = TOK_NOT; CurTok.Tok = TOK_NOT;
return; return;
case '\'': case '\'':
@ -1288,11 +1283,11 @@ CharAgain:
*/ */
if (LooseStringTerm) { if (LooseStringTerm) {
ReadStringConst ('\''); ReadStringConst ('\'');
if (SB_GetLen (&SVal) == 1) { if (SB_GetLen (&CurTok.SVal) == 1) {
IVal = SB_AtUnchecked (&SVal, 0); CurTok.IVal = SB_AtUnchecked (&CurTok.SVal, 0);
Tok = TOK_CHARCON; CurTok.Tok = TOK_CHARCON;
} else { } else {
Tok = TOK_STRCON; CurTok.Tok = TOK_STRCON;
} }
} else { } else {
/* Always a character constant */ /* Always a character constant */
@ -1301,8 +1296,8 @@ CharAgain:
Error ("Illegal character constant"); Error ("Illegal character constant");
goto CharAgain; goto CharAgain;
} }
IVal = C; CurTok.IVal = C;
Tok = TOK_CHARCON; CurTok.Tok = TOK_CHARCON;
NextChar (); NextChar ();
if (C != '\'') { if (C != '\'') {
if (!MissingCharTerm) { if (!MissingCharTerm) {
@ -1316,7 +1311,7 @@ CharAgain:
case '\"': case '\"':
ReadStringConst ('\"'); ReadStringConst ('\"');
Tok = TOK_STRCON; CurTok.Tok = TOK_STRCON;
return; return;
case '\\': case '\\':
@ -1334,7 +1329,7 @@ CharAgain:
case '\n': case '\n':
NextChar (); NextChar ();
Tok = TOK_SEP; CurTok.Tok = TOK_SEP;
return; return;
case EOF: case EOF:
@ -1344,7 +1339,7 @@ CharAgain:
DoneCharSource (); DoneCharSource ();
goto Again; goto Again;
} else { } else {
Tok = TOK_EOF; CurTok.Tok = TOK_EOF;
} }
return; return;
} }
@ -1369,7 +1364,7 @@ int GetSubKey (const char** Keys, unsigned Count)
unsigned I; unsigned I;
/* Must have an identifier */ /* Must have an identifier */
PRECONDITION (Tok == TOK_IDENT); PRECONDITION (CurTok.Tok == TOK_IDENT);
/* If we aren't in ignore case mode, we have to uppercase the identifier */ /* If we aren't in ignore case mode, we have to uppercase the identifier */
if (!IgnoreCase) { if (!IgnoreCase) {
@ -1378,7 +1373,7 @@ int GetSubKey (const char** Keys, unsigned Count)
/* Do a linear search (a binary search is not worth the effort) */ /* Do a linear search (a binary search is not worth the effort) */
for (I = 0; I < Count; ++I) { for (I = 0; I < Count; ++I) {
if (SB_CompareStr (&SVal, Keys [I]) == 0) { if (SB_CompareStr (&CurTok.SVal, Keys [I]) == 0) {
/* Found it */ /* Found it */
return I; return I;
} }
@ -1399,13 +1394,13 @@ unsigned char ParseAddrSize (void)
unsigned char AddrSize; unsigned char AddrSize;
/* Check for an identifier */ /* Check for an identifier */
if (Tok != TOK_IDENT) { if (CurTok.Tok != TOK_IDENT) {
Error ("Address size specifier expected"); Error ("Address size specifier expected");
return ADDR_SIZE_DEFAULT; return ADDR_SIZE_DEFAULT;
} }
/* Convert the attribute */ /* Convert the attribute */
AddrSize = AddrSizeFromStr (SB_GetConstBuf (&SVal)); AddrSize = AddrSizeFromStr (SB_GetConstBuf (&CurTok.SVal));
if (AddrSize == ADDR_SIZE_INVALID) { if (AddrSize == ADDR_SIZE_INVALID) {
Error ("Address size specifier expected"); Error ("Address size specifier expected");
AddrSize = ADDR_SIZE_DEFAULT; AddrSize = ADDR_SIZE_DEFAULT;
@ -1434,3 +1429,4 @@ void DoneScanner (void)

View File

@ -38,10 +38,6 @@
/* common */
#include "filepos.h"
#include "strbuf.h"
/* ca65 */ /* ca65 */
#include "token.h" #include "token.h"
@ -54,13 +50,8 @@
/* Scanner variables */ /* Scanner variables */
extern token_t Tok; /* Current token */ extern Token CurTok; /* Current input token incl. attributes */
extern int WS; /* Flag: Whitespace before token */ extern int ForcedEnd; /* Force end of assembly */
extern long IVal; /* Integer token attribute */
extern StrBuf SVal; /* String token attribute */
extern FilePos CurPos; /* Name and position in file */
extern int ForcedEnd; /* Force end of assembly */

View File

@ -6,10 +6,10 @@
/* */ /* */
/* */ /* */
/* */ /* */
/* (C) 2003 Ullrich von Bassewitz */ /* (C) 2003-2011, Ullrich von Bassewitz */
/* Römerstraße 52 */ /* Roemerstrasse 52 */
/* D-70794 Filderstadt */ /* D-70794 Filderstadt */
/* EMail: uz@cc65.org */ /* EMail: uz@cc65.org */
/* */ /* */
/* */ /* */
/* This software is provided 'as-is', without any expressed or implied */ /* This software is provided 'as-is', without any expressed or implied */
@ -74,7 +74,7 @@ static long Member (long AllocSize)
long Multiplicator; long Multiplicator;
/* A multiplicator may follow */ /* A multiplicator may follow */
if (Tok != TOK_SEP) { if (CurTok.Tok != TOK_SEP) {
Multiplicator = ConstExpression (); Multiplicator = ConstExpression ();
if (Multiplicator <= 0) { if (Multiplicator <= 0) {
ErrorSkip ("Range error"); ErrorSkip ("Range error");
@ -103,10 +103,10 @@ static long DoStructInternal (long Offs, unsigned Type)
* union, the struct may be anonymous, in which case no new lexical level * union, the struct may be anonymous, in which case no new lexical level
* is started. * is started.
*/ */
int Anon = (Tok != TOK_IDENT); int Anon = (CurTok.Tok != TOK_IDENT);
if (!Anon) { if (!Anon) {
/* Enter a new scope, then skip the name */ /* Enter a new scope, then skip the name */
SymEnterLevel (&SVal, ST_STRUCT, ADDR_SIZE_ABS); SymEnterLevel (&CurTok.SVal, ST_STRUCT, ADDR_SIZE_ABS);
NextTok (); NextTok ();
/* Start at zero offset in the new scope */ /* Start at zero offset in the new scope */
Offs = 0; Offs = 0;
@ -116,23 +116,25 @@ static long DoStructInternal (long Offs, unsigned Type)
ConsumeSep (); ConsumeSep ();
/* Read until end of struct */ /* Read until end of struct */
while (Tok != TOK_ENDSTRUCT && Tok != TOK_ENDUNION && Tok != TOK_EOF) { while (CurTok.Tok != TOK_ENDSTRUCT &&
CurTok.Tok != TOK_ENDUNION &&
CurTok.Tok != TOK_EOF) {
long MemberSize; long MemberSize;
SymTable* Struct; SymTable* Struct;
SymEntry* Sym; SymEntry* Sym;
/* Allow empty and comment lines */ /* Allow empty and comment lines */
if (Tok == TOK_SEP) { if (CurTok.Tok == TOK_SEP) {
NextTok (); NextTok ();
continue; continue;
} }
/* The format is "[identifier] storage-allocator [, multiplicator]" */ /* The format is "[identifier] storage-allocator [, multiplicator]" */
Sym = 0; Sym = 0;
if (Tok == TOK_IDENT) { if (CurTok.Tok == TOK_IDENT) {
/* We have an identifier, generate a symbol */ /* We have an identifier, generate a symbol */
Sym = SymFind (CurrentScope, &SVal, SYM_ALLOC_NEW); Sym = SymFind (CurrentScope, &CurTok.SVal, SYM_ALLOC_NEW);
/* Assign the symbol the offset of the current member */ /* Assign the symbol the offset of the current member */
SymDef (Sym, GenLiteralExpr (Offs), ADDR_SIZE_DEFAULT, SF_NONE); SymDef (Sym, GenLiteralExpr (Offs), ADDR_SIZE_DEFAULT, SF_NONE);
@ -143,7 +145,7 @@ static long DoStructInternal (long Offs, unsigned Type)
/* Read storage allocators */ /* Read storage allocators */
MemberSize = 0; /* In case of errors, use zero */ MemberSize = 0; /* In case of errors, use zero */
switch (Tok) { switch (CurTok.Tok) {
case TOK_BYTE: case TOK_BYTE:
NextTok (); NextTok ();
@ -169,7 +171,7 @@ static long DoStructInternal (long Offs, unsigned Type)
case TOK_RES: case TOK_RES:
NextTok (); NextTok ();
if (Tok == TOK_SEP) { if (CurTok.Tok == TOK_SEP) {
ErrorSkip ("Size is missing"); ErrorSkip ("Size is missing");
} else { } else {
MemberSize = Member (1); MemberSize = Member (1);

View File

@ -6,7 +6,7 @@
/* */ /* */
/* */ /* */
/* */ /* */
/* (C) 1998-2010, Ullrich von Bassewitz */ /* (C) 1998-2011, Ullrich von Bassewitz */
/* Roemerstrasse 52 */ /* Roemerstrasse 52 */
/* D-70794 Filderstadt */ /* D-70794 Filderstadt */
/* EMail: uz@cc65.org */ /* EMail: uz@cc65.org */
@ -69,26 +69,26 @@ SymTable* ParseScopedIdent (StrBuf* Name, StrBuf* FullName)
SB_Clear (FullName); SB_Clear (FullName);
/* Get the starting table */ /* Get the starting table */
if (Tok == TOK_NAMESPACE) { if (CurTok.Tok == TOK_NAMESPACE) {
/* Start from the root scope */ /* Start from the root scope */
Scope = RootScope; Scope = RootScope;
} else if (Tok == TOK_IDENT) { } else if (CurTok.Tok == TOK_IDENT) {
/* Remember the name and skip it */ /* Remember the name and skip it */
SB_Copy (Name, &SVal); SB_Copy (Name, &CurTok.SVal);
NextTok (); NextTok ();
/* If no namespace symbol follows, we're already done */ /* If no namespace symbol follows, we're already done */
if (Tok != TOK_NAMESPACE) { if (CurTok.Tok != TOK_NAMESPACE) {
SB_Terminate (FullName); SB_Terminate (FullName);
return CurrentScope; return CurrentScope;
} }
/* Pass the scope back to the caller */ /* Pass the scope back to the caller */
SB_Append (FullName, Name); SB_Append (FullName, Name);
/* The scope must exist, so search for it starting with the current /* The scope must exist, so search for it starting with the current
* scope. * scope.
*/ */
@ -116,19 +116,19 @@ SymTable* ParseScopedIdent (StrBuf* Name, StrBuf* FullName)
while (1) { while (1) {
/* Next token must be an identifier. */ /* Next token must be an identifier. */
if (Tok != TOK_IDENT) { if (CurTok.Tok != TOK_IDENT) {
Error ("Identifier expected"); Error ("Identifier expected");
return 0; return 0;
} }
/* Remember and skip the identifier */ /* Remember and skip the identifier */
SB_Copy (Name, &SVal); SB_Copy (Name, &CurTok.SVal);
NextTok (); NextTok ();
/* If a namespace token follows, we search for another scope, otherwise /* If a namespace token follows, we search for another scope, otherwise
* the name is a symbol and we're done. * the name is a symbol and we're done.
*/ */
if (Tok != TOK_NAMESPACE) { if (CurTok.Tok != TOK_NAMESPACE) {
/* Symbol */ /* Symbol */
return Scope; return Scope;
} }
@ -253,8 +253,8 @@ SymEntry* ParseAnySymName (int AllocNew)
SymEntry* Sym; SymEntry* Sym;
/* Distinguish cheap locals and other symbols */ /* Distinguish cheap locals and other symbols */
if (Tok == TOK_LOCAL_IDENT) { if (CurTok.Tok == TOK_LOCAL_IDENT) {
Sym = SymFindLocal (SymLast, &SVal, AllocNew); Sym = SymFindLocal (SymLast, &CurTok.SVal, AllocNew);
NextTok (); NextTok ();
} else { } else {
Sym = ParseScopedSymName (AllocNew); Sym = ParseScopedSymName (AllocNew);

View File

@ -6,7 +6,7 @@
/* */ /* */
/* */ /* */
/* */ /* */
/* (C) 1998-2010, Ullrich von Bassewitz */ /* (C) 1998-2011, Ullrich von Bassewitz */
/* Roemerstrasse 52 */ /* Roemerstrasse 52 */
/* D-70794 Filderstadt */ /* D-70794 Filderstadt */
/* EMail: uz@cc65.org */ /* EMail: uz@cc65.org */
@ -86,7 +86,7 @@ SymEntry* NewSymEntry (const StrBuf* Name, unsigned Flags)
S->Right = 0; S->Right = 0;
S->Locals = 0; S->Locals = 0;
S->Sym.Tab = 0; S->Sym.Tab = 0;
S->Pos = CurPos; S->Pos = CurTok.Pos;
for (I = 0; I < sizeof (S->GuessedUse) / sizeof (S->GuessedUse[0]); ++I) { for (I = 0; I < sizeof (S->GuessedUse) / sizeof (S->GuessedUse[0]); ++I) {
S->GuessedUse[I] = 0; S->GuessedUse[I] = 0;
} }
@ -578,7 +578,7 @@ void SymGuessedAddrSize (SymEntry* Sym, unsigned char AddrSize)
} }
/* Ok, remember the file position */ /* Ok, remember the file position */
Sym->GuessedUse[AddrSize-1] = xdup (&CurPos, sizeof (CurPos)); Sym->GuessedUse[AddrSize-1] = xdup (&CurTok.Pos, sizeof (CurTok.Pos));
} }

View File

@ -39,7 +39,9 @@
/* common */ /* common */
#include "filepos.h"
#include "inline.h" #include "inline.h"
#include "strbuf.h"
@ -49,7 +51,7 @@
/* Tokens */ /* Tokens */
typedef enum token_t { typedef enum token_t {
TOK_NONE, /* Start value, invalid */ TOK_NONE, /* Start value, invalid */
TOK_EOF, /* End of input file */ TOK_EOF, /* End of input file */
@ -71,7 +73,7 @@ typedef enum token_t {
TOK_ULABEL, /* :++ or :-- */ TOK_ULABEL, /* :++ or :-- */
TOK_EQ, /* = */ TOK_EQ, /* = */
TOK_NE, /* <> */ TOK_NE, /* <> */
TOK_LT, /* < */ TOK_LT, /* < */
TOK_GT, /* > */ TOK_GT, /* > */
TOK_LE, /* <= */ TOK_LE, /* <= */
@ -83,12 +85,12 @@ typedef enum token_t {
TOK_BOOLNOT, /* .not */ TOK_BOOLNOT, /* .not */
TOK_PLUS, /* + */ TOK_PLUS, /* + */
TOK_MINUS, /* - */ TOK_MINUS, /* - */
TOK_MUL, /* * */ TOK_MUL, /* * */
TOK_STAR = TOK_MUL, /* Alias */ TOK_STAR = TOK_MUL, /* Alias */
TOK_DIV, /* / */ TOK_DIV, /* / */
TOK_MOD, /* ! */ TOK_MOD, /* ! */
TOK_OR, /* | */ TOK_OR, /* | */
TOK_XOR, /* ^ */ TOK_XOR, /* ^ */
TOK_BANK = TOK_XOR, /* Alias */ TOK_BANK = TOK_XOR, /* Alias */
TOK_AND, /* & */ TOK_AND, /* & */
@ -258,6 +260,27 @@ typedef enum token_t {
/* Complete token including attributes and flags */
typedef struct Token Token;
struct Token {
token_t Tok; /* The actual token value */
int WS; /* Flag for "whitespace before token" */
long IVal; /* Integer attribute value */
StrBuf SVal; /* String attribute value */
FilePos Pos; /* Position from which token was read */
};
/* Initializer value for a token */
#define STATIC_TOKEN_INITIALIZER { \
TOK_NONE, \
0, \
0, \
STATIC_STRBUF_INITIALIZER, \
STATIC_FILEPOS_INITIALIZER \
}
/*****************************************************************************/ /*****************************************************************************/
/* Code */ /* Code */
/*****************************************************************************/ /*****************************************************************************/

View File

@ -64,11 +64,11 @@ TokNode* NewTokNode (void)
/* Initialize the token contents */ /* Initialize the token contents */
T->Next = 0; T->Next = 0;
T->Tok = Tok; T->Tok = CurTok.Tok;
T->WS = WS; T->WS = CurTok.WS;
T->IVal = IVal; T->IVal = CurTok.IVal;
SB_Init (&T->SVal); SB_Init (&T->SVal);
SB_Copy (&T->SVal, &SVal); SB_Copy (&T->SVal, &CurTok.SVal);
/* Return the node */ /* Return the node */
return T; return T;
@ -89,11 +89,11 @@ void TokSet (TokNode* T)
/* Set the scanner token from the given token node */ /* Set the scanner token from the given token node */
{ {
/* Set the values */ /* Set the values */
Tok = T->Tok; CurTok.Tok = T->Tok;
WS = T->WS; CurTok.WS = T->WS;
IVal = T->IVal; CurTok.IVal = T->IVal;
SB_Copy (&SVal, &T->SVal); SB_Copy (&CurTok.SVal, &T->SVal);
SB_Terminate (&SVal); SB_Terminate (&CurTok.SVal);
} }
@ -101,18 +101,18 @@ void TokSet (TokNode* T)
enum TC TokCmp (const TokNode* T) enum TC TokCmp (const TokNode* T)
/* Compare the token given as parameter against the current token */ /* Compare the token given as parameter against the current token */
{ {
if (T->Tok != Tok) { if (T->Tok != CurTok.Tok) {
/* Different token */ /* Different token */
return tcDifferent; return tcDifferent;
} }
/* If the token has string attribute, check it */ /* If the token has string attribute, check it */
if (TokHasSVal (T->Tok)) { if (TokHasSVal (T->Tok)) {
if (SB_Compare (&SVal, &T->SVal) != 0) { if (SB_Compare (&CurTok.SVal, &T->SVal) != 0) {
return tcSameToken; return tcSameToken;
} }
} else if (TokHasIVal (T->Tok)) { } else if (TokHasIVal (T->Tok)) {
if (T->IVal != IVal) { if (T->IVal != CurTok.IVal) {
return tcSameToken; return tcSameToken;
} }
} }
@ -182,7 +182,7 @@ enum token_t GetTokListTerm (enum token_t Term)
* a closing brace, otherwise return Term. * a closing brace, otherwise return Term.
*/ */
{ {
if (Tok == TOK_LCURLY) { if (CurTok.Tok == TOK_LCURLY) {
NextTok (); NextTok ();
return TOK_RCURLY; return TOK_RCURLY;
} else { } else {
@ -278,3 +278,4 @@ void PushTokList (TokList* List, const char* Desc)

View File

@ -6,10 +6,10 @@
/* */ /* */
/* */ /* */
/* */ /* */
/* (C) 2000-2004 Ullrich von Bassewitz */ /* (C) 2000-2011, Ullrich von Bassewitz */
/* Römerstraße 52 */ /* Roemerstrasse 52 */
/* D-70794 Filderstadt */ /* D-70794 Filderstadt */
/* EMail: uz@cc65.org */ /* EMail: uz@cc65.org */
/* */ /* */
/* */ /* */
/* This software is provided 'as-is', without any expressed or implied */ /* This software is provided 'as-is', without any expressed or implied */
@ -82,7 +82,7 @@ static ULabel* NewULabel (ExprNode* Val)
ULabel* L = xmalloc (sizeof (ULabel)); ULabel* L = xmalloc (sizeof (ULabel));
/* Initialize the fields */ /* Initialize the fields */
L->Pos = CurPos; L->Pos = CurTok.Pos;
L->Val = Val; L->Val = Val;
L->Ref = 0; L->Ref = 0;
@ -160,7 +160,7 @@ void ULabDef (void)
ULabel* L = CollAtUnchecked (&ULabList, ULabDefCount); ULabel* L = CollAtUnchecked (&ULabList, ULabDefCount);
CHECK (L->Val == 0); CHECK (L->Val == 0);
L->Val = GenCurrentPC (); L->Val = GenCurrentPC ();
L->Pos = CurPos; L->Pos = CurTok.Pos;
} else { } else {
/* There is no such label, create it */ /* There is no such label, create it */
NewULabel (GenCurrentPC ()); NewULabel (GenCurrentPC ());