From ddb7296b6c38036c6c3001c4c471c346b9585ae6 Mon Sep 17 00:00:00 2001 From: uz Date: Sun, 16 Jan 2011 16:05:43 +0000 Subject: [PATCH] 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 --- src/ca65/asserts.c | 5 +- src/ca65/condasm.c | 19 ++-- src/ca65/dbginfo.c | 14 +-- src/ca65/ea65.c | 35 +++---- src/ca65/easw16.c | 26 ++--- src/ca65/enum.c | 23 ++--- src/ca65/error.c | 14 +-- src/ca65/expr.c | 85 ++++++++-------- src/ca65/fragment.c | 10 +- src/ca65/instr.c | 4 +- src/ca65/macro.c | 94 +++++++++--------- src/ca65/main.c | 48 ++++----- src/ca65/nexttok.c | 72 +++++++------- src/ca65/pseudo.c | 178 +++++++++++++++++----------------- src/ca65/repeat.c | 26 ++--- src/ca65/scanner.c | 230 ++++++++++++++++++++++---------------------- src/ca65/scanner.h | 13 +-- src/ca65/struct.c | 28 +++--- src/ca65/symbol.c | 22 ++--- src/ca65/symentry.c | 6 +- src/ca65/token.h | 31 +++++- src/ca65/toklist.c | 27 +++--- src/ca65/ulabel.c | 12 +-- 23 files changed, 526 insertions(+), 496 deletions(-) diff --git a/src/ca65/asserts.c b/src/ca65/asserts.c index 09341d935..126231c06 100644 --- a/src/ca65/asserts.c +++ b/src/ca65/asserts.c @@ -6,7 +6,7 @@ /* */ /* */ /* */ -/* (C) 2003-2008, Ullrich von Bassewitz */ +/* (C) 2003-2011, Ullrich von Bassewitz */ /* Roemerstrasse 52 */ /* D-70794 Filderstadt */ /* EMail: uz@cc65.org */ @@ -83,7 +83,7 @@ static Assertion* NewAssertion (ExprNode* Expr, AssertAction Action, unsigned Ms A->Expr = Expr; A->Action = Action; A->Msg = Msg; - A->Pos = CurPos; + A->Pos = CurTok.Pos; /* Return the new struct */ return A; @@ -179,3 +179,4 @@ void WriteAssertions (void) + diff --git a/src/ca65/condasm.c b/src/ca65/condasm.c index 5309a981d..28c9f4bd4 100644 --- a/src/ca65/condasm.c +++ b/src/ca65/condasm.c @@ -98,7 +98,7 @@ static IfDesc* AllocIf (const char* Directive, int NeedTerm) /* Initialize elements */ ID->Flags = NeedTerm? ifNeedTerm : ifNone; - ID->Pos = CurPos; + ID->Pos = CurTok.Pos; ID->Name = Directive; /* 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 (); do { - switch (Tok) { + switch (CurTok.Tok) { case TOK_ELSE: D = GetCurrentIf (); @@ -218,7 +218,7 @@ void DoConditionals (void) /* Allow an .ELSE */ InvertIfCond (D); SetElse (D, 1); - D->Pos = CurPos; + D->Pos = CurTok.Pos; D->Name = ".ELSE"; IfCond = GetCurrentIfCond (); } @@ -284,7 +284,7 @@ void DoConditionals (void) D = AllocIf (".IFBLANK", 1); NextTok (); if (IfCond) { - if (TokIsSep (Tok)) { + if (TokIsSep (CurTok.Tok)) { SetIfCond (D, 1); } else { SetIfCond (D, 0); @@ -320,7 +320,7 @@ void DoConditionals (void) D = AllocIf (".IFNBLANK", 1); NextTok (); if (IfCond) { - if (TokIsSep (Tok)) { + if (TokIsSep (CurTok.Tok)) { SetIfCond (D, 0); } else { 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. */ { - switch (Tok) { + switch (CurTok.Tok) { case TOK_ELSE: case TOK_ELSEIF: case TOK_ENDIF: @@ -474,7 +474,7 @@ void CheckOpenIfs (void) break; } - if (D->Pos.Name != CurPos.Name) { + if (D->Pos.Name != CurTok.Pos.Name) { /* The .if is from another file, bail out */ break; } @@ -505,3 +505,4 @@ void CleanupIfStack (unsigned SP) + diff --git a/src/ca65/dbginfo.c b/src/ca65/dbginfo.c index dad33e7d2..5466a00b0 100644 --- a/src/ca65/dbginfo.c +++ b/src/ca65/dbginfo.c @@ -6,7 +6,7 @@ /* */ /* */ /* */ -/* (C) 2000-2010, Ullrich von Bassewitz */ +/* (C) 2000-2011, Ullrich von Bassewitz */ /* Roemerstrasse 52 */ /* D-70794 Filderstadt */ /* EMail: uz@cc65.org */ @@ -65,11 +65,11 @@ void DbgInfoFile (void) 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 */ @@ -102,7 +102,7 @@ void DbgInfoLine (void) /* 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; } @@ -111,13 +111,13 @@ void DbgInfoLine (void) 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 (); @@ -146,3 +146,5 @@ void DbgInfoSym (void) + + diff --git a/src/ca65/ea65.c b/src/ca65/ea65.c index 98c5213ae..a1bda2d7b 100644 --- a/src/ca65/ea65.c +++ b/src/ca65/ea65.c @@ -6,10 +6,10 @@ /* */ /* */ /* */ -/* (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 */ @@ -59,7 +59,7 @@ void GetEA (EffAddr* A) 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 (); @@ -81,29 +81,29 @@ void GetEA (EffAddr* A) } /* 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"); @@ -113,22 +113,22 @@ void GetEA (EffAddr* A) 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; @@ -143,7 +143,7 @@ void GetEA (EffAddr* A) /* (adr) or (adr),y */ ConsumeRParen (); - if (Tok == TOK_COMMA) { + if (CurTok.Tok == TOK_COMMA) { /* (adr),y */ NextTok (); Consume (TOK_Y, "`Y' expected"); @@ -165,10 +165,10 @@ void GetEA (EffAddr* A) */ 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; @@ -203,3 +203,4 @@ void GetEA (EffAddr* A) + diff --git a/src/ca65/easw16.c b/src/ca65/easw16.c index 95a9587cf..15773a7ae 100644 --- a/src/ca65/easw16.c +++ b/src/ca65/easw16.c @@ -6,10 +6,10 @@ /* */ /* */ /* */ -/* (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 */ @@ -80,17 +80,17 @@ void GetSweet16EA (EffAddr* A) 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 */ @@ -100,12 +100,12 @@ void GetSweet16EA (EffAddr* A) 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 (); @@ -133,7 +133,7 @@ void GetSweet16EA (EffAddr* A) 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; @@ -147,4 +147,4 @@ void GetSweet16EA (EffAddr* A) } - + diff --git a/src/ca65/enum.c b/src/ca65/enum.c index 368a7484a..8b123e180 100644 --- a/src/ca65/enum.c +++ b/src/ca65/enum.c @@ -6,10 +6,10 @@ /* */ /* */ /* */ -/* (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 */ @@ -62,10 +62,10 @@ void DoEnum (void) 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 (); } @@ -73,19 +73,19 @@ void DoEnum (void) 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"); @@ -94,13 +94,13 @@ void DoEnum (void) } /* 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 (); @@ -145,3 +145,4 @@ void DoEnum (void) + diff --git a/src/ca65/error.c b/src/ca65/error.c index a0827de61..9c4ce1ede 100644 --- a/src/ca65/error.c +++ b/src/ca65/error.c @@ -6,10 +6,10 @@ /* */ /* */ /* */ -/* (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 */ @@ -94,7 +94,7 @@ void Warning (unsigned Level, const char* Format, ...) { va_list ap; va_start (ap, Format); - WarningMsg (&CurPos, Level, Format, ap); + WarningMsg (&CurTok.Pos, Level, Format, ap); va_end (ap); } @@ -140,7 +140,7 @@ void Error (const char* Format, ...) { va_list ap; va_start (ap, Format); - ErrorMsg (&CurPos, Format, ap); + ErrorMsg (&CurTok.Pos, Format, ap); va_end (ap); } @@ -162,7 +162,7 @@ void ErrorSkip (const char* Format, ...) { va_list ap; va_start (ap, Format); - ErrorMsg (&CurPos, Format, ap); + ErrorMsg (&CurTok.Pos, Format, ap); va_end (ap); SkipUntilSep (); diff --git a/src/ca65/expr.c b/src/ca65/expr.c index c299218d0..b8efe42b1 100644 --- a/src/ca65/expr.c +++ b/src/ca65/expr.c @@ -335,13 +335,13 @@ static ExprNode* FuncBlank (void) */ 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; } @@ -353,7 +353,7 @@ static ExprNode* FuncBlank (void) } /* 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 (); } @@ -438,10 +438,10 @@ static ExprNode* DoMatch (enum TC EqualityLevel) * 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 (); } @@ -476,10 +476,10 @@ static ExprNode* DoMatch (enum TC EqualityLevel) 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 (); } @@ -621,18 +621,18 @@ static ExprNode* FuncSizeOf (void) 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); @@ -708,14 +708,14 @@ static ExprNode* FuncStrAt (void) 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 */ @@ -751,11 +751,11 @@ static ExprNode* FuncStrLen (void) 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; @@ -763,7 +763,7 @@ static ExprNode* FuncStrLen (void) } else { /* Get the length of the string */ - Len = SB_GetLen (&SVal); + Len = SB_GetLen (&CurTok.SVal); /* Skip the string */ NextTok (); @@ -783,13 +783,13 @@ static ExprNode* FuncTCount (void) */ 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; } @@ -801,7 +801,7 @@ static ExprNode* FuncTCount (void) } /* 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 (); } @@ -828,7 +828,7 @@ static ExprNode* Function (ExprNode* (*F) (void)) NextTok (); /* Expression must be enclosed in braces */ - if (Tok != TOK_LPAREN) { + if (CurTok.Tok != TOK_LPAREN) { Error ("'(' expected"); SkipUntilSep (); return GenLiteral0 (); @@ -853,15 +853,15 @@ static ExprNode* Factor (void) 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; @@ -872,7 +872,7 @@ static ExprNode* Factor (void) break; case TOK_ULABEL: - N = ULabRef (IVal); + N = ULabRef (CurTok.IVal); NextTok (); break; @@ -1016,9 +1016,10 @@ static ExprNode* Factor (void) 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"); @@ -1037,16 +1038,17 @@ static ExprNode* Term (void) 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 */ @@ -1140,14 +1142,16 @@ static ExprNode* SimpleExpr (void) 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 */ @@ -1201,15 +1205,16 @@ static ExprNode* BoolExpr (void) 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 */ @@ -1269,14 +1274,14 @@ static ExprNode* Expr2 (void) 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 */ @@ -1328,14 +1333,14 @@ static ExprNode* Expr1 (void) 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 */ @@ -1384,7 +1389,7 @@ static ExprNode* Expr0 (void) ExprNode* Root; /* Handle booleans */ - if (Tok == TOK_BOOLNOT) { + if (CurTok.Tok == TOK_BOOLNOT) { long Val; ExprNode* Left; diff --git a/src/ca65/fragment.c b/src/ca65/fragment.c index 0d5a4b2e5..6ee4dad8b 100644 --- a/src/ca65/fragment.c +++ b/src/ca65/fragment.c @@ -6,10 +6,10 @@ /* */ /* */ /* */ -/* (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 */ @@ -60,7 +60,7 @@ Fragment* NewFragment (unsigned char Type, unsigned short Len) /* 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; diff --git a/src/ca65/instr.c b/src/ca65/instr.c index b5839c10a..39c32f2ea 100644 --- a/src/ca65/instr.c +++ b/src/ca65/instr.c @@ -6,7 +6,7 @@ /* */ /* */ /* */ -/* (C) 1998-2009, Ullrich von Bassewitz */ +/* (C) 1998-2011, Ullrich von Bassewitz */ /* Roemerstrasse 52 */ /* D-70794 Filderstadt */ /* EMail: uz@cc65.org */ @@ -1255,7 +1255,7 @@ static void PutTST (const InsDesc* Ins) EffAddr A; /* The first argument is always an immediate byte */ - if (Tok != TOK_HASH) { + if (CurTok.Tok != TOK_HASH) { ErrorSkip ("Invalid addressing mode"); return; } diff --git a/src/ca65/macro.c b/src/ca65/macro.c index fdb65794b..2d2dedeb6 100644 --- a/src/ca65/macro.c +++ b/src/ca65/macro.c @@ -6,10 +6,10 @@ /* */ /* */ /* */ -/* (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 */ @@ -311,10 +311,10 @@ static void MacSkipDef (unsigned Style) { 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"); @@ -335,11 +335,11 @@ void MacDef (unsigned Style) 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. */ @@ -349,16 +349,16 @@ void MacDef (unsigned Style) } /* 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 (); @@ -370,7 +370,7 @@ void MacDef (unsigned Style) if (Style == MAC_STYLE_CLASSIC) { HaveParams = 1; } else { - if (Tok == TOK_LPAREN) { + if (CurTok.Tok == TOK_LPAREN) { HaveParams = 1; NextTok (); } else { @@ -381,10 +381,10 @@ void MacDef (unsigned Style) /* 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) { @@ -392,8 +392,8 @@ void MacDef (unsigned Style) } 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; @@ -409,7 +409,7 @@ void MacDef (unsigned Style) NextTok (); /* Maybe there are more params... */ - if (Tok == TOK_COMMA) { + if (CurTok.Tok == TOK_COMMA) { NextTok (); } else { break; @@ -436,24 +436,24 @@ void MacDef (unsigned Style) /* 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) { @@ -463,21 +463,21 @@ void MacDef (unsigned Style) 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; } @@ -492,11 +492,11 @@ void MacDef (unsigned Style) 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; @@ -584,29 +584,30 @@ static int MacExpand (void* Data) 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 @@ -614,11 +615,11 @@ static int MacExpand (void* Data) */ 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; @@ -677,7 +678,7 @@ static void StartExpClassic (Macro* M) E = NewMacExp (M); /* Read the actual parameters */ - while (!TokIsSep (Tok)) { + while (!TokIsSep (CurTok.Tok)) { TokNode* Last; @@ -692,12 +693,12 @@ static void StartExpClassic (Macro* M) /* 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; @@ -725,7 +726,7 @@ static void StartExpClassic (Macro* M) * 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; } @@ -733,7 +734,7 @@ static void StartExpClassic (Macro* M) } /* Check for a comma */ - if (Tok == TOK_COMMA) { + if (CurTok.Tok == TOK_COMMA) { NextTok (); } else { break; @@ -772,7 +773,7 @@ static void StartExpDefine (Macro* M) 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; @@ -798,7 +799,7 @@ static void StartExpDefine (Macro* M) /* And skip it... */ NextTok (); - } while (Tok != Term && !TokIsSep (Tok)); + } while (CurTok.Tok != Term && !TokIsSep (CurTok.Tok)); /* One parameter more */ ++E->ParamCount; @@ -807,7 +808,7 @@ static void StartExpDefine (Macro* M) * 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; } @@ -816,7 +817,7 @@ static void StartExpDefine (Macro* M) /* Check for a comma */ if (Count > 0) { - if (Tok == TOK_COMMA) { + if (CurTok.Tok == TOK_COMMA) { NextTok (); } else { Error ("`,' expected"); @@ -841,14 +842,14 @@ void MacExpandStart (void) /* 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); } } @@ -891,3 +892,4 @@ int InMacExpansion (void) + diff --git a/src/ca65/main.c b/src/ca65/main.c index 934ad6f3d..53bd5be48 100644 --- a/src/ca65/main.c +++ b/src/ca65/main.c @@ -6,7 +6,7 @@ /* */ /* */ /* */ -/* (C) 1998-2010, Ullrich von Bassewitz */ +/* (C) 1998-2011, Ullrich von Bassewitz */ /* Roemerstrasse 52 */ /* D-70794 Filderstadt */ /* EMail: uz@cc65.org */ @@ -598,7 +598,7 @@ static void OneLine (void) InitListingLine (); } - if (Tok == TOK_COLON) { + if (CurTok.Tok == TOK_COLON) { /* An unnamed label */ ULabDef (); NextTok (); @@ -607,16 +607,16 @@ static void OneLine (void) /* 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); } } @@ -624,12 +624,12 @@ static void OneLine (void) * 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); @@ -637,10 +637,10 @@ static void OneLine (void) /* 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 (); @@ -652,7 +652,7 @@ static void OneLine (void) ConsumeSep (); return; - } else if (Tok == TOK_SET) { + } else if (CurTok.Tok == TOK_SET) { ExprNode* Expr; @@ -686,11 +686,11 @@ static void OneLine (void) * 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 (); } } @@ -702,35 +702,35 @@ static void OneLine (void) /* 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 { @@ -770,7 +770,7 @@ static void Assemble (void) NextTok (); /* Assemble lines until end of file */ - while (Tok != TOK_EOF) { + while (CurTok.Tok != TOK_EOF) { OneLine (); } } diff --git a/src/ca65/nexttok.c b/src/ca65/nexttok.c index 598f16104..cadef8a84 100644 --- a/src/ca65/nexttok.c +++ b/src/ca65/nexttok.c @@ -73,7 +73,7 @@ static int LookAtStrCon (void) * true. */ { - if (Tok != TOK_STRCON) { + if (CurTok.Tok != TOK_STRCON) { Error ("String constant expected"); SkipUntilSep (); return 0; @@ -106,10 +106,10 @@ static TokList* CollectTokens (unsigned Start, unsigned Count) /* 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; } @@ -160,13 +160,13 @@ static void FuncConcat (void) } /* 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 */ @@ -177,11 +177,11 @@ static void FuncConcat (void) /* 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 */ @@ -203,7 +203,7 @@ static void FuncIdent (void) /* Handle the .IDENT function */ { StrBuf Buf = STATIC_STRBUF_INITIALIZER; - token_t Id; + token_t Id; unsigned I; /* Skip it */ @@ -220,23 +220,23 @@ static void FuncIdent (void) /* 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; } @@ -248,13 +248,13 @@ static void FuncIdent (void) /* 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 */ @@ -442,7 +442,7 @@ static void FuncSPrintF (void) if (!LookAtStrCon ()) { return; } - SB_Copy (&Format, &SVal); + SB_Copy (&Format, &CurTok.SVal); NextTok (); /* 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 */ 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 (); @@ -596,11 +596,11 @@ static void FuncSPrintF (void) /* 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); } @@ -612,7 +612,7 @@ static void FuncSPrintF (void) } - + static void FuncString (void) /* Handle the .STRING function */ { @@ -625,9 +625,9 @@ static void FuncString (void) 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 */ @@ -638,11 +638,11 @@ static void FuncString (void) /* 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 */ @@ -661,7 +661,7 @@ void NextTok (void) if (RawMode == 0) { /* Execute token handling functions */ - switch (Tok) { + switch (CurTok.Tok) { case TOK_CONCAT: FuncConcat (); @@ -704,7 +704,7 @@ void NextTok (void) 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); @@ -720,7 +720,7 @@ void ConsumeSep (void) ExpectSep (); /* If we are at end of line, skip it */ - if (Tok == TOK_SEP) { + if (CurTok.Tok == TOK_SEP) { NextTok (); } } @@ -754,7 +754,7 @@ void ConsumeComma (void) void SkipUntilSep (void) /* Skip tokens until we reach a line separator or end of file */ { - while (!TokIsSep (Tok)) { + while (!TokIsSep (CurTok.Tok)) { NextTok (); } } @@ -766,7 +766,7 @@ void ExpectSep (void) * not skip the line separator. */ { - if (!TokIsSep (Tok)) { + if (!TokIsSep (CurTok.Tok)) { ErrorSkip ("Unexpected trailing garbage characters"); } } diff --git a/src/ca65/pseudo.c b/src/ca65/pseudo.c index a5f127eec..4b81e7c62 100644 --- a/src/ca65/pseudo.c +++ b/src/ca65/pseudo.c @@ -131,7 +131,7 @@ static unsigned char OptionalAddrSize (void) */ { unsigned AddrSize = ADDR_SIZE_DEFAULT; - if (Tok == TOK_COLON) { + if (CurTok.Tok == TOK_COLON) { NextTok (); AddrSize = ParseAddrSize (); if (!ValidAddrSizeForCPU (AddrSize)) { @@ -154,20 +154,20 @@ static void SetBoolOption (unsigned char* Flag) "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 { @@ -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 * 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; } @@ -214,13 +214,13 @@ static void ExportImport (void (*Func) (SymEntry*, unsigned char, unsigned), 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 (); @@ -235,7 +235,7 @@ static void ExportImport (void (*Func) (SymEntry*, unsigned char, unsigned), Func (Sym, AddrSize, Flags); /* More symbols? */ - if (Tok == TOK_COMMA) { + if (CurTok.Tok == TOK_COMMA) { NextTok (); } else { break; @@ -250,7 +250,7 @@ static long IntArg (long Min, long Max) * 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 { @@ -275,7 +275,7 @@ static void ConDes (const StrBuf* Name, unsigned Type) 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 (); @@ -337,7 +337,7 @@ static void DoAddr (void) /* Do a range check */ EmitWord (Expression ()); } - if (Tok != TOK_COMMA) { + if (CurTok.Tok != TOK_COMMA) { break; } else { NextTok (); @@ -362,7 +362,7 @@ static void DoAlign (void) } /* Optional value follows */ - if (Tok == TOK_COMMA) { + if (CurTok.Tok == TOK_COMMA) { NextTok (); Val = ConstExpression (); /* We need a byte value here */ @@ -390,16 +390,16 @@ static void DoASCIIZ (void) { 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; @@ -428,7 +428,7 @@ static void DoAssert (void) ConsumeComma (); /* Action follows */ - if (Tok != TOK_IDENT) { + if (CurTok.Tok != TOK_IDENT) { ErrorSkip ("Identifier expected"); return; } @@ -468,13 +468,13 @@ static void DoAssert (void) /* 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; } @@ -482,7 +482,7 @@ static void DoAssert (void) /* Translate the message into a string id. We can then skip the input * string. */ - Msg = GetStrBufId (&SVal); + Msg = GetStrBufId (&CurTok.SVal); NextTok (); } else { @@ -510,7 +510,7 @@ static void DoBankBytes (void) { while (1) { EmitByte (FuncBankByte ()); - if (Tok != TOK_COMMA) { + if (CurTok.Tok != TOK_COMMA) { break; } else { NextTok (); @@ -532,20 +532,20 @@ static void DoByte (void) /* 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; } @@ -615,16 +615,16 @@ static void DoConDes (void) 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])); @@ -664,11 +664,11 @@ static void DoConstructor (void) 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 */ @@ -700,7 +700,7 @@ static void DoDbg (void) /* We expect a subkey */ - if (Tok != TOK_IDENT) { + if (CurTok.Tok != TOK_IDENT) { ErrorSkip ("Identifier expected"); return; } @@ -727,7 +727,7 @@ static void DoDByt (void) { while (1) { EmitWord (GenSwapExpr (Expression ())); - if (Tok != TOK_COMMA) { + if (CurTok.Tok != TOK_COMMA) { break; } else { NextTok (); @@ -759,11 +759,11 @@ static void DoDestructor (void) 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 */ @@ -780,7 +780,7 @@ static void DoDWord (void) { while (1) { EmitDWord (Expression ()); - if (Tok != TOK_COMMA) { + if (CurTok.Tok != TOK_COMMA) { break; } else { NextTok (); @@ -828,10 +828,10 @@ static void DoEndScope (void) 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 (); } } @@ -872,7 +872,7 @@ static void DoFarAddr (void) { while (1) { EmitFarAddr (Expression ()); - if (Tok != TOK_COMMA) { + if (CurTok.Tok != TOK_COMMA) { break; } else { NextTok (); @@ -885,10 +885,10 @@ static void DoFarAddr (void) 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 (); } } @@ -902,7 +902,7 @@ static void DoFeature (void) while (1) { /* We expect an identifier */ - if (Tok != TOK_IDENT) { + if (CurTok.Tok != TOK_IDENT) { ErrorSkip ("Identifier expected"); return; } @@ -911,9 +911,9 @@ static void DoFeature (void) 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 */ @@ -921,7 +921,7 @@ static void DoFeature (void) } /* Allow more than one keyword */ - if (Tok == TOK_COMMA) { + if (CurTok.Tok == TOK_COMMA) { NextTok (); } else { break; @@ -937,7 +937,7 @@ static void DoFileOpt (void) 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 [] = { @@ -959,7 +959,7 @@ static void DoFileOpt (void) ConsumeComma (); /* We accept only string options for now */ - if (Tok != TOK_STRCON) { + if (CurTok.Tok != TOK_STRCON) { ErrorSkip ("String constant expected"); return; } @@ -969,17 +969,17 @@ static void DoFileOpt (void) 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: @@ -1003,13 +1003,13 @@ static void DoFileOpt (void) 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 (); @@ -1046,7 +1046,7 @@ static void DoHiBytes (void) { while (1) { EmitByte (FuncHiByte ()); - if (Tok != TOK_COMMA) { + if (CurTok.Tok != TOK_COMMA) { break; } else { NextTok (); @@ -1109,21 +1109,21 @@ static void DoIncBin (void) 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 (); } @@ -1228,11 +1228,11 @@ static void DoInclude (void) /* 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 (); } @@ -1247,11 +1247,11 @@ static void DoInterruptor (void) 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 */ @@ -1307,7 +1307,7 @@ static void DoLoBytes (void) { while (1) { EmitByte (FuncLoByte ()); - if (Tok != TOK_COMMA) { + if (CurTok.Tok != TOK_COMMA) { break; } else { NextTok (); @@ -1327,13 +1327,13 @@ static void DoListBytes (void) 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 (); } @@ -1347,14 +1347,14 @@ static void DoMacPack (void) 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"); @@ -1403,13 +1403,15 @@ static void DoOrg (void) 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 (); } @@ -1493,12 +1495,12 @@ static void DoProc (void) 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); @@ -1595,7 +1597,7 @@ static void DoRes (void) ErrorSkip ("Range error"); return; } - if (Tok == TOK_COMMA) { + if (CurTok.Tok == TOK_COMMA) { NextTok (); Val = ConstExpression (); /* We need a byte value here */ @@ -1632,10 +1634,10 @@ static void DoScope (void) 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 { @@ -1663,12 +1665,12 @@ static void DoSegment (void) 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 */ @@ -1692,14 +1694,14 @@ static void DoSetCPU (void) /* 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); @@ -1758,7 +1760,7 @@ static void DoTag (void) } /* Optional multiplicator may follow */ - if (Tok == TOK_COMMA) { + if (CurTok.Tok == TOK_COMMA) { long Multiplicator; NextTok (); Multiplicator = ConstExpression (); @@ -1788,10 +1790,10 @@ static void DoUnexpected (void) 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 (); } } @@ -1803,7 +1805,7 @@ static void DoWord (void) { while (1) { EmitWord (Expression ()); - if (Tok != TOK_COMMA) { + if (CurTok.Tok != TOK_COMMA) { break; } else { NextTok (); @@ -1990,7 +1992,7 @@ void HandlePseudo (void) 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)) { @@ -2004,7 +2006,7 @@ void HandlePseudo (void) /* Remember the instruction, then skip it if needed */ if ((D->Flags & ccKeepToken) == 0) { - SB_Copy (&Keyword, &SVal); + SB_Copy (&Keyword, &CurTok.SVal); NextTok (); } diff --git a/src/ca65/repeat.c b/src/ca65/repeat.c index 02c30eb83..d433d3136 100644 --- a/src/ca65/repeat.c +++ b/src/ca65/repeat.c @@ -6,7 +6,7 @@ /* */ /* */ /* */ -/* (C) 2000-2008, Ullrich von Bassewitz */ +/* (C) 2000-2011, Ullrich von Bassewitz */ /* Roemerstrasse 52 */ /* D-70794 Filderstadt */ /* EMail: uz@cc65.org */ @@ -63,10 +63,10 @@ static TokList* CollectRepeatTokens (void) /* 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; @@ -76,9 +76,9 @@ static TokList* CollectRepeatTokens (void) 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; } @@ -100,10 +100,12 @@ static void RepeatTokenCheck (TokList* L) * 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; } } @@ -124,18 +126,18 @@ void ParseRepeat (void) /* 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 (); } } diff --git a/src/ca65/scanner.c b/src/ca65/scanner.c index 1444cacbe..59fecbd1c 100644 --- a/src/ca65/scanner.c +++ b/src/ca65/scanner.c @@ -70,14 +70,8 @@ -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; @@ -305,7 +299,7 @@ static void UseCharSource (CharSource* S) /* 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 */ @@ -318,7 +312,7 @@ static void UseCharSource (CharSource* S) /* Setup the next token so it will be skipped on the next call to * NextRawTok(). */ - Tok = TOK_SEP; + CurTok.Tok = TOK_SEP; } @@ -332,7 +326,7 @@ static void DoneCharSource (void) Source->Func->Done (Source); /* Restore the old token */ - Tok = Source->Tok; + CurTok.Tok = Source->Tok; C = Source->C; /* Remember the last stacked input source */ @@ -356,7 +350,7 @@ static void DoneCharSource (void) static void IFMarkStart (CharSource* S) /* 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) /* Make SVal lower case */ { - SB_ToLower (&SVal); + SB_ToLower (&CurTok.SVal); } @@ -665,7 +659,7 @@ void LocaseSVal (void) void UpcaseSVal (void) /* 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, * return TOK_NONE if not found. */ @@ -687,7 +681,7 @@ static unsigned char FindDotKeyword (void) 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 */ @@ -697,7 +691,7 @@ static unsigned char FindDotKeyword (void) /* 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 { @@ -716,10 +710,10 @@ static void ReadIdent (void) { /* 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) { @@ -746,7 +740,7 @@ static void ReadStringConst (int StringTerm) } /* Append the char to the string */ - SB_AppendChar (&SVal, C); + SB_AppendChar (&CurTok.SVal, C); /* Skip the character */ NextChar (); @@ -756,7 +750,7 @@ static void ReadStringConst (int StringTerm) NextChar (); /* 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 (ForcedEnd) { - Tok = TOK_EOF; + CurTok.Tok = TOK_EOF; return; } @@ -807,7 +801,7 @@ Restart: Again: /* Skip whitespace, remember if we had some */ - if ((WS = IsBlank (C)) != 0) { + if ((CurTok.WS = IsBlank (C)) != 0) { do { NextChar (); } while (IsBlank (C)); @@ -817,7 +811,7 @@ Again: Source->Func->MarkStart (Source); /* Clear the string attribute */ - SB_Clear (&SVal); + SB_Clear (&CurTok.SVal); /* Hex number or PC symbol? */ if (C == '$') { @@ -826,7 +820,7 @@ Again: /* 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"); @@ -834,18 +828,18 @@ Again: } /* 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; } @@ -859,18 +853,18 @@ Again: } /* 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; } @@ -915,24 +909,24 @@ Again: } /* 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; } @@ -946,36 +940,36 @@ Again: 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; } } @@ -987,7 +981,7 @@ Again: */ if (CPU == CPU_SWEET16 && C == '@') { NextChar (); - Tok = TOK_AT; + CurTok.Tok = TOK_AT; return; } @@ -998,13 +992,13 @@ Again: 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; } @@ -1018,45 +1012,45 @@ Again: /* 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; @@ -1065,22 +1059,23 @@ Again: 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; } @@ -1091,21 +1086,21 @@ CharAgain: 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 != '*') { @@ -1124,21 +1119,21 @@ CharAgain: 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; @@ -1146,9 +1141,9 @@ CharAgain: NextChar (); if (C == '|') { NextChar (); - Tok = TOK_BOOLOR; + CurTok.Tok = TOK_BOOLOR; } else { - Tok = TOK_OR; + CurTok.Tok = TOK_OR; } return; @@ -1158,41 +1153,41 @@ CharAgain: 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 ';': @@ -1204,81 +1199,81 @@ CharAgain: 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 '\'': @@ -1288,11 +1283,11 @@ CharAgain: */ 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 */ @@ -1301,8 +1296,8 @@ CharAgain: Error ("Illegal character constant"); goto CharAgain; } - IVal = C; - Tok = TOK_CHARCON; + CurTok.IVal = C; + CurTok.Tok = TOK_CHARCON; NextChar (); if (C != '\'') { if (!MissingCharTerm) { @@ -1316,7 +1311,7 @@ CharAgain: case '\"': ReadStringConst ('\"'); - Tok = TOK_STRCON; + CurTok.Tok = TOK_STRCON; return; case '\\': @@ -1334,7 +1329,7 @@ CharAgain: case '\n': NextChar (); - Tok = TOK_SEP; + CurTok.Tok = TOK_SEP; return; case EOF: @@ -1344,7 +1339,7 @@ CharAgain: DoneCharSource (); goto Again; } else { - Tok = TOK_EOF; + CurTok.Tok = TOK_EOF; } return; } @@ -1369,7 +1364,7 @@ int GetSubKey (const char** Keys, unsigned Count) 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) { @@ -1378,7 +1373,7 @@ int GetSubKey (const char** Keys, unsigned Count) /* 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; } @@ -1399,13 +1394,13 @@ unsigned char ParseAddrSize (void) 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; @@ -1434,3 +1429,4 @@ void DoneScanner (void) + diff --git a/src/ca65/scanner.h b/src/ca65/scanner.h index be081dce7..0fad248d1 100644 --- a/src/ca65/scanner.h +++ b/src/ca65/scanner.h @@ -38,10 +38,6 @@ -/* common */ -#include "filepos.h" -#include "strbuf.h" - /* ca65 */ #include "token.h" @@ -54,13 +50,8 @@ /* 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 */ diff --git a/src/ca65/struct.c b/src/ca65/struct.c index 869be9947..56b9856f4 100644 --- a/src/ca65/struct.c +++ b/src/ca65/struct.c @@ -6,10 +6,10 @@ /* */ /* */ /* */ -/* (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 */ @@ -74,7 +74,7 @@ static long Member (long AllocSize) long Multiplicator; /* A multiplicator may follow */ - if (Tok != TOK_SEP) { + if (CurTok.Tok != TOK_SEP) { Multiplicator = ConstExpression (); if (Multiplicator <= 0) { 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 * 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; @@ -116,23 +116,25 @@ static long DoStructInternal (long Offs, unsigned Type) 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); @@ -143,7 +145,7 @@ static long DoStructInternal (long Offs, unsigned Type) /* Read storage allocators */ MemberSize = 0; /* In case of errors, use zero */ - switch (Tok) { + switch (CurTok.Tok) { case TOK_BYTE: NextTok (); @@ -169,7 +171,7 @@ static long DoStructInternal (long Offs, unsigned Type) case TOK_RES: NextTok (); - if (Tok == TOK_SEP) { + if (CurTok.Tok == TOK_SEP) { ErrorSkip ("Size is missing"); } else { MemberSize = Member (1); diff --git a/src/ca65/symbol.c b/src/ca65/symbol.c index 3be3b9b5c..5f5abe560 100644 --- a/src/ca65/symbol.c +++ b/src/ca65/symbol.c @@ -6,7 +6,7 @@ /* */ /* */ /* */ -/* (C) 1998-2010, Ullrich von Bassewitz */ +/* (C) 1998-2011, Ullrich von Bassewitz */ /* Roemerstrasse 52 */ /* D-70794 Filderstadt */ /* EMail: uz@cc65.org */ @@ -69,26 +69,26 @@ SymTable* ParseScopedIdent (StrBuf* Name, StrBuf* FullName) 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. */ @@ -116,19 +116,19 @@ SymTable* ParseScopedIdent (StrBuf* Name, StrBuf* FullName) 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; } @@ -253,8 +253,8 @@ SymEntry* ParseAnySymName (int AllocNew) 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); diff --git a/src/ca65/symentry.c b/src/ca65/symentry.c index 3df040d28..9844fc44e 100644 --- a/src/ca65/symentry.c +++ b/src/ca65/symentry.c @@ -6,7 +6,7 @@ /* */ /* */ /* */ -/* (C) 1998-2010, Ullrich von Bassewitz */ +/* (C) 1998-2011, Ullrich von Bassewitz */ /* Roemerstrasse 52 */ /* D-70794 Filderstadt */ /* EMail: uz@cc65.org */ @@ -86,7 +86,7 @@ SymEntry* NewSymEntry (const StrBuf* Name, unsigned Flags) 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; } @@ -578,7 +578,7 @@ void SymGuessedAddrSize (SymEntry* Sym, unsigned char AddrSize) } /* Ok, remember the file position */ - Sym->GuessedUse[AddrSize-1] = xdup (&CurPos, sizeof (CurPos)); + Sym->GuessedUse[AddrSize-1] = xdup (&CurTok.Pos, sizeof (CurTok.Pos)); } diff --git a/src/ca65/token.h b/src/ca65/token.h index b334c5bbf..ea4da599b 100644 --- a/src/ca65/token.h +++ b/src/ca65/token.h @@ -39,7 +39,9 @@ /* common */ +#include "filepos.h" #include "inline.h" +#include "strbuf.h" @@ -49,7 +51,7 @@ -/* Tokens */ +/* Tokens */ typedef enum token_t { TOK_NONE, /* Start value, invalid */ TOK_EOF, /* End of input file */ @@ -71,7 +73,7 @@ typedef enum token_t { TOK_ULABEL, /* :++ or :-- */ TOK_EQ, /* = */ - TOK_NE, /* <> */ + TOK_NE, /* <> */ TOK_LT, /* < */ TOK_GT, /* > */ TOK_LE, /* <= */ @@ -83,12 +85,12 @@ typedef enum token_t { 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, /* & */ @@ -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 */ /*****************************************************************************/ diff --git a/src/ca65/toklist.c b/src/ca65/toklist.c index 343e64e40..d5ec5ee6c 100644 --- a/src/ca65/toklist.c +++ b/src/ca65/toklist.c @@ -64,11 +64,11 @@ TokNode* NewTokNode (void) /* 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; @@ -89,11 +89,11 @@ void TokSet (TokNode* 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); } @@ -101,18 +101,18 @@ void TokSet (TokNode* T) 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; } } @@ -182,7 +182,7 @@ enum token_t GetTokListTerm (enum token_t Term) * a closing brace, otherwise return Term. */ { - if (Tok == TOK_LCURLY) { + if (CurTok.Tok == TOK_LCURLY) { NextTok (); return TOK_RCURLY; } else { @@ -278,3 +278,4 @@ void PushTokList (TokList* List, const char* Desc) + diff --git a/src/ca65/ulabel.c b/src/ca65/ulabel.c index 4a425e7b3..c02d9fb57 100644 --- a/src/ca65/ulabel.c +++ b/src/ca65/ulabel.c @@ -6,10 +6,10 @@ /* */ /* */ /* */ -/* (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 */ @@ -82,7 +82,7 @@ static ULabel* NewULabel (ExprNode* Val) ULabel* L = xmalloc (sizeof (ULabel)); /* Initialize the fields */ - L->Pos = CurPos; + L->Pos = CurTok.Pos; L->Val = Val; L->Ref = 0; @@ -160,7 +160,7 @@ void ULabDef (void) 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 ()); -- 2.39.2