diff --git a/components/codetools/definetemplates.pas b/components/codetools/definetemplates.pas index 7e9ef90ed1..a0c28ed90e 100644 --- a/components/codetools/definetemplates.pas +++ b/components/codetools/definetemplates.pas @@ -2363,7 +2363,7 @@ begin if TargetOS='' then TargetOS:=Config.TargetOS; if TargetOS='' then - TargetOS:=GetCompiledTargetOS; + TargetOS:=FPCAdds.GetCompiledTargetOS; NewDefTempl:=TDefineTemplate.Create('Define TargetOS', ctsDefaultFPCTargetOperatingSystem, ExternalMacroStart+'TargetOS',TargetOS,da_DefineRecurse); @@ -2387,7 +2387,7 @@ begin if TargetCPU='' then TargetCPU:=Config.TargetCPU; if TargetCPU='' then - TargetCPU:=GetCompiledTargetCPU; + TargetCPU:=FPCAdds.GetCompiledTargetCPU; NewDefTempl:=TDefineTemplate.Create('Define TargetCPU', ctsDefaultFPCTargetProcessor, TargetCPUMacroName,TargetCPU, @@ -9508,9 +9508,9 @@ var SrcCPU: String; begin if TargetOS='' then - TargetOS:=GetCompiledTargetOS; + TargetOS:=FPCAdds.GetCompiledTargetOS; if TargetCPU='' then - TargetCPU:=GetCompiledTargetCPU; + TargetCPU:=FPCAdds.GetCompiledTargetCPU; Result:=TargetOS+','+TargetCPU; SrcOS:=GetDefaultSrcOSForTargetOS(TargetOS); SrcOS2:=GetDefaultSrcOS2ForTargetOS(TargetOS); @@ -10415,10 +10415,10 @@ begin end else begin RealTargetOS:=TargetOS; if RealTargetOS='' then - RealTargetOS:=GetCompiledTargetOS; + RealTargetOS:=FPCAdds.GetCompiledTargetOS; RealTargetCPU:=TargetCPU; if RealTargetCPU='' then - RealTargetCPU:=GetCompiledTargetCPU; + RealTargetCPU:=FPCAdds.GetCompiledTargetCPU; end; if FullVersion<>'' then begin @@ -10557,7 +10557,7 @@ begin Result:=''; if Kind<>pcFPC then exit; - CompiledTargetCPU:=GetCompiledTargetCPU; + CompiledTargetCPU:=FPCAdds.GetCompiledTargetCPU; if aTargetCPU='' then aTargetCPU:=CompiledTargetCPU; Cross:=not SameText(aTargetCPU,CompiledTargetCPU); diff --git a/components/codetools/directorycacher.pas b/components/codetools/directorycacher.pas index 939c50c84e..5132a334cc 100644 --- a/components/codetools/directorycacher.pas +++ b/components/codetools/directorycacher.pas @@ -1114,11 +1114,12 @@ end; function TCTDirectoryCache.FindIncludeFile(const IncFilename: string; AnyCase: boolean): string; var - Files, CurFilename, IncExt, CurExt: PChar; + Files, CurFilename, IncExtP, CurExtP: PChar; Starts: PInteger; - l, r, m, first, cmp: Integer; + l, r, m, first, cmp, Best: Integer; AUnitName: String; - ExtFits: Boolean; + Fits: Boolean; + Ext, BestExt: TCTPascalIncExtType; begin Result:=''; {$IFDEF DebugDirCacheFindIncFile} @@ -1142,10 +1143,10 @@ begin l:=length(IncFilename); while (l>0) and (IncFilename[l]<>'.') do dec(l); if l>0 then begin - IncExt:=@IncFilename[l]; + IncExtP:=@IncFilename[l]; AUnitName:=LeftStr(IncFilename,l-1); end else begin - IncExt:=nil; + IncExtP:=nil; AUnitName:=IncFilename; end; // binary search the lowest filename matching the AUnitName @@ -1173,6 +1174,8 @@ begin m:=first; // -> now find a filename with correct case and extension + Best:=-1; + BestExt:=high(TCTPascalIncExtType); while m0) then DebugLn('TCTDirectoryCache.FindIncludeFile NEXT "',CurFilename,'" ExtStart=',dbgstr(CurExt^)); {$ENDIF} - ExtFits:=false; - if IncExt=nil then begin - // include file without extension -> search without and default extension - if (CurExt^=#0) - or IsPascalIncExt(IncExt) then - ExtFits:=true; - end else begin + Fits:=false; + if IncExtP<>nil then begin // include file with extension - if ComparePCharCaseInsensitiveA(CurExt,IncExt)=0 then - ExtFits:=true; + if ComparePCharCaseInsensitiveA(CurExtP,IncExtP)=0 then + Fits:=true; + end else begin + // include file without extension -> search without and default extension + if (CurExtP^=#0) then begin + Fits:=true; + Ext:=pietNone; + end else begin + Ext:=IsPascalIncExt(IncExtP); + Fits:=Ext>pietNone; + end; end; - if ExtFits then begin + if Fits then begin // the extension fits -> check case Result:=CurFilename; {$IFDEF DebugDirCacheFindIncFile} @@ -1205,21 +1212,37 @@ begin DebugLn('TCTDirectoryCache.FindIncludeFile CHECKING CASE "',CurFilename,'"'); {$ENDIF} if AnyCase then begin - exit; end else begin // check case platform dependent {$IFDEF CaseInsensitiveFilenames} - exit; {$ELSE} - if (LeftStr(Result,length(AUnitName))=AUnitName) - or (Result=lowercase(Result)) - or (Result=uppercase(Result)) then - exit; + if (LeftStr(Result,length(AUnitName))<>AUnitName) + and (Result<>lowercase(Result)) + and (Result<>uppercase(Result)) then + Fits:=false; {$ENDIF} end; + if Fits then begin + if IncExtP<>nil then begin + // include file with extension -> found + exit; + end else begin + // include file without extension -> search best extension + if (Best<0) or (BestExt>Ext) then begin + Best:=m; + BestExt:=Ext; + end; + end; + end; end; inc(m); end; + if Best>=0 then begin + CurFilename:=@Files[Starts[Best]+DirListNameOffset]; + Result:=CurFilename; + exit; + end; + {$IFDEF DebugDirCacheFindIncFile} if m0) then @@ -1741,11 +1764,13 @@ end; function TCTStarDirectoryCache.FindIncludeFile(const IncFilename: string; AnyCase: boolean): string; var - Files, CurFilename, IncExt, CurExt: PChar; + Files, CurFilename, IncExtP, CurExtP: PChar; Starts: PInteger; - l, r, m, first, cmp: TListingPosition; + l, r, m, first, cmp, DirIndex: TListingPosition; AUnitName: String; - ExtFits: Boolean; + Fits: Boolean; + Ext, BestExt: TCTPascalIncExtType; + BestDirIndex, Best: Integer; begin Result:=''; {$IFDEF DebugDirCacheFindIncFile} @@ -1761,10 +1786,10 @@ begin l:=length(IncFilename); while (l>0) and (IncFilename[l]<>'.') do dec(l); if l>0 then begin - IncExt:=@IncFilename[l]; + IncExtP:=@IncFilename[l]; AUnitName:=LeftStr(IncFilename,l-1); end else begin - IncExt:=nil; + IncExtP:=nil; AUnitName:=IncFilename; end; @@ -1791,6 +1816,9 @@ begin if first<0 then exit; m:=first; // -> now find a filename with correct case and extension + Best:=-1; + BestDirIndex:=-1; + BestExt:=high(TCTPascalIncExtType); while m0) then DebugLn('TCTDirectoryCache.FindIncludeFile NEXT "',CurFilename,'" ExtStart=',dbgstr(CurExt^)); {$ENDIF} - ExtFits:=false; - if IncExt=nil then begin - // include file without extension -> search without and default extension - if (CurExt^=#0) - or IsPascalIncExt(IncExt) then - ExtFits:=true; - end else begin + Fits:=false; + if IncExtP<>nil then begin // include file with extension - if ComparePCharCaseInsensitiveA(CurExt,IncExt)=0 then - ExtFits:=true; + if ComparePCharCaseInsensitiveA(CurExtP,IncExtP)=0 then + Fits:=true; + end else begin + // include file without extension -> search without and default extension + if (CurExtP^=#0) then begin + Fits:=true; + Ext:=pietNone; + end else begin + Ext:=IsPascalIncExt(IncExtP); + Fits:=Ext>pietNone; + end; end; - if ExtFits then begin + if Fits then begin // the extension fits -> check case Result:=CurFilename; {$IFDEF DebugDirCacheFindIncFile} @@ -1823,21 +1855,42 @@ begin DebugLn('TCTDirectoryCache.FindIncludeFile CHECKING CASE "',CurFilename,'"'); {$ENDIF} if AnyCase then begin - exit; end else begin // check case platform dependent {$IFDEF CaseInsensitiveFilenames} - exit; {$ELSE} - if (LeftStr(Result,length(AUnitName))=AUnitName) - or (Result=lowercase(Result)) - or (Result=uppercase(Result)) then - exit; + if (LeftStr(Result,length(AUnitName))<>AUnitName) + and (Result<>lowercase(Result)) + and (Result<>uppercase(Result)) then + Fits:=false; {$ENDIF} end; + if Fits then begin + if IncExtP<>nil then begin + // include file with extension -> found + Result:=FListing.GetSubDirFilename(m); + exit; + end else begin + // include file without extension + // the first in inc path wins + // filename.inc is better than filename.pas + DirIndex:=FListing.GetSubDirIndex(m); + if (Best<0) + or (BestDirIndex>DirIndex) + or ((BestDirIndex=DirIndex) and (BestExt>Ext)) then + begin + Best:=m; + BestExt:=Ext; + end; + end; + end; end; inc(m); end; + if Best>=0 then begin + Result:=FListing.GetSubDirFilename(Best); + exit; + end; {$IFDEF DebugDirCacheFindUnitSource} if m0) then diff --git a/components/codetools/fileprocs.pas b/components/codetools/fileprocs.pas index edc665d988..27e6d9d4c0 100644 --- a/components/codetools/fileprocs.pas +++ b/components/codetools/fileprocs.pas @@ -105,6 +105,16 @@ function CompareAnsiStringFilenames(Data1, Data2: Pointer): integer; function CompareFilenameOnly(Filename: PChar; FilenameLen: integer; NameOnly: PChar; NameOnlyLen: integer; CaseSensitive: boolean = false): integer; +type + TCTPascalExtType = (petNone, petPAS, petPP, petP); + TCTPascalIncExtType = (pietNone, pietINC, pietPP, pietPAS); + +const + CTPascalExtension: array[TCTPascalExtType] of string = + ('', '.pas', '.pp', '.p'); + CTPascalIncExtension: array[TCTPascalIncExtType] of string = + ('', '.inc', '.pp', '.pas'); + // searching .pas, .pp, .p function FilenameIsPascalUnit(const Filename: string; CaseSensitive: boolean = false): boolean; @@ -116,7 +126,7 @@ function SearchPascalUnitInDir(const AnUnitName, BaseDirectory: string; SearchCase: TCTSearchFileCase): string; function SearchPascalUnitInPath(const AnUnitName, BasePath, SearchPath, Delimiter: string; SearchCase: TCTSearchFileCase): string; -function IsPascalIncExt(FileExt: PChar; CaseSensitive: boolean = false): boolean; +function IsPascalIncExt(FileExt: PChar; CaseSensitive: boolean = false): TCTPascalIncExtType; // searching .ppu function SearchPascalFileInDir(const ShortFilename, BaseDirectory: string; @@ -131,16 +141,6 @@ function FindNextFPCParameter(const CmdLine, BeginsWith: string; var Position: i function GetLastFPCParameter(const CmdLine, BeginsWith: string; CutBegins: boolean = true): string; function GetFPCParameterSrcFile(const CmdLine: string): string; -type - TCTPascalExtType = (petNone, petPAS, petPP, petP); - TCTPascalIncExtType = (pietNone, pietINC, pietPP, pietPAS); - -const - CTPascalExtension: array[TCTPascalExtType] of string = - ('', '.pas', '.pp', '.p'); - CTPascalIncExtension: array[TCTPascalIncExtType] of string = - ('', '.inc', '.pp', '.pas'); - // store date locale independent, thread safe const DateAsCfgStrFormat=LazConfigStorage.DateAsCfgStrFormat; const DateTimeAsCfgStrFormat=LazConfigStorage.DateTimeAsCfgStrFormat; @@ -798,7 +798,8 @@ begin Result:=''; end; -function IsPascalIncExt(FileExt: PChar; CaseSensitive: boolean): boolean; +function IsPascalIncExt(FileExt: PChar; CaseSensitive: boolean + ): TCTPascalIncExtType; // check if asciiz FileExt is a CTPascalIncExtension var ExtLen: Integer; @@ -806,7 +807,7 @@ var e: TCTPascalIncExtType; f: PChar; begin - Result:=false; + Result:=pietNone; if (FileExt=nil) then exit; ExtLen:=strlen(FileExt); if ExtLen=0 then exit; @@ -828,7 +829,7 @@ begin end; end; if p^=#0 then - exit(true); + exit(e); end; end;