codetools: validate node caches on every BuildTree, not only when unit changed

git-svn-id: trunk@31218 -
This commit is contained in:
mattias 2011-06-14 14:48:12 +00:00
parent a4edea9f79
commit 057f07d894
6 changed files with 20 additions and 41 deletions

View File

@ -2184,9 +2184,9 @@ var
CursorPos: TCodeXYPosition;
begin
Result:=false;
{$IFDEF CTDEBUG}
{ $IFDEF CTDEBUG}
DebugLn('TCodeToolManager.GatherIdentifiers A ',Code.Filename,' x=',dbgs(x),' y=',dbgs(y));
{$ENDIF}
{ $ENDIF}
if not InitCurCodeTool(Code) then exit;
if IdentifierList<>nil then IdentifierList.Clear;
CursorPos.X:=X;
@ -5136,17 +5136,11 @@ end;
procedure TCodeToolManager.OnToolTreeChange(Tool: TCustomCodeTool;
NodesDeleting: boolean);
begin
if FCodeNodeTreeChangeStep<>High(integer) then
inc(FCodeNodeTreeChangeStep)
else
FCodeNodeTreeChangeStep:=Low(Integer);
CTIncreaseChangeStamp(FCodeNodeTreeChangeStep);
if NodesDeleting then begin
if FCodeTreeNodesDeletedStep<>High(integer) then
inc(FCodeTreeNodesDeletedStep)
else
FCodeTreeNodesDeletedStep:=Low(Integer);
CTIncreaseChangeStamp(FCodeTreeNodesDeletedStep);
if IdentifierList<>nil then
IdentifierList.ToolTreeChange(Tool,NodesDeleting);
IdentifierList.ToolTreeNodesDeleting(Tool,NodesDeleting);
end;
end;

View File

@ -2554,7 +2554,10 @@ begin
Result:=Scanner.CleanedPosToCursor(CleanPos,p,Code);
if Result then begin
Caret.Code:=TCodeBuffer(Code);
if Caret.Code.IsDeleted then exit(false);
if Caret.Code.IsDeleted then begin
debugln(['TCustomCodeTool.CleanPosToCaret IsDeleted: ',Caret.Code.Filename,' SourceLength=',Caret.Code.SourceLength]);
exit(false);
end;
TCodeBuffer(Code).AbsoluteToLineCol(p,Caret.Y,Caret.X);
Result:=(Caret.Y>=0);
end;
@ -2756,7 +2759,7 @@ end;
function TCustomCodeTool.UpdateNeeded(Range: TLinkScannerRange): boolean;
begin
{$IFDEF CTDEBUG}
DebugLn('TCustomCodeTool.UpdateNeeded A ',dbgs(Scanner<>nil),' FForceUpdateNeeded=',dbgs(FForceUpdateNeeded));
DebugLn('TCustomCodeTool.UpdateNeeded A Range=',dbgs(Range),' ',Scanner.MainFilename);
{$ENDIF}
if Range=lsrNone then exit(false);
if ord(FRangeValidTill)<ord(Range) then begin

View File

@ -9036,6 +9036,7 @@ begin
//debugln(['TFindDeclarationTool.CheckDependsOnNodeCaches ',MainFilename,' FDependsOnCodeTools=',FDependsOnCodeTools]);
if (FDependsOnCodeTools=nil) or FCheckingNodeCacheDependencies then exit;
if Scanner=nil then exit;
if Assigned(Scanner.OnGetGlobalChangeSteps) then begin
// check if any sources or values have changed
Scanner.OnGetGlobalChangeSteps(SourcesChangeStep,FilesChangeStep,
@ -9043,7 +9044,7 @@ begin
if (SourcesChangeStep=FSourcesChangeStep)
and (FilesChangeStep=FFilesChangeStep)
and (InitValuesChangeStep=FInitValuesChangeStep) then
// all sources and values are the same =>
// all sources and values are the same
exit;
FSourcesChangeStep:=SourcesChangeStep;
FFilesChangeStep:=FilesChangeStep;
@ -9053,7 +9054,7 @@ begin
if (CheckedTools<>nil) and (CheckedTools.Find(Self)<>nil) then exit;
{$IFDEF ShowCacheDependencies}
DebugLn(['[TFindDeclarationTool.CheckDependsOnNodeCaches] START ',MainFilename,' ',FDependsOnCodeTools.Count]);
DebugLn(['[TFindDeclarationTool.CheckDependsOnNodeCaches] START DependsOn=',FDependsOnCodeTools.Count,' ',MainFilename]);
{$ENDIF}
FCheckingNodeCacheDependencies:=true;
FreeCheckedTools:=false;
@ -9074,8 +9075,7 @@ begin
Result:=false;
finally
{$IFDEF ShowCacheDependencies}
DebugLn('[TFindDeclarationTool.CheckDependsOnNodeCaches] Result=',
DbgS(Result),' ',MainFilename);
DebugLn('[TFindDeclarationTool.CheckDependsOnNodeCaches] Result=',DbgS(Result),' ',MainFilename);
{$ENDIF}
FCheckingNodeCacheDependencies:=false;
if FreeCheckedTools then FreeAndNil(CheckedTools);

View File

@ -227,7 +227,7 @@ type
function StartUpAtomInFrontIs(const s: string): boolean;
function StartUpAtomBehindIs(const s: string): boolean;
function CompletePrefix(const OldPrefix: string): string;
procedure ToolTreeChange(Tool: TCustomCodeTool; NodesDeleting: boolean);
procedure ToolTreeNodesDeleting(Tool: TCustomCodeTool; NodesDeleting: boolean);
function CalcMemSize: PtrUInt;
public
property Context: TFindContext read FContext write FContext;
@ -820,28 +820,11 @@ begin
end;
end;
procedure TIdentifierList.ToolTreeChange(Tool: TCustomCodeTool;
procedure TIdentifierList.ToolTreeNodesDeleting(Tool: TCustomCodeTool;
NodesDeleting: boolean);
var
AVLNode: TAVLTreeNode;
Item: TIdentifierListItem;
RootNode: TCodeTreeNode;
begin
if (Tool.Tree=nil) then exit;
RootNode:=Tool.Tree.Root;
if RootNode=nil then exit;
//DebugLn(['TIdentifierList.ToolTreeChange START ',Tool.MainFilename]);
if FIdentView.Count=0 then exit;
//DebugLn(['TIdentifierList.ToolTreeChange ',Tool.MainFilename]);
AVLNode:=FIdentView.FindLowest;
while AVLNode<>nil do begin
Item:=TIdentifierListItem(AVLNode.Data);
if (Item.FNode<>nil) and (Item.Tool=Tool) then begin
//DebugLn(['TIdentifierList.ToolTreeChange ',Item.Identifier]);
Item.UnbindNode;
end;
AVLNode:=FIdentView.FindSuccessor(AVLNode);
end;
Clear;
end;
function TIdentifierList.CalcMemSize: PtrUInt;
@ -1832,10 +1815,8 @@ begin
fdfSearchInParentNodes,fdfSearchInAncestors];
if IgnoreCurContext then
Params.Flags:=Params.Flags+[fdfIgnoreCurContextNode];
//debugln(['TIdentCompletionTool.FindCollectionContext ',fdfIgnoreCurContextNode in Params.Flags]);
ExprType:=FindExpressionTypeOfTerm(ContextExprStartPos,IdentStartPos,
Params,false);
//DebugLn(['TIdentCompletionTool.FindCollectionContext ',ExprTypeToString(ExprType)]);
if (ExprType.Desc=xtContext) then begin
GatherContext:=ExprType.Context;
StartInSubContext:=true;

View File

@ -1711,7 +1711,7 @@ begin
// and no update is needed
if (ord(Range)>ord(ScannedRange)) and (not LastErrorIsValid) then begin
{$IFDEF VerboseUpdateNeeded}
DebugLn(['TLinkScanner.UpdateNeeded because range increased from ',dbgs(ScannedRange),' to ',dbgs(Range)]);
DebugLn(['TLinkScanner.UpdateNeeded because range increased from ',dbgs(ScannedRange),' to ',dbgs(Range),' ',ExtractFilename(MainFilename)]);
{$ENDIF}
exit;
end;
@ -1724,6 +1724,7 @@ begin
and ((not CheckFilesOnDisk) or (CurFilesChangeStep=FGlobalSourcesChangeStep))
then begin
// sources and values did not change since last check
//debugln(['TLinkScanner.UpdateNeeded global change steps still the same: ',MainFilename]);
Result:=false;
exit;
end;

View File

@ -524,6 +524,7 @@ begin
{$IFDEF CTDEBUG}
DebugLn('TPascalParserTool.BuildTree START ',MainFilename,' Range=',dbgs(Range),' ScannedRange=',dbgs(ScannedRange));
{$ENDIF}
ValidateToolDependencies;
if not UpdateNeeded(Range) then begin
// input is the same as last time -> output is the same
// => if there was an error, raise it again
@ -551,7 +552,6 @@ begin
end;
// an update is needed
ValidateToolDependencies;
// The last error was in the area to be update.
ClearLastError;