mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-10-28 04:51:34 +01: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;
|
RelativeFilename: boolean): string;
|
||||||
var
|
var
|
||||||
IdentNode: TCodeTreeNode;
|
IdentNode: TCodeTreeNode;
|
||||||
Caret: TCodeXYPosition;
|
|
||||||
aFilename: String;
|
|
||||||
begin
|
begin
|
||||||
Result:='';
|
Result:='';
|
||||||
if FindContext.Node<>nil then begin
|
if FindContext.Node<>nil then begin
|
||||||
Result:=Result+'Node="'+FindContext.Node.DescAsString+'"';
|
Result:=Result+'Node="'+FindContext.Node.DescAsString+'"';
|
||||||
IdentNode:=FindContext.Node;
|
IdentNode:=FindContext.Node;
|
||||||
while (IdentNode<>nil) do begin
|
while IdentNode<>nil do begin
|
||||||
if IdentNode.Desc in AllSimpleIdentifierDefinitions
|
if IdentNode.Desc in AllSimpleIdentifierDefinitions
|
||||||
+[ctnIdentifier,ctnEnumIdentifier,ctnLabel]
|
+[ctnIdentifier,ctnEnumIdentifier,ctnLabel]
|
||||||
then begin
|
then begin
|
||||||
@ -1391,23 +1389,16 @@ begin
|
|||||||
Result:=Result+' PropName="'+
|
Result:=Result+' PropName="'+
|
||||||
FindContext.Tool.ExtractPropName(IdentNode,false)+'"';
|
FindContext.Tool.ExtractPropName(IdentNode,false)+'"';
|
||||||
break;
|
break;
|
||||||
|
end else if IdentNode.Desc=ctnProcedure then begin
|
||||||
|
Result:=Result+' Proc="'+FindContext.Tool.ExtractProcName(IdentNode,[])+'"';
|
||||||
|
break;
|
||||||
end;
|
end;
|
||||||
IdentNode:=IdentNode.Parent;
|
IdentNode:=IdentNode.Parent;
|
||||||
end;
|
end;
|
||||||
if FindContext.Tool<>nil then begin
|
if RelativeFilename then
|
||||||
if FindContext.Tool.CleanPosToCaret(FindContext.Node.StartPos,Caret) then
|
Result:=Result+' at "'+FindContext.Tool.CleanPosToStr(FindContext.Node.StartPos,true)+'"'
|
||||||
begin
|
else
|
||||||
aFilename:=Caret.Code.Filename;
|
Result:=Result+' at "'+FindContext.Tool.CleanPosToRelativeStr(FindContext.Node.StartPos,'')+'"'
|
||||||
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;
|
|
||||||
end else
|
end else
|
||||||
Result:='nil';
|
Result:='nil';
|
||||||
end;
|
end;
|
||||||
@ -5428,9 +5419,11 @@ begin
|
|||||||
end else
|
end else
|
||||||
break;
|
break;
|
||||||
end else
|
end else
|
||||||
if (Result.Node.Desc in [ctnProcedure,ctnProcedureHead]) then begin
|
if Result.Node.Desc=ctnProcedure then begin
|
||||||
if Result.Node.Desc=ctnProcedure then
|
Result.Node:=Result.Node.FirstChild;
|
||||||
Result.Node:=Result.Node.FirstChild;
|
break;
|
||||||
|
end else
|
||||||
|
if Result.Node.Desc=ctnProcedureHead then begin
|
||||||
break;
|
break;
|
||||||
end else
|
end else
|
||||||
if (Result.Node.Desc=ctnTypeType) then begin
|
if (Result.Node.Desc=ctnTypeType) then begin
|
||||||
@ -10089,9 +10082,9 @@ begin
|
|||||||
Result.AliasType:=CleanFindContext;
|
Result.AliasType:=CleanFindContext;
|
||||||
{$IFDEF ShowExprEval}
|
{$IFDEF ShowExprEval}
|
||||||
DebugLn('[TFindDeclarationTool.CalculateBinaryOperator] A',
|
DebugLn('[TFindDeclarationTool.CalculateBinaryOperator] A',
|
||||||
' LeftOperand=',ExpressionTypeDescNames[LeftOperand.Desc],
|
' LeftOperand=',ExprTypeToString(LeftOperand.Expr),
|
||||||
' Operator=',GetAtom(BinaryOperator),
|
' Operator=',GetAtom(BinaryOperator),
|
||||||
' RightOperand=',ExpressionTypeDescNames[RightOperand.Desc]
|
' RightOperand=',ExprTypeToString(RightOperand.Expr)
|
||||||
);
|
);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
// convert Left and RightOperand contexts to expressiontype
|
// convert Left and RightOperand contexts to expressiontype
|
||||||
@ -12825,6 +12818,13 @@ begin
|
|||||||
@FindContext.Tool.Src[FindContext.Node.StartPos]);
|
@FindContext.Tool.Src[FindContext.Node.StartPos]);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
ctnProcedureHead:
|
||||||
|
begin
|
||||||
|
ANode:=GetProcResultNode(FindContext.Node);
|
||||||
|
if ANode<>nil then
|
||||||
|
Result:=FindContext.Tool.ExtractNode(ANode,[]);
|
||||||
|
end;
|
||||||
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
if Result='' then begin
|
if Result='' then begin
|
||||||
|
|||||||
@ -5877,6 +5877,12 @@ end;
|
|||||||
procedure TPascalParserTool.BuildSubTreeForProcHead(ProcNode: TCodeTreeNode;
|
procedure TPascalParserTool.BuildSubTreeForProcHead(ProcNode: TCodeTreeNode;
|
||||||
out FunctionResult: TCodeTreeNode);
|
out FunctionResult: TCodeTreeNode);
|
||||||
begin
|
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);
|
BuildSubTreeForProcHead(ProcNode);
|
||||||
FunctionResult:=ProcNode.FirstChild.FirstChild;
|
FunctionResult:=ProcNode.FirstChild.FirstChild;
|
||||||
if (FunctionResult<>nil) and (FunctionResult.Desc=ctnParameterList) then
|
if (FunctionResult<>nil) and (FunctionResult.Desc=ctnParameterList) then
|
||||||
|
|||||||
@ -178,6 +178,7 @@ type
|
|||||||
function ProcNodeHasOfObject(ProcNode: TCodeTreeNode): boolean;
|
function ProcNodeHasOfObject(ProcNode: TCodeTreeNode): boolean;
|
||||||
function GetProcParamList(ProcNode: TCodeTreeNode;
|
function GetProcParamList(ProcNode: TCodeTreeNode;
|
||||||
Parse: boolean = true): TCodeTreeNode;
|
Parse: boolean = true): TCodeTreeNode;
|
||||||
|
function GetProcResultNode(ProcNode: TCodeTreeNode): TCodeTreeNode;
|
||||||
function NodeIsInAMethod(Node: TCodeTreeNode): boolean;
|
function NodeIsInAMethod(Node: TCodeTreeNode): boolean;
|
||||||
function NodeIsMethodBody(ProcNode: TCodeTreeNode): boolean;
|
function NodeIsMethodBody(ProcNode: TCodeTreeNode): boolean;
|
||||||
function GetMethodOfBody(Node: TCodeTreeNode): TCodeTreeNode;
|
function GetMethodOfBody(Node: TCodeTreeNode): TCodeTreeNode;
|
||||||
@ -3319,6 +3320,23 @@ begin
|
|||||||
if Result.Desc<>ctnParameterList then exit(nil);
|
if Result.Desc<>ctnParameterList then exit(nil);
|
||||||
end;
|
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);
|
procedure TPascalReaderTool.MoveCursorToUsesStart(UsesNode: TCodeTreeNode);
|
||||||
begin
|
begin
|
||||||
if (UsesNode=nil)
|
if (UsesNode=nil)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user