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