DirectoryLookup.h revision 9d72851fec9e9c62570a027d42701562bbf29751
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/SourceManager.h"
18
19namespace clang {
20class HeaderMap;
21class DirectoryEntry;
22class FileEntry;
23class HeaderSearch;
24
25/// DirectoryLookup - This class represents one entry in the search list that
26/// specifies the search order for directories in #include directives.  It
27/// represents either a directory, a framework, or a headermap.
28///
29class DirectoryLookup {
30public:
31  enum LookupType_t {
32    LT_NormalDir,
33    LT_Framework,
34    LT_HeaderMap
35  };
36private:
37  union {  // This union is discriminated by isHeaderMap.
38    /// Dir - This is the actual directory that we're referring to for a normal
39    /// directory or a framework.
40    const DirectoryEntry *Dir;
41
42    /// Map - This is the HeaderMap if this is a headermap lookup.
43    ///
44    const HeaderMap *Map;
45  } u;
46
47  /// DirCharacteristic - The type of directory this is: this is an instance of
48  /// SrcMgr::CharacteristicKind.
49  unsigned DirCharacteristic : 2;
50
51  /// UserSupplied - True if this is a user-supplied directory.
52  ///
53  bool UserSupplied : 1;
54
55  /// LookupType - This indicates whether this DirectoryLookup object is a
56  /// normal directory, a framework, or a headermap.
57  unsigned LookupType : 2;
58public:
59  /// DirectoryLookup ctor - Note that this ctor *does not take ownership* of
60  /// 'dir'.
61  DirectoryLookup(const DirectoryEntry *dir, SrcMgr::CharacteristicKind DT,
62                  bool isUser, bool isFramework)
63    : DirCharacteristic(DT), UserSupplied(isUser),
64     LookupType(isFramework ? LT_Framework : LT_NormalDir) {
65    u.Dir = dir;
66  }
67
68  /// DirectoryLookup ctor - Note that this ctor *does not take ownership* of
69  /// 'map'.
70  DirectoryLookup(const HeaderMap *map, SrcMgr::CharacteristicKind DT,
71                  bool isUser)
72    : DirCharacteristic(DT), UserSupplied(isUser), LookupType(LT_HeaderMap) {
73    u.Map = map;
74  }
75
76  /// getLookupType - Return the kind of directory lookup that this is: either a
77  /// normal directory, a framework path, or a HeaderMap.
78  LookupType_t getLookupType() const { return (LookupType_t)LookupType; }
79
80  /// getName - Return the directory or filename corresponding to this lookup
81  /// object.
82  const char *getName() 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  /// isNormalDir - Return true if this is a normal directory, not a header map.
99  bool isNormalDir() const { return getLookupType() == LT_NormalDir; }
100
101  /// isFramework - True if this is a framework directory.
102  ///
103  bool isFramework() const { return getLookupType() == LT_Framework; }
104
105  /// isHeaderMap - Return true if this is a header map, not a normal directory.
106  bool isHeaderMap() const { return getLookupType() == LT_HeaderMap; }
107
108  /// DirCharacteristic - The type of directory this is, one of the DirType enum
109  /// values.
110  SrcMgr::CharacteristicKind getDirCharacteristic() const {
111    return (SrcMgr::CharacteristicKind)DirCharacteristic;
112  }
113
114  /// isUserSupplied - True if this is a user-supplied directory.
115  ///
116  bool isUserSupplied() const { return UserSupplied; }
117
118
119  /// LookupFile - Lookup the specified file in this search path, returning it
120  /// if it exists or returning null if not.
121  const FileEntry *LookupFile(const char *FilenameStart,
122                              const char *FilenameEnd, HeaderSearch &HS) const;
123
124private:
125  const FileEntry *DoFrameworkLookup(const char *FilenameStart,
126                                     const char *FilenameEnd,
127                                     HeaderSearch &HS) const;
128
129};
130
131}  // end namespace clang
132
133#endif
134