Home | History | Annotate | Download | only in Lex
      1 //===--- DirectoryLookup.h - Info for searching for headers -----*- C++ -*-===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 //
     10 // This file defines the DirectoryLookup interface.
     11 //
     12 //===----------------------------------------------------------------------===//
     13 
     14 #ifndef LLVM_CLANG_LEX_DIRECTORYLOOKUP_H
     15 #define LLVM_CLANG_LEX_DIRECTORYLOOKUP_H
     16 
     17 #include "clang/Basic/LLVM.h"
     18 #include "clang/Basic/SourceManager.h"
     19 
     20 namespace clang {
     21 class HeaderMap;
     22 class DirectoryEntry;
     23 class FileEntry;
     24 class HeaderSearch;
     25 class Module;
     26 
     27 /// DirectoryLookup - This class represents one entry in the search list that
     28 /// specifies the search order for directories in \#include directives.  It
     29 /// represents either a directory, a framework, or a headermap.
     30 ///
     31 class DirectoryLookup {
     32 public:
     33   enum LookupType_t {
     34     LT_NormalDir,
     35     LT_Framework,
     36     LT_HeaderMap
     37   };
     38 private:
     39   union {  // This union is discriminated by isHeaderMap.
     40     /// Dir - This is the actual directory that we're referring to for a normal
     41     /// directory or a framework.
     42     const DirectoryEntry *Dir;
     43 
     44     /// Map - This is the HeaderMap if this is a headermap lookup.
     45     ///
     46     const HeaderMap *Map;
     47   } u;
     48 
     49   /// DirCharacteristic - The type of directory this is: this is an instance of
     50   /// SrcMgr::CharacteristicKind.
     51   unsigned DirCharacteristic : 2;
     52 
     53   /// LookupType - This indicates whether this DirectoryLookup object is a
     54   /// normal directory, a framework, or a headermap.
     55   unsigned LookupType : 2;
     56 
     57   /// \brief Whether this is a header map used when building a framework.
     58   unsigned IsIndexHeaderMap : 1;
     59 
     60 public:
     61   /// DirectoryLookup ctor - Note that this ctor *does not take ownership* of
     62   /// 'dir'.
     63   DirectoryLookup(const DirectoryEntry *dir, SrcMgr::CharacteristicKind DT,
     64                   bool isFramework)
     65     : DirCharacteristic(DT),
     66       LookupType(isFramework ? LT_Framework : LT_NormalDir),
     67       IsIndexHeaderMap(false) {
     68     u.Dir = dir;
     69   }
     70 
     71   /// DirectoryLookup ctor - Note that this ctor *does not take ownership* of
     72   /// 'map'.
     73   DirectoryLookup(const HeaderMap *map, SrcMgr::CharacteristicKind DT,
     74                   bool isIndexHeaderMap)
     75     : DirCharacteristic(DT), LookupType(LT_HeaderMap),
     76       IsIndexHeaderMap(isIndexHeaderMap) {
     77     u.Map = map;
     78   }
     79 
     80   /// getLookupType - Return the kind of directory lookup that this is: either a
     81   /// normal directory, a framework path, or a HeaderMap.
     82   LookupType_t getLookupType() const { return (LookupType_t)LookupType; }
     83 
     84   /// getName - Return the directory or filename corresponding to this lookup
     85   /// object.
     86   const char *getName() const;
     87 
     88   /// getDir - Return the directory that this entry refers to.
     89   ///
     90   const DirectoryEntry *getDir() const { return isNormalDir() ? u.Dir : 0; }
     91 
     92   /// getFrameworkDir - Return the directory that this framework refers to.
     93   ///
     94   const DirectoryEntry *getFrameworkDir() const {
     95     return isFramework() ? u.Dir : 0;
     96   }
     97 
     98   /// getHeaderMap - Return the directory that this entry refers to.
     99   ///
    100   const HeaderMap *getHeaderMap() const { return isHeaderMap() ? u.Map : 0; }
    101 
    102   /// isNormalDir - Return true if this is a normal directory, not a header map.
    103   bool isNormalDir() const { return getLookupType() == LT_NormalDir; }
    104 
    105   /// isFramework - True if this is a framework directory.
    106   ///
    107   bool isFramework() const { return getLookupType() == LT_Framework; }
    108 
    109   /// isHeaderMap - Return true if this is a header map, not a normal directory.
    110   bool isHeaderMap() const { return getLookupType() == LT_HeaderMap; }
    111 
    112   /// DirCharacteristic - The type of directory this is, one of the DirType enum
    113   /// values.
    114   SrcMgr::CharacteristicKind getDirCharacteristic() const {
    115     return (SrcMgr::CharacteristicKind)DirCharacteristic;
    116   }
    117 
    118   /// \brief Whether this header map is building a framework or not.
    119   bool isIndexHeaderMap() const {
    120     return isHeaderMap() && IsIndexHeaderMap;
    121   }
    122 
    123   /// LookupFile - Lookup the specified file in this search path, returning it
    124   /// if it exists or returning null if not.
    125   ///
    126   /// \param Filename The file to look up relative to the search paths.
    127   ///
    128   /// \param HS The header search instance to search with.
    129   ///
    130   /// \param SearchPath If not NULL, will be set to the search path relative
    131   /// to which the file was found.
    132   ///
    133   /// \param RelativePath If not NULL, will be set to the path relative to
    134   /// SearchPath at which the file was found. This only differs from the
    135   /// Filename for framework includes.
    136   ///
    137   /// \param SuggestedModule If non-null, and the file found is semantically
    138   /// part of a known module, this will be set to the module that should
    139   /// be imported instead of preprocessing/parsing the file found.
    140   ///
    141   /// \param [out] InUserSpecifiedSystemFramework If the file is found,
    142   /// set to true if the file is located in a framework that has been
    143   /// user-specified to be treated as a system framework.
    144   const FileEntry *LookupFile(StringRef Filename, HeaderSearch &HS,
    145                               SmallVectorImpl<char> *SearchPath,
    146                               SmallVectorImpl<char> *RelativePath,
    147                               Module **SuggestedModule,
    148                               bool &InUserSpecifiedSystemFramework) const;
    149 
    150 private:
    151   const FileEntry *DoFrameworkLookup(
    152       StringRef Filename, HeaderSearch &HS,
    153       SmallVectorImpl<char> *SearchPath,
    154       SmallVectorImpl<char> *RelativePath,
    155       Module **SuggestedModule,
    156       bool &InUserSpecifiedSystemHeader) const;
    157 
    158 };
    159 
    160 }  // end namespace clang
    161 
    162 #endif
    163