fcl-js: unit out dir

This commit is contained in:
mattias 2019-02-26 09:06:41 +00:00
parent 1df109333e
commit a90481eb85
7 changed files with 68 additions and 33 deletions

View File

@ -87,6 +87,7 @@
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<OtherUnitFiles Value="../../fcl-json/src;../src"/>
<UnitOutputDirectory Value="units/$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<CodeGeneration>
<Checks>
@ -102,9 +103,6 @@
</CodeGeneration>
<Other>
<CustomOptions Value="-dVerboseSrcMap"/>
<OtherDefines Count="1">
<Define0 Value="VerboseSrcMap"/>
</OtherDefines>
</Other>
</CompilerOptions>
<Debugging>

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="10"/>
<Version Value="11"/>
<General>
<Flags>
<SaveOnlyProjectUnits Value="True"/>
@ -21,14 +21,19 @@
</BuildModes>
<PublishOptions>
<Version Value="2"/>
<IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
<ExcludeFileFilter Value="*.(bak|ppu|o|so);*~;backup"/>
</PublishOptions>
<RunParams>
<local>
<FormatVersion Value="1"/>
<CommandLineParams Value="--suite=TTestRecordTypeParser.TestFieldAndClassVar"/>
</local>
<FormatVersion Value="2"/>
<Modes Count="1">
<Mode0 Name="default">
<local>
<CommandLineParams Value="--suite=TTestRecordTypeParser.TestFieldAndClassVar"/>
</local>
</Mode0>
</Modes>
</RunParams>
<RequiredPackages Count="1">
<Item1>

View File

@ -1218,7 +1218,7 @@ const
btIntDouble,btUIntDouble,
btCurrency // in pas2js currency is more like an integer, instead of float
];
btAllJSValueSrcTypes = [btNil,btUntyped,btPointer]+btAllJSInteger
btAllJSValueSrcTypes = [btNil,btUntyped,btPointer,btSet]+btAllJSInteger
+btAllJSStringAndChars+btAllJSFloats+btAllJSBooleans;
btAllJSValueTypeCastTo = btAllJSInteger
+btAllJSStringAndChars+btAllJSFloats+btAllJSBooleans+[btPointer];
@ -9808,8 +9808,6 @@ var
Call: TJSCallExpression;
NotExpr: TJSUnaryNotExpression;
AddExpr: TJSAdditiveExpressionPlus;
TypeEl: TPasType;
C: TClass;
Int: TMaxPrecInt;
aResolver: TPas2JSResolver;
begin
@ -10072,20 +10070,6 @@ begin
begin
// type cast to jsvalue
Result:=ConvertExpression(Param,AContext);
// Note: convert value first in case it raises an exception
if ParamResolved.BaseType=btContext then
begin
TypeEl:=ParamResolved.LoTypeEl;
C:=TypeEl.ClassType;
if (C=TPasClassType) or (C=TPasRecordType) then
begin
// TObject(jsvalue) -> rtl.getObject(jsvalue)
Call:=CreateCallExpression(El);
Call.Expr:=CreateMemberExpression([GetBIName(pbivnRTL),GetBIName(pbifnGetObject)]);
Call.AddArg(Result);
Result:=Call;
end;
end;
exit;
end;
end;

View File

@ -48,6 +48,8 @@ procedure TPas2JSAnalyzer.UseExpr(El: TPasExpr);
i: Integer;
ArgType: TPasType;
ModScope: TPas2JSModuleScope;
aMod: TPasModule;
SystemVarRecs: TPasFunction;
begin
if Args=nil then exit;
for i:=0 to Args.Count-1 do
@ -58,10 +60,13 @@ procedure TPas2JSAnalyzer.UseExpr(El: TPasExpr);
and (TPasArrayType(ArgType).ElType=nil) then
begin
// array of const
ModScope:=NoNil(Resolver.RootElement.CustomData) as TPas2JSModuleScope;
if ModScope.SystemVarRecs=nil then
aMod:=El.GetModule;
ModScope:=NoNil(aMod.CustomData) as TPas2JSModuleScope;
SystemVarRecs:=ModScope.SystemVarRecs;
if SystemVarRecs=nil then
RaiseNotSupported(20190216104347,El);
UseProcedure(ModScope.SystemVarRecs);
MarkImplScopeRef(El,SystemVarRecs,psraRead);
UseProcedure(SystemVarRecs);
break;
end;
end;

View File

@ -720,6 +720,7 @@ type
// jsvalue
Procedure TestJSValue_AssignToJSValue;
Procedure TestJSValue_TypeCastToBaseType;
Procedure TestJSValue_TypecastToJSValue;
Procedure TestJSValue_Equal;
Procedure TestJSValue_If;
Procedure TestJSValue_Not;
@ -17428,7 +17429,7 @@ begin
'$mod.v = $mod.IntfVar;',
'$mod.IntfVar = rtl.getObject($mod.v);',
'if (rtl.isExt($mod.v, $mod.IBird, 1)) ;',
'$mod.v = rtl.getObject($mod.IntfVar);',
'$mod.v = $mod.IntfVar;',
'$mod.v = $mod.IBird;',
'']));
end;
@ -24882,6 +24883,50 @@ begin
'']));
end;
procedure TTestModule.TestJSValue_TypecastToJSValue;
begin
StartProgram(false);
Add([
'type',
' TArr = array of word;',
' TRec = record end;',
' TSet = set of boolean;',
'procedure Fly(v: jsvalue);',
'begin',
'end;',
'var',
' a: TArr;',
' r: TRec;',
' s: TSet;',
'begin',
' Fly(jsvalue(a));',
' Fly(jsvalue(r));',
' Fly(jsvalue(s));',
'']);
ConvertProgram;
CheckSource('TestJSValue_TypecastToJSValue',
LinesToStr([ // statements
'rtl.recNewT($mod, "TRec", function () {',
' this.$eq = function (b) {',
' return true;',
' };',
' this.$assign = function (s) {',
' return this;',
' };',
'});',
'this.Fly = function (v) {',
'};',
'this.a = [];',
'this.r = $mod.TRec.$new();',
'this.s = {};',
'']),
LinesToStr([ // $mod.$main
'$mod.Fly($mod.a);',
'$mod.Fly($mod.r);',
'$mod.Fly($mod.s);',
'']));
end;
procedure TTestModule.TestJSValue_Equal;
begin
StartProgram(false);

View File

@ -536,7 +536,7 @@ end;
procedure TTestCLI_Precompile.TestPCU_CheckVersionSystem;
var
aFile: TCLIFile;
s, JSFilename, ExpectedSrc: string;
s, JSFilename, ExpectedSrc, VerStr: string;
begin
AddUnit('src/system.pp',[
'type integer = longint;'],
@ -549,10 +549,11 @@ begin
aFile:=FindFile(JSFilename);
AssertNotNull('File not found '+JSFilename,aFile);
writeln('TTestCLI_Precompile.TestPCU_CheckVersionMain ',aFile.Source);
VerStr:=IntToStr((VersionMajor*100+VersionMinor)*100+VersionRelease);
ExpectedSrc:=LinesToStr([
UTF8BOM+'rtl.module("system",[],function () {',
' "use strict";',
' rtl.checkVersion(10301);',
' rtl.checkVersion('+VerStr+');',
' var $mod = this;',
'});']);
if not CheckSrcDiff(ExpectedSrc,aFile.Source,s) then

View File

@ -111,9 +111,6 @@
</CodeGeneration>
<Other>
<CustomOptions Value="-dVerbosePas2JS"/>
<OtherDefines Count="1">
<Define0 Value="VerbosePas2JS"/>
</OtherDefines>
</Other>
</CompilerOptions>
<Debugging>