mirror of
https://github.com/byteworksinc/ORCA-C.git
synced 2024-12-22 07:30:54 +00:00
Support 64-bit integer constants in hex/octal/binary formats.
64-bit decimal constants are not supported yet.
This commit is contained in:
parent
793f0a57cc
commit
058c0565c6
48
Scanner.pas
48
Scanner.pas
@ -3222,6 +3222,23 @@ var
|
|||||||
end; {GetDigits}
|
end; {GetDigits}
|
||||||
|
|
||||||
|
|
||||||
|
procedure ShiftAndOrValue (shiftCount, nextDigit: integer);
|
||||||
|
|
||||||
|
{ Shift the 64-bit value of token.qval left by shiftCount, }
|
||||||
|
{ then binary-or it with nextDigit. }
|
||||||
|
|
||||||
|
begin {ShiftAndOrValue}
|
||||||
|
while shiftCount > 0 do begin
|
||||||
|
token.qval.hi := token.qval.hi << 1;
|
||||||
|
if (token.qval.lo & $80000000) <> 0 then
|
||||||
|
token.qval.hi := token.qval.hi | 1;
|
||||||
|
token.qval.lo := token.qval.lo << 1;
|
||||||
|
shiftCount := shiftCount - 1;
|
||||||
|
end; {while}
|
||||||
|
token.qval.lo := token.qval.lo | nextDigit;
|
||||||
|
end; {ShiftAndOrValue}
|
||||||
|
|
||||||
|
|
||||||
begin {DoNumber}
|
begin {DoNumber}
|
||||||
isBin := false; {assume it's not binary}
|
isBin := false; {assume it's not binary}
|
||||||
isHex := false; {assume it's not hex}
|
isHex := false; {assume it's not hex}
|
||||||
@ -3361,11 +3378,12 @@ else if numString[1] <> '0' then begin {convert a decimal integer}
|
|||||||
end; {else}
|
end; {else}
|
||||||
end {else if}
|
end {else if}
|
||||||
else begin {hex, octal, & binary}
|
else begin {hex, octal, & binary}
|
||||||
token.lval := 0;
|
token.qval.lo := 0;
|
||||||
|
token.qval.hi := 0;
|
||||||
if isHex then begin
|
if isHex then begin
|
||||||
i := 3;
|
i := 3;
|
||||||
while i <= length(numString) do begin
|
while i <= length(numString) do begin
|
||||||
if token.lval & $F0000000 <> 0 then begin
|
if token.qval.hi & $F0000000 <> 0 then begin
|
||||||
i := maxint;
|
i := maxint;
|
||||||
if flagOverflows then
|
if flagOverflows then
|
||||||
FlagError(6);
|
FlagError(6);
|
||||||
@ -3375,7 +3393,7 @@ else begin {hex, octal, & binary}
|
|||||||
val := (ord(numString[i])-7) & $000F
|
val := (ord(numString[i])-7) & $000F
|
||||||
else
|
else
|
||||||
val := ord(numString[i]) & $000F;
|
val := ord(numString[i]) & $000F;
|
||||||
token.lval := (token.lval << 4) | val;
|
ShiftAndOrValue(4, val);
|
||||||
i := i+1;
|
i := i+1;
|
||||||
end; {else}
|
end; {else}
|
||||||
end; {while}
|
end; {while}
|
||||||
@ -3383,7 +3401,7 @@ else begin {hex, octal, & binary}
|
|||||||
else if isBin then begin
|
else if isBin then begin
|
||||||
i := 3;
|
i := 3;
|
||||||
while i <= length(numString) do begin
|
while i <= length(numString) do begin
|
||||||
if token.lval & $80000000 <> 0 then begin
|
if token.qval.hi & $80000000 <> 0 then begin
|
||||||
i := maxint;
|
i := maxint;
|
||||||
if flagOverflows then
|
if flagOverflows then
|
||||||
FlagError(6);
|
FlagError(6);
|
||||||
@ -3391,7 +3409,7 @@ else begin {hex, octal, & binary}
|
|||||||
else begin
|
else begin
|
||||||
if not (numString[i] in ['0','1']) then
|
if not (numString[i] in ['0','1']) then
|
||||||
FlagError(121);
|
FlagError(121);
|
||||||
token.lval := (token.lval << 1) | (ord(numString[i]) & $0001);
|
ShiftAndOrValue(1, ord(numString[i]) & $0001);
|
||||||
i := i+1;
|
i := i+1;
|
||||||
end; {else}
|
end; {else}
|
||||||
end; {while}
|
end; {while}
|
||||||
@ -3399,7 +3417,7 @@ else begin {hex, octal, & binary}
|
|||||||
else begin
|
else begin
|
||||||
i := 1;
|
i := 1;
|
||||||
while i <= length(numString) do begin
|
while i <= length(numString) do begin
|
||||||
if token.lval & $E0000000 <> 0 then begin
|
if token.qval.hi & $E0000000 <> 0 then begin
|
||||||
i := maxint;
|
i := maxint;
|
||||||
if flagOverflows then
|
if flagOverflows then
|
||||||
FlagError(6);
|
FlagError(6);
|
||||||
@ -3407,32 +3425,32 @@ else begin {hex, octal, & binary}
|
|||||||
else begin
|
else begin
|
||||||
if numString[i] in ['8','9'] then
|
if numString[i] in ['8','9'] then
|
||||||
FlagError(7);
|
FlagError(7);
|
||||||
token.lval := (token.lval << 3) | (ord(numString[i]) & $0007);
|
ShiftAndOrValue(3, ord(numString[i]) & $0007);
|
||||||
i := i+1;
|
i := i+1;
|
||||||
end; {else}
|
end; {else}
|
||||||
end; {while}
|
end; {while}
|
||||||
end; {else}
|
end; {else}
|
||||||
if long(token.lval).msw <> 0 then
|
if token.qval.hi <> 0 then
|
||||||
isLong := true;
|
isLongLong := true;
|
||||||
|
if not isLongLong then
|
||||||
|
if long(token.qval.lo).msw <> 0 then
|
||||||
|
isLong := true;
|
||||||
if isLongLong then begin
|
if isLongLong then begin
|
||||||
{TODO support actual long long range}
|
if unsigned or (token.qval.hi & $80000000 <> 0) then
|
||||||
token.qval.lo := token.lval;
|
|
||||||
token.qval.hi := 0;
|
|
||||||
if unsigned then
|
|
||||||
token.kind := ulonglongConst
|
token.kind := ulonglongConst
|
||||||
else
|
else
|
||||||
token.kind := longlongConst;
|
token.kind := longlongConst;
|
||||||
token.class := longlongConstant;
|
token.class := longlongConstant;
|
||||||
end {if}
|
end {if}
|
||||||
else if isLong then begin
|
else if isLong then begin
|
||||||
if unsigned or (token.lval & $80000000 <> 0) then
|
if unsigned or (token.qval.lo & $80000000 <> 0) then
|
||||||
token.kind := ulongConst
|
token.kind := ulongConst
|
||||||
else
|
else
|
||||||
token.kind := longConst;
|
token.kind := longConst;
|
||||||
token.class := longConstant;
|
token.class := longConstant;
|
||||||
end {if}
|
end {if}
|
||||||
else begin
|
else begin
|
||||||
if (long(token.lval).lsw & $8000) <> 0 then
|
if (long(token.qval.lo).lsw & $8000) <> 0 then
|
||||||
unsigned := true;
|
unsigned := true;
|
||||||
if unsigned then
|
if unsigned then
|
||||||
token.kind := uintConst
|
token.kind := uintConst
|
||||||
|
Loading…
Reference in New Issue
Block a user