From f0a0095c258b5959787364416615e06d587c6673 Mon Sep 17 00:00:00 2001 From: uz Date: Sat, 29 Jan 2011 20:24:44 +0000 Subject: [PATCH] Create separate line infos for macros and .repeat statements and other token lists. These are also output as diagnostic in case of an error. git-svn-id: svn://svn.cc65.org/cc65/trunk@4951 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/ca65/macro.c | 32 +++++++++++++++++++------------- src/ca65/toklist.c | 12 +++++++++--- src/ca65/toklist.h | 8 +++++--- 3 files changed, 33 insertions(+), 19 deletions(-) diff --git a/src/ca65/macro.c b/src/ca65/macro.c index bca119d99..b98925bc8 100644 --- a/src/ca65/macro.c +++ b/src/ca65/macro.c @@ -48,6 +48,7 @@ #include "global.h" #include "instr.h" #include "istack.h" +#include "lineinfo.h" #include "nexttok.h" #include "pseudo.h" #include "toklist.h" @@ -126,15 +127,16 @@ static Macro* MacroRoot = 0; /* List of all macros */ /* Structs that holds data for a macro expansion */ typedef struct MacExp MacExp; struct MacExp { - MacExp* Next; /* Pointer to next expansion */ - Macro* M; /* Which macro do we expand? */ - unsigned IfSP; /* .IF stack pointer at start of expansion */ + MacExp* Next; /* Pointer to next expansion */ + Macro* M; /* Which macro do we expand? */ + unsigned IfSP; /* .IF stack pointer at start of expansion */ TokNode* Exp; /* Pointer to current token */ - TokNode* Final; /* Pointer to final token */ + TokNode* Final; /* Pointer to final token */ unsigned LocalStart; /* Start of counter for local symbol names */ - unsigned ParamCount; /* Number of actual parameters */ - TokNode** Params; /* List of actual parameters */ - TokNode* ParamExp; /* Node for expanding parameters */ + unsigned ParamCount; /* Number of actual parameters */ + TokNode** Params; /* List of actual parameters */ + TokNode* ParamExp; /* Node for expanding parameters */ + unsigned LISlot; /* Slot for additional line infos */ }; /* Number of active macro expansions */ @@ -254,17 +256,18 @@ static MacExp* NewMacExp (Macro* M) /* Initialize the data */ E->M = M; - E->IfSP = GetIfStack (); + E->IfSP = GetIfStack (); E->Exp = M->TokRoot; - E->Final = 0; + E->Final = 0; E->LocalStart = LocalName; LocalName += M->LocalCount; E->ParamCount = 0; E->Params = xmalloc (M->ParamCount * sizeof (TokNode*)); E->ParamExp = 0; for (I = 0; I < M->ParamCount; ++I) { - E->Params [I] = 0; + E->Params[I] = 0; } + E->LISlot = AllocLineInfoSlot (LI_TYPE_MACRO | MacExpansions); /* One macro expansion more */ ++MacExpansions; @@ -295,6 +298,9 @@ static void FreeMacExp (MacExp* E) } xfree (E->Params); + /* Free the additional line info slot */ + FreeLineInfoSlot (E->LISlot); + /* Free the final token if we have one */ if (E->Final) { FreeTokNode (E->Final); @@ -562,7 +568,7 @@ static int MacExpand (void* Data) if (Mac->ParamExp) { /* Ok, use token from parameter list */ - TokSet (Mac->ParamExp); + TokSet (Mac->ParamExp, Mac->LISlot); /* Set pointer to next token */ Mac->ParamExp = Mac->ParamExp->Next; @@ -578,7 +584,7 @@ static int MacExpand (void* Data) if (Mac->Exp) { /* Use next macro token */ - TokSet (Mac->Exp); + TokSet (Mac->Exp, Mac->LISlot); /* Set pointer to next token */ Mac->Exp = Mac->Exp->Next; @@ -642,7 +648,7 @@ static int MacExpand (void* Data) if (Mac->Final) { /* Set the final token and remove it */ - TokSet (Mac->Final); + TokSet (Mac->Final, Mac->LISlot); FreeTokNode (Mac->Final); Mac->Final = 0; diff --git a/src/ca65/toklist.c b/src/ca65/toklist.c index 12e125e67..44fbd7742 100644 --- a/src/ca65/toklist.c +++ b/src/ca65/toklist.c @@ -42,6 +42,7 @@ /* ca65 */ #include "error.h" #include "istack.h" +#include "lineinfo.h" #include "nexttok.h" #include "scanner.h" #include "toklist.h" @@ -81,12 +82,17 @@ void FreeTokNode (TokNode* N) -void TokSet (TokNode* N) -/* Set the scanner token from the given token node */ +void TokSet (TokNode* N, unsigned LineInfoSlot) +/* Set the scanner token from the given token node. The given line info slot + * is used to store the position of the token fed into the scanner. + */ { /* Set the values */ CopyToken (&CurTok, &N->T); SB_Terminate (&CurTok.SVal); + + /* Set the position */ + GenLineInfo (LineInfoSlot, &CurTok.Pos); } @@ -218,7 +224,7 @@ static int ReplayTokList (void* List) CHECK (L->Last != 0); /* Set the next token from the list */ - TokSet (L->Last); + TokSet (L->Last, LI_SLOT_ASM); /* If a check function is defined, call it, so it may look at the token * just set and changed it as apropriate. diff --git a/src/ca65/toklist.h b/src/ca65/toklist.h index b31df38af..18a9c42f9 100644 --- a/src/ca65/toklist.h +++ b/src/ca65/toklist.h @@ -49,7 +49,7 @@ /*****************************************************************************/ /* Data */ /*****************************************************************************/ - + /* Struct holding a token */ @@ -95,8 +95,10 @@ TokNode* NewTokNode (void); void FreeTokNode (TokNode* N); /* Free the given token node */ -void TokSet (TokNode* N); -/* Set the scanner token from the given token node */ +void TokSet (TokNode* N, unsigned LineInfoSlot); +/* Set the scanner token from the given token node. The given line info slot + * is used to store the position of the token fed into the scanner. + */ enum TC TokCmp (const TokNode* N); /* Compare the token given as parameter against the current token */ -- 2.39.5