1
0
mirror of https://github.com/cc65/cc65.git synced 2025-08-13 08:25:28 +00:00

Add line info for macro parameters.

git-svn-id: svn://svn.cc65.org/cc65/trunk@5903 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
uz
2012-11-04 12:35:20 +00:00
parent 7b34609930
commit 5410cdea29

View File

@@ -132,6 +132,7 @@ struct MacExp {
TokNode** Params; /* List of actual parameters */ TokNode** Params; /* List of actual parameters */
TokNode* ParamExp; /* Node for expanding parameters */ TokNode* ParamExp; /* Node for expanding parameters */
LineInfo* LI; /* Line info for the expansion */ LineInfo* LI; /* Line info for the expansion */
LineInfo* ParamLI; /* Line info for parameter expansion */
}; };
/* Maximum number of nested macro expansions */ /* Maximum number of nested macro expansions */
@@ -310,6 +311,7 @@ static MacExp* NewMacExp (Macro* M)
} }
E->ParamExp = 0; E->ParamExp = 0;
E->LI = 0; E->LI = 0;
E->ParamLI = 0;
/* Mark the macro as expanding */ /* Mark the macro as expanding */
++M->Expansions; ++M->Expansions;
@@ -344,6 +346,9 @@ static void FreeMacExp (MacExp* E)
xfree (E->Params); xfree (E->Params);
/* Free the additional line info */ /* Free the additional line info */
if (E->ParamLI) {
EndLine (E->ParamLI);
}
if (E->LI) { if (E->LI) {
EndLine (E->LI); EndLine (E->LI);
} }
@@ -441,20 +446,20 @@ void MacDef (unsigned Style)
/* Insert the struct into the list, checking for duplicate idents */ /* Insert the struct into the list, checking for duplicate idents */
if (M->ParamCount == 0) { if (M->ParamCount == 0) {
M->Params = I; M->Params = I;
} else { } else {
IdDesc* List = M->Params; IdDesc* List = M->Params;
while (1) { while (1) {
if (SB_Compare (&List->Id, &CurTok.SVal) == 0) { if (SB_Compare (&List->Id, &CurTok.SVal) == 0) {
Error ("Duplicate symbol `%m%p'", &CurTok.SVal); Error ("Duplicate symbol `%m%p'", &CurTok.SVal);
} }
if (List->Next == 0) { if (List->Next == 0) {
break; break;
} else { } else {
List = List->Next; List = List->Next;
} }
} }
List->Next = I; List->Next = I;
} }
++M->ParamCount; ++M->ParamCount;
@@ -513,7 +518,7 @@ void MacDef (unsigned Style)
IdDesc* I; IdDesc* I;
/* Skip .local or comma */ /* Skip .local or comma */
NextTok (); NextTok ();
/* Need an identifer */ /* Need an identifer */
if (CurTok.Tok != TOK_IDENT && CurTok.Tok != TOK_LOCAL_IDENT) { if (CurTok.Tok != TOK_IDENT && CurTok.Tok != TOK_LOCAL_IDENT) {
@@ -544,7 +549,7 @@ void MacDef (unsigned Style)
/* Create a token node for the current token */ /* Create a token node for the current token */
N = NewTokNode (); N = NewTokNode ();
/* If the token is an ident, check if it is a local parameter */ /* If the token is an identifier, check if it is a local parameter */
if (CurTok.Tok == TOK_IDENT) { if (CurTok.Tok == TOK_IDENT) {
unsigned Count = 0; unsigned Count = 0;
IdDesc* I = M->Params; IdDesc* I = M->Params;
@@ -648,11 +653,24 @@ ExpandParam:
/* Ok, use token from parameter list */ /* Ok, use token from parameter list */
TokSet (Mac->ParamExp); TokSet (Mac->ParamExp);
/* Create new line info for this parameter token */
if (Mac->ParamLI) {
EndLine (Mac->ParamLI);
}
Mac->ParamLI = StartLine (&CurTok.Pos, LI_TYPE_MACPARAM, Mac->MacExpansions);
/* Set pointer to next token */ /* Set pointer to next token */
Mac->ParamExp = Mac->ParamExp->Next; Mac->ParamExp = Mac->ParamExp->Next;
/* Done */ /* Done */
return 1; return 1;
} else if (Mac->ParamLI) {
/* There's still line info open from the parameter expansion - end it */
EndLine (Mac->ParamLI);
Mac->ParamLI = 0;
} }
/* We're not expanding macro parameters. Check if we have tokens left from /* We're not expanding macro parameters. Check if we have tokens left from