From 4a418658985b52b8dd1033bc5aa2dcae18a65a17 Mon Sep 17 00:00:00 2001 From: uz Date: Sun, 4 Nov 2012 12:57:34 +0000 Subject: [PATCH] Fixed a problem in line info generation: Recorded token lists emitted the tokens using the standard ASM line info, overwriting the existing one from the real source line. Since this info was lost, and couldn't be recovered, the original source location was omitted in error messages. git-svn-id: svn://svn.cc65.org/cc65/trunk@5905 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/ca65/error.c | 4 +++ src/ca65/lineinfo.c | 29 ++++++++++++++++++ src/ca65/toklist.c | 75 ++++++++++++++++++++++++++------------------- src/ca65/toklist.h | 9 +++--- 4 files changed, 80 insertions(+), 37 deletions(-) diff --git a/src/ca65/error.c b/src/ca65/error.c index 45cdfe1cd..4edb1e8a3 100644 --- a/src/ca65/error.c +++ b/src/ca65/error.c @@ -139,6 +139,10 @@ static void AddNotifications (const Collection* LineInfos) const char* Msg; switch (GetLineInfoType (LI)) { + case LI_TYPE_ASM: + Msg = "Expanded from here"; + break; + case LI_TYPE_EXT: Msg = "Assembler code generated from this line"; break; diff --git a/src/ca65/lineinfo.c b/src/ca65/lineinfo.c index e17aa251d..25ef376a9 100644 --- a/src/ca65/lineinfo.c +++ b/src/ca65/lineinfo.c @@ -33,6 +33,7 @@ +#include #include /* common */ @@ -41,6 +42,7 @@ #include "xmalloc.h" /* ca65 */ +#include "filetab.h" #include "global.h" #include "lineinfo.h" #include "objfile.h" @@ -234,6 +236,33 @@ static int CheckLineInfo (void* Entry, void* Data attribute ((unused))) +#if 0 +static void DumpLineInfos (const char* Title, const Collection* C) +/* Dump line infos from the given collection */ +{ + unsigned I; + fprintf (stderr, "%s:\n", Title); + for (I = 0; I < CollCount (C); ++I) { + const LineInfo* LI = CollConstAt (C, I); + const char* Type; + switch (GetLineInfoType (LI)) { + case LI_TYPE_ASM: Type = "ASM"; break; + case LI_TYPE_EXT: Type = "EXT"; break; + case LI_TYPE_MACRO: Type = "MACRO"; break; + case LI_TYPE_MACPARAM: Type = "MACPARAM"; break; + default: Type = "unknown"; break; + } + fprintf (stderr, + "%2u: %-8s %2u %-16s %u/%u\n", + I, Type, LI->Key.Pos.Name, + SB_GetConstBuf (GetFileName (LI->Key.Pos.Name)), + LI->Key.Pos.Line, LI->Key.Pos.Col); + } +} +#endif + + + void InitLineInfo (void) /* Initialize the line infos */ { diff --git a/src/ca65/toklist.c b/src/ca65/toklist.c index e79f1808a..9c12422ec 100644 --- a/src/ca65/toklist.c +++ b/src/ca65/toklist.c @@ -6,7 +6,7 @@ /* */ /* */ /* */ -/* (C) 1998-2011, Ullrich von Bassewitz */ +/* (C) 1998-2012, Ullrich von Bassewitz */ /* Roemerstrasse 52 */ /* D-70794 Filderstadt */ /* EMail: uz@cc65.org */ @@ -49,6 +49,17 @@ +/*****************************************************************************/ +/* Data */ +/*****************************************************************************/ + + + +/* Number of currently pushed token lists */ +static unsigned PushCounter = 0; + + + /*****************************************************************************/ /* Code */ /*****************************************************************************/ @@ -117,9 +128,12 @@ enum TC TokCmp (const TokNode* N) -void InitTokList (TokList* T) -/* Initialize a token list structure for later use */ +TokList* NewTokList (void) +/* Create a new, empty token list */ { + /* Allocate memory for the list structure */ + TokList* T = xmalloc (sizeof (TokList)); + /* Initialize the fields */ T->Next = 0; T->Root = 0; @@ -129,18 +143,7 @@ void InitTokList (TokList* T) T->Count = 0; T->Check = 0; T->Data = 0; -} - - - -TokList* NewTokList (void) -/* Create a new, empty token list */ -{ - /* Allocate memory for the list structure */ - TokList* T = xmalloc (sizeof (TokList)); - - /* Initialize the fields */ - InitTokList (T); + T->LI = 0; /* Return the new list */ return T; @@ -159,6 +162,11 @@ void FreeTokList (TokList* List) FreeTokNode (Tmp); } + /* Free associated line info */ + if (List->LI) { + EndLine (List->LI); + } + /* If we have associated data, free it */ if (List->Data) { xfree (List->Data); @@ -215,14 +223,30 @@ static int ReplayTokList (void* List) /* Cast the generic pointer to an actual list */ TokList* L = List; - /* Last may never be a NULL pointer, otherwise there's a bug in the code */ - CHECK (L->Last != 0); + /* If there are no more tokens, decrement the repeat counter. If it goes + * zero, delete the list and remove the function from the stack. + */ + if (L->Last == 0) { + if (++L->RepCount >= L->RepMax) { + /* Done with this list */ + FreeTokList (L); + --PushCounter; + PopInput (); + return 0; + } else { + /* Replay one more time */ + L->Last = L->Root; + } + } /* Set the next token from the list */ TokSet (L->Last); /* Set the line info for the new token */ - NewAsmLine (); + if (L->LI) { + EndLine (L->LI); + } + L->LI = StartLine (&CurTok.Pos, LI_TYPE_ASM, PushCounter); /* If a check function is defined, call it, so it may look at the token * just set and changed it as apropriate. @@ -234,20 +258,6 @@ static int ReplayTokList (void* List) /* Set the pointer to the next token */ L->Last = L->Last->Next; - /* If this was the last token, decrement the repeat counter. If it goes - * zero, delete the list and remove the function from the stack. - */ - if (L->Last == 0) { - if (++L->RepCount >= L->RepMax) { - /* Done with this list */ - FreeTokList (L); - PopInput (); - } else { - /* Replay one more time */ - L->Last = L->Root; - } - } - /* We have a token */ return 1; } @@ -270,6 +280,7 @@ void PushTokList (TokList* List, const char* Desc) List->Last = List->Root; /* Insert the list specifying our input function */ + ++PushCounter; PushInput (ReplayTokList, List, Desc); } diff --git a/src/ca65/toklist.h b/src/ca65/toklist.h index b449ad9a0..8b4f6449b 100644 --- a/src/ca65/toklist.h +++ b/src/ca65/toklist.h @@ -6,7 +6,7 @@ /* */ /* */ /* */ -/* (C) 2000-2011, Ullrich von Bassewitz */ +/* (C) 2000-2012, Ullrich von Bassewitz */ /* Roemerstrasse 52 */ /* D-70794 Filderstadt */ /* EMail: uz@cc65.org */ @@ -42,12 +42,13 @@ #include "strbuf.h" /* ca65 */ +#include "lineinfo.h" #include "scanner.h" /*****************************************************************************/ -/* Data */ +/* Data */ /*****************************************************************************/ @@ -70,6 +71,7 @@ struct TokList { unsigned Count; /* Token count */ void (*Check)(TokList*); /* Token check function */ void* Data; /* Additional data for check */ + LineInfo* LI; /* Line info for replay */ }; @@ -101,9 +103,6 @@ void TokSet (TokNode* N); enum TC TokCmp (const TokNode* N); /* Compare the token given as parameter against the current token */ -void InitTokList (TokList* T); -/* Initialize a token list structure for later use */ - TokList* NewTokList (void); /* Create a new, empty token list */ -- 2.39.5