codetools: extended fixing alias functions to external functions

git-svn-id: trunk@12352 -
This commit is contained in:
mattias 2007-10-06 18:10:17 +00:00
parent 564ac218a6
commit 38b6bffd7b
3 changed files with 84 additions and 38 deletions

View File

@ -1420,13 +1420,11 @@ var
end else begin end else begin
// this is a const or type alias // this is a const or type alias
//DebugLn(['TCodeCompletionCodeTool.FindAliasDefinitions Alias: ',Node.DescAsString,' ',ExtractNode(Node,[])]); //DebugLn(['TCodeCompletionCodeTool.FindAliasDefinitions Alias: ',Node.DescAsString,' ',ExtractNode(Node,[])]);
if OnlyWrongType then begin
GetReferingNode; GetReferingNode;
if (ReferingNode<>nil) then begin if (ReferingNode<>nil) then begin
NeededType:=ReferingNode.Desc; NeededType:=ReferingNode.Desc;
end; end;
end; end;
end;
if NeededType=ctnNone then exit; if NeededType=ctnNone then exit;
// add alias // add alias
if NeededType<>Node.Desc then begin if NeededType<>Node.Desc then begin
@ -1480,7 +1478,7 @@ var
end; end;
ctnProcedure: ctnProcedure:
begin begin
//UpdateDefinition(GetRedefinitionNodeText(Node),Node); UpdateDefinition(ExtractProcName(Node,[]),Node);
Node:=Node.NextSkipChilds; Node:=Node.NextSkipChilds;
end; end;
else else
@ -1526,6 +1524,9 @@ var
begin begin
Result:=Node; Result:=Node;
NeededRootDesc:=Node.Desc; NeededRootDesc:=Node.Desc;
if Node.Desc=ctnProcedure then
AliasText:=ExtractProcName(Node,[])
else
AliasText:=GetRedefinitionNodeText(Node); AliasText:=GetRedefinitionNodeText(Node);
if AliasText='' then exit; if AliasText='' then exit;
AVLNode:=FindCodeTreeNodeExtAVLNode(TreeOfCodeTreeNodeExt,AliasText); AVLNode:=FindCodeTreeNodeExtAVLNode(TreeOfCodeTreeNodeExt,AliasText);
@ -1640,12 +1641,17 @@ var
AVLNode: TAVLTreeNode; AVLNode: TAVLTreeNode;
NodeExt: TCodeTreeNodeExtension; NodeExt: TCodeTreeNodeExtension;
DefNode: TCodeTreeNode; DefNode: TCodeTreeNode;
ReferingNode: TCodeTreeNode;
NextAVLNode: TAVLTreeNode; NextAVLNode: TAVLTreeNode;
ReferingNodeInFront: TCodeTreeNodeExtension; ReferingNodeInFront: TCodeTreeNodeExtension;
ReferingNodeBehind: TCodeTreeNodeExtension; ReferingNodeBehind: TCodeTreeNodeExtension;
NewSrc: String; NewSrc: String;
FromPos: LongInt; FromPos: LongInt;
ToPos: LongInt;
ReferingType: TCodeTreeNodeDesc; ReferingType: TCodeTreeNodeDesc;
NewSection: String;
ProcName: String;
OldProcName: String;
begin begin
Result:=false; Result:=false;
if SourceChangeCache=nil then exit; if SourceChangeCache=nil then exit;
@ -1660,7 +1666,14 @@ begin
NodeExt:=TCodeTreeNodeExtension(AVLNode.Data); NodeExt:=TCodeTreeNodeExtension(AVLNode.Data);
DefNode:=NodeExt.Node; DefNode:=NodeExt.Node;
ReferingType:=TCodeTreeNodeDesc(NodeExt.Flags); ReferingType:=TCodeTreeNodeDesc(NodeExt.Flags);
if (not (ReferingType in [ctnTypeDefinition,ctnConstDefinition])) ReferingNode:=TCodeTreeNode(NodeExt.Data);
if (ReferingType=ctnProcedure) then begin
// procedure alias => check if it is an 'external' procedure
if (ReferingNode=nil) or (ReferingNode.Desc<>ctnProcedure)
or (not ProcNodeHasSpecifier(ReferingNode,psEXTERNAL)) then
ReferingType:=ctnNone;
end;
if (not (ReferingType in [ctnTypeDefinition,ctnConstDefinition,ctnProcedure]))
or (DefNode.Desc=ReferingType) then begin or (DefNode.Desc=ReferingType) then begin
TreeOfCodeTreeNodeExt.Delete(AVLNode); TreeOfCodeTreeNodeExt.Delete(AVLNode);
NodeExtMemManager.DisposeNode(NodeExt); NodeExtMemManager.DisposeNode(NodeExt);
@ -1674,23 +1687,25 @@ begin
NodeExt:=TCodeTreeNodeExtension(AVLNode.Data); NodeExt:=TCodeTreeNodeExtension(AVLNode.Data);
DefNode:=NodeExt.Node; DefNode:=NodeExt.Node;
ReferingType:=TCodeTreeNodeDesc(NodeExt.Flags); ReferingType:=TCodeTreeNodeDesc(NodeExt.Flags);
ReferingType:=TCodeTreeNodeDesc(NodeExt.Flags); ReferingNode:=TCodeTreeNode(NodeExt.Data);
//DebugLn(['TCodeCompletionCodeTool.FixAliasDefinitions Old=',DefNode.DescAsString,' New=',NodeDescToStr(ReferingType)]); //DebugLn(['TCodeCompletionCodeTool.FixAliasDefinitions Old=',DefNode.DescAsString,' New=',NodeDescToStr(ReferingType)]);
// check in front
if ReferingType in [ctnTypeDefinition,ctnConstDefinition] then begin
case ReferingType of case ReferingType of
ctnTypeDefinition: NewSrc:='type'; ctnTypeDefinition: NewSection:='type';
ctnConstDefinition: NewSrc:='const'; ctnConstDefinition: NewSection:='const';
else NewSrc:='bug'; ctnProcedure: NewSrc:='';
else NewSection:='bug';
end; end;
// check in front
if DefNode.PriorBrother=nil then begin if DefNode.PriorBrother=nil then begin
// this is the start of the section // this is the start of the section
MoveCursorToNodeStart(DefNode.Parent); MoveCursorToNodeStart(DefNode.Parent);
ReadNextAtom; ReadNextAtom;
if not SourceChangeCache.Replace(gtNone,gtNone, if not SourceChangeCache.Replace(gtNone,gtNone,
CurPos.StartPos,CurPos.EndPos,NewSrc) then exit; CurPos.StartPos,CurPos.EndPos,NewSection) then exit;
end else begin end else begin
// this is not the start of the section // this is not the start of the section
ReferingNodeInFront:=FindReferingNodeExt(DefNode.PriorBrother); ReferingNodeInFront:=FindReferingNodeExt(DefNode.PriorBrother);
@ -1700,9 +1715,40 @@ begin
// the node in front has a different section // the node in front has a different section
FromPos:=FindLineEndOrCodeInFrontOfPosition(DefNode.StartPos); FromPos:=FindLineEndOrCodeInFrontOfPosition(DefNode.StartPos);
if not SourceChangeCache.Replace(gtEmptyLine,gtNewLine, if not SourceChangeCache.Replace(gtEmptyLine,gtNewLine,
FromPos,FromPos,NewSrc) then exit; FromPos,FromPos,NewSection) then exit;
end; end;
end; end;
end else if ReferingType=ctnProcedure then begin
// alias to an external procedure
// => replace alias with complete external procedure header
if DefNode.PriorBrother=nil then begin
// this is the start of the section
FromPos:=FindLineEndOrCodeInFrontOfPosition(DefNode.Parent.StartPos);
ToPos:=FindLineEndOrCodeInFrontOfPosition(DefNode.StartPos);
if not SourceChangeCache.Replace(gtNone,gtNone,
FromPos,ToPos,'') then exit;
end;
NewSrc:=ExtractProcHead(ReferingNode,[phpWithStart,phpWithVarModifiers,
phpWithParameterNames,phpWithDefaultValues,phpWithResultType,
phpWithOfObject,phpWithCallingSpecs,phpWithProcModifiers]);
OldProcName:=ExtractProcName(ReferingNode,[]);
FromPos:=System.Pos(OldProcName,NewSrc);
if DefNode.Desc in [ctnTypeDefinition,ctnConstDefinition] then
ProcName:=ExtractDefinitionName(DefNode)
else if DefNode.Desc=ctnProcedure then
ProcName:=ExtractProcName(DefNode,[])
else
ProcName:=NodeExt.Txt;
NewSrc:=copy(NewSrc,1,FromPos-1)+ProcName
+copy(NewSrc,FromPos+length(OldProcName),length(NewSrc));
FromPos:=DefNode.StartPos;
ToPos:=DefNode.EndPos;
if not SourceChangeCache.Replace(gtNone,gtNone,FromPos,ToPos,NewSrc)
then
exit;
end;
// check behind // check behind
if DefNode.NextBrother=nil then begin if DefNode.NextBrother=nil then begin

View File

@ -2,7 +2,7 @@
<CONFIG> <CONFIG>
<ProjectOptions> <ProjectOptions>
<PathDelim Value="/"/> <PathDelim Value="/"/>
<Version Value="5"/> <Version Value="6"/>
<General> <General>
<Flags> <Flags>
<MainUnitHasCreateFormStatements Value="False"/> <MainUnitHasCreateFormStatements Value="False"/>
@ -26,10 +26,10 @@
</RunParams> </RunParams>
<RequiredPackages Count="2"> <RequiredPackages Count="2">
<Item1> <Item1>
<PackageName Value="CodeTools"/> <PackageName Value="LCL"/>
</Item1> </Item1>
<Item2> <Item2>
<PackageName Value="LCL"/> <PackageName Value="CodeTools"/>
</Item2> </Item2>
</RequiredPackages> </RequiredPackages>
<Units Count="3"> <Units Count="3">

View File

@ -47,16 +47,16 @@ begin
if Code=nil then if Code=nil then
raise Exception.Create('loading failed '+Filename); raise Exception.Create('loading failed '+Filename);
if not CodeToolBoss.FixAllAliasDefinitions(Code) then begin {if not CodeToolBoss.FixAllAliasDefinitions(Code) then begin
writeln('FixAllAliasDefinitions failed'); writeln('FixAllAliasDefinitions failed');
exit; exit;
end; end;}
// fix constants // fix constants
{if not CodeToolBoss.FixForwardDefinitions(Code) then begin if not CodeToolBoss.FixForwardDefinitions(Code) then begin
writeln('FixForwardDefinitions failed'); writeln('FixForwardDefinitions failed');
exit; exit;
end;} end;
// write the new source: // write the new source:
writeln('-----------------------------------'); writeln('-----------------------------------');