cody: find overloads: find target proc node

git-svn-id: trunk@49962 -
This commit is contained in:
mattias 2015-10-06 18:36:20 +00:00
parent b0eac4a317
commit 87d9c28f9e

View File

@ -53,6 +53,10 @@ type
TCFONode = class(TCodeGraphNode) TCFONode = class(TCodeGraphNode)
public public
Tool: TFindDeclarationTool; Tool: TFindDeclarationTool;
// for ctnProcedure:
Compatibility: TTypeCompatibility;
Distance: integer;
end; end;
TCFOEdgeType = ( TCFOEdgeType = (
@ -108,7 +112,9 @@ type
procedure AddStartAndTargetUnits; procedure AddStartAndTargetUnits;
procedure GatherProcsOfAllUnits; procedure GatherProcsOfAllUnits;
procedure GatherProcsOfUnit(NodeGraph: TCodeGraph; ProgNode: TCodeTreeNode; procedure GatherProcsOfUnit(NodeGraph: TCodeGraph; ProgNode: TCodeTreeNode;
CurUnit: TCFOUnit; ExcludeAbstractProcs: boolean); CurUnit: TCFOUnit; ExcludeAbstractProcs: boolean;
var TargetGraphNode: TCFONode);
procedure CalcDistances(NodeGraph: TCodeGraph; TargetGraphNode: TCFONode);
procedure FreeUsesGraph; procedure FreeUsesGraph;
function GetDefaultCaption: string; function GetDefaultCaption: string;
procedure FillFilterControls(ProcTool: TFindDeclarationTool; procedure FillFilterControls(ProcTool: TFindDeclarationTool;
@ -290,6 +296,7 @@ var
NodeGraph: TCodeGraph; NodeGraph: TCodeGraph;
ProgNode: TCodeTreeNode; ProgNode: TCodeTreeNode;
ExcludeAbstractProcs: Boolean; ExcludeAbstractProcs: Boolean;
TargetGraphNode: TCFONode;
begin begin
Exclude(FFlags,cfofGatherProcs); Exclude(FFlags,cfofGatherProcs);
if FUsesGraph=nil then if FUsesGraph=nil then
@ -302,12 +309,20 @@ begin
try try
NodeGraph.AddGraphNode(ProgNode); NodeGraph.AddGraphNode(ProgNode);
TargetGraphNode:=nil;
FileNode:=FUsesGraph.FilesTree.FindLowest; FileNode:=FUsesGraph.FilesTree.FindLowest;
while FileNode<>nil do begin while FileNode<>nil do begin
CurUnit:=TCFOUnit(FileNode.Data); CurUnit:=TCFOUnit(FileNode.Data);
GatherProcsOfUnit(NodeGraph,ProgNode,CurUnit,ExcludeAbstractProcs); GatherProcsOfUnit(NodeGraph,ProgNode,CurUnit,ExcludeAbstractProcs,
TargetGraphNode);
FileNode:=FUsesGraph.FilesTree.FindSuccessor(FileNode); FileNode:=FUsesGraph.FilesTree.FindSuccessor(FileNode);
end; end;
// ToDo: filter using RelationComboBox
if TargetGraphNode<>nil then
CalcDistances(NodeGraph,TargetGraphNode);
finally finally
NodeGraph.Free; NodeGraph.Free;
ProgNode.Free; ProgNode.Free;
@ -316,7 +331,8 @@ begin
end; end;
procedure TCodyFindOverloadsWindow.GatherProcsOfUnit(NodeGraph: TCodeGraph; procedure TCodyFindOverloadsWindow.GatherProcsOfUnit(NodeGraph: TCodeGraph;
ProgNode: TCodeTreeNode; CurUnit: TCFOUnit; ExcludeAbstractProcs: boolean); ProgNode: TCodeTreeNode; CurUnit: TCFOUnit; ExcludeAbstractProcs: boolean;
var TargetGraphNode: TCFONode);
procedure AddAncestors(Tool: TFindDeclarationTool; ClassNode: TCodeTreeNode); forward; procedure AddAncestors(Tool: TFindDeclarationTool; ClassNode: TCodeTreeNode); forward;
@ -365,12 +381,15 @@ procedure TCodyFindOverloadsWindow.GatherProcsOfUnit(NodeGraph: TCodeGraph;
end; end;
end; end;
procedure AddProcNode(Tool: TFindDeclarationTool; ProcNode: TCodeTreeNode); procedure AddProcNode(Tool: TFindDeclarationTool; ProcNode: TCodeTreeNode;
TargetCleanPos: integer);
var var
CurProcName: String; CurProcName: String;
GraphProcNode: TCFONode; GraphProcNode: TCFONode;
ClassNode: TCodeTreeNode; ClassNode: TCodeTreeNode;
Edge: TCFOEdge; Edge: TCFOEdge;
Compatibility: TTypeCompatibility;
IsTargetProc: Boolean;
begin begin
// check name // check name
CurProcName:=Tool.ExtractProcName(ProcNode,[phpWithoutClassName]); CurProcName:=Tool.ExtractProcName(ProcNode,[phpWithoutClassName]);
@ -390,11 +409,25 @@ procedure TCodyFindOverloadsWindow.GatherProcsOfUnit(NodeGraph: TCodeGraph;
if Tool.ProcNodeHasSpecifier(ProcNode,psABSTRACT) then exit; if Tool.ProcNodeHasSpecifier(ProcNode,psABSTRACT) then exit;
end; end;
end; end;
Compatibility:=tcExact;
if (TargetGraphNode=nil)
and (ProcNode.StartPos<=TargetCleanPos)
and (TargetCleanPos<ProcNode.FirstChild.EndPos) then begin
// this is the target proc
IsTargetProc:=true;
end else begin
// ToDo: check param compatibility // ToDo: check param compatibility
IsTargetProc:=false;
end;
// add node // add node
GraphProcNode:=TCFONode(NodeGraph.AddGraphNode(ProcNode)); GraphProcNode:=TCFONode(NodeGraph.AddGraphNode(ProcNode));
GraphProcNode.Tool:=Tool; GraphProcNode.Tool:=Tool;
GraphProcNode.Compatibility:=Compatibility;
if IsTargetProc then
TargetGraphNode:=GraphProcNode;
// add edges // add edges
if ClassNode<>nil then begin if ClassNode<>nil then begin
@ -414,20 +447,32 @@ procedure TCodyFindOverloadsWindow.GatherProcsOfUnit(NodeGraph: TCodeGraph;
var var
Tool: TStandardCodeTool; Tool: TStandardCodeTool;
ProcNode: TCodeTreeNode; ProcNode: TCodeTreeNode;
TargetCleanPos: integer;
begin begin
if ugufLoadError in CurUnit.Flags then exit; if ugufLoadError in CurUnit.Flags then exit;
if not (ugufReached in CurUnit.Flags) then exit; // this unit was not reached if not (ugufReached in CurUnit.Flags) then exit; // this unit was not reached
if ugufIsIncludeFile in CurUnit.Flags then exit; if ugufIsIncludeFile in CurUnit.Flags then exit;
Tool:=CurUnit.Tool; Tool:=CurUnit.Tool;
if (TargetGraphNode<>nil)
or (Tool.CaretToCleanPos(TargetXYPosition,TargetCleanPos)<>0) then
TargetCleanPos:=0;
ProcNode:=Tool.Tree.Root; ProcNode:=Tool.Tree.Root;
while ProcNode<>nil do begin while ProcNode<>nil do begin
if ProcNode.Desc in [ctnImplementation,ctnBeginBlock] then break; if ProcNode.Desc in [ctnImplementation,ctnBeginBlock] then break;
if ProcNode.Desc=ctnProcedure then if ProcNode.Desc=ctnProcedure then
AddProcNode(Tool,ProcNode); AddProcNode(Tool,ProcNode,TargetCleanPos);
ProcNode:=ProcNode.Next; ProcNode:=ProcNode.Next;
end; end;
end; end;
procedure TCodyFindOverloadsWindow.CalcDistances(NodeGraph: TCodeGraph;
TargetGraphNode: TCFONode);
begin
debugln(['TCodyFindOverloadsWindow.CalcDistances ']);
end;
procedure TCodyFindOverloadsWindow.FreeUsesGraph; procedure TCodyFindOverloadsWindow.FreeUsesGraph;
begin begin
FreeAndNil(FUsesGraph); FreeAndNil(FUsesGraph);