1
0
mirror of https://github.com/cc65/cc65.git synced 2024-09-27 19:55:09 +00:00

Fixed wide strings for preprocessor.

This commit is contained in:
acqn 2022-08-22 14:34:50 +08:00
parent be95cb8f58
commit c7ff416ce9
3 changed files with 45 additions and 8 deletions

View File

@ -965,11 +965,28 @@ static void CopyHeaderNameToken (StrBuf* Target)
static int IsQuotedString (void)
/* Retrun 1 if the incoming characters indicate a string literal or character
** constant, otherwise return 0.
*/
{
return IsQuote (CurC) || IsWideQuoted (CurC, NextC);
}
static void CopyQuotedString (StrBuf* Target) static void CopyQuotedString (StrBuf* Target)
/* Copy a single or double quoted string from the input to Target. */ /* Copy a single or double quoted string from the input to Target. */
{ {
/* Remember the quote character, copy it to the target buffer and skip it */ /* Remember the quote character, copy it to the target buffer and skip it */
char Quote = CurC; char Quote;
if (CurC == 'L') {
SB_AppendChar (Target, CurC);
NextChar ();
}
Quote = CurC;
SB_AppendChar (Target, CurC); SB_AppendChar (Target, CurC);
NextChar (); NextChar ();
@ -1165,7 +1182,7 @@ static int TryPastePPTok (StrBuf* Target,
if (IsPPNumber (CurC, NextC)) { if (IsPPNumber (CurC, NextC)) {
/* PP-number */ /* PP-number */
CopyPPNumber (&Buf); CopyPPNumber (&Buf);
} else if (IsQuote (CurC)) { } else if (IsQuotedString ()) {
/* Quoted string */ /* Quoted string */
CopyQuotedString (&Buf); CopyQuotedString (&Buf);
} else { } else {
@ -1391,7 +1408,7 @@ static unsigned ReadMacroArgs (unsigned NameIdx, MacroExp* E, const Macro* M, in
} else if (IsPPNumber (CurC, NextC)) { } else if (IsPPNumber (CurC, NextC)) {
/* Copy a pp-number */ /* Copy a pp-number */
CopyPPNumber (&Arg.Tokens); CopyPPNumber (&Arg.Tokens);
} else if (IsQuote (CurC)) { } else if (IsQuotedString ()) {
/* Quoted string - just copy */ /* Quoted string - just copy */
CopyQuotedString (&Arg.Tokens); CopyQuotedString (&Arg.Tokens);
} else if (GetPunc (Ident)) { } else if (GetPunc (Ident)) {
@ -1545,6 +1562,11 @@ static unsigned SubstMacroArgs (unsigned NameIdx, StrBuf* Target, MacroExp* E, M
TokLen = strlen (Ident); TokLen = strlen (Ident);
} }
/* Special casing for 'L' prefixing '#' */
if (TokLen == 1 && SB_LookAtLast (Target) == 'L' && CurC == '#') {
HaveSpace = 1;
}
/* Squeeze and add the skipped whitespace back for consistency */ /* Squeeze and add the skipped whitespace back for consistency */
if (HaveSpace) { if (HaveSpace) {
SB_AppendChar (Target, ' '); SB_AppendChar (Target, ' ');
@ -1658,7 +1680,7 @@ static unsigned SubstMacroArgs (unsigned NameIdx, StrBuf* Target, MacroExp* E, M
SB_Clear (&Buf); SB_Clear (&Buf);
if (IsPPNumber (CurC, NextC)) { if (IsPPNumber (CurC, NextC)) {
CopyPPNumber (&Buf); CopyPPNumber (&Buf);
} else if (IsQuote (CurC)) { } else if (IsQuotedString ()) {
CopyQuotedString (&Buf); CopyQuotedString (&Buf);
} else { } else {
if (CurC == '#' && M->ParamCount >= 0) { if (CurC == '#' && M->ParamCount >= 0) {
@ -1957,7 +1979,7 @@ static unsigned ReplaceMacros (StrBuf* Source, StrBuf* Target, MacroExp* E, unsi
CopyHeaderNameToken (Target); CopyHeaderNameToken (Target);
} else if (IsPPNumber (CurC, NextC)) { } else if (IsPPNumber (CurC, NextC)) {
CopyPPNumber (Target); CopyPPNumber (Target);
} else if (IsQuote (CurC)) { } else if (IsQuotedString ()) {
CopyQuotedString (Target); CopyQuotedString (Target);
} else { } else {
Skipped = SkipWhitespace (0); Skipped = SkipWhitespace (0);
@ -2070,7 +2092,7 @@ static int ParseMacroReplacement (StrBuf* Source, Macro* M)
while (CurC != '\0') { while (CurC != '\0') {
if (HasWhiteSpace) { if (HasWhiteSpace) {
SB_AppendChar (&M->Replacement, ' '); SB_AppendChar (&M->Replacement, ' ');
} else if (IsQuote (CurC)) { } else if (IsQuotedString ()) {
CopyQuotedString (&M->Replacement); CopyQuotedString (&M->Replacement);
} else { } else {
if (M->ParamCount >= 0 && GetPunc (Ident)) { if (M->ParamCount >= 0 && GetPunc (Ident)) {
@ -2850,7 +2872,7 @@ static void TranslationPhase3 (StrBuf* Source, StrBuf* Target)
} }
if (HasWhiteSpace) { if (HasWhiteSpace) {
SB_AppendChar (Target, ' '); SB_AppendChar (Target, ' ');
} else if (IsQuote (CurC)) { } else if (IsQuotedString ()) {
CopyQuotedString (Target); CopyQuotedString (Target);
} else { } else {
SB_AppendChar (Target, CurC); SB_AppendChar (Target, CurC);

View File

@ -235,10 +235,20 @@ void SymName (char* S)
int IsWideQuoted (char First, char Second)
/* Return 1 if the two successive characters indicate a wide string literal or
** a wide char constant, otherwise return 0.
*/
{
return First == 'L' && IsQuote(Second);
}
int IsSym (char* S) int IsSym (char* S)
/* If a symbol follows, read it and return 1, otherwise return 0 */ /* If a symbol follows, read it and return 1, otherwise return 0 */
{ {
if (IsIdent (CurC)) { if (IsIdent (CurC) && !IsWideQuoted (CurC, NextC)) {
SymName (S); SymName (S);
return 1; return 1;
} else { } else {

View File

@ -282,6 +282,11 @@ void SymName (char* S);
** least of size MAX_IDENTLEN+1. ** least of size MAX_IDENTLEN+1.
*/ */
int IsWideQuoted (char First, char Second);
/* Return 1 if the two successive characters indicate a wide string literal or
** a wide char constant, otherwise return 0.
*/
int IsSym (char* S); int IsSym (char* S);
/* If a symbol follows, read it and return 1, otherwise return 0 */ /* If a symbol follows, read it and return 1, otherwise return 0 */