DirectoryLookup.h revision afded5bbb85607023c710c3d6a96c372feb84d7f
1//===--- DirectoryLookup.h - Info for searching for headers -----*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file was developed by Chris Lattner and is distributed under
6// the University of Illinois Open Source 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
17namespace clang {
18class HeaderMap;
19class DirectoryEntry;
20class FileEntry;
21class HeaderSearch;
22
23/// DirectoryLookup - This class represents one entry in the search list that
24/// specifies the search order for directories in #include directives.  It
25/// represents either a directory, a framework, or a headermap.
26///
27class DirectoryLookup {
28public:
29  enum DirType {
30    NormalHeaderDir,
31    SystemHeaderDir,
32    ExternCSystemHeaderDir
33  };
34
35  enum LookupType_t {
36    LT_NormalDir,
37    LT_Framework,
38    LT_HeaderMap
39  };
40private:
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;
45
46    /// Map - This is the HeaderMap if this is a headermap lookup.
47    ///
48    const HeaderMap *Map;
49  } u;
50
51  /// DirCharacteristic - The type of directory this is, one of the DirType enum
52  /// values.
53  DirType DirCharacteristic : 2;
54
55  /// UserSupplied - True if this is a user-supplied directory.
56  ///
57  bool UserSupplied : 1;
58
59  /// LookupType - This indicates whether this DirectoryLookup object is a
60  /// normal directory, a framework, or a headermap.
61  unsigned LookupType : 2;
62public:
63  /// DirectoryLookup ctor - Note that this ctor *does not take ownership* of
64  /// 'dir'.
65  DirectoryLookup(const DirectoryEntry *dir, DirType DT, bool isUser,
66                  bool isFramework)
67    : DirCharacteristic(DT), UserSupplied(isUser),
68     LookupType(isFramework ? LT_Framework : LT_NormalDir) {
69    u.Dir = dir;
70  }
71
72  /// DirectoryLookup ctor - Note that this ctor *does not take ownership* of
73  /// 'map'.
74  DirectoryLookup(const HeaderMap *map, DirType DT, bool isUser)
75    : DirCharacteristic(DT), UserSupplied(isUser), LookupType(LT_HeaderMap) {
76    u.Map = map;
77  }
78
79  /// LookupFile - Lookup the specified file in this search path, returning it
80  /// if it exists or returning null if not.
81  const FileEntry *LookupFile(const char *FilenameStart,
82                              const char *FilenameEnd, HeaderSearch &HS) const;
83
84  /// getDir - Return the directory that this entry refers to.
85  ///
86  const DirectoryEntry *getDir() const { return isNormalDir() ? u.Dir : 0; }
87
88  /// getFrameworkDir - Return the directory that this framework refers to.
89  ///
90  const DirectoryEntry *getFrameworkDir() const {
91    return isFramework() ? u.Dir : 0;
92  }
93
94  /// getHeaderMap - Return the directory that this entry refers to.
95  ///
96  const HeaderMap *getHeaderMap() const { return isHeaderMap() ? u.Map : 0; }
97
98  LookupType_t getLookupType() const { return (LookupType_t)LookupType; }
99
100  /// isNormalDir - Return true if this is a normal directory, not a header map.
101  bool isNormalDir() const { return getLookupType() == LT_NormalDir; }
102
103  /// isFramework - True if this is a framework directory.
104  ///
105  bool isFramework() const { return getLookupType() == LT_Framework; }
106
107  /// isHeaderMap - Return true if this is a header map, not a normal directory.
108  bool isHeaderMap() const { return getLookupType() == LT_HeaderMap; }
109
110  /// DirCharacteristic - The type of directory this is, one of the DirType enum
111  /// values.
112  DirType getDirCharacteristic() const { return DirCharacteristic; }
113
114  /// isUserSupplied - True if this is a user-supplied directory.
115  ///
116  bool isUserSupplied() const { return UserSupplied; }
117
118private:
119  const FileEntry *DoFrameworkLookup(const char *FilenameStart,
120                                     const char *FilenameEnd,
121                                     HeaderSearch &HS) const;
122
123};
124
125}  // end namespace clang
126
127#endif
128