mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-18 20:39:43 +02:00
pastojs: constructor New; external name globalfunc
git-svn-id: trunk@43214 -
This commit is contained in:
parent
8a10f0f4b9
commit
e28a2b0e21
@ -4052,13 +4052,7 @@ begin
|
||||
// constructor of external class can't be overriden -> forbid virtual
|
||||
RaiseMsg(20170323100447,nInvalidXModifierY,sInvalidXModifierY,
|
||||
[Proc.ElementTypeName,'virtual,external'],Proc);
|
||||
ExtName:=ComputeConstString(Proc.LibrarySymbolName,true,true);
|
||||
if CompareText(Proc.Name,'new')=0 then
|
||||
begin
|
||||
if ExtName<>Proc.Name then
|
||||
RaiseMsg(20170323083511,nVirtualMethodNameMustMatchExternal,
|
||||
sVirtualMethodNameMustMatchExternal,[],Proc.LibrarySymbolName);
|
||||
end;
|
||||
ComputeConstString(Proc.LibrarySymbolName,true,true);
|
||||
end
|
||||
else
|
||||
RaiseMsg(20170322163210,nPasElementNotSupported,sPasElementNotSupported,
|
||||
@ -10378,6 +10372,7 @@ begin
|
||||
Result:=nil;
|
||||
aResolver:=AContext.Resolver;
|
||||
NewExpr:=nil;
|
||||
ExtName:='';
|
||||
ExtNameEl:=nil;
|
||||
try
|
||||
Proc:=Ref.Declaration as TPasConstructor;
|
||||
@ -10385,7 +10380,13 @@ begin
|
||||
|
||||
if CompareText(Proc.Name,'new')=0 then
|
||||
begin
|
||||
if Left<>nil then
|
||||
if Proc.LibrarySymbolName<>nil then
|
||||
begin
|
||||
ExtName:=ComputeConstString(Proc.LibrarySymbolName,AContext,true);
|
||||
if not SameText(ExtName,'new') then
|
||||
ExtNameEl:=CreatePrimitiveDotExpr(ExtName,PosEl);
|
||||
end;
|
||||
if (ExtNameEl=nil) and (Left<>nil) then
|
||||
begin
|
||||
if aResolver<>nil then
|
||||
begin
|
||||
|
@ -44,7 +44,6 @@ type
|
||||
procedure TestGenProc_Overload;
|
||||
procedure TestGenProc_Forward;
|
||||
procedure TestGenProc_Infer_OverloadForward;
|
||||
// ToDo: specialize before impl
|
||||
end;
|
||||
|
||||
implementation
|
||||
|
@ -588,6 +588,7 @@ type
|
||||
Procedure TestExternalClass_FuncClassOf_New;
|
||||
Procedure TestExternalClass_New_PasClassFail;
|
||||
Procedure TestExternalClass_New_PasClassBracketsFail;
|
||||
Procedure TestExternalClass_NewExtName;
|
||||
Procedure TestExternalClass_Constructor;
|
||||
Procedure TestExternalClass_ConstructorBrackets;
|
||||
Procedure TestExternalClass_LocalConstSameName;
|
||||
@ -16536,6 +16537,51 @@ begin
|
||||
ConvertProgram;
|
||||
end;
|
||||
|
||||
procedure TTestModule.TestExternalClass_NewExtName;
|
||||
begin
|
||||
StartProgram(false);
|
||||
Add([
|
||||
'{$modeswitch externalclass}',
|
||||
'type',
|
||||
' TExtA = class external name ''ExtA''',
|
||||
' constructor New; external name ''Other'';',
|
||||
' constructor New(i: longint; j: longint = 2); external name ''A.B'';',
|
||||
' end;',
|
||||
'var',
|
||||
' A: texta;',
|
||||
'begin',
|
||||
' a:=texta.new;',
|
||||
' a:=texta(texta.new);',
|
||||
' a:=texta.new();',
|
||||
' a:=texta.new(1);',
|
||||
' with texta do begin',
|
||||
' a:=new;',
|
||||
' a:=new();',
|
||||
' a:=new(2);',
|
||||
' end;',
|
||||
' a:=test1.texta.new;',
|
||||
' a:=test1.texta.new();',
|
||||
' a:=test1.texta.new(3);',
|
||||
'']);
|
||||
ConvertProgram;
|
||||
CheckSource('TestExternalClass_NewExtName',
|
||||
LinesToStr([ // statements
|
||||
'this.A = null;',
|
||||
'']),
|
||||
LinesToStr([ // $mod.$main
|
||||
'$mod.A = new Other();',
|
||||
'$mod.A = new Other();',
|
||||
'$mod.A = new Other();',
|
||||
'$mod.A = new A.B(1,2);',
|
||||
'$mod.A = new Other();',
|
||||
'$mod.A = new Other();',
|
||||
'$mod.A = new A.B(2,2);',
|
||||
'$mod.A = new Other();',
|
||||
'$mod.A = new Other();',
|
||||
'$mod.A = new A.B(3,2);',
|
||||
'']));
|
||||
end;
|
||||
|
||||
procedure TTestModule.TestExternalClass_Constructor;
|
||||
begin
|
||||
StartProgram(false);
|
||||
|
@ -2695,8 +2695,9 @@ function(){
|
||||
Destructors are not allowed.<br>
|
||||
Constructors are supported in three ways:
|
||||
<ul>
|
||||
<li>With name <i>New</i> it is translated to <i>new ExtClass(params)</i>.</li>
|
||||
<li>With external name <i>'{}'</i> it is translated to <i>{}</i>.</li>
|
||||
<li><i>constructor New</i> is translated to <i>new ExtClass(params)</i>.</li>
|
||||
<li><i>constructor New; external name ''GlobalFunc''</i> is translated to <i>new GlobalFunc(params)</i>.</li>
|
||||
<li><i>constructor SomeName; external name <i>'{}'</i> is translated to <i>{}</i>.</li>
|
||||
<li>Otherwise it is translated to <i>new ExtClass.FuncName(params)</i>.</li>
|
||||
</ul>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user