codetools: FindExpressionTypeOfTerm: removed obsolete FindBaseTypeOfNode

git-svn-id: trunk@50021 -
This commit is contained in:
mattias 2015-10-09 12:24:52 +00:00
parent f7d22a8e0c
commit ced7b32ee9
4 changed files with 34 additions and 23 deletions

View File

@ -77,6 +77,7 @@ interface
{off $DEFINE VerboseCompleteEventAssign}
{off $DEFINE EnableCodeCompleteTemplates}
{$DEFINE VerboseGetPossibleInitsForVariable}
{off $DEFINE VerboseGuessTypeOfIdentifier}
uses
{$IFDEF MEM_CHECK}
@ -6426,13 +6427,17 @@ begin
// find identifier name
GetIdentStartEndAtPosition(Src,CleanCursorPos,
IdentifierAtom.StartPos,IdentifierAtom.EndPos);
{$IFDEF VerboseGuessTypeOfIdentifier}
debugln('TCodeCompletionCodeTool.GuessTypeOfIdentifier A Atom=',GetAtom(IdentifierAtom),' "',dbgstr(Src,CleanCursorPos,10),'"');
{$ENDIF}
if IdentifierAtom.StartPos=IdentifierAtom.EndPos then exit;
Result:=true;
MoveCursorToAtomPos(IdentifierAtom);
if AtomIsKeyWord then begin
{$IFDEF VerboseGuessTypeOfIdentifier}
debugln(['TCodeCompletionCodeTool.GuessTypeOfIdentifier is keyword: ',GetAtom]);
{$ENDIF}
IsKeyword:=true;
exit;
end;
@ -6442,7 +6447,7 @@ begin
try
Params:=TFindDeclarationParams.Create(Self, CursorNode);
try
{$IFDEF CTDEBUG}
{$IF defined(CTDEBUG) or defined(VerboseGuessTypeOfIdentifier)}
DebugLn(' GuessTypeOfIdentifier: check if variable is already defined ...');
{$ENDIF}
// check if identifier exists
@ -6451,7 +6456,9 @@ begin
// identifier is already defined
ExistingDefinition.Tool:=Params.NewCodeTool;
ExistingDefinition.Node:=Params.NewNode;
{$IFDEF VerboseGuessTypeOfIdentifier}
debugln(['TCodeCompletionCodeTool.GuessTypeOfIdentifier identifier already defined at ',FindContextToString(ExistingDefinition)]);
{$ENDIF}
end;
finally
Params.Free;
@ -6461,7 +6468,9 @@ begin
if not FindIdentifierContextsAtStatement(IdentifierAtom.StartPos,
IsSubIdentifier,ListOfPFindContext)
then begin
{$IFDEF VerboseGuessTypeOfIdentifier}
debugln(['TCodeCompletionCodeTool.GuessTypeOfIdentifier FindIdentifierContextsAtStatement failed']);
{$ENDIF}
exit;
end;
@ -6511,10 +6520,14 @@ begin
TermAtom.StartPos:=CurPos.StartPos;
TermAtom.EndPos:=FindEndOfExpression(TermAtom.StartPos);
if TermAtom.StartPos=TermAtom.EndPos then begin
{$IFDEF VerboseGuessTypeOfIdentifier}
debugln(['TCodeCompletionCodeTool.GuessTypeOfIdentifier nothing behind := operator']);
{$ENDIF}
exit;
end;
{$IFDEF VerboseGuessTypeOfIdentifier}
debugln(['TCodeCompletionCodeTool.GuessTypeOfIdentifier guessing type of assignment :="',dbgstr(Src,TermAtom.StartPos,TermAtom.EndPos-TermAtom.StartPos),'"']);
{$ENDIF}
// find type of term
Params:=TFindDeclarationParams.Create(Self, CursorNode);
@ -6523,7 +6536,9 @@ begin
finally
Params.Free;
end;
{$IFDEF VerboseGuessTypeOfIdentifier}
debugln(['TCodeCompletionCodeTool.GuessTypeOfIdentifier Assignment type=',NewType]);
{$ENDIF}
Result:=true;
end;
@ -6545,7 +6560,9 @@ begin
TermAtom.StartPos:=CurPos.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),'"']);
{$ENDIF}
// find type of term
Params:=TFindDeclarationParams.Create(Self, CursorNode);
try
@ -6553,13 +6570,17 @@ begin
finally
Params.Free;
end;
{$IFDEF VerboseGuessTypeOfIdentifier}
debugln(['TCodeCompletionCodeTool.GuessTypeOfIdentifier For-In type=',NewType]);
{$ENDIF}
Result:=true;
end;
end;
if not Result then begin
{$IFDEF VerboseGuessTypeOfIdentifier}
debugln(['TCodeCompletionCodeTool.GuessTypeOfIdentifier can not guess type']);
{$ENDIF}
exit;
end;

View File

@ -7853,7 +7853,7 @@ var
{ normally not the identifier is searched, but its type
but there is one exception:
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
ProcNode, FuncResultNode: TCodeTreeNode;
@ -8218,8 +8218,7 @@ var
// 'class of' => jump to the class
ExprType.Desc:=xtContext;
Params.Flags:=Params.Flags+[fdfFunctionResult,fdfFindChildren];
ExprType.Context:=ExprType.Context.Tool.FindBaseTypeOfNode(Params,
ExprType.Context.Node.FirstChild);
ExprType.Context.Node:=ExprType.Context.Node.FirstChild;
end
else if (ExprType.Desc=xtContext)
and (ExprType.Context.Node.Desc=ctnPointerType)
@ -8231,8 +8230,7 @@ var
// => this '.' is a dereference
ExprType.Desc:=xtContext;
Params.Flags:=Params.Flags+[fdfFunctionResult,fdfFindChildren];
ExprType.Context:=ExprType.Context.Tool.FindBaseTypeOfNode(Params,
ExprType.Context.Node.FirstChild);
ExprType.Context.Node:=ExprType.Context.Node.FirstChild;
end;
end;
@ -8297,7 +8295,7 @@ var
end;
ResolveBaseTypeOfIdentifier;
if (ExprType.Desc=xtPointer) then begin
// the compiler type pointer resolves to a pointer
// the compiler type 'Pointer'
exit;
end;
if (ExprType.Context.Node<>StartNode) then begin
@ -8316,8 +8314,7 @@ var
RaiseExceptionFmt(ctsIllegalQualifier,['^']);
end;
ExprType.Desc:=xtContext;
ExprType.Context:=ExprType.Context.Tool.FindBaseTypeOfNode(Params,
ExprType.Context.Node.FirstChild);
ExprType.Context.Node:=ExprType.Context.Node.FirstChild;
end else if NodeHasParentOfType(ExprType.Context.Node,ctnPointerType) then
begin
// this is a pointer type definition
@ -8401,19 +8398,16 @@ var
Params.SetIdentifier(Self,'tvarrec',nil);
Params.ContextNode:=ExprType.Context.Node;
ExprType.Context.Tool.FindIdentifierInContext(Params);
ExprType.Context:=Params.NewCodeTool.FindBaseTypeOfNode(Params,
Params.NewNode);
ExprType.Context:=CreateFindContext(Params);
Params.Load(OldInput,true);
end else begin
ExprType.Context:=ExprType.Context.Tool.FindBaseTypeOfNode(Params,
ExprType.Context.Node.LastChild);
ExprType.Context.Node:=ExprType.Context.Node.LastChild;
end;
end;
ctnPointerType:
// the pointer type is the only child node
ExprType.Context:=ExprType.Context.Tool.FindBaseTypeOfNode(Params,
ExprType.Context.Node.FirstChild);
ExprType.Context.Node:=ExprType.Context.Node.FirstChild;
ctnClass, ctnClassInterface, ctnDispinterface, ctnObject, ctnRecordType,
ctnClassHelper, ctnRecordHelper, ctnTypeHelper,
@ -8423,22 +8417,18 @@ var
Params.Save(OldInput);
Params.Flags:=[fdfSearchInAncestors,fdfExceptionOnNotFound,fdfSearchInHelpers]
+fdfGlobals*Params.Flags;
// special identifier for default property
// special identifier '[' for default property
Params.SetIdentifier(Self,@Src[CurAtom.StartPos],nil);
Params.ContextNode:=ExprType.Context.Node;
ExprType.Context.Tool.FindIdentifierInContext(Params);
ExprType.Context:=CreateFindContext(Params);
Params.Load(OldInput,true);
ExprType.Context:=ExprType.Context.Tool.FindBaseTypeOfNode(Params,
ExprType.Context.Node);
end;
ctnProperty, ctnGlobalProperty:
begin
if not ExprType.Context.Tool.PropertyNodeHasParamList(ExprType.Context.Node) then
RaiseIdentInCurContextNotFound;
ExprType.Context:=ExprType.Context.Tool.FindBaseTypeOfNode(Params,
ExprType.Context.Node);
end;
ctnIdentifier:

View File

@ -26,7 +26,7 @@ var
res: Integer;
begin
t := TTest.Create;
res{guesstype:longint} := t[3];
res{guesstype:integer} := t[3];
Writeln('value: ', res);
if res <> 3 then
Halt(1);

View File

@ -31,10 +31,10 @@ end;
var
t: TTest;
res: Integer;
res1: Integer;
begin
t := TTest.Create;
res{guesstype:longint} := t[3];
res1{guesstype:integer} := t[3];
Writeln('value: ', res);
if res <> 3 then
Halt(1);