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.
This commit is contained in:
Stephen Heumann 2017-06-18 00:03:56 -05:00
parent db2a09bd1d
commit 6ea43d34a1

View File

@ -1857,6 +1857,7 @@ var
begin {ProcessIf}
if token.kind <> eolsy then {check for extra stuff on the line}
if not tSkipping then
Error(11);
new(ip); {create a new if record}
ip^.next := ifList;
@ -2517,6 +2518,7 @@ if ch in ['a','d','e','i','l','p','u'] then begin
NextToken;
case token.kind of
ifsy: begin
if not tSkipping then
NumericDirective;
ProcessIf(expressionValue = 0);
goto 2;
@ -2559,15 +2561,22 @@ if ch in ['a','d','e','i','l','p','u'] then begin
end; {else if}
'i':
if token.name^ = 'if' then begin
if not tSkipping then
NumericDirective;
ProcessIf(expressionValue = 0);
goto 2;
end {if}
else if token.name^ = 'ifdef' then begin
if tSkipping then
ProcessIf(false)
else
ProcessIf(not Defined);
goto 2;
end {else}
else if token.name^ = 'ifndef' then begin
if tSkipping then
ProcessIf(false)
else
ProcessIf(Defined);
goto 2;
end {else}