/* */
/* */
/* */
-/* (C) 2003-2008, Ullrich von Bassewitz */
+/* (C) 2003-2011, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
A->Expr = Expr;
A->Action = Action;
A->Msg = Msg;
- A->Pos = CurPos;
+ A->Pos = CurTok.Pos;
/* Return the new struct */
return A;
+
/* Initialize elements */
ID->Flags = NeedTerm? ifNeedTerm : ifNone;
- ID->Pos = CurPos;
+ ID->Pos = CurTok.Pos;
ID->Name = Directive;
/* Return the result */
/*****************************************************************************/
-/* Code */
+/* Code */
/*****************************************************************************/
int IfCond = GetCurrentIfCond ();
do {
- switch (Tok) {
+ switch (CurTok.Tok) {
case TOK_ELSE:
D = GetCurrentIf ();
/* Allow an .ELSE */
InvertIfCond (D);
SetElse (D, 1);
- D->Pos = CurPos;
+ D->Pos = CurTok.Pos;
D->Name = ".ELSE";
IfCond = GetCurrentIfCond ();
}
D = AllocIf (".IFBLANK", 1);
NextTok ();
if (IfCond) {
- if (TokIsSep (Tok)) {
+ if (TokIsSep (CurTok.Tok)) {
SetIfCond (D, 1);
} else {
SetIfCond (D, 0);
D = AllocIf (".IFNBLANK", 1);
NextTok ();
if (IfCond) {
- if (TokIsSep (Tok)) {
+ if (TokIsSep (CurTok.Tok)) {
SetIfCond (D, 0);
} else {
SetIfCond (D, 1);
}
- } while (IfCond == 0 && Tok != TOK_EOF);
+ } while (IfCond == 0 && CurTok.Tok != TOK_EOF);
}
* return false otherwise.
*/
{
- switch (Tok) {
+ switch (CurTok.Tok) {
case TOK_ELSE:
case TOK_ELSEIF:
case TOK_ENDIF:
break;
}
- if (D->Pos.Name != CurPos.Name) {
+ if (D->Pos.Name != CurTok.Pos.Name) {
/* The .if is from another file, bail out */
break;
}
+
/* */
/* */
/* */
-/* (C) 2000-2010, Ullrich von Bassewitz */
+/* (C) 2000-2011, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
ConsumeComma ();
/* Name */
- if (Tok != TOK_STRCON) {
+ if (CurTok.Tok != TOK_STRCON) {
ErrorSkip ("String constant expected");
return;
}
- SB_Copy (&Name, &SVal);
+ SB_Copy (&Name, &CurTok.SVal);
NextTok ();
/* Comma expected */
/* If a parameters follow, this is actual line info. If no parameters
* follow, the last line info is terminated.
*/
- if (Tok == TOK_SEP) {
+ if (CurTok.Tok == TOK_SEP) {
ClearLineInfo ();
return;
}
ConsumeComma ();
/* The name of the file follows */
- if (Tok != TOK_STRCON) {
+ if (CurTok.Tok != TOK_STRCON) {
ErrorSkip ("String constant expected");
return;
}
/* Get the index in the file table for the name */
- Index = GetFileIndex (&SVal);
+ Index = GetFileIndex (&CurTok.SVal);
/* Skip the name */
NextTok ();
+
+
/* */
/* */
/* */
-/* (C) 1998-2004 Ullrich von Bassewitz */
-/* Römerstrasse 52 */
-/* D-70794 Filderstadt */
-/* EMail: uz@cc65.org */
+/* (C) 1998-2011, Ullrich von Bassewitz */
+/* Roemerstrasse 52 */
+/* D-70794 Filderstadt */
+/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
A->Expr = 0;
/* Handle an addressing size override */
- switch (Tok) {
+ switch (CurTok.Tok) {
case TOK_OVERRIDE_ZP:
Restrictions = AM65_DIR | AM65_DIR_X | AM65_DIR_Y;
NextTok ();
}
/* Parse the effective address */
- if (TokIsSep (Tok)) {
+ if (TokIsSep (CurTok.Tok)) {
A->AddrModeSet = AM65_IMPLICIT;
- } else if (Tok == TOK_HASH) {
+ } else if (CurTok.Tok == TOK_HASH) {
/* #val */
NextTok ();
A->Expr = Expression ();
A->AddrModeSet = AM65_IMM;
- } else if (Tok == TOK_A) {
+ } else if (CurTok.Tok == TOK_A) {
NextTok ();
A->AddrModeSet = AM65_ACCU;
- } else if (Tok == TOK_LBRACK) {
+ } else if (CurTok.Tok == TOK_LBRACK) {
/* [dir] or [dir],y */
NextTok ();
A->Expr = Expression ();
Consume (TOK_RBRACK, "']' expected");
- if (Tok == TOK_COMMA) {
+ if (CurTok.Tok == TOK_COMMA) {
/* [dir],y */
NextTok ();
Consume (TOK_Y, "`Y' expected");
A->AddrModeSet = AM65_DIR_IND_LONG;
}
- } else if (Tok == TOK_LPAREN) {
+ } else if (CurTok.Tok == TOK_LPAREN) {
/* One of the indirect modes */
NextTok ();
A->Expr = Expression ();
- if (Tok == TOK_COMMA) {
+ if (CurTok.Tok == TOK_COMMA) {
/* (expr,X) or (rel,S),y */
NextTok ();
- if (Tok == TOK_X) {
+ if (CurTok.Tok == TOK_X) {
/* (adr,x) */
NextTok ();
A->AddrModeSet = AM65_ABS_X_IND | AM65_DIR_X_IND;
ConsumeRParen ();
- } else if (Tok == TOK_S) {
+ } else if (CurTok.Tok == TOK_S) {
/* (rel,s),y */
NextTok ();
A->AddrModeSet = AM65_STACK_REL_IND_Y;
/* (adr) or (adr),y */
ConsumeRParen ();
- if (Tok == TOK_COMMA) {
+ if (CurTok.Tok == TOK_COMMA) {
/* (adr),y */
NextTok ();
Consume (TOK_Y, "`Y' expected");
*/
A->Expr = Expression ();
- if (Tok == TOK_COMMA) {
+ if (CurTok.Tok == TOK_COMMA) {
NextTok ();
- switch (Tok) {
+ switch (CurTok.Tok) {
case TOK_X:
A->AddrModeSet = AM65_ABS_LONG_X | AM65_ABS_X | AM65_DIR_X;
+
/* */
/* */
/* */
-/* (C) 2004 Ullrich von Bassewitz */
-/* Römerstrasse 52 */
-/* D-70794 Filderstadt */
-/* EMail: uz@cc65.org */
+/* (C) 2004-2011, Ullrich von Bassewitz */
+/* Roemerstrasse 52 */
+/* D-70794 Filderstadt */
+/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
A->Reg = 0;
/* Parse the effective address */
- if (TokIsSep (Tok)) {
+ if (TokIsSep (CurTok.Tok)) {
A->AddrModeSet = AMSW16_IMP;
- } else if (Tok == TOK_AT) {
+ } else if (CurTok.Tok == TOK_AT) {
/* @reg or @regnumber */
A->AddrModeSet = AMSW16_IND;
NextTok ();
- if (Tok == TOK_REG) {
- A->Reg = (unsigned) IVal;
+ if (CurTok.Tok == TOK_REG) {
+ A->Reg = (unsigned) CurTok.IVal;
NextTok ();
} else if ((Reg = RegNum ()) >= 0) {
/* Register number */
A->Reg = 0;
}
- } else if (Tok == TOK_REG) {
+ } else if (CurTok.Tok == TOK_REG) {
- A->Reg = (unsigned) IVal;
+ A->Reg = (unsigned) CurTok.IVal;
NextTok ();
- if (Tok == TOK_COMMA) {
+ if (CurTok.Tok == TOK_COMMA) {
/* Rx, constant */
NextTok ();
A->Reg = (unsigned) Reg;
/* If a comma follows, it is: OPC Rx, constant */
- if (Tok == TOK_COMMA) {
+ if (CurTok.Tok == TOK_COMMA) {
NextTok ();
A->Expr = Expression ();
A->AddrModeSet = AMSW16_IMM;
}
-
+
/* */
/* */
/* */
-/* (C) 2003-2008 Ullrich von Bassewitz */
-/* Roemerstrasse 52 */
-/* D-70794 Filderstadt */
-/* EMail: uz@cc65.org */
+/* (C) 2003-2011, Ullrich von Bassewitz */
+/* Roemerstrasse 52 */
+/* D-70794 Filderstadt */
+/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
ExprNode* BaseExpr = GenLiteral0 ();
/* Check for a name */
- int Anon = (Tok != TOK_IDENT);
+ int Anon = (CurTok.Tok != TOK_IDENT);
if (!Anon) {
/* Enter a new scope, then skip the name */
- SymEnterLevel (&SVal, ST_ENUM, ADDR_SIZE_ABS);
+ SymEnterLevel (&CurTok.SVal, ST_ENUM, ADDR_SIZE_ABS);
NextTok ();
}
ConsumeSep ();
/* Read until end of struct */
- while (Tok != TOK_ENDENUM && Tok != TOK_EOF) {
+ while (CurTok.Tok != TOK_ENDENUM && CurTok.Tok != TOK_EOF) {
SymEntry* Sym;
ExprNode* EnumExpr;
/* Skip empty lines */
- if (Tok == TOK_SEP) {
+ if (CurTok.Tok == TOK_SEP) {
NextTok ();
continue;
}
/* The format is "identifier [ = value ]" */
- if (Tok != TOK_IDENT) {
+ if (CurTok.Tok != TOK_IDENT) {
/* Maybe it's a conditional? */
if (!CheckConditionals ()) {
ErrorSkip ("Identifier expected");
}
/* 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 */
NextTok ();
/* Check for an assignment */
- if (Tok == TOK_EQ) {
+ if (CurTok.Tok == TOK_EQ) {
/* Skip the equal sign */
NextTok ();
+
/* */
/* */
/* */
-/* (C) 1998-2008 Ullrich von Bassewitz */
-/* Roemerstrasse 52 */
-/* D-70794 Filderstadt */
-/* EMail: uz@cc65.org */
+/* (C) 1998-2011, Ullrich von Bassewitz */
+/* Roemerstrasse 52 */
+/* D-70794 Filderstadt */
+/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
{
va_list ap;
va_start (ap, Format);
- WarningMsg (&CurPos, Level, Format, ap);
+ WarningMsg (&CurTok.Pos, Level, Format, ap);
va_end (ap);
}
{
va_list ap;
va_start (ap, Format);
- ErrorMsg (&CurPos, Format, ap);
+ ErrorMsg (&CurTok.Pos, Format, ap);
va_end (ap);
}
{
va_list ap;
va_start (ap, Format);
- ErrorMsg (&CurPos, Format, ap);
+ ErrorMsg (&CurTok.Pos, Format, ap);
va_end (ap);
SkipUntilSep ();
*/
token_t Term = GetTokListTerm (TOK_RPAREN);
unsigned Count = 0;
- while (Tok != Term) {
+ while (CurTok.Tok != Term) {
/* 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
* here, just bail out.
*/
- if (TokIsSep (Tok)) {
+ if (TokIsSep (CurTok.Tok)) {
break;
}
}
/* 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 ();
}
* either enclosed in curly braces, or terminated by a 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 */
- if (TokIsSep (Tok)) {
+ if (TokIsSep (CurTok.Tok)) {
Error ("Unexpected end of line");
return GenLiteral0 ();
}
Term = GetTokListTerm (TOK_RPAREN);
Result = 1;
Node = Root;
- while (Tok != Term) {
+ while (CurTok.Tok != Term) {
/* We may not end-of-line of end-of-file here */
- if (TokIsSep (Tok)) {
+ if (TokIsSep (CurTok.Tok)) {
Error ("Unexpected end of line");
return GenLiteral0 ();
}
SizeSym = 0;
/* Check for a cheap local which needs special handling */
- if (Tok == TOK_LOCAL_IDENT) {
+ if (CurTok.Tok == TOK_LOCAL_IDENT) {
/* Cheap local symbol */
- Sym = SymFindLocal (SymLast, &SVal, SYM_FIND_EXISTING);
+ Sym = SymFindLocal (SymLast, &CurTok.SVal, SYM_FIND_EXISTING);
if (Sym == 0) {
- Error ("Unknown symbol or scope: `%m%p'", &SVal);
+ Error ("Unknown symbol or scope: `%m%p'", &CurTok.SVal);
} else {
SizeSym = GetSizeOfSymbol (Sym);
}
/* Remember and skip SVal, terminate ScopeName so it is empty */
- SB_Copy (&Name, &SVal);
+ SB_Copy (&Name, &CurTok.SVal);
NextTok ();
SB_Terminate (&ScopeName);
unsigned char C = 0;
/* String constant expected */
- if (Tok != TOK_STRCON) {
+ if (CurTok.Tok != TOK_STRCON) {
Error ("String constant expected");
NextTok ();
goto ExitPoint;
}
/* Remember the string and skip it */
- SB_Copy (&Str, &SVal);
+ SB_Copy (&Str, &CurTok.SVal);
NextTok ();
/* Comma must follow */
int Len;
/* String constant expected */
- if (Tok != TOK_STRCON) {
+ if (CurTok.Tok != TOK_STRCON) {
Error ("String constant expected");
/* Smart error recovery */
- if (Tok != TOK_RPAREN) {
+ if (CurTok.Tok != TOK_RPAREN) {
NextTok ();
}
Len = 0;
} else {
/* Get the length of the string */
- Len = SB_GetLen (&SVal);
+ Len = SB_GetLen (&CurTok.SVal);
/* Skip the string */
NextTok ();
*/
token_t Term = GetTokListTerm (TOK_RPAREN);
int Count = 0;
- while (Tok != Term) {
+ while (CurTok.Tok != Term) {
/* 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
* here, just bail out.
*/
- if (TokIsSep (Tok)) {
+ if (TokIsSep (CurTok.Tok)) {
break;
}
}
/* 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 ();
/* Expression must be enclosed in braces */
- if (Tok != TOK_LPAREN) {
+ if (CurTok.Tok != TOK_LPAREN) {
Error ("'(' expected");
SkipUntilSep ();
return GenLiteral0 ();
ExprNode* N;
long Val;
- switch (Tok) {
+ switch (CurTok.Tok) {
case TOK_INTCON:
- N = GenLiteralExpr (IVal);
+ N = GenLiteralExpr (CurTok.IVal);
NextTok ();
break;
case TOK_CHARCON:
- N = GenLiteralExpr (TgtTranslateChar (IVal));
+ N = GenLiteralExpr (TgtTranslateChar (CurTok.IVal));
NextTok ();
break;
break;
case TOK_ULABEL:
- N = ULabRef (IVal);
+ N = ULabRef (CurTok.IVal);
NextTok ();
break;
break;
default:
- if (LooseCharTerm && Tok == TOK_STRCON && SB_GetLen (&SVal) == 1) {
+ if (LooseCharTerm && CurTok.Tok == TOK_STRCON &&
+ SB_GetLen (&CurTok.SVal) == 1) {
/* A character constant */
- N = GenLiteralExpr (TgtTranslateChar (SB_At (&SVal, 0)));
+ N = GenLiteralExpr (TgtTranslateChar (SB_At (&CurTok.SVal, 0)));
} else {
N = GenLiteral0 (); /* Dummy */
Error ("Syntax error");
ExprNode* Root = Factor ();
/* Handle multiplicative operations */
- while (Tok == TOK_MUL || Tok == TOK_DIV || Tok == TOK_MOD ||
- Tok == TOK_AND || Tok == TOK_XOR || Tok == TOK_SHL ||
- Tok == TOK_SHR) {
+ while (CurTok.Tok == TOK_MUL || CurTok.Tok == TOK_DIV ||
+ CurTok.Tok == TOK_MOD || CurTok.Tok == TOK_AND ||
+ CurTok.Tok == TOK_XOR || CurTok.Tok == TOK_SHL ||
+ CurTok.Tok == TOK_SHR) {
long LVal, RVal, Val;
ExprNode* Left;
ExprNode* Right;
/* Remember the token and skip it */
- token_t T = Tok;
+ token_t T = CurTok.Tok;
NextTok ();
/* Move root to left side and read the right side */
ExprNode* Root = Term ();
/* 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;
ExprNode* Left;
ExprNode* Right;
/* Remember the token and skip it */
- token_t T = Tok;
+ token_t T = CurTok.Tok;
NextTok ();
/* Move root to left side and read the right side */
ExprNode* Root = SimpleExpr ();
/* Handle booleans */
- while (Tok == TOK_EQ || Tok == TOK_NE || Tok == TOK_LT ||
- Tok == TOK_GT || Tok == TOK_LE || Tok == TOK_GE) {
+ while (CurTok.Tok == TOK_EQ || CurTok.Tok == TOK_NE ||
+ CurTok.Tok == TOK_LT || CurTok.Tok == TOK_GT ||
+ CurTok.Tok == TOK_LE || CurTok.Tok == TOK_GE) {
long LVal, RVal, Val;
ExprNode* Left;
ExprNode* Right;
/* Remember the token and skip it */
- token_t T = Tok;
+ token_t T = CurTok.Tok;
NextTok ();
/* Move root to left side and read the right side */
ExprNode* Root = BoolExpr ();
/* Handle booleans */
- while (Tok == TOK_BOOLAND || Tok == TOK_BOOLXOR) {
+ while (CurTok.Tok == TOK_BOOLAND || CurTok.Tok == TOK_BOOLXOR) {
long LVal, RVal, Val;
ExprNode* Left;
ExprNode* Right;
/* Remember the token and skip it */
- token_t T = Tok;
+ token_t T = CurTok.Tok;
NextTok ();
/* Move root to left side and read the right side */
ExprNode* Root = Expr2 ();
/* Handle booleans */
- while (Tok == TOK_BOOLOR) {
+ while (CurTok.Tok == TOK_BOOLOR) {
long LVal, RVal, Val;
ExprNode* Left;
ExprNode* Right;
/* Remember the token and skip it */
- token_t T = Tok;
+ token_t T = CurTok.Tok;
NextTok ();
/* Move root to left side and read the right side */
ExprNode* Root;
/* Handle booleans */
- if (Tok == TOK_BOOLNOT) {
+ if (CurTok.Tok == TOK_BOOLNOT) {
long Val;
ExprNode* Left;
/* */
/* */
/* */
-/* (C) 1998-2003 Ullrich von Bassewitz */
-/* Römerstrasse 52 */
-/* D-70794 Filderstadt */
-/* EMail: uz@cc65.org */
+/* (C) 1998-2011, Ullrich von Bassewitz */
+/* Roemerstrasse 52 */
+/* D-70794 Filderstadt */
+/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
/* Initialize it */
F->Next = 0;
F->LineList = 0;
- F->Pos = CurPos;
+ F->Pos = CurTok.Pos;
F->LI = UseLineInfo (CurLineInfo);
F->Len = Len;
F->Type = Type;
/* */
/* */
/* */
-/* (C) 1998-2009, Ullrich von Bassewitz */
+/* (C) 1998-2011, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
EffAddr A;
/* The first argument is always an immediate byte */
- if (Tok != TOK_HASH) {
+ if (CurTok.Tok != TOK_HASH) {
ErrorSkip ("Invalid addressing mode");
return;
}
/* */
/* */
/* */
-/* (C) 1998-2008 Ullrich von Bassewitz */
-/* Roemerstrasse 52 */
-/* D-70794 Filderstadt */
-/* EMail: uz@cc65.org */
+/* (C) 1998-2011, Ullrich von Bassewitz */
+/* Roemerstrasse 52 */
+/* D-70794 Filderstadt */
+/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
{
if (Style == MAC_STYLE_CLASSIC) {
/* 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 ();
}
- if (Tok != TOK_EOF) {
+ if (CurTok.Tok != TOK_EOF) {
SkipUntilSep ();
} else {
Error ("`.ENDMACRO' expected");
int HaveParams;
/* We expect a macro name here */
- if (Tok != TOK_IDENT) {
+ if (CurTok.Tok != TOK_IDENT) {
Error ("Identifier expected");
MacSkipDef (Style);
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
* allowed if not explicitly enabled.
*/
}
/* Did we already define that macro? */
- if (HT_Find (&MacroTab, &SVal) != 0) {
+ if (HT_Find (&MacroTab, &CurTok.SVal) != 0) {
/* 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 */
MacSkipDef (Style);
return;
}
/* Define the macro */
- M = NewMacro (&SVal, Style);
+ M = NewMacro (&CurTok.SVal, Style);
/* Switch to raw token mode and skip the macro name */
EnterRawTokenMode ();
if (Style == MAC_STYLE_CLASSIC) {
HaveParams = 1;
} else {
- if (Tok == TOK_LPAREN) {
+ if (CurTok.Tok == TOK_LPAREN) {
HaveParams = 1;
NextTok ();
} else {
/* Parse the parameter list */
if (HaveParams) {
- while (Tok == TOK_IDENT) {
+ while (CurTok.Tok == TOK_IDENT) {
/* 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 */
if (M->ParamCount == 0) {
} else {
IdDesc* List = M->Params;
while (1) {
- if (SB_Compare (&List->Id, &SVal) == 0) {
- Error ("Duplicate symbol `%m%p'", &SVal);
+ if (SB_Compare (&List->Id, &CurTok.SVal) == 0) {
+ Error ("Duplicate symbol `%m%p'", &CurTok.SVal);
}
if (List->Next == 0) {
break;
NextTok ();
/* Maybe there are more params... */
- if (Tok == TOK_COMMA) {
+ if (CurTok.Tok == TOK_COMMA) {
NextTok ();
} else {
break;
/* Check for end of macro */
if (Style == MAC_STYLE_CLASSIC) {
/* In classic macros, only .endmacro is allowed */
- if (Tok == TOK_ENDMACRO) {
+ if (CurTok.Tok == TOK_ENDMACRO) {
/* Done */
break;
}
/* May not have end of file in a macro definition */
- if (Tok == TOK_EOF) {
+ if (CurTok.Tok == TOK_EOF) {
Error ("`.ENDMACRO' expected");
goto Done;
}
} else {
/* Accept a newline or end of file for new style macros */
- if (TokIsSep (Tok)) {
+ if (TokIsSep (CurTok.Tok)) {
break;
}
}
/* Check for a .LOCAL declaration */
- if (Tok == TOK_LOCAL && Style == MAC_STYLE_CLASSIC) {
+ if (CurTok.Tok == TOK_LOCAL && Style == MAC_STYLE_CLASSIC) {
while (1) {
NextTok ();
/* Need an identifer */
- if (Tok != TOK_IDENT && Tok != TOK_LOCAL_IDENT) {
+ if (CurTok.Tok != TOK_IDENT && CurTok.Tok != TOK_LOCAL_IDENT) {
Error ("Identifier expected");
SkipUntilSep ();
break;
}
/* Put the identifier into the locals list and skip it */
- I = NewIdDesc (&SVal);
+ I = NewIdDesc (&CurTok.SVal);
I->Next = M->Locals;
M->Locals = I;
++M->LocalCount;
NextTok ();
/* Check for end of list */
- if (Tok != TOK_COMMA) {
+ if (CurTok.Tok != TOK_COMMA) {
break;
}
T = NewTokNode ();
/* 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;
IdDesc* I = M->Params;
while (I) {
- if (SB_Compare (&I->Id, &SVal) == 0) {
+ if (SB_Compare (&I->Id, &CurTok.SVal) == 0) {
/* Local param name, replace it */
T->Tok = TOK_MACPARAM;
T->IVal = Count;
Mac->Exp = Mac->Exp->Next;
/* Is it a request for actual parameter count? */
- if (Tok == TOK_PARAMCOUNT) {
- Tok = TOK_INTCON;
- IVal = Mac->ParamCount;
+ if (CurTok.Tok == TOK_PARAMCOUNT) {
+ CurTok.Tok = TOK_INTCON;
+ CurTok.IVal = Mac->ParamCount;
return 1;
}
/* Is it the name of a macro parameter? */
- if (Tok == TOK_MACPARAM) {
+ if (CurTok.Tok == TOK_MACPARAM) {
/* Start to expand the parameter token list */
- Mac->ParamExp = Mac->Params [IVal];
+ Mac->ParamExp = Mac->Params [CurTok.IVal];
/* Recursive call to expand the parameter */
return MacExpand (Mac);
}
/* 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 */
unsigned Index = 0;
IdDesc* I = Mac->M->Locals;
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
* to generate a local label name if the original name was
* a local label, and also generate a name that cannot be
*/
if (SB_At (&I->Id, 0) == LocalStart) {
/* Must generate a local symbol */
- SB_Printf (&SVal, "%cLOCAL-MACRO_SYMBOL-%04X",
+ SB_Printf (&CurTok.SVal, "%cLOCAL-MACRO_SYMBOL-%04X",
LocalStart, Mac->LocalStart + Index);
} else {
/* Global symbol */
- SB_Printf (&SVal, "LOCAL-MACRO_SYMBOL-%04X",
+ SB_Printf (&CurTok.SVal, "LOCAL-MACRO_SYMBOL-%04X",
Mac->LocalStart + Index);
}
break;
E = NewMacExp (M);
/* Read the actual parameters */
- while (!TokIsSep (Tok)) {
+ while (!TokIsSep (CurTok.Tok)) {
TokNode* Last;
/* Read tokens for one parameter, accept empty params */
Last = 0;
- while (Tok != Term && Tok != TOK_SEP) {
+ while (CurTok.Tok != Term && CurTok.Tok != TOK_SEP) {
TokNode* T;
/* Check for end of file */
- if (Tok == TOK_EOF) {
+ if (CurTok.Tok == TOK_EOF) {
Error ("Unexpected end of file");
FreeMacExp (E);
return;
* is an error. Skip the closing curly brace.
*/
if (Term == TOK_RCURLY) {
- if (Tok == TOK_SEP) {
+ if (CurTok.Tok == TOK_SEP) {
Error ("End of line encountered within macro argument");
break;
}
}
/* Check for a comma */
- if (Tok == TOK_COMMA) {
+ if (CurTok.Tok == TOK_COMMA) {
NextTok ();
} else {
break;
token_t Term = GetTokListTerm (TOK_COMMA);
/* 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);
FreeMacExp (E);
return;
/* And skip it... */
NextTok ();
- } while (Tok != Term && !TokIsSep (Tok));
+ } while (CurTok.Tok != Term && !TokIsSep (CurTok.Tok));
/* One parameter more */
++E->ParamCount;
* is an error. Skip the closing curly brace.
*/
if (Term == TOK_RCURLY) {
- if (TokIsSep (Tok)) {
+ if (TokIsSep (CurTok.Tok)) {
Error ("End of line encountered within macro argument");
break;
}
/* Check for a comma */
if (Count > 0) {
- if (Tok == TOK_COMMA) {
+ if (CurTok.Tok == TOK_COMMA) {
NextTok ();
} else {
Error ("`,' expected");
/* Start expanding the macro in SVal */
{
/* Search for the macro */
- Macro* M = HT_FindEntry (&MacroTab, &SVal);
+ Macro* M = HT_FindEntry (&MacroTab, &CurTok.SVal);
CHECK (M != 0);
/* Call the apropriate subroutine */
switch (M->Style) {
case MAC_STYLE_CLASSIC: StartExpClassic (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);
}
}
+
/* */
/* */
/* */
-/* (C) 1998-2010, Ullrich von Bassewitz */
+/* (C) 1998-2011, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
InitListingLine ();
}
- if (Tok == TOK_COLON) {
+ if (CurTok.Tok == TOK_COLON) {
/* An unnamed label */
ULabDef ();
NextTok ();
/* If the first token on the line is an identifier, check for a macro or
* an instruction.
*/
- if (Tok == TOK_IDENT) {
+ if (CurTok.Tok == TOK_IDENT) {
if (!UbiquitousIdents) {
/* Macros and symbols cannot use instruction names */
- Instr = FindInstruction (&SVal);
+ Instr = FindInstruction (&CurTok.SVal);
if (Instr < 0) {
- Macro = IsMacro (&SVal);
+ Macro = IsMacro (&CurTok.SVal);
}
} else {
/* Macros and symbols may use the names of instructions */
- Macro = IsMacro (&SVal);
+ Macro = IsMacro (&CurTok.SVal);
}
}
* scoped identifier which may start with a namespace token (for global
* namespace)
*/
- if (Tok == TOK_LOCAL_IDENT ||
- Tok == TOK_NAMESPACE ||
- (Tok == TOK_IDENT && Instr < 0 && !Macro)) {
+ if (CurTok.Tok == TOK_LOCAL_IDENT ||
+ CurTok.Tok == TOK_NAMESPACE ||
+ (CurTok.Tok == TOK_IDENT && Instr < 0 && !Macro)) {
/* Did we have whitespace before the ident? */
- int HadWS = WS;
+ int HadWS = CurTok.WS;
/* Generate the symbol table entry, then skip the name */
Sym = ParseAnySymName (SYM_ALLOC_NEW);
/* If a colon follows, this is a label definition. If there
* 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 */
- unsigned Flags = (Tok == TOK_ASSIGN)? SF_LABEL : SF_NONE;
+ unsigned Flags = (CurTok.Tok == TOK_ASSIGN)? SF_LABEL : SF_NONE;
/* Skip the '=' */
NextTok ();
ConsumeSep ();
return;
- } else if (Tok == TOK_SET) {
+ } else if (CurTok.Tok == TOK_SET) {
ExprNode* Expr;
* without a colon if there is no whitespace before the
* identifier.
*/
- if (Tok != TOK_COLON) {
+ if (CurTok.Tok != TOK_COLON) {
if (HadWS || !NoColonLabels) {
Error ("`:' expected");
/* Try some smart error recovery */
- if (Tok == TOK_NAMESPACE) {
+ if (CurTok.Tok == TOK_NAMESPACE) {
NextTok ();
}
}
/* If we come here, a new identifier may be waiting, which may
* be a macro or instruction.
*/
- if (Tok == TOK_IDENT) {
+ if (CurTok.Tok == TOK_IDENT) {
if (!UbiquitousIdents) {
/* Macros and symbols cannot use instruction names */
- Instr = FindInstruction (&SVal);
+ Instr = FindInstruction (&CurTok.SVal);
if (Instr < 0) {
- Macro = IsMacro (&SVal);
+ Macro = IsMacro (&CurTok.SVal);
}
} else {
/* 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 */
- if (Tok >= TOK_FIRSTPSEUDO && Tok <= TOK_LASTPSEUDO) {
+ if (CurTok.Tok >= TOK_FIRSTPSEUDO && CurTok.Tok <= TOK_LASTPSEUDO) {
/* A control command */
HandlePseudo ();
} else if (Macro) {
/* A macro expansion */
MacExpandStart ();
} else if (Instr >= 0 ||
- (UbiquitousIdents && ((Instr = FindInstruction (&SVal)) >= 0))) {
+ (UbiquitousIdents && ((Instr = FindInstruction (&CurTok.SVal)) >= 0))) {
/* A mnemonic - assemble one instruction */
HandleInstruction (Instr);
- } else if (PCAssignment && (Tok == TOK_STAR || Tok == TOK_PC)) {
+ } else if (PCAssignment && (CurTok.Tok == TOK_STAR || CurTok.Tok == TOK_PC)) {
NextTok ();
- if (Tok != TOK_EQ) {
+ if (CurTok.Tok != TOK_EQ) {
Error ("`=' expected");
SkipUntilSep ();
} else {
NextTok ();
/* Assemble lines until end of file */
- while (Tok != TOK_EOF) {
+ while (CurTok.Tok != TOK_EOF) {
OneLine ();
}
}
* true.
*/
{
- if (Tok != TOK_STRCON) {
+ if (CurTok.Tok != TOK_STRCON) {
Error ("String constant expected");
SkipUntilSep ();
return 0;
/* Read the token list */
unsigned Current = 0;
- while (Tok != Term) {
+ while (CurTok.Tok != Term) {
/* Check for end of line or end of input */
- if (TokIsSep (Tok)) {
+ if (TokIsSep (CurTok.Tok)) {
Error ("Unexpected end of line");
return List;
}
}
/* Append the string */
- SB_Append (&Buf, &SVal);
+ SB_Append (&Buf, &CurTok.SVal);
/* Skip the string token */
NextTok ();
/* Comma means another argument */
- if (Tok == TOK_COMMA) {
+ if (CurTok.Tok == TOK_COMMA) {
NextTok ();
} else {
/* Done */
/* We expect a closing parenthesis, but will not skip it but replace it
* by the string token just created.
*/
- if (Tok != TOK_RPAREN) {
+ if (CurTok.Tok != TOK_RPAREN) {
Error ("`)' expected");
} else {
- Tok = TOK_STRCON;
- SB_Copy (&SVal, &Buf);
+ CurTok.Tok = TOK_STRCON;
+ SB_Copy (&CurTok.SVal, &Buf);
}
/* Free the string buffer */
/* Handle the .IDENT function */
{
StrBuf Buf = STATIC_STRBUF_INITIALIZER;
- token_t Id;
+ token_t Id;
unsigned I;
/* Skip it */
/* Check that the string contains a valid identifier. While doing so,
* determine if it is a cheap local, or global one.
*/
- SB_Reset (&SVal);
+ SB_Reset (&CurTok.SVal);
/* Check for a cheap local symbol */
- if (SB_Peek (&SVal) == LocalStart) {
- SB_Skip (&SVal);
+ if (SB_Peek (&CurTok.SVal) == LocalStart) {
+ SB_Skip (&CurTok.SVal);
Id = TOK_LOCAL_IDENT;
} else {
Id = TOK_IDENT;
}
/* Next character must be a valid identifier start */
- if (!IsIdStart (SB_Get (&SVal))) {
+ if (!IsIdStart (SB_Get (&CurTok.SVal))) {
NoIdent ();
return;
}
- for (I = SB_GetIndex (&SVal); I < SB_GetLen (&SVal); ++I) {
- if (!IsIdChar (SB_AtUnchecked (&SVal, I))) {
+ for (I = SB_GetIndex (&CurTok.SVal); I < SB_GetLen (&CurTok.SVal); ++I) {
+ if (!IsIdChar (SB_AtUnchecked (&CurTok.SVal, I))) {
NoIdent ();
return;
}
/* 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.
*/
- SB_Copy (&Buf, &SVal);
+ SB_Copy (&Buf, &CurTok.SVal);
NextTok ();
- if (Tok != TOK_RPAREN) {
+ if (CurTok.Tok != TOK_RPAREN) {
Error ("`)' expected");
} else {
- Tok = Id;
- SB_Copy (&SVal, &Buf);
+ CurTok.Tok = Id;
+ SB_Copy (&CurTok.SVal, &Buf);
}
/* Free buffer memory */
if (!LookAtStrCon ()) {
return;
}
- SB_Copy (&Format, &SVal);
+ SB_Copy (&Format, &CurTok.SVal);
NextTok ();
/* Walk over the format string, generating the function result in R */
/* The argument must be a string constant */
if (!LookAtStrCon ()) {
/* Make it one */
- SB_CopyStr (&SVal, "**undefined**");
+ SB_CopyStr (&CurTok.SVal, "**undefined**");
}
/* 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 */
NextTok ();
/* We expect a closing parenthesis, but will not skip it but replace it
* by the string token just created.
*/
- if (Tok != TOK_RPAREN) {
+ if (CurTok.Tok != TOK_RPAREN) {
Error ("`)' expected");
} else {
- Tok = TOK_STRCON;
- SB_Copy (&SVal, &R);
+ CurTok.Tok = TOK_STRCON;
+ SB_Copy (&CurTok.SVal, &R);
}
}
-
+
static void FuncString (void)
/* Handle the .STRING function */
{
ConsumeLParen ();
/* 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 */
- SB_Copy (&Buf, &SVal);
+ SB_Copy (&Buf, &CurTok.SVal);
NextTok ();
} else {
/* Numeric expression */
/* We expect a closing parenthesis, but will not skip it but replace it
* by the string token just created.
*/
- if (Tok != TOK_RPAREN) {
+ if (CurTok.Tok != TOK_RPAREN) {
Error ("`)' expected");
} else {
- Tok = TOK_STRCON;
- SB_Copy (&SVal, &Buf);
+ CurTok.Tok = TOK_STRCON;
+ SB_Copy (&CurTok.SVal, &Buf);
}
/* Free string memory */
if (RawMode == 0) {
/* Execute token handling functions */
- switch (Tok) {
+ switch (CurTok.Tok) {
case TOK_CONCAT:
FuncConcat ();
void Consume (token_t Expected, const char* ErrMsg)
/* Consume Expected, print an error if we don't find it */
{
- if (Tok == Expected) {
+ if (CurTok.Tok == Expected) {
NextTok ();
} else {
Error ("%s", ErrMsg);
ExpectSep ();
/* If we are at end of line, skip it */
- if (Tok == TOK_SEP) {
+ if (CurTok.Tok == TOK_SEP) {
NextTok ();
}
}
void SkipUntilSep (void)
/* Skip tokens until we reach a line separator or end of file */
{
- while (!TokIsSep (Tok)) {
+ while (!TokIsSep (CurTok.Tok)) {
NextTok ();
}
}
* not skip the line separator.
*/
{
- if (!TokIsSep (Tok)) {
+ if (!TokIsSep (CurTok.Tok)) {
ErrorSkip ("Unexpected trailing garbage characters");
}
}
*/
{
unsigned AddrSize = ADDR_SIZE_DEFAULT;
- if (Tok == TOK_COLON) {
+ if (CurTok.Tok == TOK_COLON) {
NextTok ();
AddrSize = ParseAddrSize ();
if (!ValidAddrSizeForCPU (AddrSize)) {
"ON",
};
- if (Tok == TOK_PLUS) {
+ if (CurTok.Tok == TOK_PLUS) {
*Flag = 1;
NextTok ();
- } else if (Tok == TOK_MINUS) {
+ } else if (CurTok.Tok == TOK_MINUS) {
*Flag = 0;
NextTok ();
- } else if (Tok == TOK_IDENT) {
+ } else if (CurTok.Tok == TOK_IDENT) {
/* Map the keyword to a number */
switch (GetSubKey (Keys, sizeof (Keys) / sizeof (Keys [0]))) {
case 0: *Flag = 0; NextTok (); break;
case 1: *Flag = 1; NextTok (); break;
default: ErrorSkip ("`on' or `off' expected"); break;
}
- } else if (TokIsSep (Tok)) {
+ } else if (TokIsSep (CurTok.Tok)) {
/* Without anything assume switch on */
*Flag = 1;
} else {
/* The name and optional address size spec may be followed by an assignment
* 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 */
- if (Tok == TOK_ASSIGN) {
+ if (CurTok.Tok == TOK_ASSIGN) {
Flags |= SF_LABEL;
}
while (1) {
/* We need an identifier here */
- if (Tok != TOK_IDENT) {
+ if (CurTok.Tok != TOK_IDENT) {
ErrorSkip ("Identifier expected");
return;
}
/* 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 */
NextTok ();
Func (Sym, AddrSize, Flags);
/* More symbols? */
- if (Tok == TOK_COMMA) {
+ if (CurTok.Tok == TOK_COMMA) {
NextTok ();
} else {
break;
* 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 ();
return -1;
} else {
SymEntry* Sym = SymFind (CurrentScope, Name, SYM_ALLOC_NEW);
/* Optional constructor priority */
- if (Tok == TOK_COMMA) {
+ if (CurTok.Tok == TOK_COMMA) {
/* Priority value follows */
NextTok ();
Prio = ConstExpression ();
/* Do a range check */
EmitWord (Expression ());
}
- if (Tok != TOK_COMMA) {
+ if (CurTok.Tok != TOK_COMMA) {
break;
} else {
NextTok ();
}
/* Optional value follows */
- if (Tok == TOK_COMMA) {
+ if (CurTok.Tok == TOK_COMMA) {
NextTok ();
Val = ConstExpression ();
/* We need a byte value here */
{
while (1) {
/* Must have a string constant */
- if (Tok != TOK_STRCON) {
+ if (CurTok.Tok != TOK_STRCON) {
ErrorSkip ("String constant expected");
return;
}
/* Translate into target charset and emit */
- TgtTranslateStrBuf (&SVal);
- EmitStrBuf (&SVal);
+ TgtTranslateStrBuf (&CurTok.SVal);
+ EmitStrBuf (&CurTok.SVal);
NextTok ();
- if (Tok == TOK_COMMA) {
+ if (CurTok.Tok == TOK_COMMA) {
NextTok ();
} else {
break;
ConsumeComma ();
/* Action follows */
- if (Tok != TOK_IDENT) {
+ if (CurTok.Tok != TOK_IDENT) {
ErrorSkip ("Identifier expected");
return;
}
/* We can have an optional message. If no message is present, use
* "Assertion failed".
*/
- if (Tok == TOK_COMMA) {
+ if (CurTok.Tok == TOK_COMMA) {
/* Skip the comma */
NextTok ();
/* Read the message */
- if (Tok != TOK_STRCON) {
+ if (CurTok.Tok != TOK_STRCON) {
ErrorSkip ("String constant expected");
return;
}
/* Translate the message into a string id. We can then skip the input
* string.
*/
- Msg = GetStrBufId (&SVal);
+ Msg = GetStrBufId (&CurTok.SVal);
NextTok ();
} else {
{
while (1) {
EmitByte (FuncBankByte ());
- if (Tok != TOK_COMMA) {
+ if (CurTok.Tok != TOK_COMMA) {
break;
} else {
NextTok ();
/* Define bytes */
{
while (1) {
- if (Tok == TOK_STRCON) {
+ if (CurTok.Tok == TOK_STRCON) {
/* A string, translate into target charset and emit */
- TgtTranslateStrBuf (&SVal);
- EmitStrBuf (&SVal);
+ TgtTranslateStrBuf (&CurTok.SVal);
+ EmitStrBuf (&CurTok.SVal);
NextTok ();
} else {
EmitByte (Expression ());
}
- if (Tok != TOK_COMMA) {
+ if (CurTok.Tok != TOK_COMMA) {
break;
} else {
NextTok ();
/* Do smart handling of dangling comma */
- if (Tok == TOK_SEP) {
+ if (CurTok.Tok == TOK_SEP) {
Error ("Unexpected end of line");
break;
}
long Type;
/* Symbol name follows */
- if (Tok != TOK_IDENT) {
+ if (CurTok.Tok != TOK_IDENT) {
ErrorSkip ("Identifier expected");
return;
}
- SB_Copy (&Name, &SVal);
+ SB_Copy (&Name, &CurTok.SVal);
NextTok ();
/* Type follows. May be encoded as identifier or numerical */
ConsumeComma ();
- if (Tok == TOK_IDENT) {
+ if (CurTok.Tok == TOK_IDENT) {
/* Map the following keyword to a number, then skip it */
Type = GetSubKey (Keys, sizeof (Keys) / sizeof (Keys [0]));
StrBuf Name = STATIC_STRBUF_INITIALIZER;
/* Symbol name follows */
- if (Tok != TOK_IDENT) {
+ if (CurTok.Tok != TOK_IDENT) {
ErrorSkip ("Identifier expected");
return;
}
- SB_Copy (&Name, &SVal);
+ SB_Copy (&Name, &CurTok.SVal);
NextTok ();
/* Parse the remainder of the line and export the symbol */
/* We expect a subkey */
- if (Tok != TOK_IDENT) {
+ if (CurTok.Tok != TOK_IDENT) {
ErrorSkip ("Identifier expected");
return;
}
{
while (1) {
EmitWord (GenSwapExpr (Expression ()));
- if (Tok != TOK_COMMA) {
+ if (CurTok.Tok != TOK_COMMA) {
break;
} else {
NextTok ();
StrBuf Name = STATIC_STRBUF_INITIALIZER;
/* Symbol name follows */
- if (Tok != TOK_IDENT) {
+ if (CurTok.Tok != TOK_IDENT) {
ErrorSkip ("Identifier expected");
return;
}
- SB_Copy (&Name, &SVal);
+ SB_Copy (&Name, &CurTok.SVal);
NextTok ();
/* Parse the remainder of the line and export the symbol */
{
while (1) {
EmitDWord (Expression ());
- if (Tok != TOK_COMMA) {
+ if (CurTok.Tok != TOK_COMMA) {
break;
} else {
NextTok ();
static void DoError (void)
/* User error */
{
- if (Tok != TOK_STRCON) {
+ if (CurTok.Tok != TOK_STRCON) {
ErrorSkip ("String constant expected");
} else {
- Error ("User error: %m%p", &SVal);
+ Error ("User error: %m%p", &CurTok.SVal);
SkipUntilSep ();
}
}
{
while (1) {
EmitFarAddr (Expression ());
- if (Tok != TOK_COMMA) {
+ if (CurTok.Tok != TOK_COMMA) {
break;
} else {
NextTok ();
static void DoFatal (void)
/* Fatal user error */
{
- if (Tok != TOK_STRCON) {
+ if (CurTok.Tok != TOK_STRCON) {
ErrorSkip ("String constant expected");
} else {
- Fatal ("User error: %m%p", &SVal);
+ Fatal ("User error: %m%p", &CurTok.SVal);
SkipUntilSep ();
}
}
while (1) {
/* We expect an identifier */
- if (Tok != TOK_IDENT) {
+ if (CurTok.Tok != TOK_IDENT) {
ErrorSkip ("Identifier expected");
return;
}
LocaseSVal ();
/* Set the feature and check for errors */
- if (SetFeature (&SVal) == FEAT_UNKNOWN) {
+ if (SetFeature (&CurTok.SVal) == FEAT_UNKNOWN) {
/* Not found */
- ErrorSkip ("Invalid feature: `%m%p'", &SVal);
+ ErrorSkip ("Invalid feature: `%m%p'", &CurTok.SVal);
return;
} else {
/* Skip the keyword */
}
/* Allow more than one keyword */
- if (Tok == TOK_COMMA) {
+ if (CurTok.Tok == TOK_COMMA) {
NextTok ();
} else {
break;
long OptNum;
/* 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 */
static const char* Keys [] = {
ConsumeComma ();
/* We accept only string options for now */
- if (Tok != TOK_STRCON) {
+ if (CurTok.Tok != TOK_STRCON) {
ErrorSkip ("String constant expected");
return;
}
case 0:
/* Author */
- OptAuthor (&SVal);
+ OptAuthor (&CurTok.SVal);
break;
case 1:
/* Comment */
- OptComment (&SVal);
+ OptComment (&CurTok.SVal);
break;
case 2:
/* Compiler */
- OptCompiler (&SVal);
+ OptCompiler (&CurTok.SVal);
break;
default:
ConsumeComma ();
/* We accept only string options for now */
- if (Tok != TOK_STRCON) {
+ if (CurTok.Tok != TOK_STRCON) {
ErrorSkip ("String constant expected");
return;
}
/* Insert the option */
- OptStr ((unsigned char) OptNum, &SVal);
+ OptStr ((unsigned char) OptNum, &CurTok.SVal);
/* Done */
NextTok ();
{
while (1) {
EmitByte (FuncHiByte ());
- if (Tok != TOK_COMMA) {
+ if (CurTok.Tok != TOK_COMMA) {
break;
} else {
NextTok ();
FILE* F;
/* Name must follow */
- if (Tok != TOK_STRCON) {
+ if (CurTok.Tok != TOK_STRCON) {
ErrorSkip ("String constant expected");
return;
}
- SB_Copy (&Name, &SVal);
+ SB_Copy (&Name, &CurTok.SVal);
SB_Terminate (&Name);
NextTok ();
/* A starting offset may follow */
- if (Tok == TOK_COMMA) {
+ if (CurTok.Tok == TOK_COMMA) {
NextTok ();
Start = ConstExpression ();
/* And a length may follow */
- if (Tok == TOK_COMMA) {
+ if (CurTok.Tok == TOK_COMMA) {
NextTok ();
Count = ConstExpression ();
}
/* Include another file */
{
/* Name must follow */
- if (Tok != TOK_STRCON) {
+ if (CurTok.Tok != TOK_STRCON) {
ErrorSkip ("String constant expected");
} else {
- SB_Terminate (&SVal);
- if (NewInputFile (SB_GetConstBuf (&SVal)) == 0) {
+ SB_Terminate (&CurTok.SVal);
+ if (NewInputFile (SB_GetConstBuf (&CurTok.SVal)) == 0) {
/* Error opening the file, skip remainder of line */
SkipUntilSep ();
}
StrBuf Name = STATIC_STRBUF_INITIALIZER;
/* Symbol name follows */
- if (Tok != TOK_IDENT) {
+ if (CurTok.Tok != TOK_IDENT) {
ErrorSkip ("Identifier expected");
return;
}
- SB_Copy (&Name, &SVal);
+ SB_Copy (&Name, &CurTok.SVal);
NextTok ();
/* Parse the remainder of the line and export the symbol */
{
while (1) {
EmitByte (FuncLoByte ());
- if (Tok != TOK_COMMA) {
+ if (CurTok.Tok != TOK_COMMA) {
break;
} else {
NextTok ();
static void DoLocalChar (void)
/* Define the character that starts local labels */
{
- if (Tok != TOK_CHARCON) {
+ if (CurTok.Tok != TOK_CHARCON) {
ErrorSkip ("Character constant expected");
} else {
- if (IVal != '@' && IVal != '?') {
+ if (CurTok.IVal != '@' && CurTok.IVal != '?') {
Error ("Invalid start character for locals");
} else {
- LocalStart = (char) IVal;
+ LocalStart = (char) CurTok.IVal;
}
NextTok ();
}
int Package;
/* We expect an identifier */
- if (Tok != TOK_IDENT) {
+ if (CurTok.Tok != TOK_IDENT) {
ErrorSkip ("Identifier expected");
return;
}
/* Search for the macro package name */
LocaseSVal ();
- Package = MacPackFind (&SVal);
+ Package = MacPackFind (&CurTok.SVal);
if (Package < 0) {
/* Not found */
ErrorSkip ("Invalid macro package");
static void DoOut (void)
/* Output a string */
{
- if (Tok != TOK_STRCON) {
+ if (CurTok.Tok != TOK_STRCON) {
ErrorSkip ("String constant expected");
} else {
/* 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.
*/
- printf ("%.*s\n", (int) SB_GetLen (&SVal), SB_GetConstBuf (&SVal));
+ printf ("%.*s\n",
+ (int) SB_GetLen (&CurTok.SVal),
+ SB_GetConstBuf (&CurTok.SVal));
fflush (stdout);
NextTok ();
}
StrBuf Name = STATIC_STRBUF_INITIALIZER;
unsigned char AddrSize;
- if (Tok == TOK_IDENT) {
+ if (CurTok.Tok == TOK_IDENT) {
SymEntry* Sym;
/* 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 */
Sym = SymFind (CurrentScope, &Name, SYM_ALLOC_NEW);
ErrorSkip ("Range error");
return;
}
- if (Tok == TOK_COMMA) {
+ if (CurTok.Tok == TOK_COMMA) {
NextTok ();
Val = ConstExpression ();
/* We need a byte value here */
unsigned char AddrSize;
- if (Tok == TOK_IDENT) {
+ if (CurTok.Tok == TOK_IDENT) {
/* The new scope has a name. Remember and skip it. */
- SB_Copy (&Name, &SVal);
+ SB_Copy (&Name, &CurTok.SVal);
NextTok ();
} else {
StrBuf Name = STATIC_STRBUF_INITIALIZER;
SegDef Def;
- if (Tok != TOK_STRCON) {
+ if (CurTok.Tok != TOK_STRCON) {
ErrorSkip ("String constant expected");
} else {
/* Save the name of the segment and skip it */
- SB_Copy (&Name, &SVal);
+ SB_Copy (&Name, &CurTok.SVal);
NextTok ();
/* Use the name for the segment definition */
/* Switch the CPU instruction set */
{
/* We expect an identifier */
- if (Tok != TOK_STRCON) {
+ if (CurTok.Tok != TOK_STRCON) {
ErrorSkip ("String constant expected");
} else {
cpu_t CPU;
/* Try to find the CPU */
- SB_Terminate (&SVal);
- CPU = FindCPU (SB_GetConstBuf (&SVal));
+ SB_Terminate (&CurTok.SVal);
+ CPU = FindCPU (SB_GetConstBuf (&CurTok.SVal));
/* Switch to the new CPU */
SetCPU (CPU);
}
/* Optional multiplicator may follow */
- if (Tok == TOK_COMMA) {
+ if (CurTok.Tok == TOK_COMMA) {
long Multiplicator;
NextTok ();
Multiplicator = ConstExpression ();
static void DoWarning (void)
/* User warning */
{
- if (Tok != TOK_STRCON) {
+ if (CurTok.Tok != TOK_STRCON) {
ErrorSkip ("String constant expected");
} else {
- Warning (0, "User warning: %m%p", &SVal);
+ Warning (0, "User warning: %m%p", &CurTok.SVal);
SkipUntilSep ();
}
}
{
while (1) {
EmitWord (Expression ());
- if (Tok != TOK_COMMA) {
+ if (CurTok.Tok != TOK_COMMA) {
break;
} else {
NextTok ();
CtrlDesc* D;
/* Calculate the index into the table */
- unsigned Index = Tok - TOK_FIRSTPSEUDO;
+ unsigned Index = CurTok.Tok - TOK_FIRSTPSEUDO;
/* Safety check */
if (PSEUDO_COUNT != (TOK_LASTPSEUDO - TOK_FIRSTPSEUDO + 1)) {
/* Remember the instruction, then skip it if needed */
if ((D->Flags & ccKeepToken) == 0) {
- SB_Copy (&Keyword, &SVal);
+ SB_Copy (&Keyword, &CurTok.SVal);
NextTok ();
}
/* */
/* */
/* */
-/* (C) 2000-2008, Ullrich von Bassewitz */
+/* (C) 2000-2011, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* Read the token list */
unsigned Repeats = 0;
- while (Repeats != 0 || Tok != TOK_ENDREP) {
+ while (Repeats != 0 || CurTok.Tok != TOK_ENDREP) {
/* Check for end of input */
- if (Tok == TOK_EOF) {
+ if (CurTok.Tok == TOK_EOF) {
Error ("Unexpected end of file");
FreeTokList (List);
return 0;
AddCurTok (List);
/* Check for and count nested .REPEATs */
- if (Tok == TOK_REPEAT) {
+ if (CurTok.Tok == TOK_REPEAT) {
++Repeats;
- } else if (Tok == TOK_ENDREP) {
+ } else if (CurTok.Tok == TOK_ENDREP) {
--Repeats;
}
* 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 */
- Tok = TOK_INTCON;
- IVal = L->RepCount;
+ CurTok.Tok = TOK_INTCON;
+ CurTok.IVal = L->RepCount;
}
}
/* Optional there is a comma and a counter variable */
Name = 0;
- if (Tok == TOK_COMMA) {
+ if (CurTok.Tok == TOK_COMMA) {
/* Skip the comma */
NextTok ();
/* Check for an identifier */
- if (Tok != TOK_IDENT) {
+ if (CurTok.Tok != TOK_IDENT) {
ErrorSkip ("Identifier expected");
} else {
/* Remember the name and skip it */
- SB_Terminate (&SVal);
- Name = xstrdup (SB_GetConstBuf (&SVal));
+ SB_Terminate (&CurTok.SVal);
+ Name = xstrdup (SB_GetConstBuf (&CurTok.SVal));
NextTok ();
}
}
-token_t Tok = TOK_NONE; /* Current token */
-int WS; /* Flag: Whitespace before token */
-long IVal; /* Integer token attribute */
-StrBuf SVal = STATIC_STRBUF_INITIALIZER;/* String token attribute */
-
-FilePos CurPos = STATIC_FILEPOS_INITIALIZER; /* Name and position in current file */
-
-
+/* Current input token incl. attributes */
+Token CurTok = STATIC_TOKEN_INITIALIZER;
/* Struct to handle include files. */
typedef struct InputFile InputFile;
/* Initialize a new input source and start to use it. */
{
/* Remember the current input char and token */
- S->Tok = Tok;
+ S->Tok = CurTok.Tok;
S->C = C;
/* Use the new input source */
/* Setup the next token so it will be skipped on the next call to
* NextRawTok().
*/
- Tok = TOK_SEP;
+ CurTok.Tok = TOK_SEP;
}
Source->Func->Done (Source);
/* Restore the old token */
- Tok = Source->Tok;
+ CurTok.Tok = Source->Tok;
C = Source->C;
/* Remember the last stacked input source */
static void IFMarkStart (CharSource* S)
/* Mark the start of the next token */
{
- CurPos = S->V.File.Pos;
+ CurTok.Pos = S->V.File.Pos;
}
void LocaseSVal (void)
/* Make SVal lower case */
{
- SB_ToLower (&SVal);
+ SB_ToLower (&CurTok.SVal);
}
void UpcaseSVal (void)
/* Make SVal upper case */
{
- SB_ToUpper (&SVal);
+ SB_ToUpper (&CurTok.SVal);
}
-static unsigned char FindDotKeyword (void)
+static token_t FindDotKeyword (void)
/* Find the dot keyword in SVal. Return the corresponding token if found,
* return TOK_NONE if not found.
*/
struct DotKeyword* R;
/* Initialize K */
- K.Key = SB_GetConstBuf (&SVal);
+ K.Key = SB_GetConstBuf (&CurTok.SVal);
K.Tok = 0;
/* If we aren't in ignore case mode, we have to uppercase the keyword */
/* Search for the keyword */
R = bsearch (&K, DotKeywords, sizeof (DotKeywords) / sizeof (DotKeywords [0]),
- sizeof (DotKeywords [0]), CmpDotKeyword);
+ sizeof (DotKeywords [0]), CmpDotKeyword);
if (R != 0) {
return R->Tok;
} else {
{
/* Read the identifier */
do {
- SB_AppendChar (&SVal, C);
+ SB_AppendChar (&CurTok.SVal, C);
NextChar ();
} while (IsIdChar (C));
- SB_Terminate (&SVal);
+ SB_Terminate (&CurTok.SVal);
/* If we should ignore case, convert the identifier to upper case */
if (IgnoreCase) {
}
/* Append the char to the string */
- SB_AppendChar (&SVal, C);
+ SB_AppendChar (&CurTok.SVal, C);
/* Skip the character */
NextChar ();
NextChar ();
/* Terminate the string */
- SB_Terminate (&SVal);
+ SB_Terminate (&CurTok.SVal);
}
{
/* If we've a forced end of assembly, don't read further */
if (ForcedEnd) {
- Tok = TOK_EOF;
+ CurTok.Tok = TOK_EOF;
return;
}
Again:
/* Skip whitespace, remember if we had some */
- if ((WS = IsBlank (C)) != 0) {
+ if ((CurTok.WS = IsBlank (C)) != 0) {
do {
NextChar ();
} while (IsBlank (C));
Source->Func->MarkStart (Source);
/* Clear the string attribute */
- SB_Clear (&SVal);
+ SB_Clear (&CurTok.SVal);
/* Hex number or PC symbol? */
if (C == '$') {
/* Hex digit must follow or DollarIsPC must be enabled */
if (!IsXDigit (C)) {
if (DollarIsPC) {
- Tok = TOK_PC;
+ CurTok.Tok = TOK_PC;
return;
} else {
Error ("Hexadecimal digit expected");
}
/* Read the number */
- IVal = 0;
+ CurTok.IVal = 0;
while (IsXDigit (C)) {
- if (IVal & 0xF0000000) {
+ if (CurTok.IVal & 0xF0000000) {
Error ("Overflow in hexadecimal number");
- IVal = 0;
+ CurTok.IVal = 0;
}
- IVal = (IVal << 4) + DigitVal (C);
+ CurTok.IVal = (CurTok.IVal << 4) + DigitVal (C);
NextChar ();
}
/* This is an integer constant */
- Tok = TOK_INTCON;
+ CurTok.Tok = TOK_INTCON;
return;
}
}
/* Read the number */
- IVal = 0;
+ CurTok.IVal = 0;
while (IsBDigit (C)) {
- if (IVal & 0x80000000) {
- Error ("Overflow in binary number");
- IVal = 0;
+ if (CurTok.IVal & 0x80000000) {
+ Error ("Overflow in binary number");
+ CurTok.IVal = 0;
}
- IVal = (IVal << 1) + DigitVal (C);
+ CurTok.IVal = (CurTok.IVal << 1) + DigitVal (C);
NextChar ();
}
/* This is an integer constant */
- Tok = TOK_INTCON;
+ CurTok.Tok = TOK_INTCON;
return;
}
}
/* Convert the number using the given base */
- IVal = 0;
+ CurTok.IVal = 0;
for (I = 0; I < Digits; ++I) {
- if (IVal > Max) {
+ if (CurTok.IVal > Max) {
Error ("Number out of range");
- IVal = 0;
+ CurTok.IVal = 0;
break;
}
DVal = DigitVal (Buf[I]);
if (DVal > Base) {
Error ("Invalid digits in number");
- IVal = 0;
+ CurTok.IVal = 0;
break;
}
- IVal = (IVal * Base) + DVal;
+ CurTok.IVal = (CurTok.IVal * Base) + DVal;
}
/* This is an integer constant */
- Tok = TOK_INTCON;
+ CurTok.Tok = TOK_INTCON;
return;
}
if (!IsIdStart (C)) {
/* Just a dot */
- Tok = TOK_DOT;
+ CurTok.Tok = TOK_DOT;
} else {
/* Read the remainder of the identifier */
- SB_AppendChar (&SVal, '.');
+ SB_AppendChar (&CurTok.SVal, '.');
ReadIdent ();
/* Dot keyword, search for it */
- Tok = FindDotKeyword ();
- if (Tok == TOK_NONE) {
+ CurTok.Tok = FindDotKeyword ();
+ if (CurTok.Tok == TOK_NONE) {
/* Not found */
if (!LeadingDotInIdents) {
/* 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;
}
/* An identifier with a dot. Check if it's a define style
* macro.
*/
- if (IsDefine (&SVal)) {
+ if (IsDefine (&CurTok.SVal)) {
/* This is a define style macro - expand it */
MacExpandStart ();
goto Restart;
}
/* Just an identifier with a dot */
- Tok = TOK_IDENT;
+ CurTok.Tok = TOK_IDENT;
}
}
*/
if (CPU == CPU_SWEET16 && C == '@') {
NextChar ();
- Tok = TOK_AT;
+ CurTok.Tok = TOK_AT;
return;
}
ReadIdent ();
/* Start character alone is not enough */
- if (SB_GetLen (&SVal) == 1) {
+ if (SB_GetLen (&CurTok.SVal) == 1) {
Error ("Invalid cheap local symbol");
goto Again;
}
/* A local identifier */
- Tok = TOK_LOCAL_IDENT;
+ CurTok.Tok = TOK_LOCAL_IDENT;
return;
}
/* Check for special names. Bail out if we have identified the type of
* the token. Go on if the token is an identifier.
*/
- if (SB_GetLen (&SVal) == 1) {
- switch (toupper (SB_AtUnchecked (&SVal, 0))) {
+ if (SB_GetLen (&CurTok.SVal) == 1) {
+ switch (toupper (SB_AtUnchecked (&CurTok.SVal, 0))) {
- case 'A':
+ case 'A':
if (C == ':') {
NextChar ();
- Tok = TOK_OVERRIDE_ABS;
+ CurTok.Tok = TOK_OVERRIDE_ABS;
} else {
- Tok = TOK_A;
+ CurTok.Tok = TOK_A;
}
return;
case 'F':
if (C == ':') {
NextChar ();
- Tok = TOK_OVERRIDE_FAR;
+ CurTok.Tok = TOK_OVERRIDE_FAR;
return;
}
break;
case 'S':
if (CPU == CPU_65816) {
- Tok = TOK_S;
+ CurTok.Tok = TOK_S;
return;
}
break;
case 'X':
- Tok = TOK_X;
+ CurTok.Tok = TOK_X;
return;
case 'Y':
- Tok = TOK_Y;
+ CurTok.Tok = TOK_Y;
return;
case 'Z':
if (C == ':') {
NextChar ();
- Tok = TOK_OVERRIDE_ZP;
+ CurTok.Tok = TOK_OVERRIDE_ZP;
return;
}
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 */
- Tok = TOK_REG;
+ CurTok.Tok = TOK_REG;
return;
}
/* Check for define style macro */
- if (IsDefine (&SVal)) {
+ if (IsDefine (&CurTok.SVal)) {
/* Macro - expand it */
MacExpandStart ();
goto Restart;
} else {
/* An identifier */
- Tok = TOK_IDENT;
+ CurTok.Tok = TOK_IDENT;
}
return;
}
case '+':
NextChar ();
- Tok = TOK_PLUS;
+ CurTok.Tok = TOK_PLUS;
return;
case '-':
NextChar ();
- Tok = TOK_MINUS;
+ CurTok.Tok = TOK_MINUS;
return;
case '/':
NextChar ();
if (C != '*') {
- Tok = TOK_DIV;
+ CurTok.Tok = TOK_DIV;
} else if (CComments) {
/* Remember the position, then skip the '*' */
- FilePos Pos = CurPos;
+ FilePos Pos = CurTok.Pos;
NextChar ();
do {
while (C != '*') {
case '*':
NextChar ();
- Tok = TOK_MUL;
+ CurTok.Tok = TOK_MUL;
return;
case '^':
NextChar ();
- Tok = TOK_XOR;
+ CurTok.Tok = TOK_XOR;
return;
case '&':
NextChar ();
if (C == '&') {
NextChar ();
- Tok = TOK_BOOLAND;
+ CurTok.Tok = TOK_BOOLAND;
} else {
- Tok = TOK_AND;
+ CurTok.Tok = TOK_AND;
}
return;
NextChar ();
if (C == '|') {
NextChar ();
- Tok = TOK_BOOLOR;
+ CurTok.Tok = TOK_BOOLOR;
} else {
- Tok = TOK_OR;
+ CurTok.Tok = TOK_OR;
}
return;
case ':':
NextChar ();
- Tok = TOK_NAMESPACE;
+ CurTok.Tok = TOK_NAMESPACE;
break;
case '-':
- IVal = 0;
+ CurTok.IVal = 0;
do {
- --IVal;
- NextChar ();
+ --CurTok.IVal;
+ NextChar ();
} while (C == '-');
- Tok = TOK_ULABEL;
+ CurTok.Tok = TOK_ULABEL;
break;
case '+':
- IVal = 0;
+ CurTok.IVal = 0;
do {
- ++IVal;
+ ++CurTok.IVal;
NextChar ();
} while (C == '+');
- Tok = TOK_ULABEL;
+ CurTok.Tok = TOK_ULABEL;
break;
case '=':
NextChar ();
- Tok = TOK_ASSIGN;
+ CurTok.Tok = TOK_ASSIGN;
break;
default:
- Tok = TOK_COLON;
+ CurTok.Tok = TOK_COLON;
break;
}
return;
case ',':
NextChar ();
- Tok = TOK_COMMA;
+ CurTok.Tok = TOK_COMMA;
return;
case ';':
case '#':
NextChar ();
- Tok = TOK_HASH;
+ CurTok.Tok = TOK_HASH;
return;
case '(':
NextChar ();
- Tok = TOK_LPAREN;
+ CurTok.Tok = TOK_LPAREN;
return;
case ')':
NextChar ();
- Tok = TOK_RPAREN;
+ CurTok.Tok = TOK_RPAREN;
return;
case '[':
NextChar ();
- Tok = TOK_LBRACK;
+ CurTok.Tok = TOK_LBRACK;
return;
case ']':
NextChar ();
- Tok = TOK_RBRACK;
+ CurTok.Tok = TOK_RBRACK;
return;
case '{':
NextChar ();
- Tok = TOK_LCURLY;
+ CurTok.Tok = TOK_LCURLY;
return;
case '}':
NextChar ();
- Tok = TOK_RCURLY;
+ CurTok.Tok = TOK_RCURLY;
return;
case '<':
NextChar ();
if (C == '=') {
NextChar ();
- Tok = TOK_LE;
+ CurTok.Tok = TOK_LE;
} else if (C == '<') {
NextChar ();
- Tok = TOK_SHL;
+ CurTok.Tok = TOK_SHL;
} else if (C == '>') {
NextChar ();
- Tok = TOK_NE;
+ CurTok.Tok = TOK_NE;
} else {
- Tok = TOK_LT;
+ CurTok.Tok = TOK_LT;
}
return;
case '=':
NextChar ();
- Tok = TOK_EQ;
+ CurTok.Tok = TOK_EQ;
return;
case '!':
NextChar ();
- Tok = TOK_BOOLNOT;
+ CurTok.Tok = TOK_BOOLNOT;
return;
case '>':
NextChar ();
if (C == '=') {
NextChar ();
- Tok = TOK_GE;
+ CurTok.Tok = TOK_GE;
} else if (C == '>') {
NextChar ();
- Tok = TOK_SHR;
+ CurTok.Tok = TOK_SHR;
} else {
- Tok = TOK_GT;
+ CurTok.Tok = TOK_GT;
}
return;
case '~':
NextChar ();
- Tok = TOK_NOT;
+ CurTok.Tok = TOK_NOT;
return;
case '\'':
*/
if (LooseStringTerm) {
ReadStringConst ('\'');
- if (SB_GetLen (&SVal) == 1) {
- IVal = SB_AtUnchecked (&SVal, 0);
- Tok = TOK_CHARCON;
+ if (SB_GetLen (&CurTok.SVal) == 1) {
+ CurTok.IVal = SB_AtUnchecked (&CurTok.SVal, 0);
+ CurTok.Tok = TOK_CHARCON;
} else {
- Tok = TOK_STRCON;
+ CurTok.Tok = TOK_STRCON;
}
} else {
/* Always a character constant */
Error ("Illegal character constant");
goto CharAgain;
}
- IVal = C;
- Tok = TOK_CHARCON;
+ CurTok.IVal = C;
+ CurTok.Tok = TOK_CHARCON;
NextChar ();
if (C != '\'') {
if (!MissingCharTerm) {
case '\"':
ReadStringConst ('\"');
- Tok = TOK_STRCON;
+ CurTok.Tok = TOK_STRCON;
return;
case '\\':
case '\n':
NextChar ();
- Tok = TOK_SEP;
+ CurTok.Tok = TOK_SEP;
return;
case EOF:
DoneCharSource ();
goto Again;
} else {
- Tok = TOK_EOF;
+ CurTok.Tok = TOK_EOF;
}
return;
}
unsigned I;
/* 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 (!IgnoreCase) {
/* Do a linear search (a binary search is not worth the effort) */
for (I = 0; I < Count; ++I) {
- if (SB_CompareStr (&SVal, Keys [I]) == 0) {
+ if (SB_CompareStr (&CurTok.SVal, Keys [I]) == 0) {
/* Found it */
return I;
}
unsigned char AddrSize;
/* Check for an identifier */
- if (Tok != TOK_IDENT) {
+ if (CurTok.Tok != TOK_IDENT) {
Error ("Address size specifier expected");
return ADDR_SIZE_DEFAULT;
}
/* Convert the attribute */
- AddrSize = AddrSizeFromStr (SB_GetConstBuf (&SVal));
+ AddrSize = AddrSizeFromStr (SB_GetConstBuf (&CurTok.SVal));
if (AddrSize == ADDR_SIZE_INVALID) {
Error ("Address size specifier expected");
AddrSize = ADDR_SIZE_DEFAULT;
+
-/* common */
-#include "filepos.h"
-#include "strbuf.h"
-
/* ca65 */
#include "token.h"
/* Scanner variables */
-extern token_t Tok; /* Current token */
-extern int WS; /* Flag: Whitespace before token */
-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 */
+extern Token CurTok; /* Current input token incl. attributes */
+extern int ForcedEnd; /* Force end of assembly */
/* */
/* */
/* */
-/* (C) 2003 Ullrich von Bassewitz */
-/* Römerstraße 52 */
-/* D-70794 Filderstadt */
-/* EMail: uz@cc65.org */
+/* (C) 2003-2011, Ullrich von Bassewitz */
+/* Roemerstrasse 52 */
+/* D-70794 Filderstadt */
+/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
long Multiplicator;
/* A multiplicator may follow */
- if (Tok != TOK_SEP) {
+ if (CurTok.Tok != TOK_SEP) {
Multiplicator = ConstExpression ();
if (Multiplicator <= 0) {
ErrorSkip ("Range error");
* union, the struct may be anonymous, in which case no new lexical level
* is started.
*/
- int Anon = (Tok != TOK_IDENT);
+ int Anon = (CurTok.Tok != TOK_IDENT);
if (!Anon) {
/* Enter a new scope, then skip the name */
- SymEnterLevel (&SVal, ST_STRUCT, ADDR_SIZE_ABS);
+ SymEnterLevel (&CurTok.SVal, ST_STRUCT, ADDR_SIZE_ABS);
NextTok ();
/* Start at zero offset in the new scope */
Offs = 0;
ConsumeSep ();
/* 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;
SymTable* Struct;
SymEntry* Sym;
/* Allow empty and comment lines */
- if (Tok == TOK_SEP) {
+ if (CurTok.Tok == TOK_SEP) {
NextTok ();
continue;
}
/* The format is "[identifier] storage-allocator [, multiplicator]" */
Sym = 0;
- if (Tok == TOK_IDENT) {
+ if (CurTok.Tok == TOK_IDENT) {
/* 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 */
SymDef (Sym, GenLiteralExpr (Offs), ADDR_SIZE_DEFAULT, SF_NONE);
/* Read storage allocators */
MemberSize = 0; /* In case of errors, use zero */
- switch (Tok) {
+ switch (CurTok.Tok) {
case TOK_BYTE:
NextTok ();
case TOK_RES:
NextTok ();
- if (Tok == TOK_SEP) {
+ if (CurTok.Tok == TOK_SEP) {
ErrorSkip ("Size is missing");
} else {
MemberSize = Member (1);
/* */
/* */
/* */
-/* (C) 1998-2010, Ullrich von Bassewitz */
+/* (C) 1998-2011, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
SB_Clear (FullName);
/* Get the starting table */
- if (Tok == TOK_NAMESPACE) {
+ if (CurTok.Tok == TOK_NAMESPACE) {
/* Start from the root scope */
Scope = RootScope;
- } else if (Tok == TOK_IDENT) {
+ } else if (CurTok.Tok == TOK_IDENT) {
/* Remember the name and skip it */
- SB_Copy (Name, &SVal);
+ SB_Copy (Name, &CurTok.SVal);
NextTok ();
/* If no namespace symbol follows, we're already done */
- if (Tok != TOK_NAMESPACE) {
+ if (CurTok.Tok != TOK_NAMESPACE) {
SB_Terminate (FullName);
return CurrentScope;
}
/* Pass the scope back to the caller */
SB_Append (FullName, Name);
-
+
/* The scope must exist, so search for it starting with the current
* scope.
*/
while (1) {
/* Next token must be an identifier. */
- if (Tok != TOK_IDENT) {
+ if (CurTok.Tok != TOK_IDENT) {
Error ("Identifier expected");
return 0;
}
/* Remember and skip the identifier */
- SB_Copy (Name, &SVal);
+ SB_Copy (Name, &CurTok.SVal);
NextTok ();
/* If a namespace token follows, we search for another scope, otherwise
* the name is a symbol and we're done.
*/
- if (Tok != TOK_NAMESPACE) {
+ if (CurTok.Tok != TOK_NAMESPACE) {
/* Symbol */
return Scope;
}
SymEntry* Sym;
/* Distinguish cheap locals and other symbols */
- if (Tok == TOK_LOCAL_IDENT) {
- Sym = SymFindLocal (SymLast, &SVal, AllocNew);
+ if (CurTok.Tok == TOK_LOCAL_IDENT) {
+ Sym = SymFindLocal (SymLast, &CurTok.SVal, AllocNew);
NextTok ();
} else {
Sym = ParseScopedSymName (AllocNew);
/* */
/* */
/* */
-/* (C) 1998-2010, Ullrich von Bassewitz */
+/* (C) 1998-2011, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
S->Right = 0;
S->Locals = 0;
S->Sym.Tab = 0;
- S->Pos = CurPos;
+ S->Pos = CurTok.Pos;
for (I = 0; I < sizeof (S->GuessedUse) / sizeof (S->GuessedUse[0]); ++I) {
S->GuessedUse[I] = 0;
}
}
/* Ok, remember the file position */
- Sym->GuessedUse[AddrSize-1] = xdup (&CurPos, sizeof (CurPos));
+ Sym->GuessedUse[AddrSize-1] = xdup (&CurTok.Pos, sizeof (CurTok.Pos));
}
/* common */
+#include "filepos.h"
#include "inline.h"
+#include "strbuf.h"
-/* Tokens */
+/* Tokens */
typedef enum token_t {
TOK_NONE, /* Start value, invalid */
TOK_EOF, /* End of input file */
TOK_ULABEL, /* :++ or :-- */
TOK_EQ, /* = */
- TOK_NE, /* <> */
+ TOK_NE, /* <> */
TOK_LT, /* < */
TOK_GT, /* > */
TOK_LE, /* <= */
TOK_BOOLNOT, /* .not */
TOK_PLUS, /* + */
- TOK_MINUS, /* - */
+ TOK_MINUS, /* - */
TOK_MUL, /* * */
TOK_STAR = TOK_MUL, /* Alias */
TOK_DIV, /* / */
TOK_MOD, /* ! */
- TOK_OR, /* | */
+ TOK_OR, /* | */
TOK_XOR, /* ^ */
TOK_BANK = TOK_XOR, /* Alias */
TOK_AND, /* & */
+/* 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 */
/*****************************************************************************/
/* Initialize the token contents */
T->Next = 0;
- T->Tok = Tok;
- T->WS = WS;
- T->IVal = IVal;
+ T->Tok = CurTok.Tok;
+ T->WS = CurTok.WS;
+ T->IVal = CurTok.IVal;
SB_Init (&T->SVal);
- SB_Copy (&T->SVal, &SVal);
+ SB_Copy (&T->SVal, &CurTok.SVal);
/* Return the node */
return T;
/* Set the scanner token from the given token node */
{
/* Set the values */
- Tok = T->Tok;
- WS = T->WS;
- IVal = T->IVal;
- SB_Copy (&SVal, &T->SVal);
- SB_Terminate (&SVal);
+ CurTok.Tok = T->Tok;
+ CurTok.WS = T->WS;
+ CurTok.IVal = T->IVal;
+ SB_Copy (&CurTok.SVal, &T->SVal);
+ SB_Terminate (&CurTok.SVal);
}
enum TC TokCmp (const TokNode* T)
/* Compare the token given as parameter against the current token */
{
- if (T->Tok != Tok) {
+ if (T->Tok != CurTok.Tok) {
/* Different token */
return tcDifferent;
}
/* If the token has string attribute, check it */
if (TokHasSVal (T->Tok)) {
- if (SB_Compare (&SVal, &T->SVal) != 0) {
+ if (SB_Compare (&CurTok.SVal, &T->SVal) != 0) {
return tcSameToken;
}
} else if (TokHasIVal (T->Tok)) {
- if (T->IVal != IVal) {
+ if (T->IVal != CurTok.IVal) {
return tcSameToken;
}
}
* a closing brace, otherwise return Term.
*/
{
- if (Tok == TOK_LCURLY) {
+ if (CurTok.Tok == TOK_LCURLY) {
NextTok ();
return TOK_RCURLY;
} else {
+
/* */
/* */
/* */
-/* (C) 2000-2004 Ullrich von Bassewitz */
-/* Römerstraße 52 */
-/* D-70794 Filderstadt */
-/* EMail: uz@cc65.org */
+/* (C) 2000-2011, Ullrich von Bassewitz */
+/* Roemerstrasse 52 */
+/* D-70794 Filderstadt */
+/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
ULabel* L = xmalloc (sizeof (ULabel));
/* Initialize the fields */
- L->Pos = CurPos;
+ L->Pos = CurTok.Pos;
L->Val = Val;
L->Ref = 0;
ULabel* L = CollAtUnchecked (&ULabList, ULabDefCount);
CHECK (L->Val == 0);
L->Val = GenCurrentPC ();
- L->Pos = CurPos;
+ L->Pos = CurTok.Pos;
} else {
/* There is no such label, create it */
NewULabel (GenCurrentPC ());