mirror of
https://github.com/cc65/cc65.git
synced 2025-04-12 00:37:12 +00:00
Mark tokens with the file position from where they're read. Restore this
position for tokens read from a token list. This means that line info does now show the actual point of definition. This is an improvement but needs to be refined. git-svn-id: svn://svn.cc65.org/cc65/trunk@4911 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
ddb7296b6c
commit
3b59a8ca6f
@ -133,7 +133,7 @@ void DbgInfoLine (void)
|
||||
}
|
||||
|
||||
/* Remember the line info */
|
||||
GenLineInfo (Index, LineNum);
|
||||
GenLineInfo (Index, LineNum, 0);
|
||||
}
|
||||
|
||||
|
||||
@ -147,4 +147,4 @@ void DbgInfoSym (void)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -6,10 +6,10 @@
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* (C) 2001 Ullrich von Bassewitz */
|
||||
/* Wacholderweg 14 */
|
||||
/* D-70597 Stuttgart */
|
||||
/* EMail: uz@cc65.org */
|
||||
/* (C) 2001-2011, Ullrich von Bassewitz */
|
||||
/* Roemerstrasse 52 */
|
||||
/* 70794 Filderstadt */
|
||||
/* EMail: uz@cc65.org */
|
||||
/* */
|
||||
/* */
|
||||
/* This software is provided 'as-is', without any expressed or implied */
|
||||
@ -74,7 +74,7 @@ LineInfo* CurLineInfo = 0;
|
||||
|
||||
|
||||
|
||||
static LineInfo* NewLineInfo (unsigned FileIndex, unsigned long LineNum)
|
||||
static LineInfo* NewLineInfo (unsigned File, unsigned long Line, unsigned Col)
|
||||
/* Create and return a new line info. Usage will be zero. */
|
||||
{
|
||||
/* Allocate memory */
|
||||
@ -83,9 +83,9 @@ static LineInfo* NewLineInfo (unsigned FileIndex, unsigned long LineNum)
|
||||
/* Initialize the fields */
|
||||
LI->Usage = 0;
|
||||
LI->Index = 0; /* Currently invalid */
|
||||
LI->Pos.Line = LineNum;
|
||||
LI->Pos.Col = 0;
|
||||
LI->Pos.Name = FileIndex;
|
||||
LI->Pos.Line = Line;
|
||||
LI->Pos.Col = Col;
|
||||
LI->Pos.Name = File;
|
||||
|
||||
/* Insert this structure into the collection */
|
||||
CollAppend (&LineInfoColl, LI);
|
||||
@ -112,11 +112,11 @@ LineInfo* UseLineInfo (LineInfo* LI)
|
||||
|
||||
|
||||
|
||||
void GenLineInfo (unsigned FileIndex, unsigned long LineNum)
|
||||
void GenLineInfo (unsigned FileIndex, unsigned long LineNum, unsigned ColNum)
|
||||
/* Generate a new line info */
|
||||
{
|
||||
/* Create a new line info and make it current */
|
||||
CurLineInfo = NewLineInfo (FileIndex, LineNum);
|
||||
CurLineInfo = NewLineInfo (FileIndex, LineNum, ColNum);
|
||||
}
|
||||
|
||||
|
||||
@ -129,7 +129,7 @@ void ClearLineInfo (void)
|
||||
|
||||
|
||||
|
||||
static int CmpLineInfo (void* Data attribute ((unused)),
|
||||
static int CmpLineInfo (void* Data attribute ((unused)),
|
||||
const void* LI1_, const void* LI2_)
|
||||
/* Compare function for the sort */
|
||||
{
|
||||
@ -162,7 +162,7 @@ static int CmpLineInfo (void* Data attribute ((unused)),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void MakeLineInfoIndex (void)
|
||||
/* Sort the line infos and drop all unreferenced ones */
|
||||
|
@ -6,10 +6,10 @@
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* (C) 2001 Ullrich von Bassewitz */
|
||||
/* Wacholderweg 14 */
|
||||
/* D-70597 Stuttgart */
|
||||
/* EMail: uz@cc65.org */
|
||||
/* (C) 2001-2011, Ullrich von Bassewitz */
|
||||
/* Roemerstrasse 52 */
|
||||
/* 70794 Filderstadt */
|
||||
/* EMail: uz@cc65.org */
|
||||
/* */
|
||||
/* */
|
||||
/* This software is provided 'as-is', without any expressed or implied */
|
||||
@ -93,7 +93,7 @@ LineInfo* UseLineInfo (LineInfo* LI);
|
||||
* function will gracefully accept NULL pointers and do nothing in this case.
|
||||
*/
|
||||
|
||||
void GenLineInfo (unsigned FileIndex, unsigned long LineNum);
|
||||
void GenLineInfo (unsigned FileIndex, unsigned long LineNum, unsigned ColNum);
|
||||
/* Generate a new line info */
|
||||
|
||||
void ClearLineInfo (void);
|
||||
|
@ -331,7 +331,7 @@ void MacDef (unsigned Style)
|
||||
/* Parse a macro definition */
|
||||
{
|
||||
Macro* M;
|
||||
TokNode* T;
|
||||
TokNode* N;
|
||||
int HaveParams;
|
||||
|
||||
/* We expect a macro name here */
|
||||
@ -489,7 +489,7 @@ void MacDef (unsigned Style)
|
||||
}
|
||||
|
||||
/* Create a token node for the current token */
|
||||
T = NewTokNode ();
|
||||
N = NewTokNode ();
|
||||
|
||||
/* If the token is an ident, check if it is a local parameter */
|
||||
if (CurTok.Tok == TOK_IDENT) {
|
||||
@ -498,8 +498,8 @@ void MacDef (unsigned Style)
|
||||
while (I) {
|
||||
if (SB_Compare (&I->Id, &CurTok.SVal) == 0) {
|
||||
/* Local param name, replace it */
|
||||
T->Tok = TOK_MACPARAM;
|
||||
T->IVal = Count;
|
||||
N->T.Tok = TOK_MACPARAM;
|
||||
N->T.IVal = Count;
|
||||
break;
|
||||
}
|
||||
++Count;
|
||||
@ -510,11 +510,11 @@ void MacDef (unsigned Style)
|
||||
/* Insert the new token in the list */
|
||||
if (M->TokCount == 0) {
|
||||
/* First token */
|
||||
M->TokRoot = M->TokLast = T;
|
||||
M->TokRoot = M->TokLast = N;
|
||||
} else {
|
||||
/* We have already tokens */
|
||||
M->TokLast->Next = T;
|
||||
M->TokLast = T;
|
||||
M->TokLast->Next = N;
|
||||
M->TokLast = N;
|
||||
}
|
||||
++M->TokCount;
|
||||
|
||||
|
@ -60,3 +60,18 @@ int TokHasIVal (token_t Tok)
|
||||
|
||||
|
||||
|
||||
void CopyToken (Token* Dst, const Token* Src)
|
||||
/* Copy a token from Src to Dst. The current value of Dst.SVal is free'd,
|
||||
* so Dst must be initialized.
|
||||
*/
|
||||
{
|
||||
/* Copy the fields */
|
||||
Dst->Tok = Src->Tok;
|
||||
Dst->WS = Src->WS;
|
||||
Dst->IVal = Src->IVal;
|
||||
SB_Copy (&Dst->SVal, &Src->SVal);
|
||||
Dst->Pos = Src->Pos;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -303,6 +303,11 @@ INLINE int TokIsSep (enum token_t T)
|
||||
# define TokIsSep(T) ((T) == TOK_SEP || (T) == TOK_EOF)
|
||||
#endif
|
||||
|
||||
void CopyToken (Token* Dst, const Token* Src);
|
||||
/* Copy a token. The current value of Dst.SVal is free'd, so Dst must be
|
||||
* initialized.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/* End of token.h */
|
||||
|
@ -57,62 +57,55 @@
|
||||
TokNode* NewTokNode (void)
|
||||
/* Create and return a token node with the current token value */
|
||||
{
|
||||
TokNode* T;
|
||||
|
||||
/* Allocate memory */
|
||||
T = xmalloc (sizeof (TokNode));
|
||||
TokNode* N = xmalloc (sizeof (TokNode));
|
||||
|
||||
/* Initialize the token contents */
|
||||
T->Next = 0;
|
||||
T->Tok = CurTok.Tok;
|
||||
T->WS = CurTok.WS;
|
||||
T->IVal = CurTok.IVal;
|
||||
SB_Init (&T->SVal);
|
||||
SB_Copy (&T->SVal, &CurTok.SVal);
|
||||
N->Next = 0;
|
||||
SB_Init (&N->T.SVal);
|
||||
CopyToken (&N->T, &CurTok);
|
||||
|
||||
/* Return the node */
|
||||
return T;
|
||||
return N;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void FreeTokNode (TokNode* T)
|
||||
void FreeTokNode (TokNode* N)
|
||||
/* Free the given token node */
|
||||
{
|
||||
SB_Done (&T->SVal);
|
||||
xfree (T);
|
||||
SB_Done (&N->T.SVal);
|
||||
xfree (N);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void TokSet (TokNode* T)
|
||||
void TokSet (TokNode* N)
|
||||
/* Set the scanner token from the given token node */
|
||||
{
|
||||
/* Set the values */
|
||||
CurTok.Tok = T->Tok;
|
||||
CurTok.WS = T->WS;
|
||||
CurTok.IVal = T->IVal;
|
||||
SB_Copy (&CurTok.SVal, &T->SVal);
|
||||
CopyToken (&CurTok, &N->T);
|
||||
SB_Terminate (&CurTok.SVal);
|
||||
}
|
||||
|
||||
|
||||
|
||||
enum TC TokCmp (const TokNode* T)
|
||||
enum TC TokCmp (const TokNode* N)
|
||||
/* Compare the token given as parameter against the current token */
|
||||
{
|
||||
if (T->Tok != CurTok.Tok) {
|
||||
if (N->T.Tok != CurTok.Tok) {
|
||||
/* Different token */
|
||||
return tcDifferent;
|
||||
}
|
||||
|
||||
/* If the token has string attribute, check it */
|
||||
if (TokHasSVal (T->Tok)) {
|
||||
if (SB_Compare (&CurTok.SVal, &T->SVal) != 0) {
|
||||
if (TokHasSVal (N->T.Tok)) {
|
||||
if (SB_Compare (&CurTok.SVal, &N->T.SVal) != 0) {
|
||||
return tcSameToken;
|
||||
}
|
||||
} else if (TokHasIVal (T->Tok)) {
|
||||
if (T->IVal != CurTok.IVal) {
|
||||
} else if (TokHasIVal (N->T.Tok)) {
|
||||
if (N->T.IVal != CurTok.IVal) {
|
||||
return tcSameToken;
|
||||
}
|
||||
}
|
||||
@ -278,4 +271,3 @@ void PushTokList (TokList* List, const char* Desc)
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -49,17 +49,14 @@
|
||||
/*****************************************************************************/
|
||||
/* Data */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
/* Struct holding a token */
|
||||
typedef struct TokNode TokNode;
|
||||
struct TokNode {
|
||||
TokNode* Next; /* For single linked list */
|
||||
token_t Tok; /* Token value */
|
||||
int WS; /* Whitespace before token? */
|
||||
long IVal; /* Integer token attribute */
|
||||
StrBuf SVal; /* String attribute, dyn. allocated */
|
||||
Token T; /* Token value */
|
||||
};
|
||||
|
||||
/* Struct holding a token list */
|
||||
@ -95,13 +92,13 @@ enum TC {
|
||||
TokNode* NewTokNode (void);
|
||||
/* Create and return a token node with the current token value */
|
||||
|
||||
void FreeTokNode (TokNode* T);
|
||||
void FreeTokNode (TokNode* N);
|
||||
/* Free the given token node */
|
||||
|
||||
void TokSet (TokNode* T);
|
||||
void TokSet (TokNode* N);
|
||||
/* Set the scanner token from the given token node */
|
||||
|
||||
enum TC TokCmp (const TokNode* T);
|
||||
enum TC TokCmp (const TokNode* N);
|
||||
/* Compare the token given as parameter against the current token */
|
||||
|
||||
void InitTokList (TokList* T);
|
||||
|
Loading…
x
Reference in New Issue
Block a user