codetools: added TFindDeclarationTool.IsHiddenUsedUnit

git-svn-id: trunk@34198 -
This commit is contained in:
mattias 2011-12-15 05:47:52 +00:00
parent cdcfe47a33
commit ed7ffcbdab
2 changed files with 33 additions and 22 deletions

View File

@ -810,6 +810,7 @@ type
out NamePos, InPos: TAtomPosition): boolean;
function GetUnitNameForUsesSection(TargetTool: TFindDeclarationTool): string;
function GetUnitForUsesSection(TargetTool: TFindDeclarationTool): string; deprecated;
function IsHiddenUsedUnit(TheUnitName: PChar): boolean;
function FindUnitSource(const AnUnitName,
AnUnitInFilename: string; ExceptionOnNotFound: boolean): TCodeBuffer;
@ -1936,17 +1937,7 @@ begin
if Result='' then exit;
// check if system unit
if (CompareIdentifiers(PChar(Result),'system')=0)
or ((Scanner.CompilerMode in [cmDELPHI,cmOBJFPC])
and (Scanner.PascalCompiler=pcFPC)
and (CompareIdentifiers(PChar(Result),'ObjPas')=0))
or ((Scanner.CompilerMode=cmMacPas)
and (Scanner.PascalCompiler=pcFPC)
and (CompareIdentifiers(PChar(Result),'MacPas')=0))
or ((cmsObjectiveC1 in Scanner.CompilerModeSwitches)
and ((CompareIdentifiers(PChar(Result),'ObjC')=0)
or (CompareIdentifiers(PChar(Result),'ObjCBase')=0)))
then begin
if IsHiddenUsedUnit(PChar(Result)) then begin
Result:='';
exit;
end;
@ -1979,6 +1970,24 @@ begin
Result:=GetUnitNameForUsesSection(TargetTool);
end;
function TFindDeclarationTool.IsHiddenUsedUnit(TheUnitName: PChar): boolean;
begin
if (CompareIdentifiers(TheUnitName,'system')=0)
or ((Scanner.CompilerMode in [cmDELPHI,cmOBJFPC])
and (Scanner.PascalCompiler=pcFPC)
and (CompareIdentifiers(TheUnitName,'ObjPas')=0))
or ((Scanner.CompilerMode=cmMacPas)
and (Scanner.PascalCompiler=pcFPC)
and (CompareIdentifiers(TheUnitName,'MacPas')=0))
or (([cmsObjectiveC1,cmsObjectiveC2]*Scanner.CompilerModeSwitches<>[])
and ((CompareIdentifiers(TheUnitName,'ObjC')=0)
or (CompareIdentifiers(TheUnitName,'ObjCBase')=0)))
then begin
exit(true);
end;
Result:=false;
end;
function TFindDeclarationTool.FindInitializationSection: TCodeTreeNode;
begin
Result:=FindInitializationNode;

View File

@ -774,7 +774,7 @@ var
end else if Group.Name=PackageNameFPCSrcDir then begin
// it's a FPC source directory
// => check if it is the current one
Dir:=ExtractFilePath(Group.Filename);
Dir:=ChompPathDelim(ExtractFilePath(Group.Filename));
if CompareFilenames(Dir,FPCSrcDir)<>0 then continue;
FPCSrcFilename:=UnitSet.GetUnitSrcFile(Item.DUnit.Name);
if (FPCSrcFilename<>'')
@ -1286,6 +1286,18 @@ begin
UpdateTool;
if (CurNode=nil) then exit;
// check if already in uses section
NewUnitName:=ExtractFileNameOnly(NewUnitFilename);
if CurTool.IsHiddenUsedUnit(PChar(NewUnitName)) then exit;
UsesNode:=CurTool.FindMainUsesSection;
if (UsesNode<>nil) and (CurTool.FindNameInUsesSection(UsesNode,NewUnitName)<>nil)
then exit;
if CurInImplementation then begin
UsesNode:=CurTool.FindImplementationUsesSection;
if (UsesNode<>nil) and (CurTool.FindNameInUsesSection(UsesNode,NewUnitName)<>nil)
then exit;
end;
// get unit name
NewUnitCode:=CodeToolBoss.LoadFile(NewUnitFilename,true,false);
if NewUnitCode=nil then exit;
@ -1301,16 +1313,6 @@ begin
exit;
end;
// check if already in uses section
UsesNode:=CurTool.FindMainUsesSection;
if (UsesNode<>nil) and (CurTool.FindNameInUsesSection(UsesNode,NewUnitName)<>nil)
then exit;
if CurInImplementation then begin
UsesNode:=CurTool.FindImplementationUsesSection;
if (UsesNode<>nil) and (CurTool.FindNameInUsesSection(UsesNode,NewUnitName)<>nil)
then exit;
end;
// add to uses section
debugln(['TCodyIdentifiersDlg.AddToUsesSection adding to uses section']);
if CurInImplementation and AddToImplementationUsesCheckBox.Checked then