pastojs: fixed typeinfo arg dyn array

git-svn-id: trunk@35867 -
This commit is contained in:
Mattias Gaertner 2017-04-20 21:16:58 +00:00
parent 1c3b8c70f7
commit 798c1c71e6
2 changed files with 72 additions and 25 deletions

View File

@ -237,6 +237,7 @@ Works:
- built-in function typeinfo(): Pointer/TTypeInfo/...; - built-in function typeinfo(): Pointer/TTypeInfo/...;
- typeinfo(class) -> class.$rtti - typeinfo(class) -> class.$rtti
- WPO skip not used typeinfo - WPO skip not used typeinfo
- open array param
- pointer - pointer
- compare with and assign nil - compare with and assign nil
- ECMAScript6: - ECMAScript6:
@ -245,13 +246,10 @@ Works:
ToDos: ToDos:
- RTTI - RTTI
- open array param
- codetools function typeinfo
- jsinteger (pasresolver: btIntDouble) - jsinteger (pasresolver: btIntDouble)
- class property - class property
- defaultvalue - defaultvalue
- type alias type - type alias type
- typinfo.pp functions to get/setprop
- documentation - documentation
- warn int64 - warn int64
- move local types to unit scope - move local types to unit scope
@ -461,6 +459,7 @@ type
pbivnSelf, pbivnSelf,
pbivnWith, pbivnWith,
pbitnAnonymousPostfix, pbitnAnonymousPostfix,
pbitnIntDouble,
pbitnTI, pbitnTI,
pbitnTIClass, pbitnTIClass,
pbitnTIClassRef, pbitnTIClassRef,
@ -473,7 +472,8 @@ type
pbitnTIRecord, pbitnTIRecord,
pbitnTIRefToProcVar, pbitnTIRefToProcVar,
pbitnTISet, pbitnTISet,
pbitnTIStaticArray pbitnTIStaticArray,
pbitnUIntDouble
); );
const const
@ -555,6 +555,7 @@ const
'Self', 'Self',
'$with', '$with',
'$a', '$a',
'NativeInt',
'tTypeInfo', 'tTypeInfo',
'tTypeInfoClass', 'tTypeInfoClass',
'tTypeInfoClassRef', 'tTypeInfoClassRef',
@ -567,7 +568,8 @@ const
'tTypeInfoRecord', 'tTypeInfoRecord',
'tTypeInfoRefToProcVar', 'tTypeInfoRefToProcVar',
'tTypeInfoSet', 'tTypeInfoSet',
'tTypeInfoStaticArray' 'tTypeInfoStaticArray',
'NativeUInt'
); );
JSReservedWords: array[0..113] of string = ( JSReservedWords: array[0..113] of string = (
@ -690,8 +692,8 @@ const
const const
ClassVarModifiersType = [vmClass,vmStatic]; ClassVarModifiersType = [vmClass,vmStatic];
LowJSInteger = -$10000000000000; LowJSNativeInt = -$10000000000000;
HighJSInteger = $fffffffffffff; HighJSNativeInt = $fffffffffffff;
LowJSBoolean = false; LowJSBoolean = false;
HighJSBoolean = true; HighJSBoolean = true;
Type Type
@ -777,22 +779,19 @@ const
btString, btString,
btDouble, btDouble,
btBoolean, btBoolean,
//btByteBool, btByteBool,
//btWordBool, btWordBool,
//btLongBool, btLongBool,
//btQWordBool, btQWordBool,
btByte, btByte,
btShortInt, btShortInt,
btWord, btWord,
btSmallInt, btSmallInt,
btLongWord, btLongWord,
btLongint, btLongint,
//btQWord, btUIntDouble,
btInt64, btIntDouble,
btPointer btPointer
//btFile,
//btText,
//btVariant
]; ];
bfAllJSBaseProcs = bfAllStandardProcs; bfAllJSBaseProcs = bfAllStandardProcs;
@ -802,8 +801,7 @@ const
btAllJSFloats = [btDouble]; btAllJSFloats = [btDouble];
btAllJSBooleans = [btBoolean]; btAllJSBooleans = [btBoolean];
btAllJSInteger = [btByte,btShortInt,btWord,btSmallInt,btLongWord,btLongint, btAllJSInteger = [btByte,btShortInt,btWord,btSmallInt,btLongWord,btLongint,
btInt64 // ToDo: remove int64 btIntDouble,btUIntDouble];
];
btAllJSValueSrcTypes = [btNil,btUntyped,btPointer]+btAllJSInteger btAllJSValueSrcTypes = [btNil,btUntyped,btPointer]+btAllJSInteger
+btAllJSStringAndChars+btAllJSFloats+btAllJSBooleans; +btAllJSStringAndChars+btAllJSFloats+btAllJSBooleans;
btAllJSValueTypeCastTo = btAllJSInteger btAllJSValueTypeCastTo = btAllJSInteger
@ -1300,6 +1298,7 @@ type
pfVar = 1; pfVar = 1;
pfConst = 2; pfConst = 2;
pfOut = 4; pfOut = 4;
pfArray = 8;
// TProcedureFlag // TProcedureFlag
pfStatic = 1; pfStatic = 1;
pfVarargs = 2; pfVarargs = 2;
@ -2570,6 +2569,7 @@ begin
AnonymousElTypePostfix:=Pas2JSBuiltInNames[pbitnAnonymousPostfix]; AnonymousElTypePostfix:=Pas2JSBuiltInNames[pbitnAnonymousPostfix];
BaseTypeChar:=btWideChar; BaseTypeChar:=btWideChar;
BaseTypeString:=btUnicodeString; BaseTypeString:=btUnicodeString;
BaseTypeLength:=btIntDouble;
end; end;
destructor TPas2JSResolver.Destroy; destructor TPas2JSResolver.Destroy;
@ -2596,7 +2596,11 @@ begin
if InvalidProcs<>[] then if InvalidProcs<>[] then
for bf in InvalidProcs do for bf in InvalidProcs do
RaiseInternalError(20170409180246,ResolverBuiltInProcNames[bf]); RaiseInternalError(20170409180246,ResolverBuiltInProcNames[bf]);
inherited AddObjFPCBuiltInIdentifiers(TheBaseTypes,TheBaseProcs); inherited AddObjFPCBuiltInIdentifiers(TheBaseTypes-[btUIntDouble,btIntDouble],TheBaseProcs);
if btUIntDouble in TheBaseTypes then
AddBaseType(Pas2JSBuiltInNames[pbitnUIntDouble],btUIntDouble);
if btIntDouble in TheBaseTypes then
AddBaseType(Pas2JSBuiltInNames[pbitnIntDouble],btIntDouble);
end; end;
function TPas2JSResolver.CheckTypeCastRes(const FromResolved, function TPas2JSResolver.CheckTypeCastRes(const FromResolved,
@ -8908,6 +8912,7 @@ var
Param: TJSArrayLiteral; Param: TJSArrayLiteral;
ArgName: String; ArgName: String;
Flags: Integer; Flags: Integer;
ArrType: TPasArrayType;
begin begin
// for each param add "["argname",argtype,flags]" Note: flags only if >0 // for each param add "["argname",argtype,flags]" Note: flags only if >0
Param:=TJSArrayLiteral(CreateElement(TJSArrayLiteral,Arg)); Param:=TJSArrayLiteral(CreateElement(TJSArrayLiteral,Arg));
@ -8915,14 +8920,21 @@ begin
// add "argname" // add "argname"
ArgName:=TransformVariableName(Arg,Arg.Name,AContext); ArgName:=TransformVariableName(Arg,Arg.Name,AContext);
Param.Elements.AddElement.Expr:=CreateLiteralString(Arg,ArgName); Param.Elements.AddElement.Expr:=CreateLiteralString(Arg,ArgName);
Flags:=0;
// add "argtype" // add "argtype"
if Arg.ArgType=nil then if Arg.ArgType=nil then
// untyped // untyped
Param.Elements.AddElement.Expr:=CreateLiteralNull(Arg) Param.Elements.AddElement.Expr:=CreateLiteralNull(Arg)
else if (Arg.ArgType.Name='') and (Arg.ArgType.ClassType=TPasArrayType) then
begin
// open array param
inc(Flags,pfArray);
ArrType:=TPasArrayType(Arg.ArgType);
Param.Elements.AddElement.Expr:=CreateTypeInfoRef(ArrType.ElType,AContext,Arg);
end
else else
Param.Elements.AddElement.Expr:=CreateTypeInfoRef(Arg.ArgType,AContext,Arg); Param.Elements.AddElement.Expr:=CreateTypeInfoRef(Arg.ArgType,AContext,Arg);
// add flags // add flags
Flags:=0;
case Arg.Access of case Arg.Access of
argDefault: ; argDefault: ;
argConst: inc(Flags,pfConst); argConst: inc(Flags,pfConst);

View File

@ -457,6 +457,7 @@ type
Procedure TestRTTI_PublishedFieldExternalFail; Procedure TestRTTI_PublishedFieldExternalFail;
Procedure TestRTTI_Class_Field; Procedure TestRTTI_Class_Field;
Procedure TestRTTI_Class_Method; Procedure TestRTTI_Class_Method;
Procedure TestRTTI_Class_MethodArgFlags;
Procedure TestRTTI_Class_Property; Procedure TestRTTI_Class_Property;
Procedure TestRTTI_Class_PropertyParams; Procedure TestRTTI_Class_PropertyParams;
// ToDo: property default value // ToDo: property default value
@ -1394,10 +1395,12 @@ begin
Add(' b2: boolean = true;'); Add(' b2: boolean = true;');
Add(' d2: double = 5.6;'); Add(' d2: double = 5.6;');
Add(' i3: longint = $707;'); Add(' i3: longint = $707;');
Add(' i4: int64 = 4503599627370495;'); Add(' i4: nativeint = 4503599627370495;');
Add(' i5: int64 = -4503599627370496;'); Add(' i5: nativeint = -4503599627370496;');
Add(' i6: int64 = $fffffffffffff;'); Add(' i6: nativeint = $fffffffffffff;');
Add(' i7: int64 = -$10000000000000;'); Add(' i7: nativeint = -$10000000000000;');
Add(' u8: nativeuint = $fffffffffffff;');
Add(' u9: nativeuint = $0000000000000;');
Add('begin'); Add('begin');
ConvertProgram; ConvertProgram;
CheckSource('TestVarBaseTypes', CheckSource('TestVarBaseTypes',
@ -1416,7 +1419,9 @@ begin
'this.i4= 4503599627370495;', 'this.i4= 4503599627370495;',
'this.i5= -4503599627370496;', 'this.i5= -4503599627370496;',
'this.i6= 0xfffffffffffff;', 'this.i6= 0xfffffffffffff;',
'this.i7=-0x10000000000000;' 'this.i7=-0x10000000000000;',
'this.u8= 0xfffffffffffff;',
'this.u9= 0x0000000000000;'
]), ]),
''); '');
end; end;
@ -11891,6 +11896,36 @@ begin
''])); '']));
end; end;
procedure TTestModule.TestRTTI_Class_MethodArgFlags;
begin
Converter.Options:=Converter.Options-[coNoTypeInfo];
StartProgram(false);
Add('type');
Add(' TObject = class');
Add(' published');
Add(' procedure OpenArray(const Args: array of string); virtual; abstract;');
Add(' procedure ByRef(var Value: longint; out Item: longint); virtual; abstract;');
Add(' procedure Untyped(var Value; out Item); virtual; abstract;');
Add(' end;');
Add('begin');
ConvertProgram;
CheckSource('TestRTTI_Class_MethodOpenArray',
LinesToStr([ // statements
'rtl.createClass($mod, "TObject", null, function () {',
' this.$init = function () {',
' };',
' this.$final = function () {',
' };',
' var $r = this.$rtti;',
'$r.addMethod("OpenArray", 0, [["Args", rtl.string, 10]]);',
'$r.addMethod("ByRef", 0, [["Value", rtl.longint, 1], ["Item", rtl.longint, 4]]);',
'$r.addMethod("Untyped", 0, [["Value", null, 1], ["Item", null, 4]]);',
'});',
'']),
LinesToStr([ // $mod.$main
'']));
end;
procedure TTestModule.TestRTTI_Class_Property; procedure TTestModule.TestRTTI_Class_Property;
begin begin
Converter.Options:=Converter.Options-[coNoTypeInfo]; Converter.Options:=Converter.Options-[coNoTypeInfo];