Allow skipped code to contain pp-numbers that are not valid numeric constants.

The C standards define "pp-number" tokens handled by the preprocessor using a syntax that encompasses various things that aren't valid integer or floating constants, or are constants too large for ORCA/C to handle. These cases would previously give errors even in code skipped by the preprocessor. With this patch, most such errors in skipped code are now ignored.

This is useful, e.g., to allow for #ifdefed-out code containing 64-bit constants.

There are still some cases involving pp-numbers that should be allowed but aren't, particularly in the context of macros.
This commit is contained in:
Stephen Heumann 2017-06-18 23:31:53 -05:00
parent 02de5f4137
commit 8ca3d5f4f0
1 changed files with 22 additions and 10 deletions

View File

@ -2907,6 +2907,18 @@ var
end; {NextChar}
procedure FlagError (errCode: integer);
{ Handle an error when processing a number. Don't report }
{ errors when skipping code, because pp-numbers in skipped }
{ code never actually get converted to numeric constants. }
begin {FlagError}
if not skipping then
Error(errCode);
end; {FlagError}
procedure GetDigits;
{ Read in a digit stream }
@ -2923,7 +2935,7 @@ var
c2 := chr(ord(c2) & $5F);
stringIndex := stringIndex+1;
if stringIndex > 255 then begin
Error(6);
FlagError(6);
stringIndex := 1;
end; {if}
numString[stringIndex] := c2;
@ -2988,7 +3000,7 @@ if c2 in ['e','E'] then begin {handle an exponent}
else begin
stringIndex := stringIndex+1;
numString[stringIndex] := '0';
Error(101);
FlagError(101);
end; {else}
end; {if}
1:
@ -3002,13 +3014,13 @@ while c2 in ['l','u','L','U'] do {check for long or unsigned}
NextChar;
unsigned := true;
if isReal then
Error(91);
FlagError(91);
end; {else}
if c2 in ['f','F'] then begin {allow F designator on reals}
if unsigned then
Error(91);
FlagError(91);
if not isReal then begin
Error(100);
FlagError(100);
isReal := true;
end; {if}
NextChar;
@ -3018,7 +3030,7 @@ if isReal then begin {convert a real constant}
token.kind := doubleConst;
token.class := doubleConstant;
if stringIndex > 80 then begin
Error(6);
FlagError(6);
token.rval := 0.0;
end {if}
else
@ -3033,7 +3045,7 @@ else if numString[1] <> '0' then begin {convert a decimal integer}
((stringIndex = 10) and (numString > '4294967295')) then begin
numString := '0';
if flagOverflows then
Error(6);
FlagError(6);
end; {if}
if isLong then begin
token.class := longConstant;
@ -3063,7 +3075,7 @@ else begin {hex & octal}
if token.lval & $F0000000 <> 0 then begin
i := maxint;
if flagOverflows then
Error(6);
FlagError(6);
end {if}
else begin
if numString[i] > '9' then
@ -3081,11 +3093,11 @@ else begin {hex & octal}
if token.lval & $E0000000 <> 0 then begin
i := maxint;
if flagOverflows then
Error(6);
FlagError(6);
end {if}
else begin
if numString[i] in ['8','9'] then
Error(7);
FlagError(7);
token.lval := (token.lval << 3) | (ord(numString[i]) & $0007);
i := i+1;
end; {else}