From 76eb4768093dce6e5dd06c0d1f5d29f078d3a258 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Thu, 30 Jan 2020 12:48:16 -0600 Subject: [PATCH] Address some issues with stringization of macro arguments. We now insert spaces corresponding to whitespace between tokens, and string tokens are enclosed in quotes. There are still issues with (at least) escape sequences in strings and comments between tokens. --- Scanner.pas | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/Scanner.pas b/Scanner.pas index 16ccf90..d14a6a0 100644 --- a/Scanner.pas +++ b/Scanner.pas @@ -267,6 +267,8 @@ var workString: pstring; {for building strings and identifiers} ucnString: string[10]; {string of a UCN} lintErrors: set of 1..maxLint; {lint error codes} + spaceStr: string[2]; {string ' ' (used in stringization)} + quoteStr: string[2]; {string '"' (used in stringization)} {-- External procedures; see expression evaluator for notes ----} @@ -1513,12 +1515,25 @@ else begin if tcPtr = nil then BuildStringToken(nil, 0); while tcPtr <> nil do begin - if tcPtr^.token.kind = stringconst then + if tcPtr^.token.kind = stringconst then begin + BuildStringToken(@quoteStr[1], 1); BuildStringToken(@tcPtr^.token.sval^.str, - tcPtr^.token.sval^.length) - else + tcPtr^.token.sval^.length); + BuildStringToken(@quoteStr[1], 1); + end {if} + else begin + if tcPtr <> pptr^.tokens then + if charKinds[tcPtr^.tokenEnd^] = ch_white then + BuildStringToken(@spaceStr[1], 1); BuildStringToken(tcPtr^.tokenStart, ord(ord4(tcPtr^.tokenEnd)-ord4(tcPtr^.tokenStart))); + + {hack because stringconst may not have proper tokenEnd} + if tcPtr^.next <> nil then + if tcPtr^.next^.token.kind = stringconst then + if charKinds[ptr(ord4(tcPtr^.tokenStart)-1)^] = ch_white then + BuildStringToken(@spaceStr[1], 1); + end; tcPtr := tcPtr^.next; end; {while} tlPtr := tlPtr^.next; @@ -3640,6 +3655,9 @@ lintIsError := true; {lint messages are considered errors} {if changed, also change maxLint} lintErrors := [51,104,105,110,124,125,128,129,130,147,151,152,153]; +spaceStr := ' '; {strings used in stringization} +quoteStr := '"'; + new(mp); {__LINE__} mp^.name := @'__LINE__'; mp^.parameters := -1;