codetools: read unit scopes from fpc output

git-svn-id: trunk@57839 -
This commit is contained in:
mattias 2018-05-08 08:31:57 +00:00
parent 333a8e95d4
commit 1189d43fa2

View File

@ -794,6 +794,7 @@ type
ConfigFiles: TPCConfigFileStateList; ConfigFiles: TPCConfigFileStateList;
UnitPaths: TStrings; UnitPaths: TStrings;
IncludePaths: TStrings; IncludePaths: TStrings;
UnitScopes: TStrings;
Defines: TStringToStringTree; // macro to value Defines: TStringToStringTree; // macro to value
Undefines: TStringToStringTree; // macro Undefines: TStringToStringTree; // macro
Units: TStringToStringTree; // unit name to file name Units: TStringToStringTree; // unit name to file name
@ -1081,13 +1082,15 @@ function ParseFPCVerbose(List: TStrings; // fpc -va output
out ConfigFiles: TStrings; // prefix '-' for file not found, '+' for found and read out ConfigFiles: TStrings; // prefix '-' for file not found, '+' for found and read
out RealCompilerFilename: string; // what compiler is used by fpc out RealCompilerFilename: string; // what compiler is used by fpc
out UnitPaths: TStrings; // unit search paths out UnitPaths: TStrings; // unit search paths
out IncludePaths: TStrings; // inc search paths out IncludePaths: TStrings; // include search paths
out UnitScopes: TStrings; // unit scopes/namespaces
out Defines, Undefines: TStringToStringTree): boolean; out Defines, Undefines: TStringToStringTree): boolean;
function RunFPCVerbose(const CompilerFilename, TestFilename: string; function RunFPCVerbose(const CompilerFilename, TestFilename: string;
out ConfigFiles: TStrings; out ConfigFiles: TStrings;
out RealCompilerFilename: string; out RealCompilerFilename: string;
out UnitPaths: TStrings; out UnitPaths: TStrings;
out IncludePaths: TStrings; out IncludePaths: TStrings;
out UnitScopes: TStrings; // unit scopes/namespaces
out Defines, Undefines: TStringToStringTree; out Defines, Undefines: TStringToStringTree;
const Options: string = ''): boolean; const Options: string = ''): boolean;
procedure GatherUnitsInSearchPaths(SearchUnitPaths, SearchIncludePaths: TStrings; procedure GatherUnitsInSearchPaths(SearchUnitPaths, SearchIncludePaths: TStrings;
@ -1588,8 +1591,8 @@ end;
function ParseFPCVerbose(List: TStrings; const WorkDir: string; out function ParseFPCVerbose(List: TStrings; const WorkDir: string; out
ConfigFiles: TStrings; out RealCompilerFilename: string; out ConfigFiles: TStrings; out RealCompilerFilename: string; out
UnitPaths: TStrings; out IncludePaths: TStrings; out Defines, UnitPaths: TStrings; out IncludePaths: TStrings; out UnitScopes: TStrings; out
Undefines: TStringToStringTree): boolean; Defines, Undefines: TStringToStringTree): boolean;
procedure UndefineSymbol(const MacroName: string); procedure UndefineSymbol(const MacroName: string);
begin begin
@ -1722,6 +1725,13 @@ function ParseFPCVerbose(List: TStrings; const WorkDir: string; out
DebugLn('Using include path: "',NewPath,'"'); DebugLn('Using include path: "',NewPath,'"');
{$ENDIF} {$ENDIF}
IncludePaths.Add(NewPath); IncludePaths.Add(NewPath);
end else if (StrLComp(@UpLine[CurPos], 'USING UNIT SCOPE: ', 18) = 0) then begin
Inc(CurPos, 18);
NewPath:=Trim(copy(Line,CurPos,len));
{$IFDEF VerboseFPCSrcScan}
DebugLn('Using unit scope: "',NewPath,'"');
{$ENDIF}
UnitScopes.Add(NewPath);
end; end;
end; end;
end; end;
@ -1734,6 +1744,7 @@ begin
RealCompilerFilename:=''; RealCompilerFilename:='';
UnitPaths:=TStringList.Create; UnitPaths:=TStringList.Create;
IncludePaths:=TStringList.Create; IncludePaths:=TStringList.Create;
UnitScopes:=TStringList.Create;
Defines:=TStringToStringTree.Create(false); Defines:=TStringToStringTree.Create(false);
Undefines:=TStringToStringTree.Create(false); Undefines:=TStringToStringTree.Create(false);
try try
@ -1745,15 +1756,16 @@ begin
FreeAndNil(ConfigFiles); FreeAndNil(ConfigFiles);
FreeAndNil(UnitPaths); FreeAndNil(UnitPaths);
FreeAndNil(IncludePaths); FreeAndNil(IncludePaths);
FreeAndNil(UnitScopes);
FreeAndNil(Undefines); FreeAndNil(Undefines);
FreeAndNil(Defines); FreeAndNil(Defines);
end; end;
end; end;
end; end;
function RunFPCVerbose(const CompilerFilename, TestFilename: string; function RunFPCVerbose(const CompilerFilename, TestFilename: string; out
out ConfigFiles: TStrings; out RealCompilerFilename: string; ConfigFiles: TStrings; out RealCompilerFilename: string; out
out UnitPaths: TStrings; out IncludePaths: TStrings; UnitPaths: TStrings; out IncludePaths: TStrings; out UnitScopes: TStrings;
out Defines, Undefines: TStringToStringTree; const Options: string): boolean; out Defines, Undefines: TStringToStringTree; const Options: string): boolean;
var var
Params: String; Params: String;
@ -1794,7 +1806,7 @@ begin
exit; exit;
end; end;
Result:=ParseFPCVerbose(List,WorkDir,ConfigFiles,RealCompilerFilename, Result:=ParseFPCVerbose(List,WorkDir,ConfigFiles,RealCompilerFilename,
UnitPaths,IncludePaths,Defines,Undefines); UnitPaths,IncludePaths,UnitScopes,Defines,Undefines);
finally finally
List.Free; List.Free;
DeleteFileUTF8(TestFilename); DeleteFileUTF8(TestFilename);
@ -8411,6 +8423,7 @@ begin
FreeAndNil(Undefines); FreeAndNil(Undefines);
FreeAndNil(UnitPaths); FreeAndNil(UnitPaths);
FreeAndNil(IncludePaths); FreeAndNil(IncludePaths);
FreeAndNil(UnitScopes);
FreeAndNil(Units); FreeAndNil(Units);
FreeAndNil(Includes); FreeAndNil(Includes);
end; end;
@ -8470,6 +8483,7 @@ begin
if not CompareStringTrees(Undefines,Item.Undefines) then exit; if not CompareStringTrees(Undefines,Item.Undefines) then exit;
if not CompareStrings(UnitPaths,Item.UnitPaths) then exit; if not CompareStrings(UnitPaths,Item.UnitPaths) then exit;
if not CompareStrings(IncludePaths,Item.IncludePaths) then exit; if not CompareStrings(IncludePaths,Item.IncludePaths) then exit;
if not CompareStrings(UnitScopes,Item.UnitScopes) then exit;
if not CompareStringTrees(Units,Item.Units) then exit; if not CompareStringTrees(Units,Item.Units) then exit;
if not CompareStringTrees(Includes,Item.Includes) then exit; if not CompareStringTrees(Includes,Item.Includes) then exit;
Result:=true; Result:=true;
@ -8523,6 +8537,7 @@ begin
AssignStringTree(Undefines,Item.Undefines); AssignStringTree(Undefines,Item.Undefines);
AssignStringList(UnitPaths,Item.UnitPaths); AssignStringList(UnitPaths,Item.UnitPaths);
AssignStringList(IncludePaths,Item.IncludePaths); AssignStringList(IncludePaths,Item.IncludePaths);
AssignStringList(UnitScopes,Item.UnitScopes);
AssignStringTree(Units,Item.Units); AssignStringTree(Units,Item.Units);
AssignStringTree(Includes,Item.Includes); AssignStringTree(Includes,Item.Includes);
@ -8534,21 +8549,12 @@ end;
procedure TPCTargetConfigCache.LoadFromXMLConfig(XMLConfig: TXMLConfig; procedure TPCTargetConfigCache.LoadFromXMLConfig(XMLConfig: TXMLConfig;
const Path: string); const Path: string);
var
Cnt: integer;
SubPath: String;
DefineName, DefineValue: String;
s: String;
i: Integer;
p: Integer;
StartPos: Integer;
Filename: String;
procedure LoadPathsFor(out ADest: TStrings; const ASubPath: string); procedure LoadPathsFor(out ADest: TStrings; const ASubPath: string);
var var
i: Integer; i: Integer;
List: TStringList; List: TStringList;
BaseDir: String; BaseDir, s: String;
begin begin
// Paths: format: semicolon separated compressed list // Paths: format: semicolon separated compressed list
List:=TStringList.Create; List:=TStringList.Create;
@ -8574,19 +8580,33 @@ var
end; end;
end; end;
procedure LoadSemicolonList(UnitScopes: TStrings; const ASubPath: string);
var
s, Scope: String;
p: Integer;
begin
s:=XMLConfig.GetValue(Path+ASubPath,'');
p:=1;
while p<=length(s) do begin
Scope:=GetNextDelimitedItem(s,';',p);
if Scope<>'' then
UnitScopes.Add(Scope);
end;
end;
procedure LoadFilesFor(var ADest: TStringToStringTree; const ASubPath: string); procedure LoadFilesFor(var ADest: TStringToStringTree; const ASubPath: string);
var var
i: Integer; i: Integer;
List: TStringList; List: TStringList;
File_Name: String; File_Name, CurPath, s, Filename: String;
FileList: TStringList; FileList: TStringList;
begin begin
// files: format: ASubPath+Values semicolon separated list of compressed filename // files: format: ASubPath+Values semicolon separated list of compressed filename
List:=TStringList.Create; List:=TStringList.Create;
FileList:=nil; FileList:=nil;
try try
SubPath:=Path+ASubPath+'Value'; CurPath:=Path+ASubPath+'Value';
s:=XMLConfig.GetValue(SubPath,''); s:=XMLConfig.GetValue(CurPath,'');
List.Delimiter:=';'; List.Delimiter:=';';
List.StrictDelimiter:=true; List.StrictDelimiter:=true;
List.DelimitedText:=s; List.DelimitedText:=s;
@ -8595,7 +8615,7 @@ var
Filename:=TrimFilename(FileList[i]); Filename:=TrimFilename(FileList[i]);
File_Name:=ExtractFileNameOnly(Filename); File_Name:=ExtractFileNameOnly(Filename);
if (File_Name='') or not IsDottedIdentifier(File_Name) then begin if (File_Name='') or not IsDottedIdentifier(File_Name) then begin
DebugLn(['Warning: [TPCTargetConfigCache.LoadFromXMLConfig] invalid filename "',File_Name,'" in "',XMLConfig.Filename,'" at "',SubPath,'"']); DebugLn(['Warning: [TPCTargetConfigCache.LoadFromXMLConfig] invalid filename "',File_Name,'" in "',XMLConfig.Filename,'" at "',CurPath,'"']);
continue; continue;
end; end;
if ADest=nil then if ADest=nil then
@ -8608,6 +8628,15 @@ var
end; end;
end; end;
var
Cnt: integer;
SubPath: String;
DefineName, DefineValue: String;
s: String;
i: Integer;
p: Integer;
StartPos: Integer;
Filename: String;
begin begin
Clear; Clear;
@ -8662,6 +8691,9 @@ begin
LoadPathsFor(UnitPaths,'UnitPaths/'); LoadPathsFor(UnitPaths,'UnitPaths/');
LoadPathsFor(IncludePaths,'IncludePaths/'); LoadPathsFor(IncludePaths,'IncludePaths/');
// Unit scopes
LoadSemicolonList(UnitScopes, 'UnitScopes');
// Files // Files
LoadFilesFor(Units,'Units/'); LoadFilesFor(Units,'Units/');
LoadFilesFor(Includes,'Includes/'); LoadFilesFor(Includes,'Includes/');
@ -8669,18 +8701,12 @@ end;
procedure TPCTargetConfigCache.SaveToXMLConfig(XMLConfig: TXMLConfig; procedure TPCTargetConfigCache.SaveToXMLConfig(XMLConfig: TXMLConfig;
const Path: string); const Path: string);
var
Node: TAVLTreeNode;
Item: PStringToStringItem;
Cnt: Integer;
SubPath: String;
s: String;
procedure SavePathsFor(const ASource: TStrings; const ASubPath: string); procedure SavePathsFor(const ASource: TStrings; const ASubPath: string);
var var
List: TStringList; List: TStringList;
RelativeUnitPaths: TStringList; RelativeUnitPaths: TStringList;
BaseDir: string; BaseDir, s: string;
begin begin
// Paths: write as semicolon separated compressed list // Paths: write as semicolon separated compressed list
s:=''; s:='';
@ -8704,11 +8730,25 @@ var
XMLConfig.SetDeleteValue(Path+ASubPath+'Value',s,''); XMLConfig.SetDeleteValue(Path+ASubPath+'Value',s,'');
end; end;
procedure SaveSemicolonList(List: TStrings; const ASubPath: string);
var
i: Integer;
s: String;
begin
s:='';
for i:=0 to List.Count-1 do
s:=s+';'+List[i];
delete(s,1,1);
XMLConfig.SetDeleteValue(Path+ASubPath+'Value',s,'');
end;
procedure SaveFilesFor(const ASource: TStringToStringTree; const ASubPath: string); procedure SaveFilesFor(const ASource: TStringToStringTree; const ASubPath: string);
var var
List: TStringList; List: TStringList;
FileList: TStringList; FileList: TStringList;
Filename: String; Filename, s: String;
Node: TAVLTreeNode;
Item: PStringToStringItem;
begin begin
// Files: ASubPath+Values semicolon separated list of compressed filenames // Files: ASubPath+Values semicolon separated list of compressed filenames
// Files contains thousands of file names. This needs compression. // Files contains thousands of file names. This needs compression.
@ -8739,9 +8779,15 @@ var
List.Free; List.Free;
FileList.Free; FileList.Free;
end; end;
XMLConfig.SetDeleteValue(Path+ASubPath+'Value',s,''); XMLConfig.SetDeleteValue(Path+ASubPath,s,'');
end; end;
var
Node: TAVLTreeNode;
Item: PStringToStringItem;
Cnt: Integer;
SubPath: String;
s: String;
begin begin
XMLConfig.SetDeleteValue(Path+'Kind',PascalCompilerNames[Kind],PascalCompilerNames[pcFPC]); XMLConfig.SetDeleteValue(Path+'Kind',PascalCompilerNames[Kind],PascalCompilerNames[pcFPC]);
XMLConfig.SetDeleteValue(Path+'TargetOS',TargetOS,''); XMLConfig.SetDeleteValue(Path+'TargetOS',TargetOS,'');
@ -8794,6 +8840,9 @@ begin
SavePathsFor(UnitPaths, 'UnitPaths/'); SavePathsFor(UnitPaths, 'UnitPaths/');
SavePathsFor(IncludePaths, 'IncludePaths/'); SavePathsFor(IncludePaths, 'IncludePaths/');
// Unit scopes
SaveSemicolonList(UnitScopes, 'UnitScopes');
// Files // Files
SaveFilesFor(Units, 'Units/'); SaveFilesFor(Units, 'Units/');
SaveFilesFor(Includes, 'Includes/'); SaveFilesFor(Includes, 'Includes/');
@ -8896,6 +8945,16 @@ end;
function TPCTargetConfigCache.Update(TestFilename: string; function TPCTargetConfigCache.Update(TestFilename: string;
ExtraOptions: string; const OnProgress: TDefinePoolProgress): boolean; ExtraOptions: string; const OnProgress: TDefinePoolProgress): boolean;
procedure PreparePaths(APaths: TStrings);
var
i: Integer;
begin
if APaths<>nil then
for i:=0 to APaths.Count-1 do
APaths[i]:=ChompPathDelim(TrimFilename(APaths[i]));
end;
var var
i: Integer; i: Integer;
OldOptions: TPCTargetConfigCache; OldOptions: TPCTargetConfigCache;
@ -8908,16 +8967,6 @@ var
InfoTypes: TFPCInfoTypes; InfoTypes: TFPCInfoTypes;
BaseDir: String; BaseDir: String;
FullFilename: String; FullFilename: String;
procedure PreparePaths(APaths: TStrings);
var
i: Integer;
begin
if APaths<>nil then
for i:=0 to APaths.Count-1 do
APaths[i]:=ChompPathDelim(TrimFilename(APaths[i]));
end;
begin begin
OldOptions:=TPCTargetConfigCache.Create(nil); OldOptions:=TPCTargetConfigCache.Create(nil);
CfgFiles:=nil; CfgFiles:=nil;
@ -8953,7 +9002,7 @@ begin
// run fpc and parse output // run fpc and parse output
HasPPUs:=false; HasPPUs:=false;
RunFPCVerbose(Compiler,TestFilename,CfgFiles,RealCompiler,UnitPaths, RunFPCVerbose(Compiler,TestFilename,CfgFiles,RealCompiler,UnitPaths,
IncludePaths,Defines,Undefines,ExtraOptions); IncludePaths,UnitScopes,Defines,Undefines,ExtraOptions);
PreparePaths(UnitPaths); PreparePaths(UnitPaths);
PreparePaths(IncludePaths); PreparePaths(IncludePaths);
// store the real compiler file and date // store the real compiler file and date