mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-14 09:09:19 +02:00
pastojs: check name of external class constructor
git-svn-id: trunk@40882 -
This commit is contained in:
parent
ccdc0ce767
commit
73ebd10999
@ -487,7 +487,7 @@ const
|
|||||||
nVirtualMethodNameMustMatchExternal = 4013;
|
nVirtualMethodNameMustMatchExternal = 4013;
|
||||||
nPublishedNameMustMatchExternal = 4014;
|
nPublishedNameMustMatchExternal = 4014;
|
||||||
nInvalidVariableModifier = 4015;
|
nInvalidVariableModifier = 4015;
|
||||||
nNoArgumentsAllowedForExternalObjectConstructor = 4016;
|
nExternalObjectConstructorMustBeNamedNew = 4016;
|
||||||
nNewInstanceFunctionMustBeVirtual = 4017;
|
nNewInstanceFunctionMustBeVirtual = 4017;
|
||||||
nNewInstanceFunctionMustHaveTwoParameters = 4018;
|
nNewInstanceFunctionMustHaveTwoParameters = 4018;
|
||||||
nNewInstanceFunctionMustNotHaveOverloadAtX = 4019;
|
nNewInstanceFunctionMustNotHaveOverloadAtX = 4019;
|
||||||
@ -515,7 +515,7 @@ resourcestring
|
|||||||
sVirtualMethodNameMustMatchExternal = 'Virtual method name must match external';
|
sVirtualMethodNameMustMatchExternal = 'Virtual method name must match external';
|
||||||
sInvalidVariableModifier = 'Invalid variable modifier "%s"';
|
sInvalidVariableModifier = 'Invalid variable modifier "%s"';
|
||||||
sPublishedNameMustMatchExternal = 'Published name must match external';
|
sPublishedNameMustMatchExternal = 'Published name must match external';
|
||||||
sNoArgumentsAllowedForExternalObjectConstructor = 'no arguments allowed for external object constructor';
|
sExternalObjectConstructorMustBeNamedNew = 'external object constructor must be named "new"';
|
||||||
sNewInstanceFunctionMustBeVirtual = 'NewInstance function must be virtual';
|
sNewInstanceFunctionMustBeVirtual = 'NewInstance function must be virtual';
|
||||||
sNewInstanceFunctionMustHaveTwoParameters = 'NewInstance function must have two parameters';
|
sNewInstanceFunctionMustHaveTwoParameters = 'NewInstance function must have two parameters';
|
||||||
sNewInstanceFunctionMustNotHaveOverloadAtX = 'NewInstance function must not have overload at %s';
|
sNewInstanceFunctionMustNotHaveOverloadAtX = 'NewInstance function must not have overload at %s';
|
||||||
@ -3728,12 +3728,9 @@ begin
|
|||||||
RaiseMsg(20170323083511,nVirtualMethodNameMustMatchExternal,
|
RaiseMsg(20170323083511,nVirtualMethodNameMustMatchExternal,
|
||||||
sVirtualMethodNameMustMatchExternal,[],Proc.LibrarySymbolName);
|
sVirtualMethodNameMustMatchExternal,[],Proc.LibrarySymbolName);
|
||||||
end
|
end
|
||||||
else if El.Args.Count>0 then
|
else
|
||||||
RaiseMsg(20170322164357,nNoArgumentsAllowedForExternalObjectConstructor,
|
RaiseMsg(20190116211019,nExternalObjectConstructorMustBeNamedNew,
|
||||||
sNoArgumentsAllowedForExternalObjectConstructor,[],TPasArgument(El.Args[0]));
|
sExternalObjectConstructorMustBeNamedNew,[],El);
|
||||||
if pmVirtual in Proc.Modifiers then
|
|
||||||
RaiseMsg(20170322183141,nInvalidXModifierY,sInvalidXModifierY,
|
|
||||||
[Proc.ElementTypeName,'virtual'],Proc.ProcType);
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
RaiseMsg(20170322163210,nPasElementNotSupported,sPasElementNotSupported,
|
RaiseMsg(20170322163210,nPasElementNotSupported,sPasElementNotSupported,
|
||||||
@ -9259,7 +9256,6 @@ var
|
|||||||
Proc: TPasConstructor;
|
Proc: TPasConstructor;
|
||||||
ExtName: String;
|
ExtName: String;
|
||||||
NewExpr: TJSNewMemberExpression;
|
NewExpr: TJSNewMemberExpression;
|
||||||
Call: TJSCallExpression;
|
|
||||||
LeftResolved: TPasResolverResult;
|
LeftResolved: TPasResolverResult;
|
||||||
OldAccess: TCtxAccess;
|
OldAccess: TCtxAccess;
|
||||||
ExtNameEl: TJSElement;
|
ExtNameEl: TJSElement;
|
||||||
@ -9267,7 +9263,6 @@ var
|
|||||||
begin
|
begin
|
||||||
Result:=nil;
|
Result:=nil;
|
||||||
NewExpr:=nil;
|
NewExpr:=nil;
|
||||||
Call:=nil;
|
|
||||||
ExtNameEl:=nil;
|
ExtNameEl:=nil;
|
||||||
try
|
try
|
||||||
Proc:=Ref.Declaration as TPasConstructor;
|
Proc:=Ref.Declaration as TPasConstructor;
|
||||||
@ -9313,7 +9308,7 @@ begin
|
|||||||
|
|
||||||
if CompareText(Proc.Name,'new')=0 then
|
if CompareText(Proc.Name,'new')=0 then
|
||||||
begin
|
begin
|
||||||
// create 'new ExtName(params)'
|
// create "new ExtName(params)"
|
||||||
NewExpr:=TJSNewMemberExpression(CreateElement(TJSNewMemberExpression,Ref.Element));
|
NewExpr:=TJSNewMemberExpression(CreateElement(TJSNewMemberExpression,Ref.Element));
|
||||||
NewExpr.MExpr:=ExtNameEl;
|
NewExpr.MExpr:=ExtNameEl;
|
||||||
NewExpr.Args:=TJSArguments(CreateElement(TJSArguments,Ref.Element));
|
NewExpr.Args:=TJSArguments(CreateElement(TJSArguments,Ref.Element));
|
||||||
@ -9324,11 +9319,10 @@ begin
|
|||||||
NewExpr:=nil;
|
NewExpr:=nil;
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
RaiseInconsistency(20170323083214,Proc);
|
RaiseNotSupported(Ref.Element,AContext,20190116210204);
|
||||||
finally
|
finally
|
||||||
ExtNameEl.Free;
|
ExtNameEl.Free;
|
||||||
NewExpr.Free;
|
NewExpr.Free;
|
||||||
Call.Free;
|
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -15012,6 +15012,7 @@ begin
|
|||||||
Add('type');
|
Add('type');
|
||||||
Add(' TExtAClass = class of TExtA;');
|
Add(' TExtAClass = class of TExtA;');
|
||||||
Add(' TExtA = class external name ''ExtA''');
|
Add(' TExtA = class external name ''ExtA''');
|
||||||
|
Add(' C: TExtAClass;');
|
||||||
Add(' constructor New;');
|
Add(' constructor New;');
|
||||||
Add(' end;');
|
Add(' end;');
|
||||||
Add('var');
|
Add('var');
|
||||||
@ -15026,6 +15027,7 @@ begin
|
|||||||
Add(' end;');
|
Add(' end;');
|
||||||
Add(' a:=test1.c.new;');
|
Add(' a:=test1.c.new;');
|
||||||
Add(' a:=test1.c.new();');
|
Add(' a:=test1.c.new();');
|
||||||
|
Add(' a:=A.c.new();');
|
||||||
ConvertProgram;
|
ConvertProgram;
|
||||||
CheckSource('TestExternalClass_ClassOf_New',
|
CheckSource('TestExternalClass_ClassOf_New',
|
||||||
LinesToStr([ // statements
|
LinesToStr([ // statements
|
||||||
@ -15040,6 +15042,7 @@ begin
|
|||||||
'$mod.A = new $with1();',
|
'$mod.A = new $with1();',
|
||||||
'$mod.A = new $mod.C();',
|
'$mod.A = new $mod.C();',
|
||||||
'$mod.A = new $mod.C();',
|
'$mod.A = new $mod.C();',
|
||||||
|
'$mod.A = new $mod.A.C();',
|
||||||
'']));
|
'']));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -15698,6 +15701,8 @@ begin
|
|||||||
' v:=GetItems(14);',
|
' v:=GetItems(14);',
|
||||||
' setitems(15,16);',
|
' setitems(15,16);',
|
||||||
' end;',
|
' end;',
|
||||||
|
' v:=test1.arr.items[17];',
|
||||||
|
' test1.arr.items[18]:=v;',
|
||||||
'']);
|
'']);
|
||||||
ConvertProgram;
|
ConvertProgram;
|
||||||
CheckSource('TestExternalClass_BracketAccessor',
|
CheckSource('TestExternalClass_BracketAccessor',
|
||||||
@ -15741,6 +15746,8 @@ begin
|
|||||||
'var $with2 = $mod.Arr;',
|
'var $with2 = $mod.Arr;',
|
||||||
'$mod.v = $with2[14];',
|
'$mod.v = $with2[14];',
|
||||||
'$with2[15] = 16;',
|
'$with2[15] = 16;',
|
||||||
|
'$mod.v = $mod.Arr[17];',
|
||||||
|
'$mod.Arr[18] = $mod.v;',
|
||||||
'']));
|
'']));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user