]> CyberLeo.Net >> Repos - FreeBSD/releng/9.0.git/blob - contrib/llvm/tools/clang/include/clang/Lex/DirectoryLookup.h
Copy stable/9 to releng/9.0 as part of the FreeBSD 9.0-RELEASE release
[FreeBSD/releng/9.0.git] / contrib / llvm / tools / clang / include / clang / Lex / DirectoryLookup.h
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
26 /// DirectoryLookup - This class represents one entry in the search list that
27 /// specifies the search order for directories in #include directives.  It
28 /// represents either a directory, a framework, or a headermap.
29 ///
30 class DirectoryLookup {
31 public:
32   enum LookupType_t {
33     LT_NormalDir,
34     LT_Framework,
35     LT_HeaderMap
36   };
37 private:
38   union {  // This union is discriminated by isHeaderMap.
39     /// Dir - This is the actual directory that we're referring to for a normal
40     /// directory or a framework.
41     const DirectoryEntry *Dir;
42
43     /// Map - This is the HeaderMap if this is a headermap lookup.
44     ///
45     const HeaderMap *Map;
46   } u;
47
48   /// DirCharacteristic - The type of directory this is: this is an instance of
49   /// SrcMgr::CharacteristicKind.
50   unsigned DirCharacteristic : 2;
51
52   /// UserSupplied - True if this is a user-supplied directory.
53   ///
54   bool UserSupplied : 1;
55
56   /// LookupType - This indicates whether this DirectoryLookup object is a
57   /// normal directory, a framework, or a headermap.
58   unsigned LookupType : 2;
59   
60   /// \brief Whether this is a header map used when building a framework.
61   unsigned IsIndexHeaderMap : 1;
62   
63 public:
64   /// DirectoryLookup ctor - Note that this ctor *does not take ownership* of
65   /// 'dir'.
66   DirectoryLookup(const DirectoryEntry *dir, SrcMgr::CharacteristicKind DT,
67                   bool isUser, bool isFramework)
68     : DirCharacteristic(DT), UserSupplied(isUser), 
69       LookupType(isFramework ? LT_Framework : LT_NormalDir),
70       IsIndexHeaderMap(false) {
71     u.Dir = dir;
72   }
73
74   /// DirectoryLookup ctor - Note that this ctor *does not take ownership* of
75   /// 'map'.
76   DirectoryLookup(const HeaderMap *map, SrcMgr::CharacteristicKind DT,
77                   bool isUser, bool isIndexHeaderMap)
78     : DirCharacteristic(DT), UserSupplied(isUser), LookupType(LT_HeaderMap),
79       IsIndexHeaderMap(isIndexHeaderMap) {
80     u.Map = map;
81   }
82
83   /// getLookupType - Return the kind of directory lookup that this is: either a
84   /// normal directory, a framework path, or a HeaderMap.
85   LookupType_t getLookupType() const { return (LookupType_t)LookupType; }
86
87   /// getName - Return the directory or filename corresponding to this lookup
88   /// object.
89   const char *getName() const;
90
91   /// getDir - Return the directory that this entry refers to.
92   ///
93   const DirectoryEntry *getDir() const { return isNormalDir() ? u.Dir : 0; }
94
95   /// getFrameworkDir - Return the directory that this framework refers to.
96   ///
97   const DirectoryEntry *getFrameworkDir() const {
98     return isFramework() ? u.Dir : 0;
99   }
100
101   /// getHeaderMap - Return the directory that this entry refers to.
102   ///
103   const HeaderMap *getHeaderMap() const { return isHeaderMap() ? u.Map : 0; }
104
105   /// isNormalDir - Return true if this is a normal directory, not a header map.
106   bool isNormalDir() const { return getLookupType() == LT_NormalDir; }
107
108   /// isFramework - True if this is a framework directory.
109   ///
110   bool isFramework() const { return getLookupType() == LT_Framework; }
111
112   /// isHeaderMap - Return true if this is a header map, not a normal directory.
113   bool isHeaderMap() const { return getLookupType() == LT_HeaderMap; }
114
115   /// DirCharacteristic - The type of directory this is, one of the DirType enum
116   /// values.
117   SrcMgr::CharacteristicKind getDirCharacteristic() const {
118     return (SrcMgr::CharacteristicKind)DirCharacteristic;
119   }
120
121   /// isUserSupplied - True if this is a user-supplied directory.
122   ///
123   bool isUserSupplied() const { return UserSupplied; }
124
125   /// \brief Whether this header map is building a framework or not.
126   bool isIndexHeaderMap() const { 
127     return isHeaderMap() && IsIndexHeaderMap; 
128   }
129   
130   /// LookupFile - Lookup the specified file in this search path, returning it
131   /// if it exists or returning null if not.
132   ///
133   /// \param Filename The file to look up relative to the search paths.
134   ///
135   /// \param HS The header search instance to search with.
136   ///
137   /// \param SearchPath If not NULL, will be set to the search path relative
138   /// to which the file was found.
139   ///
140   /// \param RelativePath If not NULL, will be set to the path relative to
141   /// SearchPath at which the file was found. This only differs from the
142   /// Filename for framework includes.
143   ///
144   /// \param BuildingModule The name of the module we're currently building.
145   ///
146   /// \param SuggestedModule If non-null, and the file found is semantically
147   /// part of a known module, this will be set to the name of the module that
148   /// could be imported instead of preprocessing/parsing the file found.
149   const FileEntry *LookupFile(StringRef Filename, HeaderSearch &HS,
150                               SmallVectorImpl<char> *SearchPath,
151                               SmallVectorImpl<char> *RelativePath,
152                               StringRef BuildingModule,
153                               StringRef *SuggestedModule) const;
154
155 private:
156   const FileEntry *DoFrameworkLookup(
157       StringRef Filename, HeaderSearch &HS,
158       SmallVectorImpl<char> *SearchPath,
159       SmallVectorImpl<char> *RelativePath,
160       StringRef BuildingModule,
161       StringRef *SuggestedModule) const;
162
163 };
164
165 }  // end namespace clang
166
167 #endif