clang API Documentation

DirectoryLookup.h
Go to the documentation of this file.
00001 //===--- DirectoryLookup.h - Info for searching for headers -----*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file defines the DirectoryLookup interface.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #ifndef LLVM_CLANG_LEX_DIRECTORYLOOKUP_H
00015 #define LLVM_CLANG_LEX_DIRECTORYLOOKUP_H
00016 
00017 #include "clang/Basic/LLVM.h"
00018 #include "clang/Basic/SourceManager.h"
00019 #include "clang/Lex/ModuleMap.h"
00020 
00021 namespace clang {
00022 class HeaderMap;
00023 class DirectoryEntry;
00024 class FileEntry;
00025 class HeaderSearch;
00026 class Module;
00027   
00028 /// DirectoryLookup - This class represents one entry in the search list that
00029 /// specifies the search order for directories in \#include directives.  It
00030 /// represents either a directory, a framework, or a headermap.
00031 ///
00032 class DirectoryLookup {
00033 public:
00034   enum LookupType_t {
00035     LT_NormalDir,
00036     LT_Framework,
00037     LT_HeaderMap
00038   };
00039 private:
00040   union {  // This union is discriminated by isHeaderMap.
00041     /// Dir - This is the actual directory that we're referring to for a normal
00042     /// directory or a framework.
00043     const DirectoryEntry *Dir;
00044 
00045     /// Map - This is the HeaderMap if this is a headermap lookup.
00046     ///
00047     const HeaderMap *Map;
00048   } u;
00049 
00050   /// DirCharacteristic - The type of directory this is: this is an instance of
00051   /// SrcMgr::CharacteristicKind.
00052   unsigned DirCharacteristic : 2;
00053 
00054   /// LookupType - This indicates whether this DirectoryLookup object is a
00055   /// normal directory, a framework, or a headermap.
00056   unsigned LookupType : 2;
00057   
00058   /// \brief Whether this is a header map used when building a framework.
00059   unsigned IsIndexHeaderMap : 1;
00060 
00061   /// \brief Whether we've performed an exhaustive search for module maps
00062   /// within the subdirectories of this directory.
00063   unsigned SearchedAllModuleMaps : 1;
00064   
00065 public:
00066   /// DirectoryLookup ctor - Note that this ctor *does not take ownership* of
00067   /// 'dir'.
00068   DirectoryLookup(const DirectoryEntry *dir, SrcMgr::CharacteristicKind DT,
00069                   bool isFramework)
00070     : DirCharacteristic(DT),
00071       LookupType(isFramework ? LT_Framework : LT_NormalDir),
00072       IsIndexHeaderMap(false), SearchedAllModuleMaps(false) {
00073     u.Dir = dir;
00074   }
00075 
00076   /// DirectoryLookup ctor - Note that this ctor *does not take ownership* of
00077   /// 'map'.
00078   DirectoryLookup(const HeaderMap *map, SrcMgr::CharacteristicKind DT,
00079                   bool isIndexHeaderMap)
00080     : DirCharacteristic(DT), LookupType(LT_HeaderMap),
00081       IsIndexHeaderMap(isIndexHeaderMap), SearchedAllModuleMaps(false) {
00082     u.Map = map;
00083   }
00084 
00085   /// getLookupType - Return the kind of directory lookup that this is: either a
00086   /// normal directory, a framework path, or a HeaderMap.
00087   LookupType_t getLookupType() const { return (LookupType_t)LookupType; }
00088 
00089   /// getName - Return the directory or filename corresponding to this lookup
00090   /// object.
00091   const char *getName() const;
00092 
00093   /// getDir - Return the directory that this entry refers to.
00094   ///
00095   const DirectoryEntry *getDir() const {
00096     return isNormalDir() ? u.Dir : nullptr;
00097   }
00098 
00099   /// getFrameworkDir - Return the directory that this framework refers to.
00100   ///
00101   const DirectoryEntry *getFrameworkDir() const {
00102     return isFramework() ? u.Dir : nullptr;
00103   }
00104 
00105   /// getHeaderMap - Return the directory that this entry refers to.
00106   ///
00107   const HeaderMap *getHeaderMap() const {
00108     return isHeaderMap() ? u.Map : nullptr;
00109   }
00110 
00111   /// isNormalDir - Return true if this is a normal directory, not a header map.
00112   bool isNormalDir() const { return getLookupType() == LT_NormalDir; }
00113 
00114   /// isFramework - True if this is a framework directory.
00115   ///
00116   bool isFramework() const { return getLookupType() == LT_Framework; }
00117 
00118   /// isHeaderMap - Return true if this is a header map, not a normal directory.
00119   bool isHeaderMap() const { return getLookupType() == LT_HeaderMap; }
00120 
00121   /// \brief Determine whether we have already searched this entire
00122   /// directory for module maps.
00123   bool haveSearchedAllModuleMaps() const { return SearchedAllModuleMaps; }
00124 
00125   /// \brief Specify whether we have already searched all of the subdirectories
00126   /// for module maps.
00127   void setSearchedAllModuleMaps(bool SAMM) {
00128     SearchedAllModuleMaps = SAMM;
00129   }
00130 
00131   /// DirCharacteristic - The type of directory this is, one of the DirType enum
00132   /// values.
00133   SrcMgr::CharacteristicKind getDirCharacteristic() const {
00134     return (SrcMgr::CharacteristicKind)DirCharacteristic;
00135   }
00136 
00137   /// \brief Whether this describes a system header directory.
00138   bool isSystemHeaderDirectory() const {
00139     return getDirCharacteristic() != SrcMgr::C_User;
00140   }
00141 
00142   /// \brief Whether this header map is building a framework or not.
00143   bool isIndexHeaderMap() const { 
00144     return isHeaderMap() && IsIndexHeaderMap; 
00145   }
00146   
00147   /// LookupFile - Lookup the specified file in this search path, returning it
00148   /// if it exists or returning null if not.
00149   ///
00150   /// \param Filename The file to look up relative to the search paths.
00151   ///
00152   /// \param HS The header search instance to search with.
00153   ///
00154   /// \param SearchPath If not NULL, will be set to the search path relative
00155   /// to which the file was found.
00156   ///
00157   /// \param RelativePath If not NULL, will be set to the path relative to
00158   /// SearchPath at which the file was found. This only differs from the
00159   /// Filename for framework includes.
00160   ///
00161   /// \param SuggestedModule If non-null, and the file found is semantically
00162   /// part of a known module, this will be set to the module that should
00163   /// be imported instead of preprocessing/parsing the file found.
00164   ///
00165   /// \param [out] InUserSpecifiedSystemFramework If the file is found,
00166   /// set to true if the file is located in a framework that has been
00167   /// user-specified to be treated as a system framework.
00168   ///
00169   /// \param [out] MappedName if this is a headermap which maps the filename to
00170   /// a framework include ("Foo.h" -> "Foo/Foo.h"), set the new name to this
00171   /// vector and point Filename to it.
00172   const FileEntry *LookupFile(StringRef &Filename, HeaderSearch &HS,
00173                               SmallVectorImpl<char> *SearchPath,
00174                               SmallVectorImpl<char> *RelativePath,
00175                               ModuleMap::KnownHeader *SuggestedModule,
00176                               bool &InUserSpecifiedSystemFramework,
00177                               bool &HasBeenMapped,
00178                               SmallVectorImpl<char> &MappedName) const;
00179 
00180 private:
00181   const FileEntry *DoFrameworkLookup(
00182       StringRef Filename, HeaderSearch &HS,
00183       SmallVectorImpl<char> *SearchPath,
00184       SmallVectorImpl<char> *RelativePath,
00185       ModuleMap::KnownHeader *SuggestedModule,
00186       bool &InUserSpecifiedSystemHeader) const;
00187 
00188 };
00189 
00190 }  // end namespace clang
00191 
00192 #endif