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;
5355ea75bf61a5d76f6453513d937944ce68181c6aArgyrios Kyrtzidis
5455ea75bf61a5d76f6453513d937944ce68181c6aArgyrios Kyrtzidis  /// \brief Whether this header is part of a module.
5555ea75bf61a5d76f6453513d937944ce68181c6aArgyrios Kyrtzidis  unsigned isModuleHeader : 1;
56d3220dbeeadc4ac54ceecea8cf63f8d8be291d2aArgyrios Kyrtzidis
57d3220dbeeadc4ac54ceecea8cf63f8d8be291d2aArgyrios Kyrtzidis  /// \brief Whether this header is part of the module that we are building.
58d3220dbeeadc4ac54ceecea8cf63f8d8be291d2aArgyrios Kyrtzidis  unsigned isCompilingModuleHeader : 1;
59bc3f628815b3841dc99109e7f67f9afa7793bc94Lawrence Crowl
60bc3f628815b3841dc99109e7f67f9afa7793bc94Lawrence Crowl  /// \brief Whether this header is part of the module that we are building.
61bc3f628815b3841dc99109e7f67f9afa7793bc94Lawrence Crowl  /// This is an instance of ModuleMap::ModuleHeaderRole.
62bc3f628815b3841dc99109e7f67f9afa7793bc94Lawrence Crowl  unsigned HeaderRole : 2;
63cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor
64cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor  /// \brief Whether this structure is considered to already have been
65cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor  /// "resolved", meaning that it was loaded from the external source.
66cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor  unsigned Resolved : 1;
67cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor
6865e02fa80e1c185f18e5f81cefc30d75383a7301Douglas Gregor  /// \brief Whether this is a header inside a framework that is currently
6965e02fa80e1c185f18e5f81cefc30d75383a7301Douglas Gregor  /// being built.
7065e02fa80e1c185f18e5f81cefc30d75383a7301Douglas Gregor  ///
7165e02fa80e1c185f18e5f81cefc30d75383a7301Douglas Gregor  /// When a framework is being built, the headers have not yet been placed
7265e02fa80e1c185f18e5f81cefc30d75383a7301Douglas Gregor  /// into the appropriate framework subdirectories, and therefore are
7365e02fa80e1c185f18e5f81cefc30d75383a7301Douglas Gregor  /// provided via a header map. This bit indicates when this is one of
7465e02fa80e1c185f18e5f81cefc30d75383a7301Douglas Gregor  /// those framework headers.
7565e02fa80e1c185f18e5f81cefc30d75383a7301Douglas Gregor  unsigned IndexHeaderMapHeader : 1;
7665e02fa80e1c185f18e5f81cefc30d75383a7301Douglas Gregor
77a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett  /// \brief The number of times the file has been included already.
7883d63c78810556d26b62ac4cbae2eda6cdd2570cSteve Naroff  unsigned short NumIncludes;
791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
80cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor  /// \brief The ID number of the controlling macro.
81cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor  ///
82cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor  /// This ID number will be non-zero when there is a controlling
83cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor  /// macro whose IdentifierInfo may not yet have been loaded from
84cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor  /// external storage.
85cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor  unsigned ControllingMacroID;
86cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor
87a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett  /// If this file has a \#ifndef XXX (or equivalent) guard that
88a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett  /// protects the entire contents of the file, this is the identifier
8983d63c78810556d26b62ac4cbae2eda6cdd2570cSteve Naroff  /// for the macro that controls whether or not it has any effect.
908c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor  ///
918c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor  /// Note: Most clients should use getControllingMacro() to access
928c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor  /// the controlling macro of this header, since
938c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor  /// getControllingMacro() is able to load a controlling macro from
948c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor  /// external storage.
9583d63c78810556d26b62ac4cbae2eda6cdd2570cSteve Naroff  const IdentifierInfo *ControllingMacro;
968c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor
9765e02fa80e1c185f18e5f81cefc30d75383a7301Douglas Gregor  /// \brief If this header came from a framework include, this is the name
9865e02fa80e1c185f18e5f81cefc30d75383a7301Douglas Gregor  /// of the framework.
9965e02fa80e1c185f18e5f81cefc30d75383a7301Douglas Gregor  StringRef Framework;
10065e02fa80e1c185f18e5f81cefc30d75383a7301Douglas Gregor
1011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  HeaderFileInfo()
102dd3e5549e3c11e217078938aacf72f042eea5343Douglas Gregor    : isImport(false), isPragmaOnce(false), DirInfo(SrcMgr::C_User),
103d3220dbeeadc4ac54ceecea8cf63f8d8be291d2aArgyrios Kyrtzidis      External(false), isModuleHeader(false), isCompilingModuleHeader(false),
104bc3f628815b3841dc99109e7f67f9afa7793bc94Lawrence Crowl      HeaderRole(ModuleMap::NormalHeader),
105d3220dbeeadc4ac54ceecea8cf63f8d8be291d2aArgyrios Kyrtzidis      Resolved(false), IndexHeaderMapHeader(false),
10665e02fa80e1c185f18e5f81cefc30d75383a7301Douglas Gregor      NumIncludes(0), ControllingMacroID(0), ControllingMacro(0)  {}
1078c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor
1088c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor  /// \brief Retrieve the controlling macro for this header file, if
1098c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor  /// any.
1108c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor  const IdentifierInfo *getControllingMacro(ExternalIdentifierLookup *External);
111cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor
112cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor  /// \brief Determine whether this is a non-default header file info, e.g.,
113cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor  /// it corresponds to an actual header we've included or tried to include.
114cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor  bool isNonDefault() const {
115dd3e5549e3c11e217078938aacf72f042eea5343Douglas Gregor    return isImport || isPragmaOnce || NumIncludes || ControllingMacro ||
116dd3e5549e3c11e217078938aacf72f042eea5343Douglas Gregor      ControllingMacroID;
117cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor  }
118bc3f628815b3841dc99109e7f67f9afa7793bc94Lawrence Crowl
119bc3f628815b3841dc99109e7f67f9afa7793bc94Lawrence Crowl  /// \brief Get the HeaderRole properly typed.
120bc3f628815b3841dc99109e7f67f9afa7793bc94Lawrence Crowl  ModuleMap::ModuleHeaderRole getHeaderRole() const {
121bc3f628815b3841dc99109e7f67f9afa7793bc94Lawrence Crowl    return static_cast<ModuleMap::ModuleHeaderRole>(HeaderRole);
122bc3f628815b3841dc99109e7f67f9afa7793bc94Lawrence Crowl  }
123bc3f628815b3841dc99109e7f67f9afa7793bc94Lawrence Crowl
124bc3f628815b3841dc99109e7f67f9afa7793bc94Lawrence Crowl  /// \brief Set the HeaderRole properly typed.
125bc3f628815b3841dc99109e7f67f9afa7793bc94Lawrence Crowl  void setHeaderRole(ModuleMap::ModuleHeaderRole Role) {
126bc3f628815b3841dc99109e7f67f9afa7793bc94Lawrence Crowl    HeaderRole = Role;
127bc3f628815b3841dc99109e7f67f9afa7793bc94Lawrence Crowl  }
12883d63c78810556d26b62ac4cbae2eda6cdd2570cSteve Naroff};
12983d63c78810556d26b62ac4cbae2eda6cdd2570cSteve Naroff
130cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor/// \brief An external source of header file information, which may supply
131cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor/// information about header files already included.
132cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregorclass ExternalHeaderFileInfoSource {
133cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregorpublic:
134cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor  virtual ~ExternalHeaderFileInfoSource();
135cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor
136cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor  /// \brief Retrieve the header file information for the given file entry.
137cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor  ///
138cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor  /// \returns Header file information for the given file entry, with the
139cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor  /// \c External bit set. If the file entry is not known, return a
140cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor  /// default-constructed \c HeaderFileInfo.
141cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor  virtual HeaderFileInfo GetHeaderFileInfo(const FileEntry *FE) = 0;
142cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor};
143cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor
144a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett/// \brief Encapsulates the information needed to find the file referenced
145a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett/// by a \#include or \#include_next, (sub-)framework lookup, etc.
1465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass HeaderSearch {
1479ee35f9f35452dec05c81fd1bbdd2f700872ea7fDaniel Dunbar  /// This structure is used to record entries in our framework cache.
1489ee35f9f35452dec05c81fd1bbdd2f700872ea7fDaniel Dunbar  struct FrameworkCacheEntry {
1499ee35f9f35452dec05c81fd1bbdd2f700872ea7fDaniel Dunbar    /// The directory entry which should be used for the cached framework.
1509ee35f9f35452dec05c81fd1bbdd2f700872ea7fDaniel Dunbar    const DirectoryEntry *Directory;
15185ff9693b178658f9d8af7be30a086fb1ab81fddDaniel Dunbar
15285ff9693b178658f9d8af7be30a086fb1ab81fddDaniel Dunbar    /// Whether this framework has been "user-specified" to be treated as if it
15385ff9693b178658f9d8af7be30a086fb1ab81fddDaniel Dunbar    /// were a system framework (even if it was found outside a system framework
15485ff9693b178658f9d8af7be30a086fb1ab81fddDaniel Dunbar    /// directory).
15585ff9693b178658f9d8af7be30a086fb1ab81fddDaniel Dunbar    bool IsUserSpecifiedSystemFramework;
1569ee35f9f35452dec05c81fd1bbdd2f700872ea7fDaniel Dunbar  };
1579ee35f9f35452dec05c81fd1bbdd2f700872ea7fDaniel Dunbar
158c042edd54face617a3b9d0b4b9d5a3ff229d0f48Douglas Gregor  /// \brief Header-search options used to initialize this header search.
159cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko  IntrusiveRefCntPtr<HeaderSearchOptions> HSOpts;
160c042edd54face617a3b9d0b4b9d5a3ff229d0f48Douglas Gregor
1615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  FileManager &FileMgr;
162a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett  /// \#include search path information.  Requests for \#include "x" search the
163a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett  /// directory of the \#including file first, then each directory in SearchDirs
16474a5fd8bcc68b540b58f6fcd2d80e6e926966e71Nico Weber  /// consecutively. Requests for <x> search the current dir first, then each
16574a5fd8bcc68b540b58f6fcd2d80e6e926966e71Nico Weber  /// directory in SearchDirs, starting at AngledDirIdx, consecutively.  If
1665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// NoCurDirSearch is true, then the check for the file in the current
167fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner  /// directory is suppressed.
1685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  std::vector<DirectoryLookup> SearchDirs;
16974a5fd8bcc68b540b58f6fcd2d80e6e926966e71Nico Weber  unsigned AngledDirIdx;
1705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned SystemDirIdx;
1715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool NoCurDirSearch;
1721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
173a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett  /// \brief \#include prefixes for which the 'system header' property is
174a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett  /// overridden.
175a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett  ///
176a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett  /// For a \#include "x" or \#include \<x> directive, the last string in this
177f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith  /// list which is a prefix of 'x' determines whether the file is treated as
178f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith  /// a system header.
179f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith  std::vector<std::pair<std::string, bool> > SystemHeaderPrefixes;
180f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith
1819a6da6930644b4f2dbe4885b0eb4fc1274ff56a4Douglas Gregor  /// \brief The path to the module cache.
1829a6da6930644b4f2dbe4885b0eb4fc1274ff56a4Douglas Gregor  std::string ModuleCachePath;
1839a6da6930644b4f2dbe4885b0eb4fc1274ff56a4Douglas Gregor
184a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett  /// \brief All of the preprocessor-specific data about files that are
185a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett  /// included, indexed by the FileEntry's UID.
18683d63c78810556d26b62ac4cbae2eda6cdd2570cSteve Naroff  std::vector<HeaderFileInfo> FileInfo;
1875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
188a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett  /// \brief Keeps track of each lookup performed by LookupFile.
189a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett  ///
190a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett  /// The first part of the value is the starting index in SearchDirs
191a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett  /// that the cached search was performed from.  If there is a hit and
192a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett  /// this value doesn't match the current query, the cache has to be
193a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett  /// ignored.  The second value is the entry in SearchDirs that satisfied
194a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett  /// the query.
195d1194fbbf65374bfa3578eb40a547e4f97b497d1Ted Kremenek  llvm::StringMap<std::pair<unsigned, unsigned>, llvm::BumpPtrAllocator>
196d1194fbbf65374bfa3578eb40a547e4f97b497d1Ted Kremenek    LookupFileCache;
1971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
198a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett  /// \brief Collection mapping a framework or subframework
1995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// name like "Carbon" to the Carbon.framework directory.
2009ee35f9f35452dec05c81fd1bbdd2f700872ea7fDaniel Dunbar  llvm::StringMap<FrameworkCacheEntry, llvm::BumpPtrAllocator> FrameworkMap;
2015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2024c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman  /// IncludeAliases - maps include file names (including the quotes or
2034c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman  /// angle brackets) to other include file names.  This is used to support the
2044c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman  /// include_alias pragma for Microsoft compatibility.
2054c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman  typedef llvm::StringMap<std::string, llvm::BumpPtrAllocator>
2064c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman    IncludeAliasMap;
2074c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman  OwningPtr<IncludeAliasMap> IncludeAliases;
2084c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman
2091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// HeaderMaps - This is a mapping from FileEntry -> HeaderMap, uniquing
210822da61b74ce14e89b3fa8774db18c833aa5748bChris Lattner  /// headermaps.  This vector owns the headermap.
211822da61b74ce14e89b3fa8774db18c833aa5748bChris Lattner  std::vector<std::pair<const FileEntry*, const HeaderMap*> > HeaderMaps;
2128c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor
213a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor  /// \brief The mapping between modules and headers.
21455ea75bf61a5d76f6453513d937944ce68181c6aArgyrios Kyrtzidis  mutable ModuleMap ModMap;
215a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor
216a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor  /// \brief Describes whether a given directory has a module map in it.
217a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor  llvm::DenseMap<const DirectoryEntry *, bool> DirectoryHasModuleMap;
218a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor
21965e02fa80e1c185f18e5f81cefc30d75383a7301Douglas Gregor  /// \brief Uniqued set of framework names, which is used to track which
22065e02fa80e1c185f18e5f81cefc30d75383a7301Douglas Gregor  /// headers were included as framework headers.
22165e02fa80e1c185f18e5f81cefc30d75383a7301Douglas Gregor  llvm::StringSet<llvm::BumpPtrAllocator> FrameworkNames;
22265e02fa80e1c185f18e5f81cefc30d75383a7301Douglas Gregor
2238c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor  /// \brief Entity used to resolve the identifier IDs of controlling
2248c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor  /// macros into IdentifierInfo pointers, as needed.
2258c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor  ExternalIdentifierLookup *ExternalLookup;
2268c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor
227cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor  /// \brief Entity used to look up stored header file information.
228cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor  ExternalHeaderFileInfoSource *ExternalSource;
229cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor
2305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // Various statistics we track for performance analysis.
2315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned NumIncluded;
2325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned NumMultiIncludeFileOptzn;
2335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned NumFrameworkLookups, NumSubFrameworkLookups;
23449c1f4aa2a6c360d25d605004ec3c4affd62db77Steve Naroff
23549c1f4aa2a6c360d25d605004ec3c4affd62db77Steve Naroff  // HeaderSearch doesn't support default or copy construction.
236be2fa7ebf01259b63dc52fe46c8d101c18e72269Craig Topper  HeaderSearch(const HeaderSearch&) LLVM_DELETED_FUNCTION;
237be2fa7ebf01259b63dc52fe46c8d101c18e72269Craig Topper  void operator=(const HeaderSearch&) LLVM_DELETED_FUNCTION;
238be2fa7ebf01259b63dc52fe46c8d101c18e72269Craig Topper
239e434ec71fccfe078906403affd641f709702d598Douglas Gregor  friend class DirectoryLookup;
240e434ec71fccfe078906403affd641f709702d598Douglas Gregor
2415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
242cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko  HeaderSearch(IntrusiveRefCntPtr<HeaderSearchOptions> HSOpts,
243c042edd54face617a3b9d0b4b9d5a3ff229d0f48Douglas Gregor               FileManager &FM, DiagnosticsEngine &Diags,
244dc58aa71026cce539ca9b5c2c52cc4efc7bd77feDouglas Gregor               const LangOptions &LangOpts, const TargetInfo *Target);
245822da61b74ce14e89b3fa8774db18c833aa5748bChris Lattner  ~HeaderSearch();
2465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
247c042edd54face617a3b9d0b4b9d5a3ff229d0f48Douglas Gregor  /// \brief Retrieve the header-search options with which this header search
248c042edd54face617a3b9d0b4b9d5a3ff229d0f48Douglas Gregor  /// was initialized.
249c042edd54face617a3b9d0b4b9d5a3ff229d0f48Douglas Gregor  HeaderSearchOptions &getHeaderSearchOpts() const { return *HSOpts; }
250c042edd54face617a3b9d0b4b9d5a3ff229d0f48Douglas Gregor
2515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  FileManager &getFileMgr() const { return FileMgr; }
2525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
253a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett  /// \brief Interface for setting the file search paths.
2545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void SetSearchPaths(const std::vector<DirectoryLookup> &dirs,
25574a5fd8bcc68b540b58f6fcd2d80e6e926966e71Nico Weber                      unsigned angledDirIdx, unsigned systemDirIdx,
25674a5fd8bcc68b540b58f6fcd2d80e6e926966e71Nico Weber                      bool noCurDirSearch) {
25774a5fd8bcc68b540b58f6fcd2d80e6e926966e71Nico Weber    assert(angledDirIdx <= systemDirIdx && systemDirIdx <= dirs.size() &&
25874a5fd8bcc68b540b58f6fcd2d80e6e926966e71Nico Weber        "Directory indicies are unordered");
2595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    SearchDirs = dirs;
26074a5fd8bcc68b540b58f6fcd2d80e6e926966e71Nico Weber    AngledDirIdx = angledDirIdx;
2615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    SystemDirIdx = systemDirIdx;
2625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    NoCurDirSearch = noCurDirSearch;
2639960ae8ecfa2c4278dac708a02e463f83fdf17e8Chris Lattner    //LookupFileCache.clear();
2645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
2651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
266a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett  /// \brief Add an additional search path.
2671c2e9332fa69727425a3a2b912e36e2ab62083f8Douglas Gregor  void AddSearchPath(const DirectoryLookup &dir, bool isAngled) {
2681c2e9332fa69727425a3a2b912e36e2ab62083f8Douglas Gregor    unsigned idx = isAngled ? SystemDirIdx : AngledDirIdx;
2691c2e9332fa69727425a3a2b912e36e2ab62083f8Douglas Gregor    SearchDirs.insert(SearchDirs.begin() + idx, dir);
2701c2e9332fa69727425a3a2b912e36e2ab62083f8Douglas Gregor    if (!isAngled)
2711c2e9332fa69727425a3a2b912e36e2ab62083f8Douglas Gregor      AngledDirIdx++;
2721c2e9332fa69727425a3a2b912e36e2ab62083f8Douglas Gregor    SystemDirIdx++;
2731c2e9332fa69727425a3a2b912e36e2ab62083f8Douglas Gregor  }
2741c2e9332fa69727425a3a2b912e36e2ab62083f8Douglas Gregor
275a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett  /// \brief Set the list of system header prefixes.
276f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith  void SetSystemHeaderPrefixes(ArrayRef<std::pair<std::string, bool> > P) {
277f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith    SystemHeaderPrefixes.assign(P.begin(), P.end());
278f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith  }
279f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith
280a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett  /// \brief Checks whether the map exists or not.
2814c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman  bool HasIncludeAliasMap() const {
2827247c88d1e41514a41085f83ebf03dd5220e054aDavid Blaikie    return IncludeAliases.isValid();
2834c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman  }
2844c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman
285a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett  /// \brief Map the source include name to the dest include name.
286a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett  ///
2874c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman  /// The Source should include the angle brackets or quotes, the dest
2884c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman  /// should not.  This allows for distinction between <> and "" headers.
2894c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman  void AddIncludeAlias(StringRef Source, StringRef Dest) {
2904c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman    if (!IncludeAliases)
2914c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman      IncludeAliases.reset(new IncludeAliasMap);
2924c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman    (*IncludeAliases)[Source] = Dest;
2934c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman  }
2944c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman
2954c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman  /// MapHeaderToIncludeAlias - Maps one header file name to a different header
2964c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman  /// file name, for use with the include_alias pragma.  Note that the source
2974c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman  /// file name should include the angle brackets or quotes.  Returns StringRef
2984c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman  /// as null if the header cannot be mapped.
2994c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman  StringRef MapHeaderToIncludeAlias(StringRef Source) {
3004c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman    assert(IncludeAliases && "Trying to map headers when there's no map");
3014c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman
3024c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman    // Do any filename replacements before anything else
3034c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman    IncludeAliasMap::const_iterator Iter = IncludeAliases->find(Source);
3044c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman    if (Iter != IncludeAliases->end())
3054c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman      return Iter->second;
3064c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman    return StringRef();
3074c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman  }
3084c55c54db8e676aa3e042188773d9d82d59fff91Aaron Ballman
3095e3f9223db88227d6d21679c613b139d8160186dDouglas Gregor  /// \brief Set the path to the module cache.
3105e3f9223db88227d6d21679c613b139d8160186dDouglas Gregor  void setModuleCachePath(StringRef CachePath) {
311fba18aa8f2cd1994dc65e8cb9f4be201c560dc0bDouglas Gregor    ModuleCachePath = CachePath;
3129a6da6930644b4f2dbe4885b0eb4fc1274ff56a4Douglas Gregor  }
3139a6da6930644b4f2dbe4885b0eb4fc1274ff56a4Douglas Gregor
314db1cde7dc7bb3aaf48118bd9605192ab94a93635Douglas Gregor  /// \brief Retrieve the path to the module cache.
315db1cde7dc7bb3aaf48118bd9605192ab94a93635Douglas Gregor  StringRef getModuleCachePath() const { return ModuleCachePath; }
3161ecf0e6e271f3046bc53264318c47eae0fb80afdAxel Naumann
3171ecf0e6e271f3046bc53264318c47eae0fb80afdAxel Naumann  /// \brief Consider modules when including files from this directory.
3181ecf0e6e271f3046bc53264318c47eae0fb80afdAxel Naumann  void setDirectoryHasModuleMap(const DirectoryEntry* Dir) {
3191ecf0e6e271f3046bc53264318c47eae0fb80afdAxel Naumann    DirectoryHasModuleMap[Dir] = true;
3201ecf0e6e271f3046bc53264318c47eae0fb80afdAxel Naumann  }
321db1cde7dc7bb3aaf48118bd9605192ab94a93635Douglas Gregor
322a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett  /// \brief Forget everything we know about headers so far.
3235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void ClearFileInfo() {
3245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    FileInfo.clear();
3255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
3261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3278c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor  void SetExternalLookup(ExternalIdentifierLookup *EIL) {
3288c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor    ExternalLookup = EIL;
3298c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor  }
3308c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor
331cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor  ExternalIdentifierLookup *getExternalLookup() const {
332cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor    return ExternalLookup;
333cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor  }
334cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor
335cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor  /// \brief Set the external source of header information.
336cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor  void SetExternalSource(ExternalHeaderFileInfoSource *ES) {
337cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor    ExternalSource = ES;
338cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor  }
339cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor
340dc58aa71026cce539ca9b5c2c52cc4efc7bd77feDouglas Gregor  /// \brief Set the target information for the header search, if not
341dc58aa71026cce539ca9b5c2c52cc4efc7bd77feDouglas Gregor  /// already known.
342dc58aa71026cce539ca9b5c2c52cc4efc7bd77feDouglas Gregor  void setTarget(const TargetInfo &Target);
343dc58aa71026cce539ca9b5c2c52cc4efc7bd77feDouglas Gregor
344198129e24b56ffcc85f66e798d52a8614e3a07a4James Dennett  /// \brief Given a "foo" or \<foo> reference, look up the indicated file,
3457412494982c8b50c90961302c3a718633b2c3ab7Manuel Klimek  /// return null on failure.
3467412494982c8b50c90961302c3a718633b2c3ab7Manuel Klimek  ///
3477412494982c8b50c90961302c3a718633b2c3ab7Manuel Klimek  /// \returns If successful, this returns 'UsedDir', the DirectoryLookup member
3487412494982c8b50c90961302c3a718633b2c3ab7Manuel Klimek  /// the file was found in, or null if not applicable.
3497412494982c8b50c90961302c3a718633b2c3ab7Manuel Klimek  ///
3507412494982c8b50c90961302c3a718633b2c3ab7Manuel Klimek  /// \param isAngled indicates whether the file reference is a <> reference.
3517412494982c8b50c90961302c3a718633b2c3ab7Manuel Klimek  ///
3527412494982c8b50c90961302c3a718633b2c3ab7Manuel Klimek  /// \param CurDir If non-null, the file was found in the specified directory
353a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett  /// search location.  This is used to implement \#include_next.
3547412494982c8b50c90961302c3a718633b2c3ab7Manuel Klimek  ///
355a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett  /// \param CurFileEnt If non-null, indicates where the \#including file is, in
3567412494982c8b50c90961302c3a718633b2c3ab7Manuel Klimek  /// case a relative search is needed.
3577412494982c8b50c90961302c3a718633b2c3ab7Manuel Klimek  ///
3587412494982c8b50c90961302c3a718633b2c3ab7Manuel Klimek  /// \param SearchPath If non-null, will be set to the search path relative
3597412494982c8b50c90961302c3a718633b2c3ab7Manuel Klimek  /// to which the file was found. If the include path is absolute, SearchPath
3607412494982c8b50c90961302c3a718633b2c3ab7Manuel Klimek  /// will be set to an empty string.
3617412494982c8b50c90961302c3a718633b2c3ab7Manuel Klimek  ///
3627412494982c8b50c90961302c3a718633b2c3ab7Manuel Klimek  /// \param RelativePath If non-null, will be set to the path relative to
3637412494982c8b50c90961302c3a718633b2c3ab7Manuel Klimek  /// SearchPath at which the file was found. This only differs from the
3647412494982c8b50c90961302c3a718633b2c3ab7Manuel Klimek  /// Filename for framework includes.
365fba18aa8f2cd1994dc65e8cb9f4be201c560dc0bDouglas Gregor  ///
366fba18aa8f2cd1994dc65e8cb9f4be201c560dc0bDouglas Gregor  /// \param SuggestedModule If non-null, and the file found is semantically
367c69c42e939e6bdaa56d162cc36da4f6b6c53e8dbDouglas Gregor  /// part of a known module, this will be set to the module that should
368c69c42e939e6bdaa56d162cc36da4f6b6c53e8dbDouglas Gregor  /// be imported instead of preprocessing/parsing the file found.
369686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  const FileEntry *LookupFile(StringRef Filename, bool isAngled,
3705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                              const DirectoryLookup *FromDir,
3715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                              const DirectoryLookup *&CurDir,
372b5142bb7af5c70fffd09f05172a1379a35a9c29aChandler Carruth                              const FileEntry *CurFileEnt,
373686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                              SmallVectorImpl<char> *SearchPath,
374fba18aa8f2cd1994dc65e8cb9f4be201c560dc0bDouglas Gregor                              SmallVectorImpl<char> *RelativePath,
375bc3f628815b3841dc99109e7f67f9afa7793bc94Lawrence Crowl                              ModuleMap::KnownHeader *SuggestedModule,
3761c2e9332fa69727425a3a2b912e36e2ab62083f8Douglas Gregor                              bool SkipCache = false);
3771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
378a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett  /// \brief Look up a subframework for the specified \#include file.
379a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett  ///
380a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett  /// For example, if \#include'ing <HIToolbox/HIToolbox.h> from
381a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett  /// within ".../Carbon.framework/Headers/Carbon.h", check to see if
382a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett  /// HIToolbox is a subframework within Carbon.framework.  If so, return
383a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett  /// the FileEntry for the designated file, otherwise return null.
384b5142bb7af5c70fffd09f05172a1379a35a9c29aChandler Carruth  const FileEntry *LookupSubframeworkHeader(
385686775deca8b8685eb90801495880e3abdd844c2Chris Lattner      StringRef Filename,
386b5142bb7af5c70fffd09f05172a1379a35a9c29aChandler Carruth      const FileEntry *RelativeFileEnt,
387686775deca8b8685eb90801495880e3abdd844c2Chris Lattner      SmallVectorImpl<char> *SearchPath,
3881b58c74af272a1d8228b8161c93a8a018456098eDouglas Gregor      SmallVectorImpl<char> *RelativePath,
389bc3f628815b3841dc99109e7f67f9afa7793bc94Lawrence Crowl      ModuleMap::KnownHeader *SuggestedModule);
3901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
391a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett  /// \brief Look up the specified framework name in our framework cache.
392a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett  /// \returns The DirectoryEntry it is in if we know, null otherwise.
3939ee35f9f35452dec05c81fd1bbdd2f700872ea7fDaniel Dunbar  FrameworkCacheEntry &LookupFrameworkCache(StringRef FWName) {
394a139481e62fdb209d9d87a54a5733f989d2e8d51Chris Lattner    return FrameworkMap.GetOrCreateValue(FWName).getValue();
395afded5bbb85607023c710c3d6a96c372feb84d7fChris Lattner  }
3961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
397a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett  /// \brief Mark the specified file as a target of of a \#include,
398a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett  /// \#include_next, or \#import directive.
399a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett  ///
400a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett  /// \return false if \#including the file will have no effect or true
401a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett  /// if we should include it.
4025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool ShouldEnterIncludeFile(const FileEntry *File, bool isImport);
4031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
405a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett  /// \brief Return whether the specified file is a normal header,
4065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// a system header, or a C++ friendly system header.
4079d72851fec9e9c62570a027d42701562bbf29751Chris Lattner  SrcMgr::CharacteristicKind getFileDirFlavor(const FileEntry *File) {
4089d72851fec9e9c62570a027d42701562bbf29751Chris Lattner    return (SrcMgr::CharacteristicKind)getFileInfo(File).DirInfo;
4095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
411a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett  /// \brief Mark the specified file as a "once only" file, e.g. due to
412a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett  /// \#pragma once.
4135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void MarkFileIncludeOnce(const FileEntry *File) {
414dd3e5549e3c11e217078938aacf72f042eea5343Douglas Gregor    HeaderFileInfo &FI = getFileInfo(File);
415dd3e5549e3c11e217078938aacf72f042eea5343Douglas Gregor    FI.isImport = true;
416dd3e5549e3c11e217078938aacf72f042eea5343Douglas Gregor    FI.isPragmaOnce = true;
4175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
419a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett  /// \brief Mark the specified file as a system header, e.g. due to
420a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett  /// \#pragma GCC system_header.
4215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void MarkFileSystemHeader(const FileEntry *File) {
4220b9e736308af5397f558ffc8e780c438c2fdb563Chris Lattner    getFileInfo(File).DirInfo = SrcMgr::C_System;
4235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
42555ea75bf61a5d76f6453513d937944ce68181c6aArgyrios Kyrtzidis  /// \brief Mark the specified file as part of a module.
426bc3f628815b3841dc99109e7f67f9afa7793bc94Lawrence Crowl  void MarkFileModuleHeader(const FileEntry *File,
427bc3f628815b3841dc99109e7f67f9afa7793bc94Lawrence Crowl                            ModuleMap::ModuleHeaderRole Role,
428bc3f628815b3841dc99109e7f67f9afa7793bc94Lawrence Crowl                            bool IsCompiledModuleHeader);
42955ea75bf61a5d76f6453513d937944ce68181c6aArgyrios Kyrtzidis
430a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett  /// \brief Increment the count for the number of times the specified
431a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett  /// FileEntry has been entered.
43225bfcb927d9169ea675ce6e98d8992efceeb0e42Chris Lattner  void IncrementIncludeCount(const FileEntry *File) {
43325bfcb927d9169ea675ce6e98d8992efceeb0e42Chris Lattner    ++getFileInfo(File).NumIncludes;
43425bfcb927d9169ea675ce6e98d8992efceeb0e42Chris Lattner  }
4351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
436a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett  /// \brief Mark the specified file as having a controlling macro.
437a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett  ///
438a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett  /// This is used by the multiple-include optimization to eliminate
439809d1be9820039b4cf6efa48246a0d70ffa13394James Dennett  /// no-op \#includes.
4405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void SetFileControllingMacro(const FileEntry *File,
4415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                               const IdentifierInfo *ControllingMacro) {
4425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    getFileInfo(File).ControllingMacro = ControllingMacro;
4435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
445671538e8a51eab5bd65a1f9f327ba7f44f84e486Richard Trieu  /// \brief Return true if this is the first time encountering this header.
446671538e8a51eab5bd65a1f9f327ba7f44f84e486Richard Trieu  bool FirstTimeLexingFile(const FileEntry *File) {
447671538e8a51eab5bd65a1f9f327ba7f44f84e486Richard Trieu    return getFileInfo(File).NumIncludes == 1;
448671538e8a51eab5bd65a1f9f327ba7f44f84e486Richard Trieu  }
449671538e8a51eab5bd65a1f9f327ba7f44f84e486Richard Trieu
450dd3e5549e3c11e217078938aacf72f042eea5343Douglas Gregor  /// \brief Determine whether this file is intended to be safe from
451809d1be9820039b4cf6efa48246a0d70ffa13394James Dennett  /// multiple inclusions, e.g., it has \#pragma once or a controlling
452dd3e5549e3c11e217078938aacf72f042eea5343Douglas Gregor  /// macro.
453dd3e5549e3c11e217078938aacf72f042eea5343Douglas Gregor  ///
454809d1be9820039b4cf6efa48246a0d70ffa13394James Dennett  /// This routine does not consider the effect of \#import
455dd3e5549e3c11e217078938aacf72f042eea5343Douglas Gregor  bool isFileMultipleIncludeGuarded(const FileEntry *File);
456dd3e5549e3c11e217078938aacf72f042eea5343Douglas Gregor
457822da61b74ce14e89b3fa8774db18c833aa5748bChris Lattner  /// CreateHeaderMap - This method returns a HeaderMap for the specified
458bed28ac1d1463adca3ecf24fca5c30646fa9dbb2Sylvestre Ledru  /// FileEntry, uniquing them through the 'HeaderMaps' datastructure.
4591bfd4a6313ea8ebf710c46c10111732cc65d51f6Chris Lattner  const HeaderMap *CreateHeaderMap(const FileEntry *FE);
4601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
461e434ec71fccfe078906403affd641f709702d598Douglas Gregor  /// \brief Retrieve the name of the module file that should be used to
462e434ec71fccfe078906403affd641f709702d598Douglas Gregor  /// load the given module.
4639a6da6930644b4f2dbe4885b0eb4fc1274ff56a4Douglas Gregor  ///
464e434ec71fccfe078906403affd641f709702d598Douglas Gregor  /// \param Module The module whose module file name will be returned.
465a4d36a6dd00c1495cfe3b64f949d70ba9f778391Douglas Gregor  ///
466e434ec71fccfe078906403affd641f709702d598Douglas Gregor  /// \returns The name of the module file that corresponds to this module,
467e434ec71fccfe078906403affd641f709702d598Douglas Gregor  /// or an empty string if this module does not correspond to any module file.
468e434ec71fccfe078906403affd641f709702d598Douglas Gregor  std::string getModuleFileName(Module *Module);
469e434ec71fccfe078906403affd641f709702d598Douglas Gregor
470e434ec71fccfe078906403affd641f709702d598Douglas Gregor  /// \brief Retrieve the name of the module file that should be used to
471e434ec71fccfe078906403affd641f709702d598Douglas Gregor  /// load a module with the given name.
4726e975c4517958bcc11c834336d340797356058dbDouglas Gregor  ///
473efce31f51d6e7e31e125f96c20f6cdab3ead0a47James Dennett  /// \param ModuleName The module whose module file name will be returned.
474e434ec71fccfe078906403affd641f709702d598Douglas Gregor  ///
475e434ec71fccfe078906403affd641f709702d598Douglas Gregor  /// \returns The name of the module file that corresponds to this module,
476e434ec71fccfe078906403affd641f709702d598Douglas Gregor  /// or an empty string if this module does not correspond to any module file.
477e434ec71fccfe078906403affd641f709702d598Douglas Gregor  std::string getModuleFileName(StringRef ModuleName);
478e434ec71fccfe078906403affd641f709702d598Douglas Gregor
479e434ec71fccfe078906403affd641f709702d598Douglas Gregor  /// \brief Lookup a module Search for a module with the given name.
480e434ec71fccfe078906403affd641f709702d598Douglas Gregor  ///
481e434ec71fccfe078906403affd641f709702d598Douglas Gregor  /// \param ModuleName The name of the module we're looking for.
482e434ec71fccfe078906403affd641f709702d598Douglas Gregor  ///
483e434ec71fccfe078906403affd641f709702d598Douglas Gregor  /// \param AllowSearch Whether we are allowed to search in the various
484e434ec71fccfe078906403affd641f709702d598Douglas Gregor  /// search directories to produce a module definition. If not, this lookup
485e434ec71fccfe078906403affd641f709702d598Douglas Gregor  /// will only return an already-known module.
486e434ec71fccfe078906403affd641f709702d598Douglas Gregor  ///
487e434ec71fccfe078906403affd641f709702d598Douglas Gregor  /// \returns The module with the given name.
488e434ec71fccfe078906403affd641f709702d598Douglas Gregor  Module *lookupModule(StringRef ModuleName, bool AllowSearch = true);
4899a6da6930644b4f2dbe4885b0eb4fc1274ff56a4Douglas Gregor
490afded5bbb85607023c710c3d6a96c372feb84d7fChris Lattner  void IncrementFrameworkLookupCount() { ++NumFrameworkLookups; }
49183d63c78810556d26b62ac4cbae2eda6cdd2570cSteve Naroff
492a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor  /// \brief Determine whether there is a module map that may map the header
493a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor  /// with the given file name to a (sub)module.
494a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor  ///
495a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor  /// \param Filename The name of the file.
496a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor  ///
497a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor  /// \param Root The "root" directory, at which we should stop looking for
498a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor  /// module maps.
4998f5d7d1d1f990f174c7f2682271a83acf64dd93dDouglas Gregor  ///
5008f5d7d1d1f990f174c7f2682271a83acf64dd93dDouglas Gregor  /// \param IsSystem Whether the directories we're looking at are system
5018f5d7d1d1f990f174c7f2682271a83acf64dd93dDouglas Gregor  /// header directories.
5028f5d7d1d1f990f174c7f2682271a83acf64dd93dDouglas Gregor  bool hasModuleMap(StringRef Filename, const DirectoryEntry *Root,
5038f5d7d1d1f990f174c7f2682271a83acf64dd93dDouglas Gregor                    bool IsSystem);
504a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor
505a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor  /// \brief Retrieve the module that corresponds to the given file, if any.
50651f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor  ///
50751f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor  /// \param File The header that we wish to map to a module.
508bc3f628815b3841dc99109e7f67f9afa7793bc94Lawrence Crowl  ModuleMap::KnownHeader findModuleForHeader(const FileEntry *File) const;
509a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor
510db1cde7dc7bb3aaf48118bd9605192ab94a93635Douglas Gregor  /// \brief Read the contents of the given module map file.
511db1cde7dc7bb3aaf48118bd9605192ab94a93635Douglas Gregor  ///
512db1cde7dc7bb3aaf48118bd9605192ab94a93635Douglas Gregor  /// \param File The module map file.
5138f5d7d1d1f990f174c7f2682271a83acf64dd93dDouglas Gregor  /// \param IsSystem Whether this file is in a system header directory.
514db1cde7dc7bb3aaf48118bd9605192ab94a93635Douglas Gregor  ///
515db1cde7dc7bb3aaf48118bd9605192ab94a93635Douglas Gregor  /// \returns true if an error occurred, false otherwise.
5168f5d7d1d1f990f174c7f2682271a83acf64dd93dDouglas Gregor  bool loadModuleMapFile(const FileEntry *File, bool IsSystem);
5172821c7f8870629b56b9c41e1c50c7a091edd544dDouglas Gregor
518c5b2e58840748145d1706c1d1481369d1863fabfDouglas Gregor  /// \brief Collect the set of all known, top-level modules.
519c5b2e58840748145d1706c1d1481369d1863fabfDouglas Gregor  ///
520c5b2e58840748145d1706c1d1481369d1863fabfDouglas Gregor  /// \param Modules Will be filled with the set of known, top-level modules.
521cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko  void collectAllModules(SmallVectorImpl<Module *> &Modules);
52230a16f1383b56cb71be251999a577b2e37db2ce0Douglas Gregor
52330a16f1383b56cb71be251999a577b2e37db2ce0Douglas Gregor  /// \brief Load all known, top-level system modules.
52430a16f1383b56cb71be251999a577b2e37db2ce0Douglas Gregor  void loadTopLevelSystemModules();
52530a16f1383b56cb71be251999a577b2e37db2ce0Douglas Gregor
526e434ec71fccfe078906403affd641f709702d598Douglas Gregorprivate:
5272821c7f8870629b56b9c41e1c50c7a091edd544dDouglas Gregor  /// \brief Retrieve a module with the given name, which may be part of the
5282821c7f8870629b56b9c41e1c50c7a091edd544dDouglas Gregor  /// given framework.
5292821c7f8870629b56b9c41e1c50c7a091edd544dDouglas Gregor  ///
5302821c7f8870629b56b9c41e1c50c7a091edd544dDouglas Gregor  /// \param Name The name of the module to retrieve.
5312821c7f8870629b56b9c41e1c50c7a091edd544dDouglas Gregor  ///
5322821c7f8870629b56b9c41e1c50c7a091edd544dDouglas Gregor  /// \param Dir The framework directory (e.g., ModuleName.framework).
5332821c7f8870629b56b9c41e1c50c7a091edd544dDouglas Gregor  ///
534a1f1fad8b60e1cb9d21a40a37f2e03150bcbeb6fDouglas Gregor  /// \param IsSystem Whether the framework directory is part of the system
535a1f1fad8b60e1cb9d21a40a37f2e03150bcbeb6fDouglas Gregor  /// frameworks.
536a1f1fad8b60e1cb9d21a40a37f2e03150bcbeb6fDouglas Gregor  ///
5372821c7f8870629b56b9c41e1c50c7a091edd544dDouglas Gregor  /// \returns The module, if found; otherwise, null.
538e434ec71fccfe078906403affd641f709702d598Douglas Gregor  Module *loadFrameworkModule(StringRef Name,
539e434ec71fccfe078906403affd641f709702d598Douglas Gregor                              const DirectoryEntry *Dir,
540e434ec71fccfe078906403affd641f709702d598Douglas Gregor                              bool IsSystem);
541cdf2808c4e735a717599751dcd2b434f239e1c68Douglas Gregor
542cdf2808c4e735a717599751dcd2b434f239e1c68Douglas Gregor  /// \brief Load all of the module maps within the immediate subdirectories
543cdf2808c4e735a717599751dcd2b434f239e1c68Douglas Gregor  /// of the given search directory.
544cdf2808c4e735a717599751dcd2b434f239e1c68Douglas Gregor  void loadSubdirectoryModuleMaps(DirectoryLookup &SearchDir);
545cdf2808c4e735a717599751dcd2b434f239e1c68Douglas Gregor
546e434ec71fccfe078906403affd641f709702d598Douglas Gregorpublic:
5472821c7f8870629b56b9c41e1c50c7a091edd544dDouglas Gregor  /// \brief Retrieve the module map.
5482821c7f8870629b56b9c41e1c50c7a091edd544dDouglas Gregor  ModuleMap &getModuleMap() { return ModMap; }
549db1cde7dc7bb3aaf48118bd9605192ab94a93635Douglas Gregor
55012fab31aa5868b1a6b52246b5a87daa48a338fe2Douglas Gregor  unsigned header_file_size() const { return FileInfo.size(); }
55183d63c78810556d26b62ac4cbae2eda6cdd2570cSteve Naroff
552a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett  /// \brief Return the HeaderFileInfo structure for the specified FileEntry.
553590ad93bf59f4e5f6adcba0d78efc3a58cac15ceArgyrios Kyrtzidis  const HeaderFileInfo &getFileInfo(const FileEntry *FE) const {
554590ad93bf59f4e5f6adcba0d78efc3a58cac15ceArgyrios Kyrtzidis    return const_cast<HeaderSearch*>(this)->getFileInfo(FE);
555590ad93bf59f4e5f6adcba0d78efc3a58cac15ceArgyrios Kyrtzidis  }
556590ad93bf59f4e5f6adcba0d78efc3a58cac15ceArgyrios Kyrtzidis
557ec356c320a81062b1843f0dbe7fedf29ed947eceDouglas Gregor  // Used by external tools
558ec356c320a81062b1843f0dbe7fedf29ed947eceDouglas Gregor  typedef std::vector<DirectoryLookup>::const_iterator search_dir_iterator;
559ec356c320a81062b1843f0dbe7fedf29ed947eceDouglas Gregor  search_dir_iterator search_dir_begin() const { return SearchDirs.begin(); }
560ec356c320a81062b1843f0dbe7fedf29ed947eceDouglas Gregor  search_dir_iterator search_dir_end() const { return SearchDirs.end(); }
561ec356c320a81062b1843f0dbe7fedf29ed947eceDouglas Gregor  unsigned search_dir_size() const { return SearchDirs.size(); }
562ec356c320a81062b1843f0dbe7fedf29ed947eceDouglas Gregor
56374a5fd8bcc68b540b58f6fcd2d80e6e926966e71Nico Weber  search_dir_iterator quoted_dir_begin() const {
56474a5fd8bcc68b540b58f6fcd2d80e6e926966e71Nico Weber    return SearchDirs.begin();
56574a5fd8bcc68b540b58f6fcd2d80e6e926966e71Nico Weber  }
56674a5fd8bcc68b540b58f6fcd2d80e6e926966e71Nico Weber  search_dir_iterator quoted_dir_end() const {
56774a5fd8bcc68b540b58f6fcd2d80e6e926966e71Nico Weber    return SearchDirs.begin() + AngledDirIdx;
56874a5fd8bcc68b540b58f6fcd2d80e6e926966e71Nico Weber  }
56974a5fd8bcc68b540b58f6fcd2d80e6e926966e71Nico Weber
57074a5fd8bcc68b540b58f6fcd2d80e6e926966e71Nico Weber  search_dir_iterator angled_dir_begin() const {
57174a5fd8bcc68b540b58f6fcd2d80e6e926966e71Nico Weber    return SearchDirs.begin() + AngledDirIdx;
57274a5fd8bcc68b540b58f6fcd2d80e6e926966e71Nico Weber  }
57374a5fd8bcc68b540b58f6fcd2d80e6e926966e71Nico Weber  search_dir_iterator angled_dir_end() const {
57474a5fd8bcc68b540b58f6fcd2d80e6e926966e71Nico Weber    return SearchDirs.begin() + SystemDirIdx;
57574a5fd8bcc68b540b58f6fcd2d80e6e926966e71Nico Weber  }
57674a5fd8bcc68b540b58f6fcd2d80e6e926966e71Nico Weber
577ec356c320a81062b1843f0dbe7fedf29ed947eceDouglas Gregor  search_dir_iterator system_dir_begin() const {
578ec356c320a81062b1843f0dbe7fedf29ed947eceDouglas Gregor    return SearchDirs.begin() + SystemDirIdx;
579ec356c320a81062b1843f0dbe7fedf29ed947eceDouglas Gregor  }
580ec356c320a81062b1843f0dbe7fedf29ed947eceDouglas Gregor  search_dir_iterator system_dir_end() const { return SearchDirs.end(); }
581ec356c320a81062b1843f0dbe7fedf29ed947eceDouglas Gregor
58265e02fa80e1c185f18e5f81cefc30d75383a7301Douglas Gregor  /// \brief Retrieve a uniqued framework name.
58365e02fa80e1c185f18e5f81cefc30d75383a7301Douglas Gregor  StringRef getUniqueFrameworkName(StringRef Framework);
58465e02fa80e1c185f18e5f81cefc30d75383a7301Douglas Gregor
5855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void PrintStats();
586d1194fbbf65374bfa3578eb40a547e4f97b497d1Ted Kremenek
587d1194fbbf65374bfa3578eb40a547e4f97b497d1Ted Kremenek  size_t getTotalMemory() const;
588d1194fbbf65374bfa3578eb40a547e4f97b497d1Ted Kremenek
589cb381eac84e5a14a8c7e7654eadbe1d3d54d795cChandler Carruth  static std::string NormalizeDashIncludePath(StringRef File,
590cb381eac84e5a14a8c7e7654eadbe1d3d54d795cChandler Carruth                                              FileManager &FileMgr);
591cb381eac84e5a14a8c7e7654eadbe1d3d54d795cChandler Carruth
5925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate:
59326697979fb0a4e2b720a0c8d062047edca92bc92Douglas Gregor  /// \brief Describes what happened when we tried to load a module map file.
59426697979fb0a4e2b720a0c8d062047edca92bc92Douglas Gregor  enum LoadModuleMapResult {
59526697979fb0a4e2b720a0c8d062047edca92bc92Douglas Gregor    /// \brief The module map file had already been loaded.
59626697979fb0a4e2b720a0c8d062047edca92bc92Douglas Gregor    LMM_AlreadyLoaded,
59726697979fb0a4e2b720a0c8d062047edca92bc92Douglas Gregor    /// \brief The module map file was loaded by this invocation.
59826697979fb0a4e2b720a0c8d062047edca92bc92Douglas Gregor    LMM_NewlyLoaded,
59926697979fb0a4e2b720a0c8d062047edca92bc92Douglas Gregor    /// \brief There is was directory with the given name.
60026697979fb0a4e2b720a0c8d062047edca92bc92Douglas Gregor    LMM_NoDirectory,
60126697979fb0a4e2b720a0c8d062047edca92bc92Douglas Gregor    /// \brief There was either no module map file or the module map file was
60226697979fb0a4e2b720a0c8d062047edca92bc92Douglas Gregor    /// invalid.
60326697979fb0a4e2b720a0c8d062047edca92bc92Douglas Gregor    LMM_InvalidModuleMap
60426697979fb0a4e2b720a0c8d062047edca92bc92Douglas Gregor  };
60526697979fb0a4e2b720a0c8d062047edca92bc92Douglas Gregor
606cf70d7873fe3098bdac72e7628f4e832d14d5143Douglas Gregor  /// \brief Try to load the module map file in the given directory.
607cf70d7873fe3098bdac72e7628f4e832d14d5143Douglas Gregor  ///
60826697979fb0a4e2b720a0c8d062047edca92bc92Douglas Gregor  /// \param DirName The name of the directory where we will look for a module
60926697979fb0a4e2b720a0c8d062047edca92bc92Douglas Gregor  /// map file.
6108f5d7d1d1f990f174c7f2682271a83acf64dd93dDouglas Gregor  /// \param IsSystem Whether this is a system header directory.
61126697979fb0a4e2b720a0c8d062047edca92bc92Douglas Gregor  ///
61226697979fb0a4e2b720a0c8d062047edca92bc92Douglas Gregor  /// \returns The result of attempting to load the module map file from the
61326697979fb0a4e2b720a0c8d062047edca92bc92Douglas Gregor  /// named directory.
6148f5d7d1d1f990f174c7f2682271a83acf64dd93dDouglas Gregor  LoadModuleMapResult loadModuleMapFile(StringRef DirName, bool IsSystem);
615cf70d7873fe3098bdac72e7628f4e832d14d5143Douglas Gregor
616cf70d7873fe3098bdac72e7628f4e832d14d5143Douglas Gregor  /// \brief Try to load the module map file in the given directory.
617cf70d7873fe3098bdac72e7628f4e832d14d5143Douglas Gregor  ///
61826697979fb0a4e2b720a0c8d062047edca92bc92Douglas Gregor  /// \param Dir The directory where we will look for a module map file.
6198f5d7d1d1f990f174c7f2682271a83acf64dd93dDouglas Gregor  /// \param IsSystem Whether this is a system header directory.
62026697979fb0a4e2b720a0c8d062047edca92bc92Douglas Gregor  ///
62126697979fb0a4e2b720a0c8d062047edca92bc92Douglas Gregor  /// \returns The result of attempting to load the module map file from the
62226697979fb0a4e2b720a0c8d062047edca92bc92Douglas Gregor  /// named directory.
6238f5d7d1d1f990f174c7f2682271a83acf64dd93dDouglas Gregor  LoadModuleMapResult loadModuleMapFile(const DirectoryEntry *Dir,
6248f5d7d1d1f990f174c7f2682271a83acf64dd93dDouglas Gregor                                        bool IsSystem);
6251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
626a24bd5d9ad79be50cec0e25364d8267e7623c33fJames Dennett  /// \brief Return the HeaderFileInfo structure for the specified FileEntry.
62783d63c78810556d26b62ac4cbae2eda6cdd2570cSteve Naroff  HeaderFileInfo &getFileInfo(const FileEntry *FE);
6285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
6295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace clang
6315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
633