mirror of
https://gitlab.com/freepascal.org/fpc/pas2js.git
synced 2025-09-14 14:39:04 +02:00
pastojs: ord(integer)
This commit is contained in:
parent
ea2fcf3efb
commit
e1d0d3b185
@ -19050,19 +19050,19 @@ begin
|
||||
exit(cIncompatible);
|
||||
Params:=TParamsExpr(Expr);
|
||||
|
||||
// first param: bool, enum or char
|
||||
// first param: bool, integer, enum or char
|
||||
Param:=Params.Params[0];
|
||||
ComputeElement(Param,ParamResolved,[]);
|
||||
Result:=cIncompatible;
|
||||
if rrfReadable in ParamResolved.Flags then
|
||||
begin
|
||||
if ParamResolved.BaseType in (btAllBooleans+btAllChars) then
|
||||
if ParamResolved.BaseType in btArrayRangeTypes then
|
||||
Result:=cExact
|
||||
else if (ParamResolved.BaseType=btContext) and (ParamResolved.LoTypeEl is TPasEnumType) then
|
||||
Result:=cExact
|
||||
else if ParamResolved.BaseType=btRange then
|
||||
begin
|
||||
if ParamResolved.SubType in btAllBooleans+btAllChars then
|
||||
if ParamResolved.SubType in btArrayRangeTypes then
|
||||
Result:=cExact
|
||||
else if ParamResolved.SubType=btContext then
|
||||
begin
|
||||
|
@ -3350,8 +3350,10 @@ begin
|
||||
' i2: TInt2;',
|
||||
'begin',
|
||||
' i:=i2;',
|
||||
' if i=i2 then ;']);
|
||||
' if i=i2 then ;',
|
||||
' i:=ord(i);']);
|
||||
ParseProgram;
|
||||
CheckResolverUnexpectedHints;
|
||||
end;
|
||||
|
||||
procedure TTestResolver.TestIntegerRangeHighLowerLowFail;
|
||||
|
@ -13348,6 +13348,15 @@ begin
|
||||
Result:=Add;
|
||||
exit;
|
||||
end
|
||||
else if bt in btAllJSInteger then
|
||||
begin
|
||||
// ord(integer)
|
||||
Result:=CheckOrdConstant(aResolver,Param);
|
||||
if Result<>nil then exit;
|
||||
// ord(integer) -> integer
|
||||
Result:=ConvertExpression(Param,AContext);
|
||||
exit;
|
||||
end
|
||||
else if bt=btContext then
|
||||
begin
|
||||
C:=ParamResolved.LoTypeEl.ClassType;
|
||||
|
@ -7135,7 +7135,9 @@ begin
|
||||
'begin',
|
||||
' i:=i2;',
|
||||
' i:=default(TMyInt);',
|
||||
' if i=i2 then ;']);
|
||||
' if i=i2 then ;',
|
||||
' i:=ord(i2);',
|
||||
'']);
|
||||
ConvertProgram;
|
||||
CheckSource('TestIntegerRange',
|
||||
LinesToStr([
|
||||
@ -7156,6 +7158,7 @@ begin
|
||||
'$mod.i = $mod.i2;',
|
||||
'$mod.i = -1;',
|
||||
'if ($mod.i === $mod.i2) ;',
|
||||
'$mod.i = $mod.i2;',
|
||||
'']));
|
||||
end;
|
||||
|
||||
@ -7270,6 +7273,7 @@ begin
|
||||
' i:=system.high(i);',
|
||||
' i:=system.pred(i);',
|
||||
' i:=system.succ(i);',
|
||||
' i:=system.ord(i);',
|
||||
'']);
|
||||
ConvertProgram;
|
||||
CheckResolverUnexpectedHints;
|
||||
@ -7286,6 +7290,7 @@ begin
|
||||
'$mod.i = 255;',
|
||||
'$mod.i = $mod.i - 1;',
|
||||
'$mod.i = $mod.i + 1;',
|
||||
'$mod.i = $mod.i;',
|
||||
'']));
|
||||
end;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user