}
/* Remember the line info */
- GenLineInfo (Index, LineNum);
+ GenLineInfo (Index, LineNum, 0);
}
-
+
/* */
/* */
/* */
-/* (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 */
-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 */
/* 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);
-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);
}
-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 */
{
}
}
-
+
void MakeLineInfoIndex (void)
/* Sort the line infos and drop all unreferenced ones */
/* */
/* */
/* */
-/* (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 */
* 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);
/* Parse a macro definition */
{
Macro* M;
- TokNode* T;
+ TokNode* N;
int HaveParams;
/* We expect a macro name here */
}
/* 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) {
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;
/* 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;
+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;
+}
+
+
+
# 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 */
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;
}
}
-
/*****************************************************************************/
/* 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 */
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);