Allow comments inside of macro calls that are spread over more than one line
git-svn-id: svn://svn.cc65.org/cc65/trunk@1141 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
5f7ca4b2f4
commit
6b654255ba
1 changed files with 47 additions and 33 deletions
|
@ -147,7 +147,7 @@ static void keepch (char c)
|
||||||
{
|
{
|
||||||
*mptr++ = c;
|
*mptr++ = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void keepstr (const char* S)
|
static void keepstr (const char* S)
|
||||||
|
@ -160,8 +160,8 @@ static void keepstr (const char* S)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void Comment (void)
|
static void OldStyleComment (void)
|
||||||
/* Remove a C comment from line. */
|
/* Remove an old style C comment from line. */
|
||||||
{
|
{
|
||||||
/* Remember the current line number, so we can output better error
|
/* Remember the current line number, so we can output better error
|
||||||
* messages if the comment is not terminated in the current file.
|
* messages if the comment is not terminated in the current file.
|
||||||
|
@ -176,13 +176,13 @@ static void Comment (void)
|
||||||
while (CurC != '*' || NextC != '/') {
|
while (CurC != '*' || NextC != '/') {
|
||||||
if (CurC == '\0') {
|
if (CurC == '\0') {
|
||||||
if (NextLine () == 0) {
|
if (NextLine () == 0) {
|
||||||
PPError ("End-of-file reached in comment starting at line %u",
|
PPError ("End-of-file reached in comment starting at line %u",
|
||||||
StartingLine);
|
StartingLine);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (CurC == '/' && NextC == '*') {
|
if (CurC == '/' && NextC == '*') {
|
||||||
PPWarning ("`/*' found inside a comment");
|
PPWarning ("`/*' found inside a comment");
|
||||||
}
|
}
|
||||||
NextChar ();
|
NextChar ();
|
||||||
}
|
}
|
||||||
|
@ -195,6 +195,24 @@ static void Comment (void)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static void NewStyleComment (void)
|
||||||
|
/* Remove a new style C comment from line. */
|
||||||
|
{
|
||||||
|
/* Beware: Because line continuation chars are handled when reading
|
||||||
|
* lines, we may only skip til the end of the source line, which
|
||||||
|
* may not be the same as the end of the input line. The end of the
|
||||||
|
* source line is denoted by a lf (\n) character.
|
||||||
|
*/
|
||||||
|
do {
|
||||||
|
NextChar ();
|
||||||
|
} while (CurC != '\n' && CurC != '\0');
|
||||||
|
if (CurC == '\n') {
|
||||||
|
NextChar ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void SkipBlank (void)
|
static void SkipBlank (void)
|
||||||
/* Skip blanks and tabs in the input stream. */
|
/* Skip blanks and tabs in the input stream. */
|
||||||
{
|
{
|
||||||
|
@ -361,15 +379,15 @@ static int MacroCall (Macro* M)
|
||||||
++ArgCount;
|
++ArgCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check for end of macro param list */
|
/* Check for end of macro param list */
|
||||||
if (CurC == ')') {
|
if (CurC == ')') {
|
||||||
NextChar ();
|
NextChar ();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Start the next param */
|
/* Start the next param */
|
||||||
ArgStart = B;
|
ArgStart = B;
|
||||||
NextChar ();
|
NextChar ();
|
||||||
} else {
|
} else {
|
||||||
/* Comma or right paren inside nested parenthesis */
|
/* Comma or right paren inside nested parenthesis */
|
||||||
if (CurC == ')') {
|
if (CurC == ')') {
|
||||||
|
@ -382,25 +400,31 @@ static int MacroCall (Macro* M)
|
||||||
/* Squeeze runs of blanks */
|
/* Squeeze runs of blanks */
|
||||||
*B++ = ' ';
|
*B++ = ' ';
|
||||||
SkipBlank ();
|
SkipBlank ();
|
||||||
|
} else if (CurC == '/' && NextC == '*') {
|
||||||
|
*B++ = ' ';
|
||||||
|
OldStyleComment ();
|
||||||
|
} else if (ANSI == 0 && CurC == '/' && NextC == '/') {
|
||||||
|
*B++ = ' ';
|
||||||
|
NewStyleComment ();
|
||||||
} else if (CurC == '\0') {
|
} else if (CurC == '\0') {
|
||||||
/* End of line inside macro argument list - read next line */
|
/* End of line inside macro argument list - read next line */
|
||||||
if (NextLine () == 0) {
|
if (NextLine () == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* Just copy the character */
|
/* Just copy the character */
|
||||||
*B++ = CurC;
|
*B++ = CurC;
|
||||||
NextChar ();
|
NextChar ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Compare formal argument count with actual */
|
/* Compare formal argument count with actual */
|
||||||
if (M->ArgCount != ArgCount) {
|
if (M->ArgCount != ArgCount) {
|
||||||
PPError ("Macro argument count mismatch");
|
PPError ("Macro argument count mismatch");
|
||||||
/* Be sure to make enough empty arguments available */
|
/* Be sure to make enough empty arguments available */
|
||||||
while (ArgCount < M->ArgCount) {
|
while (ArgCount < M->ArgCount) {
|
||||||
M->ActualArgs [ArgCount++] = "";
|
M->ActualArgs [ArgCount++] = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Preprocess the line, replacing macro parameters */
|
/* Preprocess the line, replacing macro parameters */
|
||||||
|
@ -570,20 +594,10 @@ static int Pass1 (const char* From, char* To)
|
||||||
mptr = CopyQuotedString (mptr);
|
mptr = CopyQuotedString (mptr);
|
||||||
} else if (CurC == '/' && NextC == '*') {
|
} else if (CurC == '/' && NextC == '*') {
|
||||||
keepch (' ');
|
keepch (' ');
|
||||||
Comment ();
|
OldStyleComment ();
|
||||||
} else if (ANSI == 0 && CurC == '/' && NextC == '/') {
|
} else if (ANSI == 0 && CurC == '/' && NextC == '/') {
|
||||||
keepch (' ');
|
keepch (' ');
|
||||||
/* Beware: Because line continuation chars are handled when reading
|
NewStyleComment ();
|
||||||
* lines, we may only skip til the end of the source line, which
|
|
||||||
* may not be the same as the end of the input line. The end of the
|
|
||||||
* source line is denoted by a lf (\n) character.
|
|
||||||
*/
|
|
||||||
do {
|
|
||||||
NextChar ();
|
|
||||||
} while (CurC != '\n' && CurC != '\0');
|
|
||||||
if (CurC == '\n') {
|
|
||||||
NextChar ();
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
*mptr++ = CurC;
|
*mptr++ = CurC;
|
||||||
NextChar ();
|
NextChar ();
|
||||||
|
@ -906,7 +920,7 @@ void Preprocess (void)
|
||||||
|
|
||||||
case PP_ELSE:
|
case PP_ELSE:
|
||||||
if (IfIndex >= 0) {
|
if (IfIndex >= 0) {
|
||||||
if ((IfStack[IfIndex] & IFCOND_ELSE) == 0) {
|
if ((IfStack[IfIndex] & IFCOND_ELSE) == 0) {
|
||||||
if ((IfStack[IfIndex] & IFCOND_SKIP) == 0) {
|
if ((IfStack[IfIndex] & IFCOND_SKIP) == 0) {
|
||||||
Skip = !Skip;
|
Skip = !Skip;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue