Browse Source

fcl-passrc: fixed treating big ints as extended

git-svn-id: trunk@41155 -
Mattias Gaertner 6 years ago
parent
commit
dd49ad6183
2 changed files with 19 additions and 7 deletions
  1. 2 2
      packages/fcl-passrc/src/pasresolveeval.pas
  2. 17 5
      packages/fcl-passrc/src/pasresolver.pp

+ 2 - 2
packages/fcl-passrc/src/pasresolveeval.pas

@@ -4872,14 +4872,14 @@ begin
     revkInt:
       {$IFDEF Pas2js}
       if ShiftSize=32 then
-        uint := (TResEvalInt(Value).Int div $100000000) and Mask;
+        uint := longword(TResEvalInt(Value).Int div $100000000)
       else
       {$ENDIF}
         uint := (TResEvalInt(Value).Int shr ShiftSize) and Mask;
     revkUInt:
       {$IFDEF Pas2js}
       if ShiftSize=32 then
-        uint := (TResEvalUInt(Value).UInt div $100000000) and Mask;
+        uint := longword(TResEvalUInt(Value).UInt div $100000000)
       else
       {$ENDIF}
         uint := (TResEvalUInt(Value).UInt shr ShiftSize) and Mask;

+ 17 - 5
packages/fcl-passrc/src/pasresolver.pp

@@ -406,6 +406,7 @@ type
   TResolveBaseTypes = set of TResolverBaseType;
 const
   btIntMax = {$ifdef HasInt64}btInt64{$else}btIntDouble{$endif};
+  btUIntMax = {$ifdef HasInt64}btQWord{$else}btUIntDouble{$endif};
   btAllInteger = [btByte,btShortInt,btWord,btSmallInt,btIntSingle,btUIntSingle,
     btLongWord,btLongint,btIntDouble,btUIntDouble
     {$ifdef HasInt64}
@@ -2026,7 +2027,7 @@ type
     procedure GetIntegerProps(bt: TResolverBaseType; out Precision: word; out Signed: boolean);
     function GetIntegerRange(bt: TResolverBaseType; out MinVal, MaxVal: TMaxPrecInt): boolean;
     function GetIntegerBaseType(Precision: word; Signed: boolean; ErrorEl: TPasElement): TResolverBaseType;
-    function GetSmallestIntegerBaseType(MinVal, MaxVal: TMaxPrecInt): TResolverBaseType;
+    function GetSmallestIntegerBaseType(MinVal, MaxVal: TMaxPrecInt): TResolverBaseType; // returns BaseTypeExtended if too big
     function GetCombinedChar(const Char1, Char2: TPasResolverResult; ErrorEl: TPasElement): TResolverBaseType; virtual;
     function GetCombinedString(const Str1, Str2: TPasResolverResult; ErrorEl: TPasElement): TResolverBaseType; virtual;
     function IsElementSkipped(El: TPasElement): boolean; virtual;
@@ -21230,8 +21231,10 @@ begin
                 Int:=TResEvalInt(Value).Int;
                 bt:=GetSmallestIntegerBaseType(Int,Int);
                 end;
+              {$IFDEF HasInt64}
               revkUInt:
                 bt:=btQWord;
+              {$ENDIF}
               else
                 bt:=BaseTypeExtended;
               end;
@@ -22540,6 +22543,7 @@ end;
 
 function TPasResolver.GetSmallestIntegerBaseType(MinVal, MaxVal: TMaxPrecInt
   ): TResolverBaseType;
+// returns BaseTypeExtended if too big
 var
   V: TMaxPrecInt;
 begin
@@ -22555,14 +22559,18 @@ begin
       Result:=btShortInt
     else if V<=high(SmallInt) then
       Result:=btSmallInt
-    else if (BaseTypes[btIntSingle]<>nil) and (V<MaxSafeIntSingle) then
+    else if (BaseTypes[btIntSingle]<>nil) and (V<=MaxSafeIntSingle) then
       Result:=btIntSingle
     else if V<=High(Longint) then
       Result:=btLongint
-    else if (BaseTypes[btIntDouble]<>nil) and (V<MaxSafeIntDouble) then
+    else if (BaseTypes[btIntDouble]<>nil) and (V<=MaxSafeIntDouble) then
       Result:=btIntDouble
     else
+      begin
       Result:=btIntMax;
+      if BaseTypes[Result]=nil then
+        Result:=BaseTypeExtended;
+      end;
     end
   else
     begin
@@ -22571,14 +22579,18 @@ begin
       Result:=btByte
     else if V<=high(Word) then
       Result:=btWord
-    else if (BaseTypes[btUIntSingle]<>nil) and (V<MaxSafeIntSingle) then
+    else if (BaseTypes[btUIntSingle]<>nil) and (V<=MaxSafeIntSingle) then
       Result:=btUIntSingle
     else if V<=High(LongWord) then
       Result:=btLongWord
-    else if (BaseTypes[btUIntDouble]<>nil) and (V<MaxSafeIntDouble) then
+    else if (BaseTypes[btUIntDouble]<>nil) and (V<=MaxSafeIntDouble) then
       Result:=btUIntDouble
     else
+      begin
       Result:=btIntMax;
+      if BaseTypes[Result]=nil then
+        Result:=BaseTypeExtended;
+      end;
     end;
 end;