mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-25 21:52:17 +02:00
* Enable namespaced units, only write namespaces when needed
This commit is contained in:
parent
5c3763ffdf
commit
cb926961ce
@ -183,6 +183,8 @@ type
|
|||||||
Function AsString(Full : Boolean): UTF8String; override;
|
Function AsString(Full : Boolean): UTF8String; override;
|
||||||
Function HasAttributes : Boolean;
|
Function HasAttributes : Boolean;
|
||||||
Function HasSimpleAttribute(Const AName : UTF8String) : Boolean;
|
Function HasSimpleAttribute(Const AName : UTF8String) : Boolean;
|
||||||
|
Function GetPrefAttribute : String;
|
||||||
|
Function HasPrefAttribute : Boolean;
|
||||||
Function GetNamePath : String;
|
Function GetNamePath : String;
|
||||||
Property Name : UTF8String Read FName Write FName;
|
Property Name : UTF8String Read FName Write FName;
|
||||||
Property Data : TObject Read FData Write FData;
|
Property Data : TObject Read FData Write FData;
|
||||||
@ -1629,6 +1631,43 @@ begin
|
|||||||
Result:=HasAttributes and (FAttributes.IndexOf(aName)<>-1);
|
Result:=HasAttributes and (FAttributes.IndexOf(aName)<>-1);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TIDLDefinition.GetPrefAttribute: String;
|
||||||
|
|
||||||
|
var
|
||||||
|
I,P : integer;
|
||||||
|
S : String;
|
||||||
|
|
||||||
|
begin
|
||||||
|
Result:='';
|
||||||
|
if Not HasAttributes then exit;
|
||||||
|
For I:=0 to FAttributes.Count-1 do
|
||||||
|
begin
|
||||||
|
S:=FAttributes[i];
|
||||||
|
if (Pos('Pref',S)=1) then
|
||||||
|
begin
|
||||||
|
P:=Pos('=',S);
|
||||||
|
if P>0 then
|
||||||
|
Result:=Trim(Copy(FAttributes[i],P+1));
|
||||||
|
Exit;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TIDLDefinition.HasPrefAttribute: Boolean;
|
||||||
|
var
|
||||||
|
I : integer;
|
||||||
|
S : String;
|
||||||
|
begin
|
||||||
|
Result:=False;
|
||||||
|
if Not HasAttributes then exit;
|
||||||
|
For I:=0 to FAttributes.Count-1 do
|
||||||
|
begin
|
||||||
|
S:=FAttributes[i];
|
||||||
|
if (Pos('Pref',S)=1) and (Pos('=',S)>4) then
|
||||||
|
Exit(True);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
function TIDLDefinition.GetNamePath: String;
|
function TIDLDefinition.GetNamePath: String;
|
||||||
|
|
||||||
Function GetName(Def : TIDLDefinition) : string;
|
Function GetName(Def : TIDLDefinition) : string;
|
||||||
|
@ -459,7 +459,8 @@ begin
|
|||||||
Result:=False;
|
Result:=False;
|
||||||
For D in aList do
|
For D in aList do
|
||||||
if D is TIDLConstDefinition then
|
if D is TIDLConstDefinition then
|
||||||
Exit(True);
|
if ConvertDef(D) then
|
||||||
|
Exit(True);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TBaseWebIDLToPas.WriteFunctionImplicitTypes(aList: TIDLDefinitionList): Integer;
|
function TBaseWebIDLToPas.WriteFunctionImplicitTypes(aList: TIDLDefinitionList): Integer;
|
||||||
|
@ -110,9 +110,11 @@ type
|
|||||||
function GetKnownResultAllocator(aDef: TIDLTypeDefinition; ArgTypeName, ArgResolvedTypename: String): string;
|
function GetKnownResultAllocator(aDef: TIDLTypeDefinition; ArgTypeName, ArgResolvedTypename: String): string;
|
||||||
function GetNativeTypeHelperAllocatorName(aNativeType: TPascalNativeType): string;
|
function GetNativeTypeHelperAllocatorName(aNativeType: TPascalNativeType): string;
|
||||||
function GetNativeTypeHelperGetterName(aNativeType: TPascalNativeType): string;
|
function GetNativeTypeHelperGetterName(aNativeType: TPascalNativeType): string;
|
||||||
|
function OnlyConstants(D: TIDLStructuredDefinition): Boolean;
|
||||||
|
|
||||||
Protected
|
Protected
|
||||||
function BaseUnits: String; override;
|
function BaseUnits: String; override;
|
||||||
|
function DottedBaseUnits: String; override;
|
||||||
// Auxiliary routines
|
// Auxiliary routines
|
||||||
function GetAliasPascalType(D: TIDLDefinition; out PascalTypeName : string): TPascalNativeType; override;
|
function GetAliasPascalType(D: TIDLDefinition; out PascalTypeName : string): TPascalNativeType; override;
|
||||||
function GetPasClassName(const aName: String): String; overload; override; // convert to PasInterfacePrefix+X+FPasInterfaceSuffix
|
function GetPasClassName(const aName: String): String; overload; override; // convert to PasInterfacePrefix+X+FPasInterfaceSuffix
|
||||||
@ -226,6 +228,11 @@ begin
|
|||||||
Result:='SysUtils, Job.JS';
|
Result:='SysUtils, Job.JS';
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TWebIDLToPasWasmJob.DottedBaseUnits: String;
|
||||||
|
begin
|
||||||
|
Result:='System.SysUtils, Wasm.Job.Js';
|
||||||
|
end;
|
||||||
|
|
||||||
function TWebIDLToPasWasmJob.GetAliasPascalType(D: TIDLDefinition; out PascalTypeName: string): TPascalNativeType;
|
function TWebIDLToPasWasmJob.GetAliasPascalType(D: TIDLDefinition; out PascalTypeName: string): TPascalNativeType;
|
||||||
|
|
||||||
var
|
var
|
||||||
@ -1438,11 +1445,7 @@ var
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
Result:='';
|
Result:='';
|
||||||
if aMemberName='publicExponent' then
|
|
||||||
Writeln('so');
|
|
||||||
Case aInfo.NativeType of
|
Case aInfo.NativeType of
|
||||||
|
|
||||||
|
|
||||||
ntBoolean: ReadFuncName:='ReadJSPropertyBoolean';
|
ntBoolean: ReadFuncName:='ReadJSPropertyBoolean';
|
||||||
ntShortInt,
|
ntShortInt,
|
||||||
ntByte,
|
ntByte,
|
||||||
@ -1751,8 +1754,18 @@ var
|
|||||||
i: Integer;
|
i: Integer;
|
||||||
VarName, VarType: String;
|
VarName, VarType: String;
|
||||||
NS : TIDLNamespaceDefinition;
|
NS : TIDLNamespaceDefinition;
|
||||||
|
HaveNamespaces : Boolean;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
HaveNameSpaces:=False;
|
||||||
|
I:=0;
|
||||||
|
While (Not HaveNameSpaces) and (I<Context.Definitions.Count) do
|
||||||
|
begin
|
||||||
|
HaveNameSpaces:=Context.Definitions[i] is TIDLNamespaceDefinition;
|
||||||
|
Inc(I);
|
||||||
|
end;
|
||||||
|
if HaveNameSpaces then
|
||||||
|
Comment('Namespaces');
|
||||||
for I:=0 to Context.Definitions.Count-1 do
|
for I:=0 to Context.Definitions.Count-1 do
|
||||||
if Context.Definitions[i] is TIDLNamespaceDefinition then
|
if Context.Definitions[i] is TIDLNamespaceDefinition then
|
||||||
begin
|
begin
|
||||||
@ -2113,6 +2126,22 @@ begin
|
|||||||
WriteNamespaceImplemention(D as TIDLNamespaceDefinition);
|
WriteNamespaceImplemention(D as TIDLNamespaceDefinition);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TWebIDLToPasWasmJob.OnlyConstants(D : TIDLStructuredDefinition) : Boolean;
|
||||||
|
|
||||||
|
var
|
||||||
|
i,aCount : Integer;
|
||||||
|
|
||||||
|
begin
|
||||||
|
Result:=True;
|
||||||
|
I:=0;
|
||||||
|
aCount:=D.Members.Count;
|
||||||
|
While Result and (I<aCount) do
|
||||||
|
begin
|
||||||
|
Result:=D.Members[i] is TIDLConstDefinition;
|
||||||
|
Inc(I);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TWebIDLToPasWasmJob.WriteImplementation;
|
procedure TWebIDLToPasWasmJob.WriteImplementation;
|
||||||
var
|
var
|
||||||
i: Integer;
|
i: Integer;
|
||||||
@ -2136,10 +2165,11 @@ begin
|
|||||||
aDef:=Context.Definitions[i];
|
aDef:=Context.Definitions[i];
|
||||||
if aDef is TIDLNamespaceDefinition then
|
if aDef is TIDLNamespaceDefinition then
|
||||||
if not NSDef.IsPartial and ConvertDef(aDef) then
|
if not NSDef.IsPartial and ConvertDef(aDef) then
|
||||||
begin
|
if not (OnlyConstants(NSDef) or NSDef.HasPrefAttribute) then
|
||||||
PasVarName:=Context.Definitions[i].Name;
|
begin
|
||||||
AddLn(PasVarName+':='+GetPasName(aDef)+'.JOBCreateGlobal('''+PasVarName+''');');
|
PasVarName:=Context.Definitions[i].Name;
|
||||||
end;
|
AddLn(PasVarName+':='+GetPasName(aDef)+'.JOBCreateGlobal('''+PasVarName+''');');
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
Undent;
|
Undent;
|
||||||
|
|
||||||
@ -2155,10 +2185,11 @@ begin
|
|||||||
aDef:=Context.Definitions[i];
|
aDef:=Context.Definitions[i];
|
||||||
if aDef is TIDLNamespaceDefinition then
|
if aDef is TIDLNamespaceDefinition then
|
||||||
if not NSDef.IsPartial and ConvertDef(aDef) then
|
if not NSDef.IsPartial and ConvertDef(aDef) then
|
||||||
begin
|
if not (OnlyConstants(NSDef) or NSDef.HasPrefAttribute) then
|
||||||
PasVarName:=Context.Definitions[i].Name;
|
begin
|
||||||
AddLn(PasVarName+':=Nil;');
|
PasVarName:=Context.Definitions[i].Name;
|
||||||
end;
|
AddLn(PasVarName+':=Nil;');
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
Undent;
|
Undent;
|
||||||
end;
|
end;
|
||||||
|
Loading…
Reference in New Issue
Block a user