mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-10-24 00:01:40 +02:00
codetools: fixed resolving function result, simplified code
git-svn-id: trunk@54649 -
This commit is contained in:
parent
5fdd4105b4
commit
00d6a447b5
@ -1367,14 +1367,12 @@ function FindContextToString(const FindContext: TFindContext;
|
||||
RelativeFilename: boolean): string;
|
||||
var
|
||||
IdentNode: TCodeTreeNode;
|
||||
Caret: TCodeXYPosition;
|
||||
aFilename: String;
|
||||
begin
|
||||
Result:='';
|
||||
if FindContext.Node<>nil then begin
|
||||
Result:=Result+'Node="'+FindContext.Node.DescAsString+'"';
|
||||
IdentNode:=FindContext.Node;
|
||||
while (IdentNode<>nil) do begin
|
||||
while IdentNode<>nil do begin
|
||||
if IdentNode.Desc in AllSimpleIdentifierDefinitions
|
||||
+[ctnIdentifier,ctnEnumIdentifier,ctnLabel]
|
||||
then begin
|
||||
@ -1391,23 +1389,16 @@ begin
|
||||
Result:=Result+' PropName="'+
|
||||
FindContext.Tool.ExtractPropName(IdentNode,false)+'"';
|
||||
break;
|
||||
end else if IdentNode.Desc=ctnProcedure then begin
|
||||
Result:=Result+' Proc="'+FindContext.Tool.ExtractProcName(IdentNode,[])+'"';
|
||||
break;
|
||||
end;
|
||||
IdentNode:=IdentNode.Parent;
|
||||
end;
|
||||
if FindContext.Tool<>nil then begin
|
||||
if FindContext.Tool.CleanPosToCaret(FindContext.Node.StartPos,Caret) then
|
||||
begin
|
||||
aFilename:=Caret.Code.Filename;
|
||||
if RelativeFilename then
|
||||
aFilename:=ExtractRelativepath(ExtractFilePath(FindContext.Tool.MainFilename),aFilename);
|
||||
Result:=Result+' File='+aFilename+'('+IntToStr(Caret.Y)+','+IntToStr(Caret.X)+')';
|
||||
end else begin
|
||||
aFilename:=FindContext.Tool.MainFilename;
|
||||
if RelativeFilename then
|
||||
aFilename:=ExtractFileName(aFilename);
|
||||
Result:=Result+' File="'+aFilename+'"';
|
||||
end;
|
||||
end;
|
||||
if RelativeFilename then
|
||||
Result:=Result+' at "'+FindContext.Tool.CleanPosToStr(FindContext.Node.StartPos,true)+'"'
|
||||
else
|
||||
Result:=Result+' at "'+FindContext.Tool.CleanPosToRelativeStr(FindContext.Node.StartPos,'')+'"'
|
||||
end else
|
||||
Result:='nil';
|
||||
end;
|
||||
@ -5428,9 +5419,11 @@ begin
|
||||
end else
|
||||
break;
|
||||
end else
|
||||
if (Result.Node.Desc in [ctnProcedure,ctnProcedureHead]) then begin
|
||||
if Result.Node.Desc=ctnProcedure then
|
||||
Result.Node:=Result.Node.FirstChild;
|
||||
if Result.Node.Desc=ctnProcedure then begin
|
||||
Result.Node:=Result.Node.FirstChild;
|
||||
break;
|
||||
end else
|
||||
if Result.Node.Desc=ctnProcedureHead then begin
|
||||
break;
|
||||
end else
|
||||
if (Result.Node.Desc=ctnTypeType) then begin
|
||||
@ -10089,9 +10082,9 @@ begin
|
||||
Result.AliasType:=CleanFindContext;
|
||||
{$IFDEF ShowExprEval}
|
||||
DebugLn('[TFindDeclarationTool.CalculateBinaryOperator] A',
|
||||
' LeftOperand=',ExpressionTypeDescNames[LeftOperand.Desc],
|
||||
' LeftOperand=',ExprTypeToString(LeftOperand.Expr),
|
||||
' Operator=',GetAtom(BinaryOperator),
|
||||
' RightOperand=',ExpressionTypeDescNames[RightOperand.Desc]
|
||||
' RightOperand=',ExprTypeToString(RightOperand.Expr)
|
||||
);
|
||||
{$ENDIF}
|
||||
// convert Left and RightOperand contexts to expressiontype
|
||||
@ -12825,6 +12818,13 @@ begin
|
||||
@FindContext.Tool.Src[FindContext.Node.StartPos]);
|
||||
end;
|
||||
|
||||
ctnProcedureHead:
|
||||
begin
|
||||
ANode:=GetProcResultNode(FindContext.Node);
|
||||
if ANode<>nil then
|
||||
Result:=FindContext.Tool.ExtractNode(ANode,[]);
|
||||
end;
|
||||
|
||||
end;
|
||||
|
||||
if Result='' then begin
|
||||
|
@ -5877,6 +5877,12 @@ end;
|
||||
procedure TPascalParserTool.BuildSubTreeForProcHead(ProcNode: TCodeTreeNode;
|
||||
out FunctionResult: TCodeTreeNode);
|
||||
begin
|
||||
if ProcNode.Desc=ctnReferenceTo then
|
||||
ProcNode:=ProcNode.FirstChild;
|
||||
if ProcNode.Desc=ctnProcedureHead then
|
||||
ProcNode:=ProcNode.Parent;
|
||||
if not (ProcNode.Desc in [ctnProcedure,ctnProcedureType]) then
|
||||
RaiseException('INTERNAL ERROR: TPascalParserTool.BuildSubTreeForProcHead with FunctionResult');
|
||||
BuildSubTreeForProcHead(ProcNode);
|
||||
FunctionResult:=ProcNode.FirstChild.FirstChild;
|
||||
if (FunctionResult<>nil) and (FunctionResult.Desc=ctnParameterList) then
|
||||
|
@ -178,6 +178,7 @@ type
|
||||
function ProcNodeHasOfObject(ProcNode: TCodeTreeNode): boolean;
|
||||
function GetProcParamList(ProcNode: TCodeTreeNode;
|
||||
Parse: boolean = true): TCodeTreeNode;
|
||||
function GetProcResultNode(ProcNode: TCodeTreeNode): TCodeTreeNode;
|
||||
function NodeIsInAMethod(Node: TCodeTreeNode): boolean;
|
||||
function NodeIsMethodBody(ProcNode: TCodeTreeNode): boolean;
|
||||
function GetMethodOfBody(Node: TCodeTreeNode): TCodeTreeNode;
|
||||
@ -3319,6 +3320,23 @@ begin
|
||||
if Result.Desc<>ctnParameterList then exit(nil);
|
||||
end;
|
||||
|
||||
function TPascalReaderTool.GetProcResultNode(ProcNode: TCodeTreeNode
|
||||
): TCodeTreeNode;
|
||||
begin
|
||||
Result:=nil;
|
||||
if ProcNode=nil then exit;
|
||||
if ProcNode.Desc in [ctnProcedure,ctnProcedureType] then begin
|
||||
Result:=ProcNode.FirstChild;
|
||||
if Result=nil then exit;
|
||||
end;
|
||||
if (ProcNode=nil) or (ProcNode.Desc<>ctnProcedureHead) then exit;
|
||||
Result:=ProcNode.FirstChild;
|
||||
while Result<>nil do begin
|
||||
if Result.Desc=ctnIdentifier then exit;
|
||||
Result:=Result.NextBrother;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TPascalReaderTool.MoveCursorToUsesStart(UsesNode: TCodeTreeNode);
|
||||
begin
|
||||
if (UsesNode=nil)
|
||||
|
Loading…
Reference in New Issue
Block a user