• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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   /// UserSupplied - True if this is a user-supplied directory.
54   ///
55   bool UserSupplied : 1;
56 
57   /// LookupType - This indicates whether this DirectoryLookup object is a
58   /// normal directory, a framework, or a headermap.
59   unsigned LookupType : 2;
60 
61   /// \brief Whether this is a header map used when building a framework.
62   unsigned IsIndexHeaderMap : 1;
63 
64 public:
65   /// DirectoryLookup ctor - Note that this ctor *does not take ownership* of
66   /// 'dir'.
DirectoryLookup(const DirectoryEntry * dir,SrcMgr::CharacteristicKind DT,bool isUser,bool isFramework)67   DirectoryLookup(const DirectoryEntry *dir, SrcMgr::CharacteristicKind DT,
68                   bool isUser, bool isFramework)
69     : DirCharacteristic(DT), UserSupplied(isUser),
70       LookupType(isFramework ? LT_Framework : LT_NormalDir),
71       IsIndexHeaderMap(false) {
72     u.Dir = dir;
73   }
74 
75   /// DirectoryLookup ctor - Note that this ctor *does not take ownership* of
76   /// 'map'.
DirectoryLookup(const HeaderMap * map,SrcMgr::CharacteristicKind DT,bool isUser,bool isIndexHeaderMap)77   DirectoryLookup(const HeaderMap *map, SrcMgr::CharacteristicKind DT,
78                   bool isUser, bool isIndexHeaderMap)
79     : DirCharacteristic(DT), UserSupplied(isUser), LookupType(LT_HeaderMap),
80       IsIndexHeaderMap(isIndexHeaderMap) {
81     u.Map = map;
82   }
83 
84   /// getLookupType - Return the kind of directory lookup that this is: either a
85   /// normal directory, a framework path, or a HeaderMap.
getLookupType()86   LookupType_t getLookupType() const { return (LookupType_t)LookupType; }
87 
88   /// getName - Return the directory or filename corresponding to this lookup
89   /// object.
90   const char *getName() const;
91 
92   /// getDir - Return the directory that this entry refers to.
93   ///
getDir()94   const DirectoryEntry *getDir() const { return isNormalDir() ? u.Dir : 0; }
95 
96   /// getFrameworkDir - Return the directory that this framework refers to.
97   ///
getFrameworkDir()98   const DirectoryEntry *getFrameworkDir() const {
99     return isFramework() ? u.Dir : 0;
100   }
101 
102   /// getHeaderMap - Return the directory that this entry refers to.
103   ///
getHeaderMap()104   const HeaderMap *getHeaderMap() const { return isHeaderMap() ? u.Map : 0; }
105 
106   /// isNormalDir - Return true if this is a normal directory, not a header map.
isNormalDir()107   bool isNormalDir() const { return getLookupType() == LT_NormalDir; }
108 
109   /// isFramework - True if this is a framework directory.
110   ///
isFramework()111   bool isFramework() const { return getLookupType() == LT_Framework; }
112 
113   /// isHeaderMap - Return true if this is a header map, not a normal directory.
isHeaderMap()114   bool isHeaderMap() const { return getLookupType() == LT_HeaderMap; }
115 
116   /// DirCharacteristic - The type of directory this is, one of the DirType enum
117   /// values.
getDirCharacteristic()118   SrcMgr::CharacteristicKind getDirCharacteristic() const {
119     return (SrcMgr::CharacteristicKind)DirCharacteristic;
120   }
121 
122   /// isUserSupplied - True if this is a user-supplied directory.
123   ///
isUserSupplied()124   bool isUserSupplied() const { return UserSupplied; }
125 
126   /// \brief Whether this header map is building a framework or not.
isIndexHeaderMap()127   bool isIndexHeaderMap() const {
128     return isHeaderMap() && IsIndexHeaderMap;
129   }
130 
131   /// LookupFile - Lookup the specified file in this search path, returning it
132   /// if it exists or returning null if not.
133   ///
134   /// \param Filename The file to look up relative to the search paths.
135   ///
136   /// \param HS The header search instance to search with.
137   ///
138   /// \param SearchPath If not NULL, will be set to the search path relative
139   /// to which the file was found.
140   ///
141   /// \param RelativePath If not NULL, will be set to the path relative to
142   /// SearchPath at which the file was found. This only differs from the
143   /// Filename for framework includes.
144   ///
145   /// \param SuggestedModule If non-null, and the file found is semantically
146   /// part of a known module, this will be set to the module that should
147   /// be imported instead of preprocessing/parsing the file found.
148   ///
149   /// \param [out] InUserSpecifiedSystemFramework If the file is found,
150   /// set to true if the file is located in a framework that has been
151   /// user-specified to be treated as a system framework.
152   const FileEntry *LookupFile(StringRef Filename, HeaderSearch &HS,
153                               SmallVectorImpl<char> *SearchPath,
154                               SmallVectorImpl<char> *RelativePath,
155                               Module **SuggestedModule,
156                               bool &InUserSpecifiedSystemFramework) const;
157 
158 private:
159   const FileEntry *DoFrameworkLookup(
160       StringRef Filename, HeaderSearch &HS,
161       SmallVectorImpl<char> *SearchPath,
162       SmallVectorImpl<char> *RelativePath,
163       Module **SuggestedModule,
164       bool &InUserSpecifiedSystemHeader) const;
165 
166 };
167 
168 }  // end namespace clang
169 
170 #endif
171