pas2js: fixed system.inc()

This commit is contained in:
mattias 2020-06-20 09:35:13 +00:00
parent ca81b87183
commit a9af2a4169
2 changed files with 43 additions and 3 deletions

View File

@ -10841,11 +10841,16 @@ var
IsInc: Boolean;
AddJS: TJSAdditiveExpression;
AssignContext: TAssignContext;
aResolver: TPas2JSResolver;
begin
Result:=nil;
IsInc:=CompareText((El.Value as TPrimitiveExpr).Value,'inc')=0;
aResolver:=AContext.Resolver;
Expr:=aResolver.GetRightMostExpr(El.Value);
if not (Expr is TPrimitiveExpr) then
RaiseNotSupported(Expr,AContext,20200620113218);
IsInc:=CompareText(TPrimitiveExpr(Expr).Value,'inc')=0;
Expr:=El.Params[0];
AContext.Resolver.ComputeElement(Expr,ExprResolved,[]);
aResolver.ComputeElement(Expr,ExprResolved,[]);
// convert value
if length(El.Params)=1 then
@ -10897,7 +10902,7 @@ begin
end;
AssignContext:=TAssignContext.Create(Expr,nil,AContext);
AContext.Resolver.ComputeElement(Expr,AssignContext.LeftResolved,[rcNoImplicitProc]);
aResolver.ComputeElement(Expr,AssignContext.LeftResolved,[rcNoImplicitProc]);
SetResolverValueExpr(AssignContext.RightResolved,
AssignContext.LeftResolved.BaseType,AssignContext.LeftResolved.LoTypeEl,
AssignContext.LeftResolved.HiTypeEl,Expr,[rrfReadable]);

View File

@ -265,6 +265,7 @@ type
Procedure TestIntegerTypecasts;
Procedure TestInteger_BitwiseShrNativeInt;
Procedure TestInteger_BitwiseShlNativeInt;
Procedure TestInteger_SystemFunc;
Procedure TestCurrency;
Procedure TestForBoolDo;
Procedure TestForIntDo;
@ -6747,6 +6748,40 @@ begin
'']));
end;
procedure TTestModule.TestInteger_SystemFunc;
begin
StartProgram(true);
Add([
'var',
' i: byte;',
' s: string;',
'begin',
' system.inc(i);',
' system.str(i,s);',
' s:=system.str(i);',
' i:=system.low(i);',
' i:=system.high(i);',
' i:=system.pred(i);',
' i:=system.succ(i);',
'']);
ConvertProgram;
CheckResolverUnexpectedHints;
CheckSource('TestInteger_SystemFunc',
LinesToStr([
'this.i = 0;',
'this.s = "";',
'']),
LinesToStr([
'$mod.i += 1;',
'$mod.s = "" + $mod.i;',
'$mod.s = "" + $mod.i;',
'$mod.i = 0;',
'$mod.i = 255;',
'$mod.i = $mod.i - 1;',
'$mod.i = $mod.i + 1;',
'']));
end;
procedure TTestModule.TestCurrency;
begin
StartProgram(false);