From ced7b32ee9e553e684d475ac1770b90a9467b9c3 Mon Sep 17 00:00:00 2001 From: mattias Date: Fri, 9 Oct 2015 12:24:52 +0000 Subject: [PATCH] codetools: FindExpressionTypeOfTerm: removed obsolete FindBaseTypeOfNode git-svn-id: trunk@50021 - --- components/codetools/codecompletiontool.pas | 23 ++++++++++++++- components/codetools/finddeclarationtool.pas | 28 ++++++------------- components/codetools/tests/fpctests/tchlp6.pp | 2 +- components/codetools/tests/fpctests/tchlp7.pp | 4 +-- 4 files changed, 34 insertions(+), 23 deletions(-) diff --git a/components/codetools/codecompletiontool.pas b/components/codetools/codecompletiontool.pas index 4008cf0c36..4e1a25c042 100644 --- a/components/codetools/codecompletiontool.pas +++ b/components/codetools/codecompletiontool.pas @@ -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; diff --git a/components/codetools/finddeclarationtool.pas b/components/codetools/finddeclarationtool.pas index e1f5978fa7..30f7ca7fa0 100644 --- a/components/codetools/finddeclarationtool.pas +++ b/components/codetools/finddeclarationtool.pas @@ -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: diff --git a/components/codetools/tests/fpctests/tchlp6.pp b/components/codetools/tests/fpctests/tchlp6.pp index 5ed942f276..47a988220f 100644 --- a/components/codetools/tests/fpctests/tchlp6.pp +++ b/components/codetools/tests/fpctests/tchlp6.pp @@ -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); diff --git a/components/codetools/tests/fpctests/tchlp7.pp b/components/codetools/tests/fpctests/tchlp7.pp index 32d20cab0d..58fe298df1 100644 --- a/components/codetools/tests/fpctests/tchlp7.pp +++ b/components/codetools/tests/fpctests/tchlp7.pp @@ -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);