mirror of
https://github.com/byteworksinc/ORCA-C.git
synced 2024-06-10 22:29:27 +00:00
Do preprocessor arithmetic in intmax_t/uintmax_t (aka long long types).
This is what C99 and later require.
This commit is contained in:
parent
955ee74b25
commit
b4604e079e
|
@ -929,7 +929,7 @@ var
|
||||||
|
|
||||||
{ do an operation }
|
{ do an operation }
|
||||||
|
|
||||||
label 1;
|
label 1,2;
|
||||||
|
|
||||||
var
|
var
|
||||||
baseType: baseTypeEnum; {base type of value to cast}
|
baseType: baseTypeEnum; {base type of value to cast}
|
||||||
|
@ -1047,10 +1047,10 @@ var
|
||||||
{ adjust kind of token for use in preprocessor expression }
|
{ adjust kind of token for use in preprocessor expression }
|
||||||
|
|
||||||
begin {PPKind}
|
begin {PPKind}
|
||||||
if token.kind = intconst then
|
if token.kind in [intconst,longconst] then
|
||||||
PPKind := longconst
|
PPKind := longlongconst
|
||||||
else if token.kind = uintconst then
|
else if token.kind in [uintconst,ulongconst] then
|
||||||
PPKind := ulongconst
|
PPKind := ulonglongconst
|
||||||
else
|
else
|
||||||
PPKind := token.kind;
|
PPKind := token.kind;
|
||||||
end; {PPKind}
|
end; {PPKind}
|
||||||
|
@ -1133,10 +1133,8 @@ var
|
||||||
kindLeft := op^.left^.token.kind;
|
kindLeft := op^.left^.token.kind;
|
||||||
if kindRight in [intconst,uintconst,longconst,ulongconst] then begin
|
if kindRight in [intconst,uintconst,longconst,ulongconst] then begin
|
||||||
if kindLeft in [intconst,uintconst,longconst,ulongconst] then begin
|
if kindLeft in [intconst,uintconst,longconst,ulongconst] then begin
|
||||||
if kind = preprocessorExpression then begin
|
if kind = preprocessorExpression then
|
||||||
kindLeft := PPKind(op^.left^.token);
|
goto 2;
|
||||||
kindRight := PPKind(op^.right^.token);
|
|
||||||
end; {if}
|
|
||||||
|
|
||||||
{do the usual binary conversions}
|
{do the usual binary conversions}
|
||||||
if (kindRight = ulongconst) or (kindLeft = ulongconst) then
|
if (kindRight = ulongconst) or (kindLeft = ulongconst) then
|
||||||
|
@ -1269,7 +1267,7 @@ var
|
||||||
goto 1;
|
goto 1;
|
||||||
end; {if}
|
end; {if}
|
||||||
end; {if}
|
end; {if}
|
||||||
|
2:
|
||||||
if kindRight in [intconst,uintconst,longconst,ulongconst,
|
if kindRight in [intconst,uintconst,longconst,ulongconst,
|
||||||
longlongconst,ulonglongconst] then begin
|
longlongconst,ulonglongconst] then begin
|
||||||
if kindLeft in [intconst,uintconst,longconst,ulongconst,
|
if kindLeft in [intconst,uintconst,longconst,ulongconst,
|
||||||
|
@ -1610,13 +1608,11 @@ var
|
||||||
else if not (op^.token.kind in
|
else if not (op^.token.kind in
|
||||||
[typedef,plusplusop,minusminusop,opplusplus,opminusminus,uand]) then
|
[typedef,plusplusop,minusminusop,opplusplus,opminusminus,uand]) then
|
||||||
begin
|
begin
|
||||||
if (op^.left^.token.kind
|
if (kind <> preprocessorExpression) and (op^.left^.token.kind
|
||||||
in [intconst,uintconst,longconst,ulongconst]) then begin
|
in [intconst,uintconst,longconst,ulongconst]) then begin
|
||||||
|
|
||||||
{evaluate a constant operation}
|
{evaluate a constant operation}
|
||||||
ekind := op^.left^.token.kind;
|
ekind := op^.left^.token.kind;
|
||||||
if kind = preprocessorExpression then
|
|
||||||
ekind := PPKind(op^.left^.token);
|
|
||||||
op1 := IntVal(op^.left^.token);
|
op1 := IntVal(op^.left^.token);
|
||||||
dispose(op^.left);
|
dispose(op^.left);
|
||||||
op^.left := nil;
|
op^.left := nil;
|
||||||
|
@ -1640,12 +1636,14 @@ var
|
||||||
op^.token.ival := long(op1).lsw;
|
op^.token.ival := long(op1).lsw;
|
||||||
end; {else}
|
end; {else}
|
||||||
end {if}
|
end {if}
|
||||||
else if op^.left^.token.kind
|
else if op^.left^.token.kind in [longlongconst,ulonglongconst,
|
||||||
in [longlongconst,ulonglongconst] then begin
|
intconst,uintconst,longconst,ulongconst] then begin
|
||||||
|
|
||||||
{evaluate a constant operation}
|
{evaluate a constant operation with long long operand}
|
||||||
ekind := op^.left^.token.kind;
|
ekind := op^.left^.token.kind;
|
||||||
llop1 := op^.left^.token.qval;
|
if kind = preprocessorExpression then
|
||||||
|
ekind := PPKind(op^.left^.token);
|
||||||
|
GetLongLongVal(llop1, op^.left^.token);
|
||||||
dispose(op^.left);
|
dispose(op^.left);
|
||||||
op^.left := nil;
|
op^.left := nil;
|
||||||
case op^.token.kind of
|
case op^.token.kind of
|
||||||
|
|
20
Scanner.pas
20
Scanner.pas
|
@ -2845,6 +2845,9 @@ if ch in ['a','d','e','i','l','p','u','w'] then begin
|
||||||
{ 16 - check for stack errors }
|
{ 16 - check for stack errors }
|
||||||
FlagPragmas(p_debug);
|
FlagPragmas(p_debug);
|
||||||
NumericDirective;
|
NumericDirective;
|
||||||
|
if expressionType^.kind = scalarType then
|
||||||
|
if expressionType^.baseType in [cgQuad,cgUQuad] then
|
||||||
|
expressionValue := llExpressionValue.lo;
|
||||||
val := long(expressionValue).lsw;
|
val := long(expressionValue).lsw;
|
||||||
rangeCheck := odd(val);
|
rangeCheck := odd(val);
|
||||||
debugFlag := odd(val >> 1);
|
debugFlag := odd(val >> 1);
|
||||||
|
@ -2859,7 +2862,10 @@ if ch in ['a','d','e','i','l','p','u','w'] then begin
|
||||||
end {else}
|
end {else}
|
||||||
else if token.name^ = 'lint' then begin
|
else if token.name^ = 'lint' then begin
|
||||||
FlagPragmas(p_lint);
|
FlagPragmas(p_lint);
|
||||||
NumericDirective;
|
NumericDirective;
|
||||||
|
if expressionType^.kind = scalarType then
|
||||||
|
if expressionType^.baseType in [cgQuad,cgUQuad] then
|
||||||
|
expressionValue := llExpressionValue.lo;
|
||||||
lint := long(expressionValue).lsw;
|
lint := long(expressionValue).lsw;
|
||||||
lintIsError := true;
|
lintIsError := true;
|
||||||
if token.kind = semicolonch then begin
|
if token.kind = semicolonch then begin
|
||||||
|
@ -2893,7 +2899,10 @@ if ch in ['a','d','e','i','l','p','u','w'] then begin
|
||||||
{ 16 - common subexpression elimination }
|
{ 16 - common subexpression elimination }
|
||||||
{ 32 - loop invariant removal }
|
{ 32 - loop invariant removal }
|
||||||
FlagPragmas(p_optimize);
|
FlagPragmas(p_optimize);
|
||||||
NumericDirective;
|
NumericDirective;
|
||||||
|
if expressionType^.kind = scalarType then
|
||||||
|
if expressionType^.baseType in [cgQuad,cgUQuad] then
|
||||||
|
expressionValue := llExpressionValue.lo;
|
||||||
val := long(expressionValue).lsw;
|
val := long(expressionValue).lsw;
|
||||||
peepHole := odd(val);
|
peepHole := odd(val);
|
||||||
npeepHole := odd(val >> 1);
|
npeepHole := odd(val >> 1);
|
||||||
|
@ -2990,7 +2999,10 @@ if ch in ['a','d','e','i','l','p','u','w'] then begin
|
||||||
{ 8 - allow // comments }
|
{ 8 - allow // comments }
|
||||||
{ 16 - allow mixed decls & use C99 scope rules }
|
{ 16 - allow mixed decls & use C99 scope rules }
|
||||||
FlagPragmas(p_ignore);
|
FlagPragmas(p_ignore);
|
||||||
NumericDirective;
|
NumericDirective;
|
||||||
|
if expressionType^.kind = scalarType then
|
||||||
|
if expressionType^.baseType in [cgQuad,cgUQuad] then
|
||||||
|
expressionValue := llExpressionValue.lo;
|
||||||
val := long(expressionValue).lsw;
|
val := long(expressionValue).lsw;
|
||||||
skipIllegalTokens := odd(val);
|
skipIllegalTokens := odd(val);
|
||||||
allowLongIntChar := odd(val >> 1);
|
allowLongIntChar := odd(val >> 1);
|
||||||
|
@ -3342,6 +3354,8 @@ if c2 in ['f','F'] then begin {allow F designator on reals}
|
||||||
NextChar;
|
NextChar;
|
||||||
end; {if}
|
end; {if}
|
||||||
numString[0] := chr(stringIndex); {set the length of the string}
|
numString[0] := chr(stringIndex); {set the length of the string}
|
||||||
|
if doingPPExpression then
|
||||||
|
isLongLong := true;
|
||||||
if isReal then begin {convert a real constant}
|
if isReal then begin {convert a real constant}
|
||||||
token.kind := doubleConst;
|
token.kind := doubleConst;
|
||||||
token.class := doubleConstant;
|
token.class := doubleConstant;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user