webidl: remove empty forward interfaces

This commit is contained in:
mattias 2022-07-18 19:05:31 +02:00
parent 62e9de223d
commit 99f34158ca
3 changed files with 75 additions and 8 deletions

View File

@ -203,6 +203,7 @@ type
Function AsString(Full : Boolean): UTF8String; override; Function AsString(Full : Boolean): UTF8String; override;
Function Add(aClass : TIDLDefinitionClass; Const AName : UTF8String; const aFile: string; aLine, aCol: integer) : TIDLDefinition; override; Function Add(aClass : TIDLDefinitionClass; Const AName : UTF8String; const aFile: string; aLine, aCol: integer) : TIDLDefinition; override;
Function Add(aItem : TIDLDefinition) : Integer; Function Add(aItem : TIDLDefinition) : Integer;
Function Delete(aItem : TIDLDefinition) : boolean; // true if found and deleted
function GetEnumerator: TIDLDefinitionEnumerator; function GetEnumerator: TIDLDefinitionEnumerator;
Property Parent : TIDLDefinition Read FParent; Property Parent : TIDLDefinition Read FParent;
Property Definitions[aIndex : Integer] : TIDLDefinition Read GetD;default; Property Definitions[aIndex : Integer] : TIDLDefinition Read GetD;default;
@ -283,6 +284,7 @@ type
private private
FHasSerializer: Boolean; FHasSerializer: Boolean;
FHasStringifier: Boolean; FHasStringifier: Boolean;
FIsForward: Boolean;
FIsInclude: Boolean; FIsInclude: Boolean;
FIsMixin: Boolean; FIsMixin: Boolean;
FParentInterface: TIDLInterfaceDefinition; FParentInterface: TIDLInterfaceDefinition;
@ -294,6 +296,7 @@ type
// is this a mixin definition? // is this a mixin definition?
Property IsMixin : Boolean Read FIsMixin Write FIsMixin; Property IsMixin : Boolean Read FIsMixin Write FIsMixin;
Property IsInclude : Boolean Read FIsInclude Write FIsInclude; Property IsInclude : Boolean Read FIsInclude Write FIsInclude;
Property IsForward: Boolean read FIsForward write FIsForward;
end; end;
{ TIDLArgumentDefinition } { TIDLArgumentDefinition }
@ -1323,6 +1326,19 @@ begin
aItem.Parent:=FParent; aItem.Parent:=FParent;
end; end;
function TIDLDefinitionList.Delete(aItem: TIDLDefinition): boolean;
var
i: Integer;
begin
for i:=0 to FList.Count-1 do
if FList[i]=aItem then
begin
FList.Delete(i);
exit(true);
end;
Result:=false;
end;
function TIDLDefinitionList.GetEnumerator: TIDLDefinitionEnumerator; function TIDLDefinitionList.GetEnumerator: TIDLDefinitionEnumerator;
begin begin
Result:=TIDLDefinitionEnumerator.Create(Self); Result:=TIDLDefinitionEnumerator.Create(Self);

View File

@ -889,7 +889,7 @@ end;
function TWebIDLParser.ParseInterface(aParent : TIDLBaseObject): TIDLInterfaceDefinition; function TWebIDLParser.ParseInterface(aParent : TIDLBaseObject): TIDLInterfaceDefinition;
(* (*
On Entry we're on interface. On exit, we're on the } character On Entry we're on interface. On exit, we're on the } character or the ; if it is an empty forward definition
*) *)
Var Var
@ -909,17 +909,18 @@ begin
try try
Result.IsMixin:=IsMixin; Result.IsMixin:=IsMixin;
tk:=GetToken; tk:=GetToken;
if tk=tkSemiColon then
begin
// empty interface
Result.IsForward:=true;
exit;
end;
if tk=tkColon then if tk=tkColon then
begin begin
ExpectToken(tkIdentifier); ExpectToken(tkIdentifier);
Result.ParentName:=CurrentTokenString; Result.ParentName:=CurrentTokenString;
tk:=GetToken; tk:=GetToken;
end; end;
if CurrentToken=tkSemiColon then
begin
// empty interface
exit;
end;
CheckCurrentToken(tkCurlyBraceOpen); CheckCurrentToken(tkCurlyBraceOpen);
tk:=GetToken; tk:=GetToken;
While (tk<>tkCurlyBraceClose) do While (tk<>tkCurlyBraceClose) do

View File

@ -99,6 +99,7 @@ type
procedure AddJSIdentifier(D: TIDLDefinition); virtual; procedure AddJSIdentifier(D: TIDLDefinition); virtual;
procedure ResolveTypeDefs(aList: TIDLDefinitionList); virtual; procedure ResolveTypeDefs(aList: TIDLDefinitionList); virtual;
procedure ResolveTypeDef(D: TIDLDefinition); virtual; procedure ResolveTypeDef(D: TIDLDefinition); virtual;
procedure RemoveInterfaceForwards(aList: TIDLDefinitionList); virtual;
function FindGlobalDef(const aName: UTF8String): TIDLDefinition; virtual; function FindGlobalDef(const aName: UTF8String): TIDLDefinition; virtual;
function GetDefPos(Def: TIDLBaseObject; WithoutFile: boolean = false): string; virtual; function GetDefPos(Def: TIDLBaseObject; WithoutFile: boolean = false): string; virtual;
function GetPasDataPos(D: TPasData; WithoutFile: boolean = false): string; virtual; function GetPasDataPos(D: TPasData; WithoutFile: boolean = false): string; virtual;
@ -561,7 +562,6 @@ Var
var var
D: TIDLDefinition; D: TIDLDefinition;
begin begin
L:=TFPObjectHashTable.Create(False); L:=TFPObjectHashTable.Create(False);
try try
@ -1467,7 +1467,7 @@ begin
begin begin
Old:=FindGlobalDef(D.Name); Old:=FindGlobalDef(D.Name);
if Old<>nil then if Old<>nil then
raise EWebIDLParser.Create('Duplicate identifier '+D.Name+' at '+GetDefPos(D)+' and '+GetDefPos(Old)); raise EWebIDLParser.Create('Duplicate identifier '+D.Name+' at '+GetDefPos(D)+' and '+GetDefPos(Old)+' (20220718185400)');
FGlobalDefs.Add(D.Name,D); FGlobalDefs.Add(D.Name,D);
end end
else else
@ -1551,6 +1551,55 @@ begin
writeln('TBaseWebIDLToPas.ResolveTypeDef unknown ',D.Name,':',D.ClassName,' at ',GetDefPos(D)); writeln('TBaseWebIDLToPas.ResolveTypeDef unknown ',D.Name,':',D.ClassName,' at ',GetDefPos(D));
end; end;
procedure TBaseWebIDLToPas.RemoveInterfaceForwards(aList: TIDLDefinitionList);
Var
L: TFPObjectHashTable;
Procedure DeleteIntf(Def: TIDLInterfaceDefinition);
begin
writeln('DeleteIntf ',Def.Name);
aList.Delete(Def);
end;
Procedure CheckDuplicateInterfaceDef(Def: TIDLInterfaceDefinition);
var
aName: UTF8String;
OldDef: TIDLInterfaceDefinition;
begin
if Def.IsPartial then exit;
aName:=Def.Name;
OldDef:=TIDLInterfaceDefinition(L.Items[aName]);
if OldDef=nil then
L.add(aName,Def)
else
begin
if OldDef.IsForward then
begin
L.Delete(OldDef.Name);
DeleteIntf(OldDef);
L.Add(aName,Def);
end
else if Def.IsForward then
DeleteIntf(Def)
else
raise EConvertError.Create('Duplicate interface '+GetDefPos(Def)+' and '+GetDefPos(OldDef)+' (20220718184717)');
end;
end;
var
i: Integer;
begin
L:=TFPObjectHashTable.Create(False);
try
For i:=aList.Count-1 downto 0 do
if (aList[i] is TIDLInterfaceDefinition) then
CheckDuplicateInterfaceDef(TIDLInterfaceDefinition(aList[i]));
finally
L.Free;
end;
end;
function TBaseWebIDLToPas.FindGlobalDef(const aName: UTF8String function TBaseWebIDLToPas.FindGlobalDef(const aName: UTF8String
): TIDLDefinition; ): TIDLDefinition;
begin begin
@ -1604,6 +1653,7 @@ end;
procedure TBaseWebIDLToPas.ProcessDefinitions; procedure TBaseWebIDLToPas.ProcessDefinitions;
begin begin
RemoveInterfaceForwards(FContext.Definitions);
FContext.AppendPartials; FContext.AppendPartials;
FContext.AppendIncludes; FContext.AppendIncludes;
AllocatePasNames(FContext.Definitions); AllocatePasNames(FContext.Definitions);