codetools: fixed checking unit dependencies each time a unit is parsed, bug #12269

git-svn-id: trunk@16838 -
This commit is contained in:
mattias 2008-10-02 07:52:08 +00:00
parent 2080c834cf
commit 3e2ce6e7d3
6 changed files with 32 additions and 26 deletions

View File

@ -474,6 +474,7 @@ begin
Result:=LoadFile(AFilename);
end else
Result:=LoadFile(AFilename);
//debugln(['TCodeCache.OnScannerLoadSource ']);
if Result<>nil then
OnScannerCheckFileOnDisk(Result);
end;

View File

@ -265,7 +265,6 @@ begin
DebugLn('[TEventsCodeTool.GetCompatiblePublishedMethods] D');
{$ENDIF}
// 1. convert the TypeData to an expression type list
CheckDependsOnNodeCaches;
Params:=TFindDeclarationParams.Create;
Params.ContextNode:=ClassNode.Parent;
SearchedExprList:=CreateExprListFromMethodTypeData(TypeData,Params);
@ -323,7 +322,6 @@ begin
ActivateGlobalWriteLock;
Params:=nil;
try
CheckDependsOnNodeCaches;
Params:=TFindDeclarationParams.Create;
Params.ContextNode:=ClassNode;
Params.SetIdentifier(Self,@UpperMethodName[1],nil);
@ -406,7 +404,6 @@ begin
try
// find method type declaration
TypeName:=ATypeInfo^.Name;
CheckDependsOnNodeCaches;
Params:=TFindDeclarationParams.Create;
try
// find method in interface and used units
@ -479,7 +476,6 @@ begin
MethodIsPublished:=false;
ActivateGlobalWriteLock;
try
CheckDependsOnNodeCaches;
Params:=TFindDeclarationParams.Create;
try
// first search a published method definition with same name
@ -866,7 +862,6 @@ begin
if TypeData=nil then exit;
ParamCount:=TypeData^.ParamCount;
if ParamCount>0 then begin
CheckDependsOnNodeCaches;
Offset:=0;
for i:=0 to ParamCount-1 do begin

View File

@ -694,10 +694,10 @@ type
ExceptionOnNotFound: boolean): TFindDeclarationTool;
function CheckDirectoryCache: boolean;
public
procedure BuildTree(OnlyInterfaceNeeded: boolean); override;
destructor Destroy; override;
procedure ConsistencyCheck; override;
procedure ValidateToolDependencies; override;
function FindDeclaration(const CursorPos: TCodeXYPosition;
out NewPos: TCodeXYPosition; out NewTopLine: integer): boolean;
function FindMainDeclaration(const CursorPos: TCodeXYPosition;
@ -4973,15 +4973,6 @@ begin
end;
end;
procedure TFindDeclarationTool.BuildTree(OnlyInterfaceNeeded: boolean);
begin
{$IFDEF MEM_CHECK}CheckHeapWrtMemCnt('TFindDeclarationTool.BuildTree Checking depends ...');{$ENDIF}
CheckDependsOnNodeCaches;
{$IFDEF MEM_CHECK}CheckHeapWrtMemCnt('TFindDeclarationTool.BuildTree building tree');{$ENDIF}
inherited BuildTree(OnlyInterfaceNeeded);
{$IFDEF MEM_CHECK}CheckHeapWrtMemCnt('TFindDeclarationTool.BuildTree tree built');{$ENDIF}
end;
function TFindDeclarationTool.FindIdentifierInHiddenUsedUnits(
Params: TFindDeclarationParams): boolean;
type
@ -7472,23 +7463,24 @@ var
ATool: TFindDeclarationTool;
begin
Result:=false;
//debugln(['TFindDeclarationTool.CheckDependsOnNodeCaches ',MainFilename,' FDependsOnCodeTools=',FDependsOnCodeTools]);
if (FDependsOnCodeTools=nil) or FCheckingNodeCacheDependencies
or NodeCacheGlobalWriteLockStepDidNotChange
then exit;
FCheckingNodeCacheDependencies:=true;
{$IFDEF ShowCacheDependencies}
DebugLn('[TFindDeclarationTool.CheckDependsOnNodeCaches] START ',MainFilename);
DebugLn(['[TFindDeclarationTool.CheckDependsOnNodeCaches] START ',MainFilename,' ',FDependsOnCodeTools.Count]);
{$ENDIF}
try
ANode:=FDependsOnCodeTools.FindLowest;
while ANode<>nil do begin
ATool:=TFindDeclarationTool(ANode.Data);
Result:=ATool.CheckDependsOnNodeCaches;
Result:=ATool.UpdateNeeded(true) or ATool.CheckDependsOnNodeCaches;
if Result then exit;
ANode:=FDependsOnCodeTools.FindSuccessor(ANode);
end;
Result:=UpdateNeeded(Scanner.ScanTill=lsrInterface);
Result:=false;
finally
{$IFDEF ShowCacheDependencies}
DebugLn('[TFindDeclarationTool.CheckDependsOnNodeCaches] Result=',
@ -7636,6 +7628,13 @@ begin
end;
end;
procedure TFindDeclarationTool.ValidateToolDependencies;
begin
debugln(['TFindDeclarationTool.ValidateToolDependencies ',MainFilename]);
inherited ValidateToolDependencies;
CheckDependsOnNodeCaches;
end;
function TFindDeclarationTool.GetNodeCache(Node: TCodeTreeNode;
CreateIfNotExists: boolean): TCodeTreeNodeCache;
begin

View File

@ -1294,7 +1294,7 @@ begin
LastCleanSrcPos:=SourcePos;
end;
procedure TLinkScanner.AddSourceChangeStep(ACode: pointer;AChangeStep: integer);
procedure TLinkScanner.AddSourceChangeStep(ACode: pointer; AChangeStep: integer);
procedure RaiseCodeNil;
begin
@ -1412,7 +1412,7 @@ end;
function TLinkScanner.UpdateNeeded(
Range: TLinkScannerRange; CheckFilesOnDisk: boolean): boolean;
{ the clean source must be rebuild if
{ the clean source must be rebuilt if
1. scanrange changed from only interface to whole source
2. unit source changed
3. one of its include files changed
@ -1424,6 +1424,7 @@ var i: integer;
GlobalWriteLockIsSet: boolean;
GlobalWriteLockStep: integer;
NewInitValuesChangeStep: integer;
SrcChange: PSourceChangeStep;
begin
Result:=true;
if FForceUpdateNeeded then exit;
@ -1459,15 +1460,16 @@ begin
if CheckFilesOnDisk and Assigned(FOnCheckFileOnDisk) then begin
// if files changed on disk, reload them
for i:=0 to FSourceChangeSteps.Count-1 do begin
SrcLog:=FOnGetSource(Self,
PSourceChangeStep(FSourceChangeSteps[i])^.Code);
SrcChange:=PSourceChangeStep(FSourceChangeSteps[i]);
SrcLog:=FOnGetSource(Self,SrcChange^.Code);
FOnCheckFileOnDisk(SrcLog);
end;
end;
for i:=0 to FSourceChangeSteps.Count-1 do begin
SrcLog:=FOnGetSource(Self,PSourceChangeStep(FSourceChangeSteps[i])^.Code);
if PSourceChangeStep(FSourceChangeSteps[i])^.ChangeStep<>SrcLog.ChangeStep
then exit;
SrcChange:=PSourceChangeStep(FSourceChangeSteps[i]);
SrcLog:=FOnGetSource(Self,SrcChange^.Code);
//debugln(['TLinkScanner.UpdateNeeded ',ExtractFilename(MainFilename),' i=',i,' File=',FOnGetFileName(Self,SrcLog),' Last=',SrcChange^.ChangeStep,' Now=',SrcLog.ChangeStep]);
if SrcChange^.ChangeStep<>SrcLog.ChangeStep then exit;
end;
end;

View File

@ -211,7 +211,8 @@ type
ImplementationSectionFound: boolean;
EndOfSourceFound: boolean;
procedure BuildTree(OnlyInterfaceNeeded: boolean); virtual;
procedure ValidateToolDependencies; virtual;
procedure BuildTree(OnlyInterfaceNeeded: boolean);
procedure BuildTreeAndGetCleanPos(TreeRange: TTreeRange;
const CursorPos: TCodeXYPosition; out CleanCursorPos: integer;
BuildTreeFlags: TBuildTreeFlags);
@ -468,6 +469,7 @@ begin
{$IFDEF CTDEBUG}
DebugLn('TPascalParserTool.BuildTree A');
{$ENDIF}
ValidateToolDependencies;
if not UpdateNeeded(OnlyInterfaceNeeded) then begin
// input is the same as last time -> output is the same
// -> if there was an error, raise it again
@ -4021,6 +4023,7 @@ begin
and (not UpdateNeeded(true)) then begin
// interface section is already parsed, is still valid and
// cursor is in this section
ValidateToolDependencies;
exit;
end;
end;
@ -4119,6 +4122,11 @@ begin
ReadNextAtom;
end;
procedure TPascalParserTool.ValidateToolDependencies;
begin
end;
procedure TPascalParserTool.BuildSubTreeForProcHead(ProcNode: TCodeTreeNode);
var HasForwardModifier, IsFunction, IsOperator, IsMethod: boolean;
ParseAttr: TParseProcHeadAttributes;

View File

@ -12406,6 +12406,7 @@ begin
LogCaretXY.X,LogCaretXY.Y,
NewSource,NewX,NewY,NewTopLine) then
begin
//debugln(['TMainIDE.DoFindDeclarationAtCaret ',NewSource.Filename,' NewX=',Newx,',y=',NewY,' ',NewTopLine]);
DoJumpToCodePos(ActiveSrcEdit, ActiveUnitInfo,
NewSource, NewX, NewY, NewTopLine, true);
end else begin