1 //===--- DirectoryLookup.h - Info for searching for headers -----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the DirectoryLookup interface.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_LEX_DIRECTORYLOOKUP_H
15 #define LLVM_CLANG_LEX_DIRECTORYLOOKUP_H
17 #include "clang/Basic/SourceManager.h"
21 template <typename T> class SmallVectorImpl;
29 /// DirectoryLookup - This class represents one entry in the search list that
30 /// specifies the search order for directories in #include directives. It
31 /// represents either a directory, a framework, or a headermap.
33 class DirectoryLookup {
41 union { // This union is discriminated by isHeaderMap.
42 /// Dir - This is the actual directory that we're referring to for a normal
43 /// directory or a framework.
44 const DirectoryEntry *Dir;
46 /// Map - This is the HeaderMap if this is a headermap lookup.
51 /// DirCharacteristic - The type of directory this is: this is an instance of
52 /// SrcMgr::CharacteristicKind.
53 unsigned DirCharacteristic : 2;
55 /// UserSupplied - True if this is a user-supplied directory.
57 bool UserSupplied : 1;
59 /// LookupType - This indicates whether this DirectoryLookup object is a
60 /// normal directory, a framework, or a headermap.
61 unsigned LookupType : 2;
63 /// DirectoryLookup ctor - Note that this ctor *does not take ownership* of
65 DirectoryLookup(const DirectoryEntry *dir, SrcMgr::CharacteristicKind DT,
66 bool isUser, bool isFramework)
67 : DirCharacteristic(DT), UserSupplied(isUser),
68 LookupType(isFramework ? LT_Framework : LT_NormalDir) {
72 /// DirectoryLookup ctor - Note that this ctor *does not take ownership* of
74 DirectoryLookup(const HeaderMap *map, SrcMgr::CharacteristicKind DT,
76 : DirCharacteristic(DT), UserSupplied(isUser), LookupType(LT_HeaderMap) {
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; }
84 /// getName - Return the directory or filename corresponding to this lookup
86 const char *getName() const;
88 /// getDir - Return the directory that this entry refers to.
90 const DirectoryEntry *getDir() const { return isNormalDir() ? u.Dir : 0; }
92 /// getFrameworkDir - Return the directory that this framework refers to.
94 const DirectoryEntry *getFrameworkDir() const {
95 return isFramework() ? u.Dir : 0;
98 /// getHeaderMap - Return the directory that this entry refers to.
100 const HeaderMap *getHeaderMap() const { return isHeaderMap() ? u.Map : 0; }
102 /// isNormalDir - Return true if this is a normal directory, not a header map.
103 bool isNormalDir() const { return getLookupType() == LT_NormalDir; }
105 /// isFramework - True if this is a framework directory.
107 bool isFramework() const { return getLookupType() == LT_Framework; }
109 /// isHeaderMap - Return true if this is a header map, not a normal directory.
110 bool isHeaderMap() const { return getLookupType() == LT_HeaderMap; }
112 /// DirCharacteristic - The type of directory this is, one of the DirType enum
114 SrcMgr::CharacteristicKind getDirCharacteristic() const {
115 return (SrcMgr::CharacteristicKind)DirCharacteristic;
118 /// isUserSupplied - True if this is a user-supplied directory.
120 bool isUserSupplied() const { return UserSupplied; }
123 /// LookupFile - Lookup the specified file in this search path, returning it
124 /// if it exists or returning null if not.
126 /// \param Filename The file to look up relative to the search paths.
128 /// \param HS The header search instance to search with.
130 /// \param SearchPath If not NULL, will be set to the search path relative
131 /// to which the file was found.
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 const FileEntry *LookupFile(llvm::StringRef Filename, HeaderSearch &HS,
137 llvm::SmallVectorImpl<char> *SearchPath,
138 llvm::SmallVectorImpl<char> *RelativePath) const;
141 const FileEntry *DoFrameworkLookup(
142 llvm::StringRef Filename, HeaderSearch &HS,
143 llvm::SmallVectorImpl<char> *SearchPath,
144 llvm::SmallVectorImpl<char> *RelativePath) const;
148 } // end namespace clang