* fix for mantis 17597, aliastypes in inheritance chains of fpdoc.

Adds aliases to the content file, using alias(realtype) syntax.

git-svn-id: trunk@16217 -
This commit is contained in:
marco 2010-10-24 21:33:41 +00:00
parent dce3405c66
commit e82d25d211

View File

@ -694,26 +694,45 @@ var
result:=Copy(AName, DotPos2 + 1, length(AName)-dotpos2); result:=Copy(AName, DotPos2 + 1, length(AName)-dotpos2);
end; end;
function SearchInList(clslist:TList;s:string):TPasElement;
var i : integer;
ClassEl: TPasElement;
begin
result:=nil;
for i:=0 to clslist.count-1 do
begin
ClassEl := TPasElement(clslist[i]);
if CompareText(ClassEl.Name,s) =0 then
exit(Classel);
end;
end;
function ResolveClassType(AName:String):TPasClassType; function ResolveClassType(AName:String):TPasClassType;
var var
pkg : TPasPackage; pkg : TPasPackage;
module : TPasModule; module : TPasModule;
s : string; s : string;
clslist : TList;
ClassEl : TPasClassType;
i : Integer;
begin begin
Result:=nil; Result:=nil;
s:=ResolvePackageModule(AName,pkg,module,False); s:=ResolvePackageModule(AName,pkg,module,False);
if not assigned(module) then if not assigned(module) then
exit; exit;
clslist:=module.InterfaceSection.Classes; result:=TPasClassType(SearchInList(Module.InterfaceSection.Classes,s));
for i:=0 to clslist.count-1 do end;
begin
ClassEl := TPasClassType(clslist[i]); function ResolveAliasType(AName:String):TPasAliasType;
if CompareText(ClassEl.Name,s) =0 then var
exit(Classel); pkg : TPasPackage;
end; module : TPasModule;
s : string;
begin
Result:=nil;
s:=ResolvePackageModule(AName,pkg,module,False);
if not assigned(module) then
exit;
result:=TPasAliasType(SearchInList(Module.InterfaceSection.Types,s));
if not (result is TPasAliasType) then
result:=nil;
end; end;
procedure ReadClasses; procedure ReadClasses;
@ -737,10 +756,80 @@ var
InheritanceInfo.AddObject(Inheritancestr,result); InheritanceInfo.AddObject(Inheritancestr,result);
end; end;
procedure splitalias(var instr:string;out outstr:string);
var i,j:integer;
begin
if length(instr)=0 then exit;
instr:=trim(instr);
i:=pos('(',instr);
if i>0 then
begin
j:=length(instr)-i;
if instr[length(instr)]=')' then
dec(j);
outstr:=copy(instr,i+1,j);
delete(instr,i,j+2);
end
end;
Function ResolveAndLinkClass(clname:String;IsClass:boolean;cls:TPasClassType):TPasClassType;
begin
result:=TPasClassType(ResolveClassType(clname));
if assigned(result) and not (cls=result) then // save from tobject=implicit tobject
begin
result.addref;
if IsClass then
begin
cls.ancestortype:=result;
// writeln(cls.name, ' has as ancestor ',result.pathname);
end
else
begin
cls.interfaces.add(result);
// writeln(cls.name, ' implements ',result.pathname);
end;
end
else
if cls<>result then
writeln(cls.name,'''s dependancy ' ,clname,' could not be resolved');
end;
function CreateAliasType (alname,clname : string;parentclass:TPasClassType; out cl2 :TPasClassType):TPasAliasType;
// create alias clname = alname
var
pkg : TPasPackage;
module : TPasModule;
s : string;
begin
Result:=nil;
s:=ResolvePackageModule(Alname,pkg,module,True);
if not assigned(module) then
exit;
cl2:=TPasClassType(ResolveClassType(alname));
if assigned( cl2) and not (parentclass=cl2) then
begin
result:=ResolveAliasType(clname);
if assigned(result) then
begin
writeln('found alias ',clname,' (',s,') ',result.classname);
end
else
begin
writeln('new alias ',clname,' (',s,') ');
cl2.addref;
Result := TPasAliasType(CreateElement(TPasAliasType,s,module.interfacesection,vispublic,'',0));
TPasAliasType(Result).DestType := cl2;
end
end
end;
procedure ProcessInheritanceStrings(inhInfo:TStringList); procedure ProcessInheritanceStrings(inhInfo:TStringList);
var i,j : integer; var i,j : integer;
cls : TPasClassType; cls : TPasClassType;
cls2: TPasClassType; cls2: TPasClassType;
clname,
alname : string;
inhclass : TStringList; inhclass : TStringList;
begin begin
inhclass:=TStringList.Create; inhclass:=TStringList.Create;
@ -754,24 +843,17 @@ var
for j:= 0 to inhclass.count-1 do for j:= 0 to inhclass.count-1 do
begin begin
// writeln('processing',inhclass[j]); //writeln('processing',inhclass[j]);
cls2:=TPasClassType(ResolveClassType(inhclass[j])); clname:=inhclass[j];
if assigned(cls2) and not (cls=cls2) then // save from tobject=implicit tobject splitalias(clname,alname);
if alname<>'' then // the class//interface we refered to is an alias
begin begin
cls2.addref; // writeln('Found alias pair ',clname,' = ',alname);
if j=0 then if not assigned(CreateAliasType(alname,clname,cls,cls2)) then
cls.ancestortype:=cls2 writeln('creating alias failed!');
else end
cls.interfaces.add(cls2);
{ if j=0 then
writeln(cls.name, ' has as ancestor ',cls2.pathname)
else
writeln(cls.name, ' implements ',cls2.pathname)
}
end
else else
if cls<>cls2 then cls2:=ResolveAndLinkClass(clname,j=0,cls);
writeln(cls.name,'''s dependancy ' ,inhclass[j],' ',j,' could not be resolved');
end; end;
end; end;
end; end;
@ -878,10 +960,18 @@ var
end; end;
end; end;
function CheckImplicitInterfaceLink(const s : String):String;
begin
if uppercase(s)='IUNKNOWN' then
Result:='#rtl.System.IUnknown'
else
Result:=s;
end;
var var
LinkNode: TLinkNode; LinkNode: TLinkNode;
i, j, k: Integer; i, j, k: Integer;
Module: TPasModule; Module: TPasModule;
Alias : TPasAliasType;
ClassDecl: TPasClassType; ClassDecl: TPasClassType;
Member: TPasElement; Member: TPasElement;
s: String; s: String;
@ -911,9 +1001,18 @@ begin
for j := 0 to Module.InterfaceSection.Classes.Count - 1 do for j := 0 to Module.InterfaceSection.Classes.Count - 1 do
begin begin
ClassDecl := TPasClassType(Module.InterfaceSection.Classes[j]); ClassDecl := TPasClassType(Module.InterfaceSection.Classes[j]);
Write(ContentFile, ClassDecl.PathName, ' '); Write(ContentFile, CheckImplicitInterfaceLink(ClassDecl.PathName), ' ');
if Assigned(ClassDecl.AncestorType) then if Assigned(ClassDecl.AncestorType) then
Write(ContentFile, ClassDecl.AncestorType.PathName) begin
// simple aliases to class types are coded as "alias(classtype)"
Write(ContentFile, CheckImplicitInterfaceLink(ClassDecl.AncestorType.PathName));
if ClassDecl.AncestorType is TPasAliasType then
begin
alias:= TPasAliasType(ClassDecl.AncestorType);
if assigned(alias.desttype) and (alias.desttype is TPasClassType) then
write(ContentFile,'(',alias.desttype.PathName,')');
end;
end
else if ClassDecl.ObjKind = okClass then else if ClassDecl.ObjKind = okClass then
Write(ContentFile, '#rtl.System.TObject') Write(ContentFile, '#rtl.System.TObject')
else if ClassDecl.ObjKind = okInterface then else if ClassDecl.ObjKind = okInterface then
@ -921,7 +1020,15 @@ begin
if ClassDecl.Interfaces.Count>0 then if ClassDecl.Interfaces.Count>0 then
begin begin
for k:=0 to ClassDecl.Interfaces.count-1 do for k:=0 to ClassDecl.Interfaces.count-1 do
write(contentfile,',',TPasClassType(ClassDecl.Interfaces[k]).PathName); begin
write(contentfile,',',CheckImplicitInterfaceLink(TPasClassType(ClassDecl.Interfaces[k]).PathName));
if TPasElement(ClassDecl.Interfaces[k]) is TPasAliasType then
begin
alias:= TPasAliasType(ClassDecl.Interfaces[k]);
if assigned(alias.desttype) and (alias.desttype is TPasClassType) then
write(ContentFile,'(',CheckImplicitInterfaceLink(alias.desttype.PathName),')');
end;
end;
end; end;
writeln(contentfile); writeln(contentfile);
for k := 0 to ClassDecl.Members.Count - 1 do for k := 0 to ClassDecl.Members.Count - 1 do