1
0
mirror of https://github.com/cc65/cc65.git synced 2024-07-23 18:29:47 +00:00

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
This commit is contained in:
uz 2011-01-29 20:24:44 +00:00
parent 1072edb0d8
commit f0a0095c25
3 changed files with 33 additions and 19 deletions

View File

@ -48,6 +48,7 @@
#include "global.h" #include "global.h"
#include "instr.h" #include "instr.h"
#include "istack.h" #include "istack.h"
#include "lineinfo.h"
#include "nexttok.h" #include "nexttok.h"
#include "pseudo.h" #include "pseudo.h"
#include "toklist.h" #include "toklist.h"
@ -135,6 +136,7 @@ struct MacExp {
unsigned ParamCount; /* Number of actual parameters */ unsigned ParamCount; /* Number of actual parameters */
TokNode** Params; /* List of actual parameters */ TokNode** Params; /* List of actual parameters */
TokNode* ParamExp; /* Node for expanding parameters */ TokNode* ParamExp; /* Node for expanding parameters */
unsigned LISlot; /* Slot for additional line infos */
}; };
/* Number of active macro expansions */ /* Number of active macro expansions */
@ -263,8 +265,9 @@ static MacExp* NewMacExp (Macro* M)
E->Params = xmalloc (M->ParamCount * sizeof (TokNode*)); E->Params = xmalloc (M->ParamCount * sizeof (TokNode*));
E->ParamExp = 0; E->ParamExp = 0;
for (I = 0; I < M->ParamCount; ++I) { 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 */ /* One macro expansion more */
++MacExpansions; ++MacExpansions;
@ -295,6 +298,9 @@ static void FreeMacExp (MacExp* E)
} }
xfree (E->Params); xfree (E->Params);
/* Free the additional line info slot */
FreeLineInfoSlot (E->LISlot);
/* Free the final token if we have one */ /* Free the final token if we have one */
if (E->Final) { if (E->Final) {
FreeTokNode (E->Final); FreeTokNode (E->Final);
@ -562,7 +568,7 @@ static int MacExpand (void* Data)
if (Mac->ParamExp) { if (Mac->ParamExp) {
/* Ok, use token from parameter list */ /* Ok, use token from parameter list */
TokSet (Mac->ParamExp); TokSet (Mac->ParamExp, Mac->LISlot);
/* Set pointer to next token */ /* Set pointer to next token */
Mac->ParamExp = Mac->ParamExp->Next; Mac->ParamExp = Mac->ParamExp->Next;
@ -578,7 +584,7 @@ static int MacExpand (void* Data)
if (Mac->Exp) { if (Mac->Exp) {
/* Use next macro token */ /* Use next macro token */
TokSet (Mac->Exp); TokSet (Mac->Exp, Mac->LISlot);
/* Set pointer to next token */ /* Set pointer to next token */
Mac->Exp = Mac->Exp->Next; Mac->Exp = Mac->Exp->Next;
@ -642,7 +648,7 @@ static int MacExpand (void* Data)
if (Mac->Final) { if (Mac->Final) {
/* Set the final token and remove it */ /* Set the final token and remove it */
TokSet (Mac->Final); TokSet (Mac->Final, Mac->LISlot);
FreeTokNode (Mac->Final); FreeTokNode (Mac->Final);
Mac->Final = 0; Mac->Final = 0;

View File

@ -42,6 +42,7 @@
/* ca65 */ /* ca65 */
#include "error.h" #include "error.h"
#include "istack.h" #include "istack.h"
#include "lineinfo.h"
#include "nexttok.h" #include "nexttok.h"
#include "scanner.h" #include "scanner.h"
#include "toklist.h" #include "toklist.h"
@ -81,12 +82,17 @@ void FreeTokNode (TokNode* N)
void TokSet (TokNode* N) void TokSet (TokNode* N, unsigned LineInfoSlot)
/* Set the scanner token from the given token node */ /* 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 */ /* Set the values */
CopyToken (&CurTok, &N->T); CopyToken (&CurTok, &N->T);
SB_Terminate (&CurTok.SVal); SB_Terminate (&CurTok.SVal);
/* Set the position */
GenLineInfo (LineInfoSlot, &CurTok.Pos);
} }
@ -218,7 +224,7 @@ static int ReplayTokList (void* List)
CHECK (L->Last != 0); CHECK (L->Last != 0);
/* Set the next token from the list */ /* 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 /* If a check function is defined, call it, so it may look at the token
* just set and changed it as apropriate. * just set and changed it as apropriate.

View File

@ -95,8 +95,10 @@ TokNode* NewTokNode (void);
void FreeTokNode (TokNode* N); void FreeTokNode (TokNode* N);
/* Free the given token node */ /* Free the given token node */
void TokSet (TokNode* N); void TokSet (TokNode* N, unsigned LineInfoSlot);
/* Set the scanner token from the given token node */ /* 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); enum TC TokCmp (const TokNode* N);
/* Compare the token given as parameter against the current token */ /* Compare the token given as parameter against the current token */