HeaderSearch.h revision 30a2e16f6c27f888dd11eba6bbbae1e980078fcb
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" 18a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor#include "clang/Lex/ModuleMap.h" 19f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith#include "llvm/ADT/ArrayRef.h" 20c042edd54face617a3b9d0b4b9d5a3ff229d0f48Douglas Gregor#include "llvm/ADT/IntrusiveRefCntPtr.h" 2130a2e16f6c27f888dd11eba6bbbae1e980078fcbChandler Carruth#include "llvm/ADT/OwningPtr.h" 225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/ADT/StringMap.h" 2365e02fa80e1c185f18e5f81cefc30d75383a7301Douglas Gregor#include "llvm/ADT/StringSet.h" 24d1194fbbf65374bfa3578eb40a547e4f97b497d1Ted Kremenek#include "llvm/Support/Allocator.h" 255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include <vector> 265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang { 288e23806863721495f9e1f84aed614f7afba774a3Douglas Gregor 298e23806863721495f9e1f84aed614f7afba774a3Douglas Gregorclass DiagnosticsEngine; 308c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregorclass ExternalIdentifierLookup; 315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FileEntry; 325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FileManager; 33c042edd54face617a3b9d0b4b9d5a3ff229d0f48Douglas Gregorclass HeaderSearchOptions; 345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass IdentifierInfo; 355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 36a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett/// \brief The preprocessor keeps track of this information for each 37809d1be9820039b4cf6efa48246a0d70ffa13394James Dennett/// file that is \#included. 3883d63c78810556d26b62ac4cbae2eda6cdd2570cSteve Naroffstruct HeaderFileInfo { 39a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett /// \brief True if this is a \#import'd or \#pragma once file. 40cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor unsigned isImport : 1; 411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 42a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett /// \brief True if this is a \#pragma once file. 43dd3e5549e3c11e217078938aacf72f042eea5343Douglas Gregor unsigned isPragmaOnce : 1; 44dd3e5549e3c11e217078938aacf72f042eea5343Douglas Gregor 4583d63c78810556d26b62ac4cbae2eda6cdd2570cSteve Naroff /// DirInfo - Keep track of whether this is a system header, and if so, 4683d63c78810556d26b62ac4cbae2eda6cdd2570cSteve Naroff /// whether it is C++ clean or not. This can be set by the include paths or 47a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett /// by \#pragma gcc system_header. This is an instance of 4883d63c78810556d26b62ac4cbae2eda6cdd2570cSteve Naroff /// SrcMgr::CharacteristicKind. 4983d63c78810556d26b62ac4cbae2eda6cdd2570cSteve Naroff unsigned DirInfo : 2; 501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 51cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor /// \brief Whether this header file info was supplied by an external source. 52cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor unsigned External : 1; 53cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 54cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor /// \brief Whether this structure is considered to already have been 55cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor /// "resolved", meaning that it was loaded from the external source. 56cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor unsigned Resolved : 1; 57cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 5865e02fa80e1c185f18e5f81cefc30d75383a7301Douglas Gregor /// \brief Whether this is a header inside a framework that is currently 5965e02fa80e1c185f18e5f81cefc30d75383a7301Douglas Gregor /// being built. 6065e02fa80e1c185f18e5f81cefc30d75383a7301Douglas Gregor /// 6165e02fa80e1c185f18e5f81cefc30d75383a7301Douglas Gregor /// When a framework is being built, the headers have not yet been placed 6265e02fa80e1c185f18e5f81cefc30d75383a7301Douglas Gregor /// into the appropriate framework subdirectories, and therefore are 6365e02fa80e1c185f18e5f81cefc30d75383a7301Douglas Gregor /// provided via a header map. This bit indicates when this is one of 6465e02fa80e1c185f18e5f81cefc30d75383a7301Douglas Gregor /// those framework headers. 6565e02fa80e1c185f18e5f81cefc30d75383a7301Douglas Gregor unsigned IndexHeaderMapHeader : 1; 6665e02fa80e1c185f18e5f81cefc30d75383a7301Douglas Gregor 67a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett /// \brief The number of times the file has been included already. 6883d63c78810556d26b62ac4cbae2eda6cdd2570cSteve Naroff unsigned short NumIncludes; 691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 70cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor /// \brief The ID number of the controlling macro. 71cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor /// 72cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor /// This ID number will be non-zero when there is a controlling 73cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor /// macro whose IdentifierInfo may not yet have been loaded from 74cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor /// external storage. 75cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor unsigned ControllingMacroID; 76cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 77a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett /// If this file has a \#ifndef XXX (or equivalent) guard that 78a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett /// protects the entire contents of the file, this is the identifier 7983d63c78810556d26b62ac4cbae2eda6cdd2570cSteve Naroff /// for the macro that controls whether or not it has any effect. 808c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor /// 818c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor /// Note: Most clients should use getControllingMacro() to access 828c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor /// the controlling macro of this header, since 838c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor /// getControllingMacro() is able to load a controlling macro from 848c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor /// external storage. 8583d63c78810556d26b62ac4cbae2eda6cdd2570cSteve Naroff const IdentifierInfo *ControllingMacro; 868c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor 8765e02fa80e1c185f18e5f81cefc30d75383a7301Douglas Gregor /// \brief If this header came from a framework include, this is the name 8865e02fa80e1c185f18e5f81cefc30d75383a7301Douglas Gregor /// of the framework. 8965e02fa80e1c185f18e5f81cefc30d75383a7301Douglas Gregor StringRef Framework; 9065e02fa80e1c185f18e5f81cefc30d75383a7301Douglas Gregor 911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump HeaderFileInfo() 92dd3e5549e3c11e217078938aacf72f042eea5343Douglas Gregor : isImport(false), isPragmaOnce(false), DirInfo(SrcMgr::C_User), 9365e02fa80e1c185f18e5f81cefc30d75383a7301Douglas Gregor External(false), Resolved(false), IndexHeaderMapHeader(false), 9465e02fa80e1c185f18e5f81cefc30d75383a7301Douglas Gregor NumIncludes(0), ControllingMacroID(0), ControllingMacro(0) {} 958c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor 968c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor /// \brief Retrieve the controlling macro for this header file, if 978c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor /// any. 988c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor const IdentifierInfo *getControllingMacro(ExternalIdentifierLookup *External); 99cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 100cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor /// \brief Determine whether this is a non-default header file info, e.g., 101cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor /// it corresponds to an actual header we've included or tried to include. 102cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor bool isNonDefault() const { 103dd3e5549e3c11e217078938aacf72f042eea5343Douglas Gregor return isImport || isPragmaOnce || NumIncludes || ControllingMacro || 104dd3e5549e3c11e217078938aacf72f042eea5343Douglas Gregor ControllingMacroID; 105cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor } 10683d63c78810556d26b62ac4cbae2eda6cdd2570cSteve Naroff}; 10783d63c78810556d26b62ac4cbae2eda6cdd2570cSteve Naroff 108cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor/// \brief An external source of header file information, which may supply 109cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor/// information about header files already included. 110cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregorclass ExternalHeaderFileInfoSource { 111cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregorpublic: 112cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor virtual ~ExternalHeaderFileInfoSource(); 113cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 114cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor /// \brief Retrieve the header file information for the given file entry. 115cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor /// 116cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor /// \returns Header file information for the given file entry, with the 117cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor /// \c External bit set. If the file entry is not known, return a 118cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor /// default-constructed \c HeaderFileInfo. 119cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor virtual HeaderFileInfo GetHeaderFileInfo(const FileEntry *FE) = 0; 120cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor}; 121cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 122a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett/// \brief Encapsulates the information needed to find the file referenced 123a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett/// by a \#include or \#include_next, (sub-)framework lookup, etc. 1245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass HeaderSearch { 1259ee35f9f35452dec05c81fd1bbdd2f700872ea7fDaniel Dunbar /// This structure is used to record entries in our framework cache. 1269ee35f9f35452dec05c81fd1bbdd2f700872ea7fDaniel Dunbar struct FrameworkCacheEntry { 1279ee35f9f35452dec05c81fd1bbdd2f700872ea7fDaniel Dunbar /// The directory entry which should be used for the cached framework. 1289ee35f9f35452dec05c81fd1bbdd2f700872ea7fDaniel Dunbar const DirectoryEntry *Directory; 12985ff9693b178658f9d8af7be30a086fb1ab81fddDaniel Dunbar 13085ff9693b178658f9d8af7be30a086fb1ab81fddDaniel Dunbar /// Whether this framework has been "user-specified" to be treated as if it 13185ff9693b178658f9d8af7be30a086fb1ab81fddDaniel Dunbar /// were a system framework (even if it was found outside a system framework 13285ff9693b178658f9d8af7be30a086fb1ab81fddDaniel Dunbar /// directory). 13385ff9693b178658f9d8af7be30a086fb1ab81fddDaniel Dunbar bool IsUserSpecifiedSystemFramework; 1349ee35f9f35452dec05c81fd1bbdd2f700872ea7fDaniel Dunbar }; 1359ee35f9f35452dec05c81fd1bbdd2f700872ea7fDaniel Dunbar 136c042edd54face617a3b9d0b4b9d5a3ff229d0f48Douglas Gregor /// \brief Header-search options used to initialize this header search. 137c042edd54face617a3b9d0b4b9d5a3ff229d0f48Douglas Gregor llvm::IntrusiveRefCntPtr<HeaderSearchOptions> HSOpts; 138c042edd54face617a3b9d0b4b9d5a3ff229d0f48Douglas Gregor 1395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer FileManager &FileMgr; 140a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett /// \#include search path information. Requests for \#include "x" search the 141a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett /// directory of the \#including file first, then each directory in SearchDirs 14274a5fd8bcc68b540b58f6fcd2d80e6e926966e71Nico Weber /// consecutively. Requests for <x> search the current dir first, then each 14374a5fd8bcc68b540b58f6fcd2d80e6e926966e71Nico Weber /// directory in SearchDirs, starting at AngledDirIdx, consecutively. If 1445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// NoCurDirSearch is true, then the check for the file in the current 145fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner /// directory is suppressed. 1465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer std::vector<DirectoryLookup> SearchDirs; 14774a5fd8bcc68b540b58f6fcd2d80e6e926966e71Nico Weber unsigned AngledDirIdx; 1485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned SystemDirIdx; 1495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool NoCurDirSearch; 1501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 151a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett /// \brief \#include prefixes for which the 'system header' property is 152a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett /// overridden. 153a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett /// 154a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett /// For a \#include "x" or \#include \<x> directive, the last string in this 155f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith /// list which is a prefix of 'x' determines whether the file is treated as 156f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith /// a system header. 157f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith std::vector<std::pair<std::string, bool> > SystemHeaderPrefixes; 158f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith 1599a6da6930644b4f2dbe4885b0eb4fc1274ff56a4Douglas Gregor /// \brief The path to the module cache. 1609a6da6930644b4f2dbe4885b0eb4fc1274ff56a4Douglas Gregor std::string ModuleCachePath; 1619a6da6930644b4f2dbe4885b0eb4fc1274ff56a4Douglas Gregor 162a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett /// \brief All of the preprocessor-specific data about files that are 163a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett /// included, indexed by the FileEntry's UID. 16483d63c78810556d26b62ac4cbae2eda6cdd2570cSteve Naroff std::vector<HeaderFileInfo> FileInfo; 1655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 166a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett /// \brief Keeps track of each lookup performed by LookupFile. 167a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett /// 168a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett /// The first part of the value is the starting index in SearchDirs 169a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett /// that the cached search was performed from. If there is a hit and 170a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett /// this value doesn't match the current query, the cache has to be 171a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett /// ignored. The second value is the entry in SearchDirs that satisfied 172a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett /// the query. 173d1194fbbf65374bfa3578eb40a547e4f97b497d1Ted Kremenek llvm::StringMap<std::pair<unsigned, unsigned>, llvm::BumpPtrAllocator> 174d1194fbbf65374bfa3578eb40a547e4f97b497d1Ted Kremenek LookupFileCache; 1751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 176a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett /// \brief Collection mapping a framework or subframework 1775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// name like "Carbon" to the Carbon.framework directory. 1789ee35f9f35452dec05c81fd1bbdd2f700872ea7fDaniel Dunbar llvm::StringMap<FrameworkCacheEntry, llvm::BumpPtrAllocator> FrameworkMap; 1795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1804c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman /// IncludeAliases - maps include file names (including the quotes or 1814c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman /// angle brackets) to other include file names. This is used to support the 1824c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman /// include_alias pragma for Microsoft compatibility. 1834c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman typedef llvm::StringMap<std::string, llvm::BumpPtrAllocator> 1844c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman IncludeAliasMap; 1854c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman OwningPtr<IncludeAliasMap> IncludeAliases; 1864c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman 1871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// HeaderMaps - This is a mapping from FileEntry -> HeaderMap, uniquing 188822da61b74ce14e89b3fa8774db18c833aa5748bChris Lattner /// headermaps. This vector owns the headermap. 189822da61b74ce14e89b3fa8774db18c833aa5748bChris Lattner std::vector<std::pair<const FileEntry*, const HeaderMap*> > HeaderMaps; 1908c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor 191a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor /// \brief The mapping between modules and headers. 192a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor ModuleMap ModMap; 193a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor 194a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor /// \brief Describes whether a given directory has a module map in it. 195a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor llvm::DenseMap<const DirectoryEntry *, bool> DirectoryHasModuleMap; 196a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor 19765e02fa80e1c185f18e5f81cefc30d75383a7301Douglas Gregor /// \brief Uniqued set of framework names, which is used to track which 19865e02fa80e1c185f18e5f81cefc30d75383a7301Douglas Gregor /// headers were included as framework headers. 19965e02fa80e1c185f18e5f81cefc30d75383a7301Douglas Gregor llvm::StringSet<llvm::BumpPtrAllocator> FrameworkNames; 20065e02fa80e1c185f18e5f81cefc30d75383a7301Douglas Gregor 2018c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor /// \brief Entity used to resolve the identifier IDs of controlling 2028c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor /// macros into IdentifierInfo pointers, as needed. 2038c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor ExternalIdentifierLookup *ExternalLookup; 2048c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor 205cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor /// \brief Entity used to look up stored header file information. 206cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor ExternalHeaderFileInfoSource *ExternalSource; 207cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 2085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Various statistics we track for performance analysis. 2095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned NumIncluded; 2105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned NumMultiIncludeFileOptzn; 2115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned NumFrameworkLookups, NumSubFrameworkLookups; 21249c1f4aa2a6c360d25d605004ec3c4affd62db77Steve Naroff 21349c1f4aa2a6c360d25d605004ec3c4affd62db77Steve Naroff // HeaderSearch doesn't support default or copy construction. 214be2fa7ebf01259b63dc52fe46c8d101c18e72269Craig Topper HeaderSearch(const HeaderSearch&) LLVM_DELETED_FUNCTION; 215be2fa7ebf01259b63dc52fe46c8d101c18e72269Craig Topper void operator=(const HeaderSearch&) LLVM_DELETED_FUNCTION; 216be2fa7ebf01259b63dc52fe46c8d101c18e72269Craig Topper 217e434ec71fccfe078906403affd641f709702d598Douglas Gregor friend class DirectoryLookup; 218e434ec71fccfe078906403affd641f709702d598Douglas Gregor 2195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 220c042edd54face617a3b9d0b4b9d5a3ff229d0f48Douglas Gregor HeaderSearch(llvm::IntrusiveRefCntPtr<HeaderSearchOptions> HSOpts, 221c042edd54face617a3b9d0b4b9d5a3ff229d0f48Douglas Gregor FileManager &FM, DiagnosticsEngine &Diags, 222dc58aa71026cce539ca9b5c2c52cc4efc7bd77feDouglas Gregor const LangOptions &LangOpts, const TargetInfo *Target); 223822da61b74ce14e89b3fa8774db18c833aa5748bChris Lattner ~HeaderSearch(); 2245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 225c042edd54face617a3b9d0b4b9d5a3ff229d0f48Douglas Gregor /// \brief Retrieve the header-search options with which this header search 226c042edd54face617a3b9d0b4b9d5a3ff229d0f48Douglas Gregor /// was initialized. 227c042edd54face617a3b9d0b4b9d5a3ff229d0f48Douglas Gregor HeaderSearchOptions &getHeaderSearchOpts() const { return *HSOpts; } 228c042edd54face617a3b9d0b4b9d5a3ff229d0f48Douglas Gregor 2295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer FileManager &getFileMgr() const { return FileMgr; } 2305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 231a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett /// \brief Interface for setting the file search paths. 2325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void SetSearchPaths(const std::vector<DirectoryLookup> &dirs, 23374a5fd8bcc68b540b58f6fcd2d80e6e926966e71Nico Weber unsigned angledDirIdx, unsigned systemDirIdx, 23474a5fd8bcc68b540b58f6fcd2d80e6e926966e71Nico Weber bool noCurDirSearch) { 23574a5fd8bcc68b540b58f6fcd2d80e6e926966e71Nico Weber assert(angledDirIdx <= systemDirIdx && systemDirIdx <= dirs.size() && 23674a5fd8bcc68b540b58f6fcd2d80e6e926966e71Nico Weber "Directory indicies are unordered"); 2375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SearchDirs = dirs; 23874a5fd8bcc68b540b58f6fcd2d80e6e926966e71Nico Weber AngledDirIdx = angledDirIdx; 2395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SystemDirIdx = systemDirIdx; 2405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer NoCurDirSearch = noCurDirSearch; 2419960ae8ecfa2c4278dac708a02e463f83fdf17e8Chris Lattner //LookupFileCache.clear(); 2425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 244a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett /// \brief Add an additional search path. 2451c2e9332fa69727425a3a2b912e36e2ab62083f8Douglas Gregor void AddSearchPath(const DirectoryLookup &dir, bool isAngled) { 2461c2e9332fa69727425a3a2b912e36e2ab62083f8Douglas Gregor unsigned idx = isAngled ? SystemDirIdx : AngledDirIdx; 2471c2e9332fa69727425a3a2b912e36e2ab62083f8Douglas Gregor SearchDirs.insert(SearchDirs.begin() + idx, dir); 2481c2e9332fa69727425a3a2b912e36e2ab62083f8Douglas Gregor if (!isAngled) 2491c2e9332fa69727425a3a2b912e36e2ab62083f8Douglas Gregor AngledDirIdx++; 2501c2e9332fa69727425a3a2b912e36e2ab62083f8Douglas Gregor SystemDirIdx++; 2511c2e9332fa69727425a3a2b912e36e2ab62083f8Douglas Gregor } 2521c2e9332fa69727425a3a2b912e36e2ab62083f8Douglas Gregor 253a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett /// \brief Set the list of system header prefixes. 254f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith void SetSystemHeaderPrefixes(ArrayRef<std::pair<std::string, bool> > P) { 255f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith SystemHeaderPrefixes.assign(P.begin(), P.end()); 256f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith } 257f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith 258a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett /// \brief Checks whether the map exists or not. 2594c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman bool HasIncludeAliasMap() const { 2604c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman return IncludeAliases; 2614c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman } 2624c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman 263a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett /// \brief Map the source include name to the dest include name. 264a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett /// 2654c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman /// The Source should include the angle brackets or quotes, the dest 2664c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman /// should not. This allows for distinction between <> and "" headers. 2674c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman void AddIncludeAlias(StringRef Source, StringRef Dest) { 2684c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman if (!IncludeAliases) 2694c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman IncludeAliases.reset(new IncludeAliasMap); 2704c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman (*IncludeAliases)[Source] = Dest; 2714c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman } 2724c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman 2734c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman /// MapHeaderToIncludeAlias - Maps one header file name to a different header 2744c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman /// file name, for use with the include_alias pragma. Note that the source 2754c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman /// file name should include the angle brackets or quotes. Returns StringRef 2764c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman /// as null if the header cannot be mapped. 2774c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman StringRef MapHeaderToIncludeAlias(StringRef Source) { 2784c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman assert(IncludeAliases && "Trying to map headers when there's no map"); 2794c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman 2804c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman // Do any filename replacements before anything else 2814c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman IncludeAliasMap::const_iterator Iter = IncludeAliases->find(Source); 2824c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman if (Iter != IncludeAliases->end()) 2834c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman return Iter->second; 2844c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman return StringRef(); 2854c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman } 2864c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman 2875e3f9223db88227d6d21679c613b139d8160186dDouglas Gregor /// \brief Set the path to the module cache. 2885e3f9223db88227d6d21679c613b139d8160186dDouglas Gregor void setModuleCachePath(StringRef CachePath) { 289fba18aa8f2cd1994dc65e8cb9f4be201c560dc0bDouglas Gregor ModuleCachePath = CachePath; 2909a6da6930644b4f2dbe4885b0eb4fc1274ff56a4Douglas Gregor } 2919a6da6930644b4f2dbe4885b0eb4fc1274ff56a4Douglas Gregor 292db1cde7dc7bb3aaf48118bd9605192ab94a93635Douglas Gregor /// \brief Retrieve the path to the module cache. 293db1cde7dc7bb3aaf48118bd9605192ab94a93635Douglas Gregor StringRef getModuleCachePath() const { return ModuleCachePath; } 2941ecf0e6e271f3046bc53264318c47eae0fb80afdAxel Naumann 2951ecf0e6e271f3046bc53264318c47eae0fb80afdAxel Naumann /// \brief Consider modules when including files from this directory. 2961ecf0e6e271f3046bc53264318c47eae0fb80afdAxel Naumann void setDirectoryHasModuleMap(const DirectoryEntry* Dir) { 2971ecf0e6e271f3046bc53264318c47eae0fb80afdAxel Naumann DirectoryHasModuleMap[Dir] = true; 2981ecf0e6e271f3046bc53264318c47eae0fb80afdAxel Naumann } 299db1cde7dc7bb3aaf48118bd9605192ab94a93635Douglas Gregor 300a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett /// \brief Forget everything we know about headers so far. 3015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ClearFileInfo() { 3025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer FileInfo.clear(); 3035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3058c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor void SetExternalLookup(ExternalIdentifierLookup *EIL) { 3068c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor ExternalLookup = EIL; 3078c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor } 3088c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor 309cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor ExternalIdentifierLookup *getExternalLookup() const { 310cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor return ExternalLookup; 311cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor } 312cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 313cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor /// \brief Set the external source of header information. 314cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor void SetExternalSource(ExternalHeaderFileInfoSource *ES) { 315cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor ExternalSource = ES; 316cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor } 317cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 318dc58aa71026cce539ca9b5c2c52cc4efc7bd77feDouglas Gregor /// \brief Set the target information for the header search, if not 319dc58aa71026cce539ca9b5c2c52cc4efc7bd77feDouglas Gregor /// already known. 320dc58aa71026cce539ca9b5c2c52cc4efc7bd77feDouglas Gregor void setTarget(const TargetInfo &Target); 321dc58aa71026cce539ca9b5c2c52cc4efc7bd77feDouglas Gregor 322198129e24b56ffcc85f66e798d52a8614e3a07a4James Dennett /// \brief Given a "foo" or \<foo> reference, look up the indicated file, 3237412494982c8b50c90961302c3a718633b2c3ab7Manuel Klimek /// return null on failure. 3247412494982c8b50c90961302c3a718633b2c3ab7Manuel Klimek /// 3257412494982c8b50c90961302c3a718633b2c3ab7Manuel Klimek /// \returns If successful, this returns 'UsedDir', the DirectoryLookup member 3267412494982c8b50c90961302c3a718633b2c3ab7Manuel Klimek /// the file was found in, or null if not applicable. 3277412494982c8b50c90961302c3a718633b2c3ab7Manuel Klimek /// 3287412494982c8b50c90961302c3a718633b2c3ab7Manuel Klimek /// \param isAngled indicates whether the file reference is a <> reference. 3297412494982c8b50c90961302c3a718633b2c3ab7Manuel Klimek /// 3307412494982c8b50c90961302c3a718633b2c3ab7Manuel Klimek /// \param CurDir If non-null, the file was found in the specified directory 331a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett /// search location. This is used to implement \#include_next. 3327412494982c8b50c90961302c3a718633b2c3ab7Manuel Klimek /// 333a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett /// \param CurFileEnt If non-null, indicates where the \#including file is, in 3347412494982c8b50c90961302c3a718633b2c3ab7Manuel Klimek /// case a relative search is needed. 3357412494982c8b50c90961302c3a718633b2c3ab7Manuel Klimek /// 3367412494982c8b50c90961302c3a718633b2c3ab7Manuel Klimek /// \param SearchPath If non-null, will be set to the search path relative 3377412494982c8b50c90961302c3a718633b2c3ab7Manuel Klimek /// to which the file was found. If the include path is absolute, SearchPath 3387412494982c8b50c90961302c3a718633b2c3ab7Manuel Klimek /// will be set to an empty string. 3397412494982c8b50c90961302c3a718633b2c3ab7Manuel Klimek /// 3407412494982c8b50c90961302c3a718633b2c3ab7Manuel Klimek /// \param RelativePath If non-null, will be set to the path relative to 3417412494982c8b50c90961302c3a718633b2c3ab7Manuel Klimek /// SearchPath at which the file was found. This only differs from the 3427412494982c8b50c90961302c3a718633b2c3ab7Manuel Klimek /// Filename for framework includes. 343fba18aa8f2cd1994dc65e8cb9f4be201c560dc0bDouglas Gregor /// 344fba18aa8f2cd1994dc65e8cb9f4be201c560dc0bDouglas Gregor /// \param SuggestedModule If non-null, and the file found is semantically 345c69c42e939e6bdaa56d162cc36da4f6b6c53e8dbDouglas Gregor /// part of a known module, this will be set to the module that should 346c69c42e939e6bdaa56d162cc36da4f6b6c53e8dbDouglas Gregor /// be imported instead of preprocessing/parsing the file found. 347686775deca8b8685eb90801495880e3abdd844c2Chris Lattner const FileEntry *LookupFile(StringRef Filename, bool isAngled, 3485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const DirectoryLookup *FromDir, 3495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const DirectoryLookup *&CurDir, 350b5142bb7af5c70fffd09f05172a1379a35a9c29aChandler Carruth const FileEntry *CurFileEnt, 351686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<char> *SearchPath, 352fba18aa8f2cd1994dc65e8cb9f4be201c560dc0bDouglas Gregor SmallVectorImpl<char> *RelativePath, 3531a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor Module **SuggestedModule, 3541c2e9332fa69727425a3a2b912e36e2ab62083f8Douglas Gregor bool SkipCache = false); 3551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 356a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett /// \brief Look up a subframework for the specified \#include file. 357a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett /// 358a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett /// For example, if \#include'ing <HIToolbox/HIToolbox.h> from 359a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett /// within ".../Carbon.framework/Headers/Carbon.h", check to see if 360a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett /// HIToolbox is a subframework within Carbon.framework. If so, return 361a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett /// the FileEntry for the designated file, otherwise return null. 362b5142bb7af5c70fffd09f05172a1379a35a9c29aChandler Carruth const FileEntry *LookupSubframeworkHeader( 363686775deca8b8685eb90801495880e3abdd844c2Chris Lattner StringRef Filename, 364b5142bb7af5c70fffd09f05172a1379a35a9c29aChandler Carruth const FileEntry *RelativeFileEnt, 365686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<char> *SearchPath, 366686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<char> *RelativePath); 3671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 368a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett /// \brief Look up the specified framework name in our framework cache. 369a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett /// \returns The DirectoryEntry it is in if we know, null otherwise. 3709ee35f9f35452dec05c81fd1bbdd2f700872ea7fDaniel Dunbar FrameworkCacheEntry &LookupFrameworkCache(StringRef FWName) { 371a139481e62fdb209d9d87a54a5733f989d2e8d51Chris Lattner return FrameworkMap.GetOrCreateValue(FWName).getValue(); 372afded5bbb85607023c710c3d6a96c372feb84d7fChris Lattner } 3731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 374a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett /// \brief Mark the specified file as a target of of a \#include, 375a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett /// \#include_next, or \#import directive. 376a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett /// 377a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett /// \return false if \#including the file will have no effect or true 378a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett /// if we should include it. 3795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool ShouldEnterIncludeFile(const FileEntry *File, bool isImport); 3801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 382a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett /// \brief Return whether the specified file is a normal header, 3835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// a system header, or a C++ friendly system header. 3849d72851fec9e9c62570a027d42701562bbf29751Chris Lattner SrcMgr::CharacteristicKind getFileDirFlavor(const FileEntry *File) { 3859d72851fec9e9c62570a027d42701562bbf29751Chris Lattner return (SrcMgr::CharacteristicKind)getFileInfo(File).DirInfo; 3865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 388a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett /// \brief Mark the specified file as a "once only" file, e.g. due to 389a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett /// \#pragma once. 3905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void MarkFileIncludeOnce(const FileEntry *File) { 391dd3e5549e3c11e217078938aacf72f042eea5343Douglas Gregor HeaderFileInfo &FI = getFileInfo(File); 392dd3e5549e3c11e217078938aacf72f042eea5343Douglas Gregor FI.isImport = true; 393dd3e5549e3c11e217078938aacf72f042eea5343Douglas Gregor FI.isPragmaOnce = true; 3945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 396a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett /// \brief Mark the specified file as a system header, e.g. due to 397a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett /// \#pragma GCC system_header. 3985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void MarkFileSystemHeader(const FileEntry *File) { 3990b9e736308af5397f558ffc8e780c438c2fdb563Chris Lattner getFileInfo(File).DirInfo = SrcMgr::C_System; 4005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 402a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett /// \brief Increment the count for the number of times the specified 403a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett /// FileEntry has been entered. 40425bfcb927d9169ea675ce6e98d8992efceeb0e42Chris Lattner void IncrementIncludeCount(const FileEntry *File) { 40525bfcb927d9169ea675ce6e98d8992efceeb0e42Chris Lattner ++getFileInfo(File).NumIncludes; 40625bfcb927d9169ea675ce6e98d8992efceeb0e42Chris Lattner } 4071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 408a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett /// \brief Mark the specified file as having a controlling macro. 409a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett /// 410a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett /// This is used by the multiple-include optimization to eliminate 411809d1be9820039b4cf6efa48246a0d70ffa13394James Dennett /// no-op \#includes. 4125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void SetFileControllingMacro(const FileEntry *File, 4135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const IdentifierInfo *ControllingMacro) { 4145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer getFileInfo(File).ControllingMacro = ControllingMacro; 4155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 417dd3e5549e3c11e217078938aacf72f042eea5343Douglas Gregor /// \brief Determine whether this file is intended to be safe from 418809d1be9820039b4cf6efa48246a0d70ffa13394James Dennett /// multiple inclusions, e.g., it has \#pragma once or a controlling 419dd3e5549e3c11e217078938aacf72f042eea5343Douglas Gregor /// macro. 420dd3e5549e3c11e217078938aacf72f042eea5343Douglas Gregor /// 421809d1be9820039b4cf6efa48246a0d70ffa13394James Dennett /// This routine does not consider the effect of \#import 422dd3e5549e3c11e217078938aacf72f042eea5343Douglas Gregor bool isFileMultipleIncludeGuarded(const FileEntry *File); 423dd3e5549e3c11e217078938aacf72f042eea5343Douglas Gregor 424822da61b74ce14e89b3fa8774db18c833aa5748bChris Lattner /// CreateHeaderMap - This method returns a HeaderMap for the specified 425bed28ac1d1463adca3ecf24fca5c30646fa9dbb2Sylvestre Ledru /// FileEntry, uniquing them through the 'HeaderMaps' datastructure. 4261bfd4a6313ea8ebf710c46c10111732cc65d51f6Chris Lattner const HeaderMap *CreateHeaderMap(const FileEntry *FE); 4271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 428e434ec71fccfe078906403affd641f709702d598Douglas Gregor /// \brief Retrieve the name of the module file that should be used to 429e434ec71fccfe078906403affd641f709702d598Douglas Gregor /// load the given module. 4309a6da6930644b4f2dbe4885b0eb4fc1274ff56a4Douglas Gregor /// 431e434ec71fccfe078906403affd641f709702d598Douglas Gregor /// \param Module The module whose module file name will be returned. 432a4d36a6dd00c1495cfe3b64f949d70ba9f778391Douglas Gregor /// 433e434ec71fccfe078906403affd641f709702d598Douglas Gregor /// \returns The name of the module file that corresponds to this module, 434e434ec71fccfe078906403affd641f709702d598Douglas Gregor /// or an empty string if this module does not correspond to any module file. 435e434ec71fccfe078906403affd641f709702d598Douglas Gregor std::string getModuleFileName(Module *Module); 436e434ec71fccfe078906403affd641f709702d598Douglas Gregor 437e434ec71fccfe078906403affd641f709702d598Douglas Gregor /// \brief Retrieve the name of the module file that should be used to 438e434ec71fccfe078906403affd641f709702d598Douglas Gregor /// load a module with the given name. 4396e975c4517958bcc11c834336d340797356058dbDouglas Gregor /// 440efce31f51d6e7e31e125f96c20f6cdab3ead0a47James Dennett /// \param ModuleName The module whose module file name will be returned. 441e434ec71fccfe078906403affd641f709702d598Douglas Gregor /// 442e434ec71fccfe078906403affd641f709702d598Douglas Gregor /// \returns The name of the module file that corresponds to this module, 443e434ec71fccfe078906403affd641f709702d598Douglas Gregor /// or an empty string if this module does not correspond to any module file. 444e434ec71fccfe078906403affd641f709702d598Douglas Gregor std::string getModuleFileName(StringRef ModuleName); 445e434ec71fccfe078906403affd641f709702d598Douglas Gregor 446e434ec71fccfe078906403affd641f709702d598Douglas Gregor /// \brief Lookup a module Search for a module with the given name. 447e434ec71fccfe078906403affd641f709702d598Douglas Gregor /// 448e434ec71fccfe078906403affd641f709702d598Douglas Gregor /// \param ModuleName The name of the module we're looking for. 449e434ec71fccfe078906403affd641f709702d598Douglas Gregor /// 450e434ec71fccfe078906403affd641f709702d598Douglas Gregor /// \param AllowSearch Whether we are allowed to search in the various 451e434ec71fccfe078906403affd641f709702d598Douglas Gregor /// search directories to produce a module definition. If not, this lookup 452e434ec71fccfe078906403affd641f709702d598Douglas Gregor /// will only return an already-known module. 453e434ec71fccfe078906403affd641f709702d598Douglas Gregor /// 454e434ec71fccfe078906403affd641f709702d598Douglas Gregor /// \returns The module with the given name. 455e434ec71fccfe078906403affd641f709702d598Douglas Gregor Module *lookupModule(StringRef ModuleName, bool AllowSearch = true); 4569a6da6930644b4f2dbe4885b0eb4fc1274ff56a4Douglas Gregor 457afded5bbb85607023c710c3d6a96c372feb84d7fChris Lattner void IncrementFrameworkLookupCount() { ++NumFrameworkLookups; } 45883d63c78810556d26b62ac4cbae2eda6cdd2570cSteve Naroff 459a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor /// \brief Determine whether there is a module map that may map the header 460a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor /// with the given file name to a (sub)module. 461a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor /// 462a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor /// \param Filename The name of the file. 463a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor /// 464a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor /// \param Root The "root" directory, at which we should stop looking for 465a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor /// module maps. 466a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor bool hasModuleMap(StringRef Filename, const DirectoryEntry *Root); 467a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor 468a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor /// \brief Retrieve the module that corresponds to the given file, if any. 46951f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor /// 47051f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor /// \param File The header that we wish to map to a module. 4711a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor Module *findModuleForHeader(const FileEntry *File); 472a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor 473db1cde7dc7bb3aaf48118bd9605192ab94a93635Douglas Gregor /// \brief Read the contents of the given module map file. 474db1cde7dc7bb3aaf48118bd9605192ab94a93635Douglas Gregor /// 475db1cde7dc7bb3aaf48118bd9605192ab94a93635Douglas Gregor /// \param File The module map file. 476db1cde7dc7bb3aaf48118bd9605192ab94a93635Douglas Gregor /// 477db1cde7dc7bb3aaf48118bd9605192ab94a93635Douglas Gregor /// \returns true if an error occurred, false otherwise. 478db1cde7dc7bb3aaf48118bd9605192ab94a93635Douglas Gregor bool loadModuleMapFile(const FileEntry *File); 4792821c7f8870629b56b9c41e1c50c7a091edd544dDouglas Gregor 480c5b2e58840748145d1706c1d1481369d1863fabfDouglas Gregor /// \brief Collect the set of all known, top-level modules. 481c5b2e58840748145d1706c1d1481369d1863fabfDouglas Gregor /// 482c5b2e58840748145d1706c1d1481369d1863fabfDouglas Gregor /// \param Modules Will be filled with the set of known, top-level modules. 483c5b2e58840748145d1706c1d1481369d1863fabfDouglas Gregor void collectAllModules(llvm::SmallVectorImpl<Module *> &Modules); 484c5b2e58840748145d1706c1d1481369d1863fabfDouglas Gregor 485e434ec71fccfe078906403affd641f709702d598Douglas Gregorprivate: 4862821c7f8870629b56b9c41e1c50c7a091edd544dDouglas Gregor /// \brief Retrieve a module with the given name, which may be part of the 4872821c7f8870629b56b9c41e1c50c7a091edd544dDouglas Gregor /// given framework. 4882821c7f8870629b56b9c41e1c50c7a091edd544dDouglas Gregor /// 4892821c7f8870629b56b9c41e1c50c7a091edd544dDouglas Gregor /// \param Name The name of the module to retrieve. 4902821c7f8870629b56b9c41e1c50c7a091edd544dDouglas Gregor /// 4912821c7f8870629b56b9c41e1c50c7a091edd544dDouglas Gregor /// \param Dir The framework directory (e.g., ModuleName.framework). 4922821c7f8870629b56b9c41e1c50c7a091edd544dDouglas Gregor /// 493a1f1fad8b60e1cb9d21a40a37f2e03150bcbeb6fDouglas Gregor /// \param IsSystem Whether the framework directory is part of the system 494a1f1fad8b60e1cb9d21a40a37f2e03150bcbeb6fDouglas Gregor /// frameworks. 495a1f1fad8b60e1cb9d21a40a37f2e03150bcbeb6fDouglas Gregor /// 4962821c7f8870629b56b9c41e1c50c7a091edd544dDouglas Gregor /// \returns The module, if found; otherwise, null. 497e434ec71fccfe078906403affd641f709702d598Douglas Gregor Module *loadFrameworkModule(StringRef Name, 498e434ec71fccfe078906403affd641f709702d598Douglas Gregor const DirectoryEntry *Dir, 499e434ec71fccfe078906403affd641f709702d598Douglas Gregor bool IsSystem); 500e434ec71fccfe078906403affd641f709702d598Douglas Gregor 501e434ec71fccfe078906403affd641f709702d598Douglas Gregorpublic: 5022821c7f8870629b56b9c41e1c50c7a091edd544dDouglas Gregor /// \brief Retrieve the module map. 5032821c7f8870629b56b9c41e1c50c7a091edd544dDouglas Gregor ModuleMap &getModuleMap() { return ModMap; } 504db1cde7dc7bb3aaf48118bd9605192ab94a93635Douglas Gregor 50512fab31aa5868b1a6b52246b5a87daa48a338fe2Douglas Gregor unsigned header_file_size() const { return FileInfo.size(); } 50683d63c78810556d26b62ac4cbae2eda6cdd2570cSteve Naroff 507c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl // Used by ASTReader. 50883d63c78810556d26b62ac4cbae2eda6cdd2570cSteve Naroff void setHeaderFileInfoForUID(HeaderFileInfo HFI, unsigned UID); 5091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 510a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett /// \brief Return the HeaderFileInfo structure for the specified FileEntry. 511590ad93bf59f4e5f6adcba0d78efc3a58cac15ceArgyrios Kyrtzidis const HeaderFileInfo &getFileInfo(const FileEntry *FE) const { 512590ad93bf59f4e5f6adcba0d78efc3a58cac15ceArgyrios Kyrtzidis return const_cast<HeaderSearch*>(this)->getFileInfo(FE); 513590ad93bf59f4e5f6adcba0d78efc3a58cac15ceArgyrios Kyrtzidis } 514590ad93bf59f4e5f6adcba0d78efc3a58cac15ceArgyrios Kyrtzidis 515ec356c320a81062b1843f0dbe7fedf29ed947eceDouglas Gregor // Used by external tools 516ec356c320a81062b1843f0dbe7fedf29ed947eceDouglas Gregor typedef std::vector<DirectoryLookup>::const_iterator search_dir_iterator; 517ec356c320a81062b1843f0dbe7fedf29ed947eceDouglas Gregor search_dir_iterator search_dir_begin() const { return SearchDirs.begin(); } 518ec356c320a81062b1843f0dbe7fedf29ed947eceDouglas Gregor search_dir_iterator search_dir_end() const { return SearchDirs.end(); } 519ec356c320a81062b1843f0dbe7fedf29ed947eceDouglas Gregor unsigned search_dir_size() const { return SearchDirs.size(); } 520ec356c320a81062b1843f0dbe7fedf29ed947eceDouglas Gregor 52174a5fd8bcc68b540b58f6fcd2d80e6e926966e71Nico Weber search_dir_iterator quoted_dir_begin() const { 52274a5fd8bcc68b540b58f6fcd2d80e6e926966e71Nico Weber return SearchDirs.begin(); 52374a5fd8bcc68b540b58f6fcd2d80e6e926966e71Nico Weber } 52474a5fd8bcc68b540b58f6fcd2d80e6e926966e71Nico Weber search_dir_iterator quoted_dir_end() const { 52574a5fd8bcc68b540b58f6fcd2d80e6e926966e71Nico Weber return SearchDirs.begin() + AngledDirIdx; 52674a5fd8bcc68b540b58f6fcd2d80e6e926966e71Nico Weber } 52774a5fd8bcc68b540b58f6fcd2d80e6e926966e71Nico Weber 52874a5fd8bcc68b540b58f6fcd2d80e6e926966e71Nico Weber search_dir_iterator angled_dir_begin() const { 52974a5fd8bcc68b540b58f6fcd2d80e6e926966e71Nico Weber return SearchDirs.begin() + AngledDirIdx; 53074a5fd8bcc68b540b58f6fcd2d80e6e926966e71Nico Weber } 53174a5fd8bcc68b540b58f6fcd2d80e6e926966e71Nico Weber search_dir_iterator angled_dir_end() const { 53274a5fd8bcc68b540b58f6fcd2d80e6e926966e71Nico Weber return SearchDirs.begin() + SystemDirIdx; 53374a5fd8bcc68b540b58f6fcd2d80e6e926966e71Nico Weber } 53474a5fd8bcc68b540b58f6fcd2d80e6e926966e71Nico Weber 535ec356c320a81062b1843f0dbe7fedf29ed947eceDouglas Gregor search_dir_iterator system_dir_begin() const { 536ec356c320a81062b1843f0dbe7fedf29ed947eceDouglas Gregor return SearchDirs.begin() + SystemDirIdx; 537ec356c320a81062b1843f0dbe7fedf29ed947eceDouglas Gregor } 538ec356c320a81062b1843f0dbe7fedf29ed947eceDouglas Gregor search_dir_iterator system_dir_end() const { return SearchDirs.end(); } 539ec356c320a81062b1843f0dbe7fedf29ed947eceDouglas Gregor 54065e02fa80e1c185f18e5f81cefc30d75383a7301Douglas Gregor /// \brief Retrieve a uniqued framework name. 54165e02fa80e1c185f18e5f81cefc30d75383a7301Douglas Gregor StringRef getUniqueFrameworkName(StringRef Framework); 54265e02fa80e1c185f18e5f81cefc30d75383a7301Douglas Gregor 5435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void PrintStats(); 544d1194fbbf65374bfa3578eb40a547e4f97b497d1Ted Kremenek 545d1194fbbf65374bfa3578eb40a547e4f97b497d1Ted Kremenek size_t getTotalMemory() const; 546d1194fbbf65374bfa3578eb40a547e4f97b497d1Ted Kremenek 547cb381eac84e5a14a8c7e7654eadbe1d3d54d795cChandler Carruth static std::string NormalizeDashIncludePath(StringRef File, 548cb381eac84e5a14a8c7e7654eadbe1d3d54d795cChandler Carruth FileManager &FileMgr); 549cb381eac84e5a14a8c7e7654eadbe1d3d54d795cChandler Carruth 5505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 55126697979fb0a4e2b720a0c8d062047edca92bc92Douglas Gregor /// \brief Describes what happened when we tried to load a module map file. 55226697979fb0a4e2b720a0c8d062047edca92bc92Douglas Gregor enum LoadModuleMapResult { 55326697979fb0a4e2b720a0c8d062047edca92bc92Douglas Gregor /// \brief The module map file had already been loaded. 55426697979fb0a4e2b720a0c8d062047edca92bc92Douglas Gregor LMM_AlreadyLoaded, 55526697979fb0a4e2b720a0c8d062047edca92bc92Douglas Gregor /// \brief The module map file was loaded by this invocation. 55626697979fb0a4e2b720a0c8d062047edca92bc92Douglas Gregor LMM_NewlyLoaded, 55726697979fb0a4e2b720a0c8d062047edca92bc92Douglas Gregor /// \brief There is was directory with the given name. 55826697979fb0a4e2b720a0c8d062047edca92bc92Douglas Gregor LMM_NoDirectory, 55926697979fb0a4e2b720a0c8d062047edca92bc92Douglas Gregor /// \brief There was either no module map file or the module map file was 56026697979fb0a4e2b720a0c8d062047edca92bc92Douglas Gregor /// invalid. 56126697979fb0a4e2b720a0c8d062047edca92bc92Douglas Gregor LMM_InvalidModuleMap 56226697979fb0a4e2b720a0c8d062047edca92bc92Douglas Gregor }; 56326697979fb0a4e2b720a0c8d062047edca92bc92Douglas Gregor 564cf70d7873fe3098bdac72e7628f4e832d14d5143Douglas Gregor /// \brief Try to load the module map file in the given directory. 565cf70d7873fe3098bdac72e7628f4e832d14d5143Douglas Gregor /// 56626697979fb0a4e2b720a0c8d062047edca92bc92Douglas Gregor /// \param DirName The name of the directory where we will look for a module 56726697979fb0a4e2b720a0c8d062047edca92bc92Douglas Gregor /// map file. 56826697979fb0a4e2b720a0c8d062047edca92bc92Douglas Gregor /// 56926697979fb0a4e2b720a0c8d062047edca92bc92Douglas Gregor /// \returns The result of attempting to load the module map file from the 57026697979fb0a4e2b720a0c8d062047edca92bc92Douglas Gregor /// named directory. 57126697979fb0a4e2b720a0c8d062047edca92bc92Douglas Gregor LoadModuleMapResult loadModuleMapFile(StringRef DirName); 572cf70d7873fe3098bdac72e7628f4e832d14d5143Douglas Gregor 573cf70d7873fe3098bdac72e7628f4e832d14d5143Douglas Gregor /// \brief Try to load the module map file in the given directory. 574cf70d7873fe3098bdac72e7628f4e832d14d5143Douglas Gregor /// 57526697979fb0a4e2b720a0c8d062047edca92bc92Douglas Gregor /// \param Dir The directory where we will look for a module map file. 57626697979fb0a4e2b720a0c8d062047edca92bc92Douglas Gregor /// 57726697979fb0a4e2b720a0c8d062047edca92bc92Douglas Gregor /// \returns The result of attempting to load the module map file from the 57826697979fb0a4e2b720a0c8d062047edca92bc92Douglas Gregor /// named directory. 57926697979fb0a4e2b720a0c8d062047edca92bc92Douglas Gregor LoadModuleMapResult loadModuleMapFile(const DirectoryEntry *Dir); 5801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 581a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett /// \brief Return the HeaderFileInfo structure for the specified FileEntry. 58283d63c78810556d26b62ac4cbae2eda6cdd2570cSteve Naroff HeaderFileInfo &getFileInfo(const FileEntry *FE); 5835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 5845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 5865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 588