mirror of
https://github.com/cc65/cc65.git
synced 2025-01-11 11:30:13 +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:
parent
1072edb0d8
commit
f0a0095c25
@ -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;
|
||||
|
||||
|
@ -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.
|
||||
|
@ -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 */
|
||||
|
Loading…
x
Reference in New Issue
Block a user