mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-12 22:19:18 +02:00
codetools: FindExpressionTypeOfTerm: removed obsolete FindBaseTypeOfNode
git-svn-id: trunk@50021 -
This commit is contained in:
parent
f7d22a8e0c
commit
ced7b32ee9
@ -77,6 +77,7 @@ interface
|
|||||||
{off $DEFINE VerboseCompleteEventAssign}
|
{off $DEFINE VerboseCompleteEventAssign}
|
||||||
{off $DEFINE EnableCodeCompleteTemplates}
|
{off $DEFINE EnableCodeCompleteTemplates}
|
||||||
{$DEFINE VerboseGetPossibleInitsForVariable}
|
{$DEFINE VerboseGetPossibleInitsForVariable}
|
||||||
|
{off $DEFINE VerboseGuessTypeOfIdentifier}
|
||||||
|
|
||||||
uses
|
uses
|
||||||
{$IFDEF MEM_CHECK}
|
{$IFDEF MEM_CHECK}
|
||||||
@ -6426,13 +6427,17 @@ begin
|
|||||||
// find identifier name
|
// find identifier name
|
||||||
GetIdentStartEndAtPosition(Src,CleanCursorPos,
|
GetIdentStartEndAtPosition(Src,CleanCursorPos,
|
||||||
IdentifierAtom.StartPos,IdentifierAtom.EndPos);
|
IdentifierAtom.StartPos,IdentifierAtom.EndPos);
|
||||||
|
{$IFDEF VerboseGuessTypeOfIdentifier}
|
||||||
debugln('TCodeCompletionCodeTool.GuessTypeOfIdentifier A Atom=',GetAtom(IdentifierAtom),' "',dbgstr(Src,CleanCursorPos,10),'"');
|
debugln('TCodeCompletionCodeTool.GuessTypeOfIdentifier A Atom=',GetAtom(IdentifierAtom),' "',dbgstr(Src,CleanCursorPos,10),'"');
|
||||||
|
{$ENDIF}
|
||||||
if IdentifierAtom.StartPos=IdentifierAtom.EndPos then exit;
|
if IdentifierAtom.StartPos=IdentifierAtom.EndPos then exit;
|
||||||
Result:=true;
|
Result:=true;
|
||||||
|
|
||||||
MoveCursorToAtomPos(IdentifierAtom);
|
MoveCursorToAtomPos(IdentifierAtom);
|
||||||
if AtomIsKeyWord then begin
|
if AtomIsKeyWord then begin
|
||||||
|
{$IFDEF VerboseGuessTypeOfIdentifier}
|
||||||
debugln(['TCodeCompletionCodeTool.GuessTypeOfIdentifier is keyword: ',GetAtom]);
|
debugln(['TCodeCompletionCodeTool.GuessTypeOfIdentifier is keyword: ',GetAtom]);
|
||||||
|
{$ENDIF}
|
||||||
IsKeyword:=true;
|
IsKeyword:=true;
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
@ -6442,7 +6447,7 @@ begin
|
|||||||
try
|
try
|
||||||
Params:=TFindDeclarationParams.Create(Self, CursorNode);
|
Params:=TFindDeclarationParams.Create(Self, CursorNode);
|
||||||
try
|
try
|
||||||
{$IFDEF CTDEBUG}
|
{$IF defined(CTDEBUG) or defined(VerboseGuessTypeOfIdentifier)}
|
||||||
DebugLn(' GuessTypeOfIdentifier: check if variable is already defined ...');
|
DebugLn(' GuessTypeOfIdentifier: check if variable is already defined ...');
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
// check if identifier exists
|
// check if identifier exists
|
||||||
@ -6451,7 +6456,9 @@ begin
|
|||||||
// identifier is already defined
|
// identifier is already defined
|
||||||
ExistingDefinition.Tool:=Params.NewCodeTool;
|
ExistingDefinition.Tool:=Params.NewCodeTool;
|
||||||
ExistingDefinition.Node:=Params.NewNode;
|
ExistingDefinition.Node:=Params.NewNode;
|
||||||
|
{$IFDEF VerboseGuessTypeOfIdentifier}
|
||||||
debugln(['TCodeCompletionCodeTool.GuessTypeOfIdentifier identifier already defined at ',FindContextToString(ExistingDefinition)]);
|
debugln(['TCodeCompletionCodeTool.GuessTypeOfIdentifier identifier already defined at ',FindContextToString(ExistingDefinition)]);
|
||||||
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
finally
|
finally
|
||||||
Params.Free;
|
Params.Free;
|
||||||
@ -6461,7 +6468,9 @@ begin
|
|||||||
if not FindIdentifierContextsAtStatement(IdentifierAtom.StartPos,
|
if not FindIdentifierContextsAtStatement(IdentifierAtom.StartPos,
|
||||||
IsSubIdentifier,ListOfPFindContext)
|
IsSubIdentifier,ListOfPFindContext)
|
||||||
then begin
|
then begin
|
||||||
|
{$IFDEF VerboseGuessTypeOfIdentifier}
|
||||||
debugln(['TCodeCompletionCodeTool.GuessTypeOfIdentifier FindIdentifierContextsAtStatement failed']);
|
debugln(['TCodeCompletionCodeTool.GuessTypeOfIdentifier FindIdentifierContextsAtStatement failed']);
|
||||||
|
{$ENDIF}
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -6511,10 +6520,14 @@ begin
|
|||||||
TermAtom.StartPos:=CurPos.StartPos;
|
TermAtom.StartPos:=CurPos.StartPos;
|
||||||
TermAtom.EndPos:=FindEndOfExpression(TermAtom.StartPos);
|
TermAtom.EndPos:=FindEndOfExpression(TermAtom.StartPos);
|
||||||
if TermAtom.StartPos=TermAtom.EndPos then begin
|
if TermAtom.StartPos=TermAtom.EndPos then begin
|
||||||
|
{$IFDEF VerboseGuessTypeOfIdentifier}
|
||||||
debugln(['TCodeCompletionCodeTool.GuessTypeOfIdentifier nothing behind := operator']);
|
debugln(['TCodeCompletionCodeTool.GuessTypeOfIdentifier nothing behind := operator']);
|
||||||
|
{$ENDIF}
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
|
{$IFDEF VerboseGuessTypeOfIdentifier}
|
||||||
debugln(['TCodeCompletionCodeTool.GuessTypeOfIdentifier guessing type of assignment :="',dbgstr(Src,TermAtom.StartPos,TermAtom.EndPos-TermAtom.StartPos),'"']);
|
debugln(['TCodeCompletionCodeTool.GuessTypeOfIdentifier guessing type of assignment :="',dbgstr(Src,TermAtom.StartPos,TermAtom.EndPos-TermAtom.StartPos),'"']);
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
// find type of term
|
// find type of term
|
||||||
Params:=TFindDeclarationParams.Create(Self, CursorNode);
|
Params:=TFindDeclarationParams.Create(Self, CursorNode);
|
||||||
@ -6523,7 +6536,9 @@ begin
|
|||||||
finally
|
finally
|
||||||
Params.Free;
|
Params.Free;
|
||||||
end;
|
end;
|
||||||
|
{$IFDEF VerboseGuessTypeOfIdentifier}
|
||||||
debugln(['TCodeCompletionCodeTool.GuessTypeOfIdentifier Assignment type=',NewType]);
|
debugln(['TCodeCompletionCodeTool.GuessTypeOfIdentifier Assignment type=',NewType]);
|
||||||
|
{$ENDIF}
|
||||||
Result:=true;
|
Result:=true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -6545,7 +6560,9 @@ begin
|
|||||||
TermAtom.StartPos:=CurPos.StartPos;
|
TermAtom.StartPos:=CurPos.StartPos;
|
||||||
TermAtom.EndPos:=FindEndOfExpression(TermAtom.StartPos);
|
TermAtom.EndPos:=FindEndOfExpression(TermAtom.StartPos);
|
||||||
|
|
||||||
|
{$IFDEF VerboseGuessTypeOfIdentifier}
|
||||||
debugln(['TCodeCompletionCodeTool.GuessTypeOfIdentifier guessing type of for-in list "',dbgstr(Src,TermAtom.StartPos,TermAtom.EndPos-TermAtom.StartPos),'"']);
|
debugln(['TCodeCompletionCodeTool.GuessTypeOfIdentifier guessing type of for-in list "',dbgstr(Src,TermAtom.StartPos,TermAtom.EndPos-TermAtom.StartPos),'"']);
|
||||||
|
{$ENDIF}
|
||||||
// find type of term
|
// find type of term
|
||||||
Params:=TFindDeclarationParams.Create(Self, CursorNode);
|
Params:=TFindDeclarationParams.Create(Self, CursorNode);
|
||||||
try
|
try
|
||||||
@ -6553,13 +6570,17 @@ begin
|
|||||||
finally
|
finally
|
||||||
Params.Free;
|
Params.Free;
|
||||||
end;
|
end;
|
||||||
|
{$IFDEF VerboseGuessTypeOfIdentifier}
|
||||||
debugln(['TCodeCompletionCodeTool.GuessTypeOfIdentifier For-In type=',NewType]);
|
debugln(['TCodeCompletionCodeTool.GuessTypeOfIdentifier For-In type=',NewType]);
|
||||||
|
{$ENDIF}
|
||||||
Result:=true;
|
Result:=true;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
if not Result then begin
|
if not Result then begin
|
||||||
|
{$IFDEF VerboseGuessTypeOfIdentifier}
|
||||||
debugln(['TCodeCompletionCodeTool.GuessTypeOfIdentifier can not guess type']);
|
debugln(['TCodeCompletionCodeTool.GuessTypeOfIdentifier can not guess type']);
|
||||||
|
{$ENDIF}
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -7853,7 +7853,7 @@ var
|
|||||||
{ normally not the identifier is searched, but its type
|
{ normally not the identifier is searched, but its type
|
||||||
but there is one exception:
|
but there is one exception:
|
||||||
if the identifier is a function and it is the end of the variable then
|
if the identifier is a function and it is the end of the variable then
|
||||||
the the decision is based on the fdfFunctionResult flag.
|
the decision is based on the fdfFunctionResult flag.
|
||||||
}
|
}
|
||||||
var
|
var
|
||||||
ProcNode, FuncResultNode: TCodeTreeNode;
|
ProcNode, FuncResultNode: TCodeTreeNode;
|
||||||
@ -8218,8 +8218,7 @@ var
|
|||||||
// 'class of' => jump to the class
|
// 'class of' => jump to the class
|
||||||
ExprType.Desc:=xtContext;
|
ExprType.Desc:=xtContext;
|
||||||
Params.Flags:=Params.Flags+[fdfFunctionResult,fdfFindChildren];
|
Params.Flags:=Params.Flags+[fdfFunctionResult,fdfFindChildren];
|
||||||
ExprType.Context:=ExprType.Context.Tool.FindBaseTypeOfNode(Params,
|
ExprType.Context.Node:=ExprType.Context.Node.FirstChild;
|
||||||
ExprType.Context.Node.FirstChild);
|
|
||||||
end
|
end
|
||||||
else if (ExprType.Desc=xtContext)
|
else if (ExprType.Desc=xtContext)
|
||||||
and (ExprType.Context.Node.Desc=ctnPointerType)
|
and (ExprType.Context.Node.Desc=ctnPointerType)
|
||||||
@ -8231,8 +8230,7 @@ var
|
|||||||
// => this '.' is a dereference
|
// => this '.' is a dereference
|
||||||
ExprType.Desc:=xtContext;
|
ExprType.Desc:=xtContext;
|
||||||
Params.Flags:=Params.Flags+[fdfFunctionResult,fdfFindChildren];
|
Params.Flags:=Params.Flags+[fdfFunctionResult,fdfFindChildren];
|
||||||
ExprType.Context:=ExprType.Context.Tool.FindBaseTypeOfNode(Params,
|
ExprType.Context.Node:=ExprType.Context.Node.FirstChild;
|
||||||
ExprType.Context.Node.FirstChild);
|
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -8297,7 +8295,7 @@ var
|
|||||||
end;
|
end;
|
||||||
ResolveBaseTypeOfIdentifier;
|
ResolveBaseTypeOfIdentifier;
|
||||||
if (ExprType.Desc=xtPointer) then begin
|
if (ExprType.Desc=xtPointer) then begin
|
||||||
// the compiler type pointer resolves to a pointer
|
// the compiler type 'Pointer'
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
if (ExprType.Context.Node<>StartNode) then begin
|
if (ExprType.Context.Node<>StartNode) then begin
|
||||||
@ -8316,8 +8314,7 @@ var
|
|||||||
RaiseExceptionFmt(ctsIllegalQualifier,['^']);
|
RaiseExceptionFmt(ctsIllegalQualifier,['^']);
|
||||||
end;
|
end;
|
||||||
ExprType.Desc:=xtContext;
|
ExprType.Desc:=xtContext;
|
||||||
ExprType.Context:=ExprType.Context.Tool.FindBaseTypeOfNode(Params,
|
ExprType.Context.Node:=ExprType.Context.Node.FirstChild;
|
||||||
ExprType.Context.Node.FirstChild);
|
|
||||||
end else if NodeHasParentOfType(ExprType.Context.Node,ctnPointerType) then
|
end else if NodeHasParentOfType(ExprType.Context.Node,ctnPointerType) then
|
||||||
begin
|
begin
|
||||||
// this is a pointer type definition
|
// this is a pointer type definition
|
||||||
@ -8401,19 +8398,16 @@ var
|
|||||||
Params.SetIdentifier(Self,'tvarrec',nil);
|
Params.SetIdentifier(Self,'tvarrec',nil);
|
||||||
Params.ContextNode:=ExprType.Context.Node;
|
Params.ContextNode:=ExprType.Context.Node;
|
||||||
ExprType.Context.Tool.FindIdentifierInContext(Params);
|
ExprType.Context.Tool.FindIdentifierInContext(Params);
|
||||||
ExprType.Context:=Params.NewCodeTool.FindBaseTypeOfNode(Params,
|
ExprType.Context:=CreateFindContext(Params);
|
||||||
Params.NewNode);
|
|
||||||
Params.Load(OldInput,true);
|
Params.Load(OldInput,true);
|
||||||
end else begin
|
end else begin
|
||||||
ExprType.Context:=ExprType.Context.Tool.FindBaseTypeOfNode(Params,
|
ExprType.Context.Node:=ExprType.Context.Node.LastChild;
|
||||||
ExprType.Context.Node.LastChild);
|
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
ctnPointerType:
|
ctnPointerType:
|
||||||
// the pointer type is the only child node
|
// the pointer type is the only child node
|
||||||
ExprType.Context:=ExprType.Context.Tool.FindBaseTypeOfNode(Params,
|
ExprType.Context.Node:=ExprType.Context.Node.FirstChild;
|
||||||
ExprType.Context.Node.FirstChild);
|
|
||||||
|
|
||||||
ctnClass, ctnClassInterface, ctnDispinterface, ctnObject, ctnRecordType,
|
ctnClass, ctnClassInterface, ctnDispinterface, ctnObject, ctnRecordType,
|
||||||
ctnClassHelper, ctnRecordHelper, ctnTypeHelper,
|
ctnClassHelper, ctnRecordHelper, ctnTypeHelper,
|
||||||
@ -8423,22 +8417,18 @@ var
|
|||||||
Params.Save(OldInput);
|
Params.Save(OldInput);
|
||||||
Params.Flags:=[fdfSearchInAncestors,fdfExceptionOnNotFound,fdfSearchInHelpers]
|
Params.Flags:=[fdfSearchInAncestors,fdfExceptionOnNotFound,fdfSearchInHelpers]
|
||||||
+fdfGlobals*Params.Flags;
|
+fdfGlobals*Params.Flags;
|
||||||
// special identifier for default property
|
// special identifier '[' for default property
|
||||||
Params.SetIdentifier(Self,@Src[CurAtom.StartPos],nil);
|
Params.SetIdentifier(Self,@Src[CurAtom.StartPos],nil);
|
||||||
Params.ContextNode:=ExprType.Context.Node;
|
Params.ContextNode:=ExprType.Context.Node;
|
||||||
ExprType.Context.Tool.FindIdentifierInContext(Params);
|
ExprType.Context.Tool.FindIdentifierInContext(Params);
|
||||||
ExprType.Context:=CreateFindContext(Params);
|
ExprType.Context:=CreateFindContext(Params);
|
||||||
Params.Load(OldInput,true);
|
Params.Load(OldInput,true);
|
||||||
ExprType.Context:=ExprType.Context.Tool.FindBaseTypeOfNode(Params,
|
|
||||||
ExprType.Context.Node);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
ctnProperty, ctnGlobalProperty:
|
ctnProperty, ctnGlobalProperty:
|
||||||
begin
|
begin
|
||||||
if not ExprType.Context.Tool.PropertyNodeHasParamList(ExprType.Context.Node) then
|
if not ExprType.Context.Tool.PropertyNodeHasParamList(ExprType.Context.Node) then
|
||||||
RaiseIdentInCurContextNotFound;
|
RaiseIdentInCurContextNotFound;
|
||||||
ExprType.Context:=ExprType.Context.Tool.FindBaseTypeOfNode(Params,
|
|
||||||
ExprType.Context.Node);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
ctnIdentifier:
|
ctnIdentifier:
|
||||||
|
@ -26,7 +26,7 @@ var
|
|||||||
res: Integer;
|
res: Integer;
|
||||||
begin
|
begin
|
||||||
t := TTest.Create;
|
t := TTest.Create;
|
||||||
res{guesstype:longint} := t[3];
|
res{guesstype:integer} := t[3];
|
||||||
Writeln('value: ', res);
|
Writeln('value: ', res);
|
||||||
if res <> 3 then
|
if res <> 3 then
|
||||||
Halt(1);
|
Halt(1);
|
||||||
|
@ -31,10 +31,10 @@ end;
|
|||||||
|
|
||||||
var
|
var
|
||||||
t: TTest;
|
t: TTest;
|
||||||
res: Integer;
|
res1: Integer;
|
||||||
begin
|
begin
|
||||||
t := TTest.Create;
|
t := TTest.Create;
|
||||||
res{guesstype:longint} := t[3];
|
res1{guesstype:integer} := t[3];
|
||||||
Writeln('value: ', res);
|
Writeln('value: ', res);
|
||||||
if res <> 3 then
|
if res <> 3 then
|
||||||
Halt(1);
|
Halt(1);
|
||||||
|
Loading…
Reference in New Issue
Block a user