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
3 changed files with 33 additions and 19 deletions
|
@ -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"
|
||||||
|
@ -126,15 +127,16 @@ static Macro* MacroRoot = 0; /* List of all macros */
|
||||||
/* Structs that holds data for a macro expansion */
|
/* Structs that holds data for a macro expansion */
|
||||||
typedef struct MacExp MacExp;
|
typedef struct MacExp MacExp;
|
||||||
struct MacExp {
|
struct MacExp {
|
||||||
MacExp* Next; /* Pointer to next expansion */
|
MacExp* Next; /* Pointer to next expansion */
|
||||||
Macro* M; /* Which macro do we expand? */
|
Macro* M; /* Which macro do we expand? */
|
||||||
unsigned IfSP; /* .IF stack pointer at start of expansion */
|
unsigned IfSP; /* .IF stack pointer at start of expansion */
|
||||||
TokNode* Exp; /* Pointer to current token */
|
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 LocalStart; /* Start of counter for local symbol names */
|
||||||
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 */
|
||||||
|
@ -254,17 +256,18 @@ static MacExp* NewMacExp (Macro* M)
|
||||||
|
|
||||||
/* Initialize the data */
|
/* Initialize the data */
|
||||||
E->M = M;
|
E->M = M;
|
||||||
E->IfSP = GetIfStack ();
|
E->IfSP = GetIfStack ();
|
||||||
E->Exp = M->TokRoot;
|
E->Exp = M->TokRoot;
|
||||||
E->Final = 0;
|
E->Final = 0;
|
||||||
E->LocalStart = LocalName;
|
E->LocalStart = LocalName;
|
||||||
LocalName += M->LocalCount;
|
LocalName += M->LocalCount;
|
||||||
E->ParamCount = 0;
|
E->ParamCount = 0;
|
||||||
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;
|
||||||
|
|
||||||
|
|
|
@ -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.
|
||||||
|
|
|
@ -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 */
|
||||||
|
|
Loading…
Add table
Reference in a new issue