Don’t produce spurious error messages when #error is used with tokens other than a string constant.

According to the C standards, #error is supposed to take an arbitrary sequence of pp-tokens, not just a string constant.
This commit is contained in:
Stephen Heumann 2016-11-05 18:57:26 -05:00
parent 8b4c83f527
commit 5618b2810e
1 changed files with 31 additions and 23 deletions

View File

@ -2237,37 +2237,45 @@ var
procedure DoError; procedure DoError;
{ #error STRING } { #error pp-tokens(opt) }
var var
i: integer; {loop variable} i: integer; {loop variable}
len: integer; {string length} len: integer; {string length}
msg: stringPtr; {error message ptr} msg: stringPtr; {error message ptr}
cp: ptr; {character pointer}
lFirstPtr: ptr; {local copy of firstPtr}
begin {DoError} begin {DoError}
lFirstPtr := firstPtr;
numErrors := numErrors+1;
new(msg);
msg^ := '#error:';
NextToken; {skip the command name} NextToken; {skip the command name}
if token.kind = stringConst then begin while not (token.kind in [eolsy, eofsy]) do begin
numErrors := numErrors+1; msg^ := concat(msg^, ' ');
new(msg); if token.kind = stringConst then begin
len := token.sval^.length; len := token.sval^.length;
if len > 246 then for i := 1 to len do
len := 246; msg^ := concat(msg^, token.sval^.str[i]);
msg^ := '#error: '; end {if}
for i := 1 to len do else begin
msg^ := concat(msg^, token.sval^.str[i]); len := ord(ord4(tokenEnd) - ord4(tokenStart));
writeln(msg^); cp := tokenStart;
if terminalErrors then begin for i := 1 to len do begin
if enterEditor then msg^ := concat(msg^, chr(cp^));
ExitToEditor(msg, ord4(firstPtr)-ord4(bofPtr)) cp := pointer(ord4(cp)+1);
else end; {for}
TermError(0); end; {else}
end; {if} NextToken;
end {if} end; {while}
else writeln(msg^);
Error(83); if terminalErrors then begin
NextToken; {skip the command name} if enterEditor then
if token.kind <> eolsy then {check for extra stuff on the line} ExitToEditor(msg, ord4(lFirstPtr)-ord4(bofPtr))
Error(11); else
TermError(0);
end; {if}
end; {DoError} end; {DoError}