From 6808002ecd610c4c7fcbccfeedb6e4642a3d09c8 Mon Sep 17 00:00:00 2001 From: mattias Date: Fri, 21 Sep 2007 21:49:14 +0000 Subject: [PATCH] codetools: improved FixAliasDefinitions for type casts git-svn-id: trunk@12121 - --- components/codetools/codecompletiontool.pas | 11 ++++------- .../codetools/examples/fixdefinitionorder.lpi | 16 +++++++++++++--- .../codetools/examples/fixdefinitionorder.lpr | 9 +++++++-- .../scanexamples/wrongforwarddefinitions.pas | 4 ++++ 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/components/codetools/codecompletiontool.pas b/components/codetools/codecompletiontool.pas index 249b584305..f21ef490a6 100644 --- a/components/codetools/codecompletiontool.pas +++ b/components/codetools/codecompletiontool.pas @@ -1430,7 +1430,7 @@ var if (NeededType<>Node.Desc) or (not OnlyWrongType) then begin // add alias if NeededType<>Node.Desc then begin - DebugLn(['TCodeCompletionCodeTool.FindAliasDefinitions Wrong: ',Node.DescAsString,' ',ExtractNode(Node,[]),' ',Node.DescAsString,'<>',ReferingNode.DescAsString]); + DebugLn(['TCodeCompletionCodeTool.FindAliasDefinitions Wrong: ',Node.DescAsString,' ',ExtractNode(Node,[]),' ',Node.DescAsString,'<>',NodeDescToStr(NeededType)]); end; if TreeOfCodeTreeNodeExt=nil then TreeOfCodeTreeNodeExt:=TAVLTree.Create(@CompareCodeTreeNodeExt); @@ -1543,7 +1543,6 @@ var AVLNode: TAVLTreeNode; NodeExt: TCodeTreeNodeExtension; DefNode: TCodeTreeNode; - ReferingNode: TCodeTreeNode; NextAVLNode: TAVLTreeNode; ReferingNodeInFront: TCodeTreeNode; ReferingNodeBehind: TCodeTreeNode; @@ -1563,12 +1562,11 @@ begin NextAVLNode:=TreeOfCodeTreeNodeExt.FindSuccessor(AVLNode); NodeExt:=TCodeTreeNodeExtension(AVLNode.Data); DefNode:=NodeExt.Node; - ReferingNode:=TCodeTreeNode(NodeExt.Data); ReferingType:=TCodeTreeNodeDesc(NodeExt.Flags); - if (ReferingNode=nil) - or (not (ReferingNode.Desc in [ctnTypeDefinition,ctnConstDefinition])) + if (not (ReferingType in [ctnTypeDefinition,ctnConstDefinition])) or (DefNode.Desc=ReferingType) then begin TreeOfCodeTreeNodeExt.Delete(AVLNode); + NodeExtMemManager.DisposeNode(NodeExt); end; AVLNode:=NextAVLNode; end; @@ -1578,10 +1576,9 @@ begin while AVLNode<>nil do begin NodeExt:=TCodeTreeNodeExtension(AVLNode.Data); DefNode:=NodeExt.Node; - ReferingNode:=TCodeTreeNode(NodeExt.Data); ReferingType:=TCodeTreeNodeDesc(NodeExt.Flags); - //DebugLn(['TCodeCompletionCodeTool.FixAliasDefinitions Old=',DefNode.DescAsString,' New=',NodeDescToStr(ReferingType)]); + DebugLn(['TCodeCompletionCodeTool.FixAliasDefinitions Old=',DefNode.DescAsString,' New=',NodeDescToStr(ReferingType)]); case ReferingType of ctnTypeDefinition: NewSrc:='type'; diff --git a/components/codetools/examples/fixdefinitionorder.lpi b/components/codetools/examples/fixdefinitionorder.lpi index b0130c5c56..9934345049 100644 --- a/components/codetools/examples/fixdefinitionorder.lpi +++ b/components/codetools/examples/fixdefinitionorder.lpi @@ -26,18 +26,28 @@ - + - + - + + + + + + + + + + + diff --git a/components/codetools/examples/fixdefinitionorder.lpr b/components/codetools/examples/fixdefinitionorder.lpr index ded282daf7..8a1e87b781 100644 --- a/components/codetools/examples/fixdefinitionorder.lpr +++ b/components/codetools/examples/fixdefinitionorder.lpr @@ -47,12 +47,17 @@ begin if Code=nil then raise Exception.Create('loading failed '+Filename); - // fix constants - if not CodeToolBoss.FixForwardDefinitions(Code) then begin + if not CodeToolBoss.FixAllAliasDefinitions(Code) then begin writeln('FixAllAliasDefinitions failed'); exit; end; + // fix constants + {if not CodeToolBoss.FixForwardDefinitions(Code) then begin + writeln('FixForwardDefinitions failed'); + exit; + end;} + // write the new source: writeln('-----------------------------------'); writeln(Code.Source); diff --git a/components/codetools/examples/scanexamples/wrongforwarddefinitions.pas b/components/codetools/examples/scanexamples/wrongforwarddefinitions.pas index 84caf7fd89..995838db8a 100644 --- a/components/codetools/examples/scanexamples/wrongforwarddefinitions.pas +++ b/components/codetools/examples/scanexamples/wrongforwarddefinitions.pas @@ -26,6 +26,10 @@ const EndValue = TMyInteger(1); type TMyInteger = longint; PMyRecord = ^TMyRecord; + TMyFunc = procedure(i: integer); + MyNilFunc = TMyFunc(0); + Func2 = MyNilFunc; + Func3 = Func2; implementation