From 6ea43d34a130f45e306b2db70536912f958a35ec Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Sun, 18 Jun 2017 00:03:56 -0500 Subject: [PATCH] Skip tokens following preprocessing directives on lines that are skipped. This allows code like the following to compile: #if 0 #if some bogus stuff ! #endif #endif This is what the C standards require. The change affects #if, #ifdef, and #ifndef directives. This may be needed to handle code targeted at other compilers that allow pseudo-functions such as "__has_feature" in preprocessor expressions. --- Scanner.pas | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/Scanner.pas b/Scanner.pas index 5be23c9..93b1122 100644 --- a/Scanner.pas +++ b/Scanner.pas @@ -1857,7 +1857,8 @@ var begin {ProcessIf} if token.kind <> eolsy then {check for extra stuff on the line} - Error(11); + if not tSkipping then + Error(11); new(ip); {create a new if record} ip^.next := ifList; ifList := ip; @@ -2517,7 +2518,8 @@ if ch in ['a','d','e','i','l','p','u'] then begin NextToken; case token.kind of ifsy: begin - NumericDirective; + if not tSkipping then + NumericDirective; ProcessIf(expressionValue = 0); goto 2; end; @@ -2559,16 +2561,23 @@ if ch in ['a','d','e','i','l','p','u'] then begin end; {else if} 'i': if token.name^ = 'if' then begin - NumericDirective; + if not tSkipping then + NumericDirective; ProcessIf(expressionValue = 0); goto 2; end {if} else if token.name^ = 'ifdef' then begin - ProcessIf(not Defined); + if tSkipping then + ProcessIf(false) + else + ProcessIf(not Defined); goto 2; end {else} else if token.name^ = 'ifndef' then begin - ProcessIf(Defined); + if tSkipping then + ProcessIf(false) + else + ProcessIf(Defined); goto 2; end {else} else if token.name^ = 'include' then begin