HeaderSearch.h revision 7412494982c8b50c90961302c3a718633b2c3ab7
15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===--- HeaderSearch.h - Resolve Header File Locations ---------*- C++ -*-===// 25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// The LLVM Compiler Infrastructure 45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source 60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details. 75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// This file defines the HeaderSearch interface. 115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#ifndef LLVM_CLANG_LEX_HEADERSEARCH_H 155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#define LLVM_CLANG_LEX_HEADERSEARCH_H 165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/Lex/DirectoryLookup.h" 185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/ADT/StringMap.h" 195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include <vector> 205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang { 228c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor 238c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregorclass ExternalIdentifierLookup; 245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FileEntry; 255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FileManager; 265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass IdentifierInfo; 275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2883d63c78810556d26b62ac4cbae2eda6cdd2570cSteve Naroff/// HeaderFileInfo - The preprocessor keeps track of this information for each 2983d63c78810556d26b62ac4cbae2eda6cdd2570cSteve Naroff/// file that is #included. 3083d63c78810556d26b62ac4cbae2eda6cdd2570cSteve Naroffstruct HeaderFileInfo { 3183d63c78810556d26b62ac4cbae2eda6cdd2570cSteve Naroff /// isImport - True if this is a #import'd or #pragma once file. 32cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor unsigned isImport : 1; 331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3483d63c78810556d26b62ac4cbae2eda6cdd2570cSteve Naroff /// DirInfo - Keep track of whether this is a system header, and if so, 3583d63c78810556d26b62ac4cbae2eda6cdd2570cSteve Naroff /// whether it is C++ clean or not. This can be set by the include paths or 3683d63c78810556d26b62ac4cbae2eda6cdd2570cSteve Naroff /// by #pragma gcc system_header. This is an instance of 3783d63c78810556d26b62ac4cbae2eda6cdd2570cSteve Naroff /// SrcMgr::CharacteristicKind. 3883d63c78810556d26b62ac4cbae2eda6cdd2570cSteve Naroff unsigned DirInfo : 2; 391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 40cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor /// \brief Whether this header file info was supplied by an external source. 41cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor unsigned External : 1; 42cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 43cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor /// \brief Whether this structure is considered to already have been 44cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor /// "resolved", meaning that it was loaded from the external source. 45cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor unsigned Resolved : 1; 46cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 4783d63c78810556d26b62ac4cbae2eda6cdd2570cSteve Naroff /// NumIncludes - This is the number of times the file has been included 4883d63c78810556d26b62ac4cbae2eda6cdd2570cSteve Naroff /// already. 4983d63c78810556d26b62ac4cbae2eda6cdd2570cSteve Naroff unsigned short NumIncludes; 501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 51cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor /// \brief The ID number of the controlling macro. 52cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor /// 53cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor /// This ID number will be non-zero when there is a controlling 54cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor /// macro whose IdentifierInfo may not yet have been loaded from 55cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor /// external storage. 56cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor unsigned ControllingMacroID; 57cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 5883d63c78810556d26b62ac4cbae2eda6cdd2570cSteve Naroff /// ControllingMacro - If this file has a #ifndef XXX (or equivalent) guard 5983d63c78810556d26b62ac4cbae2eda6cdd2570cSteve Naroff /// that protects the entire contents of the file, this is the identifier 6083d63c78810556d26b62ac4cbae2eda6cdd2570cSteve Naroff /// for the macro that controls whether or not it has any effect. 618c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor /// 628c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor /// Note: Most clients should use getControllingMacro() to access 638c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor /// the controlling macro of this header, since 648c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor /// getControllingMacro() is able to load a controlling macro from 658c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor /// external storage. 6683d63c78810556d26b62ac4cbae2eda6cdd2570cSteve Naroff const IdentifierInfo *ControllingMacro; 678c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor 681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump HeaderFileInfo() 69cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor : isImport(false), DirInfo(SrcMgr::C_User), External(false), 70cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor Resolved(false), NumIncludes(0), ControllingMacroID(0), 71cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor ControllingMacro(0) {} 728c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor 738c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor /// \brief Retrieve the controlling macro for this header file, if 748c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor /// any. 758c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor const IdentifierInfo *getControllingMacro(ExternalIdentifierLookup *External); 76cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 77cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor /// \brief Determine whether this is a non-default header file info, e.g., 78cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor /// it corresponds to an actual header we've included or tried to include. 79cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor bool isNonDefault() const { 80cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor return isImport || NumIncludes || ControllingMacro || ControllingMacroID; 81cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor } 8283d63c78810556d26b62ac4cbae2eda6cdd2570cSteve Naroff}; 8383d63c78810556d26b62ac4cbae2eda6cdd2570cSteve Naroff 84cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor/// \brief An external source of header file information, which may supply 85cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor/// information about header files already included. 86cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregorclass ExternalHeaderFileInfoSource { 87cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregorpublic: 88cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor virtual ~ExternalHeaderFileInfoSource(); 89cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 90cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor /// \brief Retrieve the header file information for the given file entry. 91cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor /// 92cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor /// \returns Header file information for the given file entry, with the 93cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor /// \c External bit set. If the file entry is not known, return a 94cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor /// default-constructed \c HeaderFileInfo. 95cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor virtual HeaderFileInfo GetHeaderFileInfo(const FileEntry *FE) = 0; 96cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor}; 97cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// HeaderSearch - This class encapsulates the information needed to find the 995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// file referenced by a #include or #include_next, (sub-)framework lookup, etc. 1005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass HeaderSearch { 1015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer FileManager &FileMgr; 1025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// #include search path information. Requests for #include "x" search the 1035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// directory of the #including file first, then each directory in SearchDirs 1045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// consequtively. Requests for <x> search the current dir first, then each 1055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// directory in SearchDirs, starting at SystemDirIdx, consequtively. If 1065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// NoCurDirSearch is true, then the check for the file in the current 107fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner /// directory is suppressed. 1085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer std::vector<DirectoryLookup> SearchDirs; 1095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned SystemDirIdx; 1105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool NoCurDirSearch; 1111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// FileInfo - This contains all of the preprocessor-specific data about files 1135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// that are included. The vector is indexed by the FileEntry's UID. 1145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 11583d63c78810556d26b62ac4cbae2eda6cdd2570cSteve Naroff std::vector<HeaderFileInfo> FileInfo; 1165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1179960ae8ecfa2c4278dac708a02e463f83fdf17e8Chris Lattner /// LookupFileCache - This is keeps track of each lookup performed by 1189960ae8ecfa2c4278dac708a02e463f83fdf17e8Chris Lattner /// LookupFile. The first part of the value is the starting index in 1199960ae8ecfa2c4278dac708a02e463f83fdf17e8Chris Lattner /// SearchDirs that the cached search was performed from. If there is a hit 1209960ae8ecfa2c4278dac708a02e463f83fdf17e8Chris Lattner /// and this value doesn't match the current query, the cache has to be 1219960ae8ecfa2c4278dac708a02e463f83fdf17e8Chris Lattner /// ignored. The second value is the entry in SearchDirs that satisfied the 1229960ae8ecfa2c4278dac708a02e463f83fdf17e8Chris Lattner /// query. 1239960ae8ecfa2c4278dac708a02e463f83fdf17e8Chris Lattner llvm::StringMap<std::pair<unsigned, unsigned> > LookupFileCache; 1241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// FrameworkMap - This is a collection mapping a framework or subframework 1275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// name like "Carbon" to the Carbon.framework directory. 1285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::StringMap<const DirectoryEntry *> FrameworkMap; 1295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// HeaderMaps - This is a mapping from FileEntry -> HeaderMap, uniquing 131822da61b74ce14e89b3fa8774db18c833aa5748bChris Lattner /// headermaps. This vector owns the headermap. 132822da61b74ce14e89b3fa8774db18c833aa5748bChris Lattner std::vector<std::pair<const FileEntry*, const HeaderMap*> > HeaderMaps; 1338c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor 1348c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor /// \brief Entity used to resolve the identifier IDs of controlling 1358c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor /// macros into IdentifierInfo pointers, as needed. 1368c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor ExternalIdentifierLookup *ExternalLookup; 1378c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor 138cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor /// \brief Entity used to look up stored header file information. 139cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor ExternalHeaderFileInfoSource *ExternalSource; 140cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 1415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Various statistics we track for performance analysis. 1425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned NumIncluded; 1435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned NumMultiIncludeFileOptzn; 1445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned NumFrameworkLookups, NumSubFrameworkLookups; 14549c1f4aa2a6c360d25d605004ec3c4affd62db77Steve Naroff 14649c1f4aa2a6c360d25d605004ec3c4affd62db77Steve Naroff // HeaderSearch doesn't support default or copy construction. 1471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit HeaderSearch(); 14849c1f4aa2a6c360d25d605004ec3c4affd62db77Steve Naroff explicit HeaderSearch(const HeaderSearch&); 14949c1f4aa2a6c360d25d605004ec3c4affd62db77Steve Naroff void operator=(const HeaderSearch&); 1505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 15139b49bcaaddb1049234fca9500c0ac02c088e23dChris Lattner HeaderSearch(FileManager &FM); 152822da61b74ce14e89b3fa8774db18c833aa5748bChris Lattner ~HeaderSearch(); 1535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer FileManager &getFileMgr() const { return FileMgr; } 1555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// SetSearchPaths - Interface for setting the file search paths. 1575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 1585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void SetSearchPaths(const std::vector<DirectoryLookup> &dirs, 1595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned systemDirIdx, bool noCurDirSearch) { 1605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SearchDirs = dirs; 1615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SystemDirIdx = systemDirIdx; 1625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer NoCurDirSearch = noCurDirSearch; 1639960ae8ecfa2c4278dac708a02e463f83fdf17e8Chris Lattner //LookupFileCache.clear(); 1645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ClearFileInfo - Forget everything we know about headers so far. 1675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ClearFileInfo() { 1685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer FileInfo.clear(); 1695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1718c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor void SetExternalLookup(ExternalIdentifierLookup *EIL) { 1728c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor ExternalLookup = EIL; 1738c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor } 1748c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor 175cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor ExternalIdentifierLookup *getExternalLookup() const { 176cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor return ExternalLookup; 177cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor } 178cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 179cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor /// \brief Set the external source of header information. 180cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor void SetExternalSource(ExternalHeaderFileInfoSource *ES) { 181cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor ExternalSource = ES; 182cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor } 183cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 1845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// LookupFile - Given a "foo" or <foo> reference, look up the indicated file, 1857412494982c8b50c90961302c3a718633b2c3ab7Manuel Klimek /// return null on failure. 1867412494982c8b50c90961302c3a718633b2c3ab7Manuel Klimek /// 1877412494982c8b50c90961302c3a718633b2c3ab7Manuel Klimek /// \returns If successful, this returns 'UsedDir', the DirectoryLookup member 1887412494982c8b50c90961302c3a718633b2c3ab7Manuel Klimek /// the file was found in, or null if not applicable. 1897412494982c8b50c90961302c3a718633b2c3ab7Manuel Klimek /// 1907412494982c8b50c90961302c3a718633b2c3ab7Manuel Klimek /// \param isAngled indicates whether the file reference is a <> reference. 1917412494982c8b50c90961302c3a718633b2c3ab7Manuel Klimek /// 1927412494982c8b50c90961302c3a718633b2c3ab7Manuel Klimek /// \param CurDir If non-null, the file was found in the specified directory 1937412494982c8b50c90961302c3a718633b2c3ab7Manuel Klimek /// search location. This is used to implement #include_next. 1947412494982c8b50c90961302c3a718633b2c3ab7Manuel Klimek /// 1957412494982c8b50c90961302c3a718633b2c3ab7Manuel Klimek /// \param CurFileEnt If non-null, indicates where the #including file is, in 1967412494982c8b50c90961302c3a718633b2c3ab7Manuel Klimek /// case a relative search is needed. 1977412494982c8b50c90961302c3a718633b2c3ab7Manuel Klimek /// 1987412494982c8b50c90961302c3a718633b2c3ab7Manuel Klimek /// \param SearchPath If non-null, will be set to the search path relative 1997412494982c8b50c90961302c3a718633b2c3ab7Manuel Klimek /// to which the file was found. If the include path is absolute, SearchPath 2007412494982c8b50c90961302c3a718633b2c3ab7Manuel Klimek /// will be set to an empty string. 2017412494982c8b50c90961302c3a718633b2c3ab7Manuel Klimek /// 2027412494982c8b50c90961302c3a718633b2c3ab7Manuel Klimek /// \param RelativePath If non-null, will be set to the path relative to 2037412494982c8b50c90961302c3a718633b2c3ab7Manuel Klimek /// SearchPath at which the file was found. This only differs from the 2047412494982c8b50c90961302c3a718633b2c3ab7Manuel Klimek /// Filename for framework includes. 205a139481e62fdb209d9d87a54a5733f989d2e8d51Chris Lattner const FileEntry *LookupFile(llvm::StringRef Filename, bool isAngled, 2065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const DirectoryLookup *FromDir, 2075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const DirectoryLookup *&CurDir, 208b5142bb7af5c70fffd09f05172a1379a35a9c29aChandler Carruth const FileEntry *CurFileEnt, 2097412494982c8b50c90961302c3a718633b2c3ab7Manuel Klimek llvm::SmallVectorImpl<char> *SearchPath, 2107412494982c8b50c90961302c3a718633b2c3ab7Manuel Klimek llvm::SmallVectorImpl<char> *RelativePath); 2111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// LookupSubframeworkHeader - Look up a subframework for the specified 2135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// #include file. For example, if #include'ing <HIToolbox/HIToolbox.h> from 2145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// within ".../Carbon.framework/Headers/Carbon.h", check to see if HIToolbox 2155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// is a subframework within Carbon.framework. If so, return the FileEntry 2165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// for the designated file, otherwise return null. 217b5142bb7af5c70fffd09f05172a1379a35a9c29aChandler Carruth const FileEntry *LookupSubframeworkHeader( 218b5142bb7af5c70fffd09f05172a1379a35a9c29aChandler Carruth llvm::StringRef Filename, 219b5142bb7af5c70fffd09f05172a1379a35a9c29aChandler Carruth const FileEntry *RelativeFileEnt, 2207412494982c8b50c90961302c3a718633b2c3ab7Manuel Klimek llvm::SmallVectorImpl<char> *SearchPath, 2217412494982c8b50c90961302c3a718633b2c3ab7Manuel Klimek llvm::SmallVectorImpl<char> *RelativePath); 2221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 223afded5bbb85607023c710c3d6a96c372feb84d7fChris Lattner /// LookupFrameworkCache - Look up the specified framework name in our 224afded5bbb85607023c710c3d6a96c372feb84d7fChris Lattner /// framework cache, returning the DirectoryEntry it is in if we know, 225afded5bbb85607023c710c3d6a96c372feb84d7fChris Lattner /// otherwise, return null. 226a139481e62fdb209d9d87a54a5733f989d2e8d51Chris Lattner const DirectoryEntry *&LookupFrameworkCache(llvm::StringRef FWName) { 227a139481e62fdb209d9d87a54a5733f989d2e8d51Chris Lattner return FrameworkMap.GetOrCreateValue(FWName).getValue(); 228afded5bbb85607023c710c3d6a96c372feb84d7fChris Lattner } 2291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ShouldEnterIncludeFile - Mark the specified file as a target of of a 2315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// #include, #include_next, or #import directive. Return false if #including 2325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// the file will have no effect or true if we should include it. 2335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool ShouldEnterIncludeFile(const FileEntry *File, bool isImport); 2341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getFileDirFlavor - Return whether the specified file is a normal header, 2375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// a system header, or a C++ friendly system header. 2389d72851fec9e9c62570a027d42701562bbf29751Chris Lattner SrcMgr::CharacteristicKind getFileDirFlavor(const FileEntry *File) { 2399d72851fec9e9c62570a027d42701562bbf29751Chris Lattner return (SrcMgr::CharacteristicKind)getFileInfo(File).DirInfo; 2405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// MarkFileIncludeOnce - Mark the specified file as a "once only" file, e.g. 2435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// due to #pragma once. 2445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void MarkFileIncludeOnce(const FileEntry *File) { 2455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer getFileInfo(File).isImport = true; 2465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 248e9eb3f88b82176d8a43f7856250efded80cb2504Daniel Dunbar /// MarkFileSystemHeader - Mark the specified file as a system header, e.g. 2495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// due to #pragma GCC system_header. 2505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void MarkFileSystemHeader(const FileEntry *File) { 2510b9e736308af5397f558ffc8e780c438c2fdb563Chris Lattner getFileInfo(File).DirInfo = SrcMgr::C_System; 2525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25425bfcb927d9169ea675ce6e98d8992efceeb0e42Chris Lattner /// IncrementIncludeCount - Increment the count for the number of times the 25525bfcb927d9169ea675ce6e98d8992efceeb0e42Chris Lattner /// specified FileEntry has been entered. 25625bfcb927d9169ea675ce6e98d8992efceeb0e42Chris Lattner void IncrementIncludeCount(const FileEntry *File) { 25725bfcb927d9169ea675ce6e98d8992efceeb0e42Chris Lattner ++getFileInfo(File).NumIncludes; 25825bfcb927d9169ea675ce6e98d8992efceeb0e42Chris Lattner } 2591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// SetFileControllingMacro - Mark the specified file as having a controlling 2615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// macro. This is used by the multiple-include optimization to eliminate 2625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// no-op #includes. 2635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void SetFileControllingMacro(const FileEntry *File, 2645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const IdentifierInfo *ControllingMacro) { 2655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer getFileInfo(File).ControllingMacro = ControllingMacro; 2665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 268822da61b74ce14e89b3fa8774db18c833aa5748bChris Lattner /// CreateHeaderMap - This method returns a HeaderMap for the specified 269822da61b74ce14e89b3fa8774db18c833aa5748bChris Lattner /// FileEntry, uniquing them through the the 'HeaderMaps' datastructure. 2701bfd4a6313ea8ebf710c46c10111732cc65d51f6Chris Lattner const HeaderMap *CreateHeaderMap(const FileEntry *FE); 2711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 272afded5bbb85607023c710c3d6a96c372feb84d7fChris Lattner void IncrementFrameworkLookupCount() { ++NumFrameworkLookups; } 27383d63c78810556d26b62ac4cbae2eda6cdd2570cSteve Naroff 27412fab31aa5868b1a6b52246b5a87daa48a338fe2Douglas Gregor typedef std::vector<HeaderFileInfo>::const_iterator header_file_iterator; 27512fab31aa5868b1a6b52246b5a87daa48a338fe2Douglas Gregor header_file_iterator header_file_begin() const { return FileInfo.begin(); } 27612fab31aa5868b1a6b52246b5a87daa48a338fe2Douglas Gregor header_file_iterator header_file_end() const { return FileInfo.end(); } 27712fab31aa5868b1a6b52246b5a87daa48a338fe2Douglas Gregor unsigned header_file_size() const { return FileInfo.size(); } 27883d63c78810556d26b62ac4cbae2eda6cdd2570cSteve Naroff 279c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl // Used by ASTReader. 28083d63c78810556d26b62ac4cbae2eda6cdd2570cSteve Naroff void setHeaderFileInfoForUID(HeaderFileInfo HFI, unsigned UID); 2811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 282ec356c320a81062b1843f0dbe7fedf29ed947eceDouglas Gregor // Used by external tools 283ec356c320a81062b1843f0dbe7fedf29ed947eceDouglas Gregor typedef std::vector<DirectoryLookup>::const_iterator search_dir_iterator; 284ec356c320a81062b1843f0dbe7fedf29ed947eceDouglas Gregor search_dir_iterator search_dir_begin() const { return SearchDirs.begin(); } 285ec356c320a81062b1843f0dbe7fedf29ed947eceDouglas Gregor search_dir_iterator search_dir_end() const { return SearchDirs.end(); } 286ec356c320a81062b1843f0dbe7fedf29ed947eceDouglas Gregor unsigned search_dir_size() const { return SearchDirs.size(); } 287ec356c320a81062b1843f0dbe7fedf29ed947eceDouglas Gregor 288ec356c320a81062b1843f0dbe7fedf29ed947eceDouglas Gregor search_dir_iterator system_dir_begin() const { 289ec356c320a81062b1843f0dbe7fedf29ed947eceDouglas Gregor return SearchDirs.begin() + SystemDirIdx; 290ec356c320a81062b1843f0dbe7fedf29ed947eceDouglas Gregor } 291ec356c320a81062b1843f0dbe7fedf29ed947eceDouglas Gregor search_dir_iterator system_dir_end() const { return SearchDirs.end(); } 292ec356c320a81062b1843f0dbe7fedf29ed947eceDouglas Gregor 2935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void PrintStats(); 2945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 2951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 29683d63c78810556d26b62ac4cbae2eda6cdd2570cSteve Naroff /// getFileInfo - Return the HeaderFileInfo structure for the specified 2975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// FileEntry. 29883d63c78810556d26b62ac4cbae2eda6cdd2570cSteve Naroff HeaderFileInfo &getFileInfo(const FileEntry *FE); 2995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 3005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 3025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 304