* Use interfaces everywhere

This commit is contained in:
Michaël Van Canneyt 2024-07-24 14:41:42 +02:00
parent 478a227aa4
commit a4c03016fc
2 changed files with 32 additions and 1 deletions

View File

@ -78,6 +78,7 @@ Type
Constructor Create(APasName: String; D: TIDLBaseObject); Constructor Create(APasName: String; D: TIDLBaseObject);
Destructor Destroy; override; Destructor Destroy; override;
Property PasName: String read FPasName write FPasName; Property PasName: String read FPasName write FPasName;
function ToString : RTLString; override;
end; end;
TPasDataClass = class of TPasData; TPasDataClass = class of TPasData;
@ -379,6 +380,17 @@ begin
inherited Destroy; inherited Destroy;
end; end;
function TPasData.ToString: RTLString;
var
S : String;
begin
Result:=inherited ToString;
WriteStr(S,NativeType);
Result:=Result+Format(': NativeType: %s, Name: %s, location: [%s: %d:%d], used: %b',[S,PasName,SrcFile,Line,Column,Used]);
end;
{ TBaseWebIDLToPas } { TBaseWebIDLToPas }
function TBaseWebIDLToPas.CreateContext: TWebIDLContext; function TBaseWebIDLToPas.CreateContext: TWebIDLContext;
@ -2284,6 +2296,7 @@ begin
Result:=PasDataClass.Create(Data.PasName,OwnerDef); Result:=PasDataClass.Create(Data.PasName,OwnerDef);
Result.Resolved:=Data.Resolved; Result.Resolved:=Data.Resolved;
Result.NativeType:=Data.NativeType; Result.NativeType:=Data.NativeType;
Result.Used:=Data.Used;
FPasNameList.Add(Result); FPasNameList.Add(Result);
end; end;

View File

@ -28,6 +28,14 @@ uses
Classes, SysUtils, webidldefs, webidltopas, webidlscanner, webidlparser, Contnrs; Classes, SysUtils, webidldefs, webidltopas, webidlscanner, webidlparser, Contnrs;
{$ENDIF FPC_DOTTEDUNITS} {$ENDIF FPC_DOTTEDUNITS}
{
Todo:
- Allocate Aliased types (TIDLUserTypeDefinition) and simple types (TIDLSimpleTypeDefinition) as TIDLTypeDefinition descendants.
(so no more special cases are needed)
- Allocate Interface names so no more pasintfname etc. is needed
}
type type
TJOB_JSValueKind = ( TJOB_JSValueKind = (
jjvkUndefined, jjvkUndefined,
@ -417,7 +425,9 @@ function TWebIDLToPasWasmJob.GetResolvedType(aDef: TIDLTypeDefDefinition; out Pa
begin begin
Result:=inherited GetResolvedType(aDef, PascalNativeType, aTypeName, aResolvedTypename); Result:=inherited GetResolvedType(aDef, PascalNativeType, aTypeName, aResolvedTypename);
if Result is TIDLInterfaceDefinition then if Result is TIDLInterfaceDefinition then
aTypeName:=GetPasClassName(aTypeName) aTypeName:=GetPasIntfName(Result)
else if Result is TIDLDictionaryDefinition then
aTypeName:=GetPasIntfName(Result)
else if Result is TIDLPromiseTypeDefDefinition then else if Result is TIDLPromiseTypeDefDefinition then
aTypeName:=PasInterfacePrefix+'Promise'+PasInterfaceSuffix; aTypeName:=PasInterfacePrefix+'Promise'+PasInterfaceSuffix;
end; end;
@ -1227,6 +1237,8 @@ begin
if FGeneratingInterface and (([foConstructor, foStatic] * aDef.Options)<>[]) then if FGeneratingInterface and (([foConstructor, foStatic] * aDef.Options)<>[]) then
exit; exit;
Suff:=''; Suff:='';
if (ADef.Name='createImageBitmap') then
Writeln('Name');
GetMethodInfo(aParent,aDef,MethodInfo); GetMethodInfo(aParent,aDef,MethodInfo);
Overloads:=GetOverloads(ADef); Overloads:=GetOverloads(ADef);
try try
@ -1611,6 +1623,8 @@ begin
aAccessInfo.PropType:=aType; aAccessInfo.PropType:=aType;
if aType is TIDLInterfaceDefinition then if aType is TIDLInterfaceDefinition then
aAccessInfo.NativeTypeName:=GetPasIntfName(aType) aAccessInfo.NativeTypeName:=GetPasIntfName(aType)
else if aType is TIDLDictionaryDefinition then
aAccessInfo.NativeTypeName:=GetPasIntfName(aType)
else if aType is TIDLFunctionDefinition then else if aType is TIDLFunctionDefinition then
// exit // not supported yet // exit // not supported yet
else if aType is TIDLEnumDefinition then else if aType is TIDLEnumDefinition then
@ -1691,6 +1705,8 @@ begin
aAccessInfo.PropType:=aType; aAccessInfo.PropType:=aType;
if aType is TIDLInterfaceDefinition then if aType is TIDLInterfaceDefinition then
aAccessInfo.NativeTypeName:=GetPasIntfName(aType) aAccessInfo.NativeTypeName:=GetPasIntfName(aType)
else if aType is TIDLDictionaryDefinition then
aAccessInfo.NativeTypeName:=GetPasIntfName(aType)
else if aType is TIDLFunctionDefinition then else if aType is TIDLFunctionDefinition then
// exit // not supported yet // exit // not supported yet
else if aType is TIDLEnumDefinition then else if aType is TIDLEnumDefinition then
@ -1819,6 +1835,8 @@ begin
PropName:=GetPasName(aProp); PropName:=GetPasName(aProp);
aType:=GetResolvedType(aProp.PropertyType,ANT,aTypeName,aResolvedTypeName); aType:=GetResolvedType(aProp.PropertyType,ANT,aTypeName,aResolvedTypeName);
if aType is TIDLInterfaceDefinition then if aType is TIDLInterfaceDefinition then
aTypeName:=GetPasIntfName(aType)
else if aType is TIDLDictionaryDefinition then
aTypeName:=GetPasIntfName(aType); aTypeName:=GetPasIntfName(aType);
GetAccessorNames(aProp,GetterName,SetterName); GetAccessorNames(aProp,GetterName,SetterName);
Code:='property '+PropName+': '+aTypeName+' read '+GetterName; Code:='property '+PropName+': '+aTypeName+' read '+GetterName;