mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-21 05:39:17 +02:00
codetools: alias for FindBaseTypeOfNode
git-svn-id: trunk@30751 -
This commit is contained in:
parent
3dc186123d
commit
156372ea58
@ -643,10 +643,11 @@ type
|
|||||||
function FindStartOfTerm(EndPos: integer; InType: boolean): integer;
|
function FindStartOfTerm(EndPos: integer; InType: boolean): integer;
|
||||||
function NodeTermInType(Node: TCodeTreeNode): boolean;
|
function NodeTermInType(Node: TCodeTreeNode): boolean;
|
||||||
function FindExpressionTypeOfTerm(StartPos, EndPos: integer;
|
function FindExpressionTypeOfTerm(StartPos, EndPos: integer;
|
||||||
Params: TFindDeclarationParams; WithAsOperator: boolean): TExpressionType;
|
Params: TFindDeclarationParams; WithAsOperator: boolean;
|
||||||
|
AliasType: PFindContext = nil): TExpressionType;
|
||||||
function FindEndOfExpression(StartPos: integer): integer; // read all operands and operators
|
function FindEndOfExpression(StartPos: integer): integer; // read all operands and operators
|
||||||
function ReadOperandTypeAtCursor(Params: TFindDeclarationParams;
|
function ReadOperandTypeAtCursor(Params: TFindDeclarationParams;
|
||||||
MaxEndPos: integer = -1): TExpressionType;
|
MaxEndPos: integer = -1; AliasType: PFindContext = nil): TExpressionType;
|
||||||
function FindExpressionTypeOfPredefinedIdentifier(StartPos: integer;
|
function FindExpressionTypeOfPredefinedIdentifier(StartPos: integer;
|
||||||
Params: TFindDeclarationParams): TExpressionType;
|
Params: TFindDeclarationParams): TExpressionType;
|
||||||
function CalculateBinaryOperator(LeftOperand, RightOperand: TExpressionType;
|
function CalculateBinaryOperator(LeftOperand, RightOperand: TExpressionType;
|
||||||
@ -803,9 +804,10 @@ type
|
|||||||
|
|
||||||
function BaseTypeOfNodeHasSubIdents(ANode: TCodeTreeNode): boolean;
|
function BaseTypeOfNodeHasSubIdents(ANode: TCodeTreeNode): boolean;
|
||||||
function FindBaseTypeOfNode(Params: TFindDeclarationParams;
|
function FindBaseTypeOfNode(Params: TFindDeclarationParams;
|
||||||
Node: TCodeTreeNode; NodeStack: PCodeTreeNodeStack = nil): TFindContext;
|
Node: TCodeTreeNode; AliasType: PFindContext = nil;
|
||||||
|
NodeStack: PCodeTreeNodeStack = nil): TFindContext;
|
||||||
function ConvertNodeToExpressionType(Node: TCodeTreeNode;
|
function ConvertNodeToExpressionType(Node: TCodeTreeNode;
|
||||||
Params: TFindDeclarationParams): TExpressionType;
|
Params: TFindDeclarationParams; AliasType: PFindContext = nil): TExpressionType;
|
||||||
|
|
||||||
function FindDeclarationAndOverload(const CursorPos: TCodeXYPosition;
|
function FindDeclarationAndOverload(const CursorPos: TCodeXYPosition;
|
||||||
out ListOfPCodeXYPosition: TFPList;
|
out ListOfPCodeXYPosition: TFPList;
|
||||||
@ -877,7 +879,8 @@ function ExprTypeToString(const ExprType: TExpressionType): string;
|
|||||||
function CreateExpressionType(const Desc, SubDesc: TExpressionTypeDesc;
|
function CreateExpressionType(const Desc, SubDesc: TExpressionTypeDesc;
|
||||||
const Context: TFindContext): TExpressionType;
|
const Context: TFindContext): TExpressionType;
|
||||||
|
|
||||||
function FindContextToString(const FindContext: TFindContext): string;
|
function FindContextToString(const FindContext: TFindContext): string; overload;
|
||||||
|
function FindContextToString(const FindContext: PFindContext): string; overload;
|
||||||
function CreateFindContext(NewTool: TFindDeclarationTool;
|
function CreateFindContext(NewTool: TFindDeclarationTool;
|
||||||
NewNode: TCodeTreeNode): TFindContext;
|
NewNode: TCodeTreeNode): TFindContext;
|
||||||
function CreateFindContext(Params: TFindDeclarationParams): TFindContext;
|
function CreateFindContext(Params: TFindDeclarationParams): TFindContext;
|
||||||
@ -1105,7 +1108,16 @@ begin
|
|||||||
Result:=Result+' File="'+FindContext.Tool.MainFilename+'"';
|
Result:=Result+' File="'+FindContext.Tool.MainFilename+'"';
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end else
|
||||||
|
Result:='nil';
|
||||||
|
end;
|
||||||
|
|
||||||
|
function FindContextToString(const FindContext: PFindContext): string;
|
||||||
|
begin
|
||||||
|
if FindContext=nil then
|
||||||
|
Result:='-'
|
||||||
|
else
|
||||||
|
Result:=FindContextToString(FindContext^);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function CreateFindContext(NewTool: TFindDeclarationTool;
|
function CreateFindContext(NewTool: TFindDeclarationTool;
|
||||||
@ -3317,7 +3329,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function TFindDeclarationTool.FindBaseTypeOfNode(
|
function TFindDeclarationTool.FindBaseTypeOfNode(
|
||||||
Params: TFindDeclarationParams; Node: TCodeTreeNode;
|
Params: TFindDeclarationParams; Node: TCodeTreeNode; AliasType: PFindContext;
|
||||||
NodeStack: PCodeTreeNodeStack): TFindContext;
|
NodeStack: PCodeTreeNodeStack): TFindContext;
|
||||||
var
|
var
|
||||||
MyNodeStack: TCodeTreeNodeStack;
|
MyNodeStack: TCodeTreeNodeStack;
|
||||||
@ -3469,9 +3481,9 @@ var
|
|||||||
OldFlags: TFindDeclarationFlags;
|
OldFlags: TFindDeclarationFlags;
|
||||||
AliasContext: TFindContext;
|
AliasContext: TFindContext;
|
||||||
Cache: TBaseTypeCache;
|
Cache: TBaseTypeCache;
|
||||||
UseAlias: Boolean;
|
|
||||||
begin
|
begin
|
||||||
UseAlias:=false;
|
if (NodeStack<>nil) and (NodeStack<>@MyNodeStack) then exit; // will be handled by caller
|
||||||
|
|
||||||
if (Context.Node<>nil) and (Context.Node.Desc in [ctnProcedure,ctnProcedureHead])
|
if (Context.Node<>nil) and (Context.Node.Desc in [ctnProcedure,ctnProcedureHead])
|
||||||
and (fdfFunctionResult in Params.Flags) then begin
|
and (fdfFunctionResult in Params.Flags) then begin
|
||||||
// a proc -> if this is a function then return the Context type
|
// a proc -> if this is a function then return the Context type
|
||||||
@ -3483,9 +3495,10 @@ var
|
|||||||
OldFlags:=Params.Flags;
|
OldFlags:=Params.Flags;
|
||||||
Exclude(Params.Flags,fdfFunctionResult);
|
Exclude(Params.Flags,fdfFunctionResult);
|
||||||
//debugln(['TFindDeclarationTool.FindBaseTypeOfNode searching for function Context type: ',Context.Tool.ExtractNode(DummyNode,[])]);
|
//debugln(['TFindDeclarationTool.FindBaseTypeOfNode searching for function Context type: ',Context.Tool.ExtractNode(DummyNode,[])]);
|
||||||
Context:=Context.Tool.FindBaseTypeOfNode(Params,ResultNode);
|
Context:=Context.Tool.FindBaseTypeOfNode(Params,ResultNode,AliasType);
|
||||||
UseAlias:=false; // aliasing has been done
|
AliasType:=nil; // aliasing has been done
|
||||||
Params.Flags:=OldFlags;
|
Params.Flags:=OldFlags;
|
||||||
|
exit;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
if (Context.Node=nil) and (fdfExceptionOnNotFound in Params.Flags) then begin
|
if (Context.Node=nil) and (fdfExceptionOnNotFound in Params.Flags) then begin
|
||||||
@ -3499,7 +3512,7 @@ var
|
|||||||
end;
|
end;
|
||||||
RaiseBaseTypeOfNotFound;
|
RaiseBaseTypeOfNotFound;
|
||||||
end;
|
end;
|
||||||
if UseAlias then begin
|
if AliasType<>nil then begin
|
||||||
// follow the base type chain to the first type
|
// follow the base type chain to the first type
|
||||||
// for example: var d: TDateTime; use TDateTime, instead of Double.
|
// for example: var d: TDateTime; use TDateTime, instead of Double.
|
||||||
AliasContext.Node:=Node;
|
AliasContext.Node:=Node;
|
||||||
@ -3509,7 +3522,7 @@ var
|
|||||||
{$IF defined(ShowExprEval) or defined(ShowTriedBaseContexts)}
|
{$IF defined(ShowExprEval) or defined(ShowTriedBaseContexts)}
|
||||||
debugln(['TFindDeclarationTool.FindBaseTypeOfNode.CheckResult using alias ',AliasContext.Tool.ExtractDefinitionName(AliasContext.Node),' instead of base type ',Context.Node.DescAsString]);
|
debugln(['TFindDeclarationTool.FindBaseTypeOfNode.CheckResult using alias ',AliasContext.Tool.ExtractDefinitionName(AliasContext.Node),' instead of base type ',Context.Node.DescAsString]);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
Context:=AliasContext;
|
AliasType^:=AliasContext;
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
if AliasContext.Node.Cache is TBaseTypeCache then begin
|
if AliasContext.Node.Cache is TBaseTypeCache then begin
|
||||||
@ -3532,6 +3545,7 @@ var
|
|||||||
IsPredefined: boolean;
|
IsPredefined: boolean;
|
||||||
OldStartFlags: TFindDeclarationFlags;
|
OldStartFlags: TFindDeclarationFlags;
|
||||||
begin
|
begin
|
||||||
|
if AliasType<>nil then AliasType^:=CleanFindContext;
|
||||||
{$IFDEF CheckNodeTool}CheckNodeTool(Node);{$ENDIF}
|
{$IFDEF CheckNodeTool}CheckNodeTool(Node);{$ENDIF}
|
||||||
//debugln(['TFindDeclarationTool.FindBaseTypeOfNode Flags=[',dbgs(Params.Flags),'] CacheValid=',Node.Cache is TBaseTypeCache]);
|
//debugln(['TFindDeclarationTool.FindBaseTypeOfNode Flags=[',dbgs(Params.Flags),'] CacheValid=',Node.Cache is TBaseTypeCache]);
|
||||||
if (Node<>nil) and (Node.Cache is TBaseTypeCache) then begin
|
if (Node<>nil) and (Node.Cache is TBaseTypeCache) then begin
|
||||||
@ -3572,7 +3586,7 @@ begin
|
|||||||
{$IFDEF ShowTriedBaseContexts}
|
{$IFDEF ShowTriedBaseContexts}
|
||||||
DebugLn(['[TFindDeclarationTool.FindBaseTypeOfNode] continuing in ',Result.Tool.MainFilename]);
|
DebugLn(['[TFindDeclarationTool.FindBaseTypeOfNode] continuing in ',Result.Tool.MainFilename]);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
Result:=Result.Tool.FindBaseTypeOfNode(Params,Result.Node,NodeStack);
|
Result:=Result.Tool.FindBaseTypeOfNode(Params,Result.Node,AliasType,NodeStack);
|
||||||
break;
|
break;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -5368,6 +5382,7 @@ type
|
|||||||
TExprStack = array[0..4] of TOperandAndOperator;
|
TExprStack = array[0..4] of TOperandAndOperator;
|
||||||
var
|
var
|
||||||
CurExprType: TExpressionType;
|
CurExprType: TExpressionType;
|
||||||
|
CurAliasType: TFindContext;
|
||||||
ExprStack: TExprStack;
|
ExprStack: TExprStack;
|
||||||
StackPtr: integer;
|
StackPtr: integer;
|
||||||
|
|
||||||
@ -5448,10 +5463,10 @@ begin
|
|||||||
MoveCursorToCleanPos(StartPos);
|
MoveCursorToCleanPos(StartPos);
|
||||||
repeat
|
repeat
|
||||||
// read operand
|
// read operand
|
||||||
CurExprType:=ReadOperandTypeAtCursor(Params,EndPos);
|
CurExprType:=ReadOperandTypeAtCursor(Params,EndPos,@CurAliasType);
|
||||||
{$IFDEF ShowExprEval}
|
{$IFDEF ShowExprEval}
|
||||||
DebugLn('[TFindDeclarationTool.FindExpressionResultType] Operand: ',
|
DebugLn(['[TFindDeclarationTool.FindExpressionResultType] Operand: ',
|
||||||
ExprTypeToString(CurExprType));
|
ExprTypeToString(CurExprType),' Alias=',FindContextToString(CurAliasType)]);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
// put operand on stack
|
// put operand on stack
|
||||||
inc(StackPtr);
|
inc(StackPtr);
|
||||||
@ -6414,8 +6429,8 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function TFindDeclarationTool.FindExpressionTypeOfTerm(StartPos,
|
function TFindDeclarationTool.FindExpressionTypeOfTerm(StartPos,
|
||||||
EndPos: integer; Params: TFindDeclarationParams; WithAsOperator: boolean
|
EndPos: integer; Params: TFindDeclarationParams; WithAsOperator: boolean;
|
||||||
): TExpressionType;
|
AliasType: PFindContext): TExpressionType;
|
||||||
{ examples
|
{ examples
|
||||||
1. A.B
|
1. A.B
|
||||||
2. A().B
|
2. A().B
|
||||||
@ -6529,7 +6544,9 @@ var
|
|||||||
var BehindFuncAtomType: TVariableAtomType;
|
var BehindFuncAtomType: TVariableAtomType;
|
||||||
begin
|
begin
|
||||||
if IsIdentEndOfVar=iieovUnknown then begin
|
if IsIdentEndOfVar=iieovUnknown then begin
|
||||||
if CurAtom.Flag=cafWord then begin
|
if CurAtom.StartPos>=EndPos then begin
|
||||||
|
IsIdentEndOfVar:=iieovYes;
|
||||||
|
end else if CurAtom.Flag=cafWord then begin
|
||||||
MoveCursorToCleanPos(CurAtom.EndPos);
|
MoveCursorToCleanPos(CurAtom.EndPos);
|
||||||
ReadNextAtom;
|
ReadNextAtom;
|
||||||
if AtomIsChar('(') then begin
|
if AtomIsChar('(') then begin
|
||||||
@ -6563,6 +6580,7 @@ var
|
|||||||
var
|
var
|
||||||
ProcNode, FuncResultNode: TCodeTreeNode;
|
ProcNode, FuncResultNode: TCodeTreeNode;
|
||||||
AtEnd: Boolean;
|
AtEnd: Boolean;
|
||||||
|
CurAliasType: PFindContext;
|
||||||
begin
|
begin
|
||||||
//DebugLn(['ResolveBaseTypeOfIdentifier ',ExprType.Context.Node<>nil]);
|
//DebugLn(['ResolveBaseTypeOfIdentifier ',ExprType.Context.Node<>nil]);
|
||||||
if (ExprType.Context.Node=nil) then exit;
|
if (ExprType.Context.Node=nil) then exit;
|
||||||
@ -6579,16 +6597,19 @@ var
|
|||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
CurAliasType:=nil;
|
||||||
|
if AtEnd then CurAliasType:=AliasType;
|
||||||
|
|
||||||
// find base type
|
// find base type
|
||||||
Exclude(Params.Flags,fdfFunctionResult);
|
Exclude(Params.Flags,fdfFunctionResult);
|
||||||
Include(Params.Flags,fdfEnumIdentifier);
|
Include(Params.Flags,fdfEnumIdentifier);
|
||||||
{$IFDEF ShowExprEval}
|
{$IFDEF ShowExprEval}
|
||||||
DebugLn(' ResolveBaseTypeOfIdentifier BEFORE ExprType=',ExprTypeToString(ExprType));
|
DebugLn([' ResolveBaseTypeOfIdentifier BEFORE ExprType=',ExprTypeToString(ExprType),' Alias=',CurAliasType<>nil]);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
ExprType:=ExprType.Context.Tool.ConvertNodeToExpressionType(
|
ExprType:=ExprType.Context.Tool.ConvertNodeToExpressionType(
|
||||||
ExprType.Context.Node,Params);
|
ExprType.Context.Node,Params,CurAliasType);
|
||||||
{$IFDEF ShowExprEval}
|
{$IFDEF ShowExprEval}
|
||||||
DebugLn(' ResolveBaseTypeOfIdentifier AFTER ExprType=',ExprTypeToString(ExprType));
|
DebugLn([' ResolveBaseTypeOfIdentifier AFTER ExprType=',ExprTypeToString(ExprType),' Alias=',FindContextToString(CurAliasType)]);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
if (ExprType.Desc=xtContext)
|
if (ExprType.Desc=xtContext)
|
||||||
and (ExprType.Context.Node.Desc in [ctnProcedure,ctnProcedureHead]) then
|
and (ExprType.Context.Node.Desc in [ctnProcedure,ctnProcedureHead]) then
|
||||||
@ -6598,7 +6619,7 @@ var
|
|||||||
if ProcNode.Desc=ctnProcedureHead then
|
if ProcNode.Desc=ctnProcedureHead then
|
||||||
ProcNode:=ProcNode.Parent;
|
ProcNode:=ProcNode.Parent;
|
||||||
ExprType.Context.Tool.BuildSubTreeForProcHead(ProcNode.FirstChild,
|
ExprType.Context.Tool.BuildSubTreeForProcHead(ProcNode.FirstChild,
|
||||||
FuncResultNode);
|
FuncResultNode);
|
||||||
{$IFDEF ShowExprEval}
|
{$IFDEF ShowExprEval}
|
||||||
DebugLn([' ResolveBaseTypeOfIdentifier IsFunction/operator=',FuncResultNode<>nil,' IsConstructor=',ExprType.Context.Tool.NodeIsConstructor(ProcNode),' IsIdentifierEndOfVariable=',IsIdentifierEndOfVariable,' fdfFunctionResult in StartFlags=',fdfFunctionResult in StartFlags]);
|
DebugLn([' ResolveBaseTypeOfIdentifier IsFunction/operator=',FuncResultNode<>nil,' IsConstructor=',ExprType.Context.Tool.NodeIsConstructor(ProcNode),' IsIdentifierEndOfVariable=',IsIdentifierEndOfVariable,' fdfFunctionResult in StartFlags=',fdfFunctionResult in StartFlags]);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
@ -6606,14 +6627,14 @@ var
|
|||||||
then begin
|
then begin
|
||||||
// it is function or a constructor
|
// it is function or a constructor
|
||||||
// -> use the result type instead of the function
|
// -> use the result type instead of the function
|
||||||
if IsIdentifierEndOfVariable then begin
|
if AtEnd then begin
|
||||||
// this function identifier is the end of the variable
|
// this function identifier is the end of the variable
|
||||||
if not (fdfFunctionResult in StartFlags) then
|
if not (fdfFunctionResult in StartFlags) then
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
Include(Params.Flags,fdfFunctionResult);
|
Include(Params.Flags,fdfFunctionResult);
|
||||||
ExprType:=ExprType.Context.Tool.ConvertNodeToExpressionType(
|
ExprType:=ExprType.Context.Tool.ConvertNodeToExpressionType(
|
||||||
ProcNode,Params);
|
ProcNode,Params,CurAliasType);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -7131,13 +7152,15 @@ var
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
Result:=CleanExpressionType;
|
Result:=CleanExpressionType;
|
||||||
|
if AliasType<>nil then AliasType^:=CleanFindContext;
|
||||||
StartFlags:=Params.Flags;
|
StartFlags:=Params.Flags;
|
||||||
StartContext.Tool:=Self;
|
StartContext.Tool:=Self;
|
||||||
StartContext.Node:=Params.ContextNode;
|
StartContext.Node:=Params.ContextNode;
|
||||||
{$IFDEF ShowExprEval}
|
{$IFDEF ShowExprEval}
|
||||||
DebugLn('[TFindDeclarationTool.FindExpressionTypeOfTerm]',
|
DebugLn(['[TFindDeclarationTool.FindExpressionTypeOfTerm] START',
|
||||||
' Flags=[',dbgs(Params.Flags),']',
|
' Flags=[',dbgs(Params.Flags),']',
|
||||||
' StartContext=',StartContext.Node.DescAsString,'=',dbgstr(copy(StartContext.Tool.Src,StartContext.Node.StartPos,15))
|
' StartContext=',StartContext.Node.DescAsString,'=',dbgstr(StartContext.Tool.Src,StartContext.Node.StartPos,15),
|
||||||
|
' Alias=',AliasType<>nil]
|
||||||
);
|
);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
{$IFDEF CheckNodeTool}
|
{$IFDEF CheckNodeTool}
|
||||||
@ -7146,14 +7169,14 @@ begin
|
|||||||
|
|
||||||
if not InitAtomQueue then exit;
|
if not InitAtomQueue then exit;
|
||||||
{$IFDEF ShowExprEval}
|
{$IFDEF ShowExprEval}
|
||||||
DebugLn(['TFindDeclarationTool.FindExpressionTypeOfTerm Expression="',copy(Src,StartPos,EndPos-StartPos),'"']);
|
DebugLn([' FindExpressionTypeOfTerm AFTER INIT Expression="',dbgstr(Src,StartPos,EndPos-StartPos),'"']);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
ExprType.Desc:=xtContext;
|
ExprType.Desc:=xtContext;
|
||||||
ExprType.SubDesc:=xtNone;
|
ExprType.SubDesc:=xtNone;
|
||||||
ExprType.Context:=StartContext;
|
ExprType.Context:=StartContext;
|
||||||
repeat
|
repeat
|
||||||
{$IFDEF ShowExprEval}
|
{$IFDEF ShowExprEval}
|
||||||
DebugLn(' FindExpressionTypeOfTerm CurAtomType=',
|
DebugLn(' FindExpressionTypeOfTerm ATOM CurAtomType=',
|
||||||
VariableAtomTypeNames[CurAtomType],' CurAtom="',GetAtom(CurAtom),'"',
|
VariableAtomTypeNames[CurAtomType],' CurAtom="',GetAtom(CurAtom),'"',
|
||||||
' ExprType=',ExprTypeToString(ExprType));
|
' ExprType=',ExprTypeToString(ExprType));
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
@ -7205,40 +7228,39 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function TFindDeclarationTool.ConvertNodeToExpressionType(Node: TCodeTreeNode;
|
function TFindDeclarationTool.ConvertNodeToExpressionType(Node: TCodeTreeNode;
|
||||||
Params: TFindDeclarationParams): TExpressionType;
|
Params: TFindDeclarationParams; AliasType: PFindContext): TExpressionType;
|
||||||
|
|
||||||
procedure ConvertIdentifierAtCursor;
|
procedure ConvertIdentifierAtCursor(Tool: TFindDeclarationTool);
|
||||||
begin
|
begin
|
||||||
if WordIsPredefinedIdentifier.DoItCaseInsensitive(Src,CurPos.StartPos,
|
if WordIsPredefinedIdentifier.DoItCaseInsensitive(Tool.Src,Tool.CurPos.StartPos,
|
||||||
CurPos.EndPos-CurPos.StartPos) then
|
Tool.CurPos.EndPos-Tool.CurPos.StartPos) then
|
||||||
begin
|
begin
|
||||||
// predefined identifiers
|
// predefined identifiers
|
||||||
ConvertNodeToExpressionType:=FindExpressionTypeOfPredefinedIdentifier(
|
ConvertNodeToExpressionType:=Tool.FindExpressionTypeOfPredefinedIdentifier(
|
||||||
CurPos.StartPos,Params);
|
Tool.CurPos.StartPos,Params);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
var
|
var
|
||||||
BaseContext: TFindContext;
|
BaseContext: TFindContext;
|
||||||
OldInput: TFindDeclarationInput;
|
OldInput: TFindDeclarationInput;
|
||||||
|
Tool: TFindDeclarationTool;
|
||||||
begin
|
begin
|
||||||
{$IFDEF CheckNodeTool}CheckNodeTool(Node);{$ENDIF}
|
{$IFDEF CheckNodeTool}CheckNodeTool(Node);{$ENDIF}
|
||||||
|
if AliasType<>nil then AliasType^:=CleanFindContext;
|
||||||
{$IFDEF ShowExprEval}
|
{$IFDEF ShowExprEval}
|
||||||
DebugLn(['[TFindDeclarationTool.ConvertNodeToExpressionType] A',
|
DebugLn(['[TFindDeclarationTool.ConvertNodeToExpressionType] A',
|
||||||
' Node=',Node.DescAsString,' "',dbgstr(copy(ExtractNode(Node,[]),1,30)),'" Flags=[',dbgs(Params.Flags),']']);
|
' Node=',Node.DescAsString,' "',dbgstr(copy(ExtractNode(Node,[]),1,30)),'" Flags=[',dbgs(Params.Flags),'] Alias=',AliasType<>nil]);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
BaseContext:=FindBaseTypeOfNode(Params,Node);
|
BaseContext:=FindBaseTypeOfNode(Params,Node,AliasType);
|
||||||
Node:=BaseContext.Node;
|
Node:=BaseContext.Node;
|
||||||
if BaseContext.Tool<>Self then begin
|
Tool:=BaseContext.Tool;
|
||||||
Result:=BaseContext.Tool.ConvertNodeToExpressionType(Node,Params);
|
|
||||||
exit;
|
|
||||||
end;
|
|
||||||
Result:=CleanExpressionType;
|
Result:=CleanExpressionType;
|
||||||
Result.Desc:=xtContext;
|
Result.Desc:=xtContext;
|
||||||
Result.Context:=CreateFindContext(Self,Node);
|
Result.Context:=BaseContext;
|
||||||
{$IFDEF ShowExprEval}
|
{$IFDEF ShowExprEval}
|
||||||
DebugLn('[TFindDeclarationTool.ConvertNodeToExpressionType] B',
|
DebugLn('[TFindDeclarationTool.ConvertNodeToExpressionType] B',
|
||||||
' Expr=',ExprTypeToString(Result));
|
' Expr=',ExprTypeToString(Result),' Alias=',FindContextToString(AliasType));
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
case Node.Desc of
|
case Node.Desc of
|
||||||
ctnRangeType:
|
ctnRangeType:
|
||||||
@ -7247,15 +7269,15 @@ begin
|
|||||||
|
|
||||||
// ToDo: ppu, dcu files
|
// ToDo: ppu, dcu files
|
||||||
|
|
||||||
MoveCursorToNodeStart(Node);
|
Tool.MoveCursorToNodeStart(Node);
|
||||||
|
|
||||||
// ToDo: check for circles
|
// ToDo: check for circles
|
||||||
|
|
||||||
Params.Save(OldInput);
|
Params.Save(OldInput);
|
||||||
Params.ContextNode:=Node;
|
Params.ContextNode:=Node;
|
||||||
Result:=ReadOperandTypeAtCursor(Params);
|
Result:=Tool.ReadOperandTypeAtCursor(Params);
|
||||||
Params.Load(OldInput,true);
|
Params.Load(OldInput,true);
|
||||||
Result.Context:=CreateFindContext(Self,Node);
|
Result.Context:=CreateFindContext(Tool,Node);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
ctnConstDefinition:
|
ctnConstDefinition:
|
||||||
@ -7264,21 +7286,21 @@ begin
|
|||||||
|
|
||||||
// ToDo: ppu, dcu files
|
// ToDo: ppu, dcu files
|
||||||
|
|
||||||
MoveCursorToNodeStart(Node);
|
Tool.MoveCursorToNodeStart(Node);
|
||||||
|
|
||||||
ReadNextAtom;
|
Tool.ReadNextAtom;
|
||||||
if not AtomIsIdentifier(false) then exit;
|
if not Tool.AtomIsIdentifier(false) then exit;
|
||||||
ReadNextAtom;
|
Tool.ReadNextAtom;
|
||||||
if not (CurPos.Flag in [cafEqual,cafColon]) then exit;
|
if not (CurPos.Flag in [cafEqual,cafColon]) then exit;
|
||||||
ReadNextAtom;
|
Tool.ReadNextAtom;
|
||||||
|
|
||||||
// ToDo: check for circles
|
// ToDo: check for circles
|
||||||
|
|
||||||
Params.Save(OldInput);
|
Params.Save(OldInput);
|
||||||
Params.ContextNode:=Node;
|
Params.ContextNode:=Node;
|
||||||
Result:=ReadOperandTypeAtCursor(Params);
|
Result:=Tool.ReadOperandTypeAtCursor(Params);
|
||||||
Params.Load(OldInput,true);
|
Params.Load(OldInput,true);
|
||||||
Result.Context:=CreateFindContext(Self,Node);
|
Result.Context:=CreateFindContext(Tool,Node);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
ctnIdentifier:
|
ctnIdentifier:
|
||||||
@ -7286,9 +7308,9 @@ begin
|
|||||||
|
|
||||||
// ToDo: ppu, dcu files
|
// ToDo: ppu, dcu files
|
||||||
|
|
||||||
MoveCursorToNodeStart(Node);
|
Tool.MoveCursorToNodeStart(Node);
|
||||||
ReadNextAtom;
|
Tool.ReadNextAtom;
|
||||||
ConvertIdentifierAtCursor;
|
ConvertIdentifierAtCursor(Tool);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
ctnProperty,ctnGlobalProperty:
|
ctnProperty,ctnGlobalProperty:
|
||||||
@ -7296,8 +7318,8 @@ begin
|
|||||||
|
|
||||||
// ToDo: ppu, dcu files
|
// ToDo: ppu, dcu files
|
||||||
|
|
||||||
if MoveCursorToPropName(Node) then
|
if Tool.MoveCursorToPropName(Node) then
|
||||||
ConvertIdentifierAtCursor;
|
ConvertIdentifierAtCursor(Tool);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
ctnConstant:
|
ctnConstant:
|
||||||
@ -7305,23 +7327,24 @@ begin
|
|||||||
|
|
||||||
// ToDo: ppu, dcu files
|
// ToDo: ppu, dcu files
|
||||||
|
|
||||||
MoveCursorToNodeStart(Node);
|
Tool.MoveCursorToNodeStart(Node);
|
||||||
Params.Save(OldInput);
|
Params.Save(OldInput);
|
||||||
Params.ContextNode:=Node;
|
Params.ContextNode:=Node;
|
||||||
Result:=ReadOperandTypeAtCursor(Params);
|
Result:=Tool.ReadOperandTypeAtCursor(Params);
|
||||||
Params.Load(OldInput,true);
|
Params.Load(OldInput,true);
|
||||||
Result.Context:=CreateFindContext(Self,Node);
|
Result.Context:=CreateFindContext(Tool,Node);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{$IFDEF ShowExprEval}
|
{$IFDEF ShowExprEval}
|
||||||
DebugLn('[TFindDeclarationTool.ConvertNodeToExpressionType] END',
|
DebugLn('[TFindDeclarationTool.ConvertNodeToExpressionType] END',
|
||||||
' Expr=',ExprTypeToString(Result));
|
' Expr=',ExprTypeToString(Result),' Alias=',FindContextToString(AliasType));
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TFindDeclarationTool.ReadOperandTypeAtCursor(
|
function TFindDeclarationTool.ReadOperandTypeAtCursor(
|
||||||
Params: TFindDeclarationParams; MaxEndPos: integer): TExpressionType;
|
Params: TFindDeclarationParams; MaxEndPos: integer; AliasType: PFindContext
|
||||||
|
): TExpressionType;
|
||||||
{ internally used by FindExpressionResultType
|
{ internally used by FindExpressionResultType
|
||||||
after reading, the cursor will be on the next atom
|
after reading, the cursor will be on the next atom
|
||||||
}
|
}
|
||||||
@ -7367,6 +7390,7 @@ var
|
|||||||
OldFlags: TFindDeclarationFlags;
|
OldFlags: TFindDeclarationFlags;
|
||||||
begin
|
begin
|
||||||
Result:=CleanExpressionType;
|
Result:=CleanExpressionType;
|
||||||
|
if AliasType<>nil then AliasType^:=CleanFindContext;
|
||||||
|
|
||||||
if CurPos.StartPos=CurPos.EndPos then ReadNextAtom;
|
if CurPos.StartPos=CurPos.EndPos then ReadNextAtom;
|
||||||
// read unary operators which have no effect on the type: +, -, not
|
// read unary operators which have no effect on the type: +, -, not
|
||||||
@ -7385,7 +7409,7 @@ begin
|
|||||||
EndPos:=MaxEndPos;
|
EndPos:=MaxEndPos;
|
||||||
OldFlags:=Params.Flags;
|
OldFlags:=Params.Flags;
|
||||||
Params.Flags:=(Params.Flags*fdfGlobals)+[fdfFunctionResult];
|
Params.Flags:=(Params.Flags*fdfGlobals)+[fdfFunctionResult];
|
||||||
Result:=FindExpressionTypeOfTerm(SubStartPos,EndPos,Params,true);
|
Result:=FindExpressionTypeOfTerm(SubStartPos,EndPos,Params,true,AliasType);
|
||||||
Params.Flags:=OldFlags;
|
Params.Flags:=OldFlags;
|
||||||
MoveCursorToCleanPos(EndPos);
|
MoveCursorToCleanPos(EndPos);
|
||||||
end
|
end
|
||||||
@ -7423,7 +7447,7 @@ begin
|
|||||||
EndPos:=MaxEndPos;
|
EndPos:=MaxEndPos;
|
||||||
OldFlags:=Params.Flags;
|
OldFlags:=Params.Flags;
|
||||||
Params.Flags:=(Params.Flags*fdfGlobals)-[fdfFunctionResult];
|
Params.Flags:=(Params.Flags*fdfGlobals)-[fdfFunctionResult];
|
||||||
Result:=FindExpressionTypeOfTerm(SubStartPos,EndPos,Params,true);
|
Result:=FindExpressionTypeOfTerm(SubStartPos,EndPos,Params,true,AliasType);
|
||||||
Params.Flags:=OldFlags;
|
Params.Flags:=OldFlags;
|
||||||
MoveCursorToCleanPos(EndPos);
|
MoveCursorToCleanPos(EndPos);
|
||||||
end else begin
|
end else begin
|
||||||
@ -7454,6 +7478,8 @@ begin
|
|||||||
DbgOut(' Context.Node=',Result.Context.Node.DescAsString)
|
DbgOut(' Context.Node=',Result.Context.Node.DescAsString)
|
||||||
else
|
else
|
||||||
DbgOut(' Context.Node=nil');
|
DbgOut(' Context.Node=nil');
|
||||||
|
if AliasType<>nil then
|
||||||
|
DbgOut(' Alias=',FindContextToString(AliasType));
|
||||||
DebugLn('');
|
DebugLn('');
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
|
Loading…
Reference in New Issue
Block a user