 |
|
 |
|
| Files: |
1 |
|
Branches Taken: |
0.0% |
0 / 0 |
| Generated: |
2010-02-10 01:31 |
|
Branches Executed: |
0.0% |
0 / 0 |
| |
|
Line Coverage: |
80.0% |
24 / 30 |
| |
 |
|
 |
1 : //===--- HeaderSearch.h - Resolve Header File Locations ---------*- 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 HeaderSearch interface.
11 : //
12 : //===----------------------------------------------------------------------===//
13 :
14 : #ifndef LLVM_CLANG_LEX_HEADERSEARCH_H
15 : #define LLVM_CLANG_LEX_HEADERSEARCH_H
16 :
17 : #include "clang/Lex/DirectoryLookup.h"
18 : #include "llvm/ADT/StringMap.h"
19 : #include <vector>
20 :
21 : namespace clang {
22 :
23 : class ExternalIdentifierLookup;
24 : class FileEntry;
25 : class FileManager;
26 : class IdentifierInfo;
27 :
28 : /// HeaderFileInfo - The preprocessor keeps track of this information for each
29 : /// file that is #included.
30 : struct HeaderFileInfo {
31 : /// isImport - True if this is a #import'd or #pragma once file.
32 : bool isImport : 1;
33 :
34 : /// DirInfo - Keep track of whether this is a system header, and if so,
35 : /// whether it is C++ clean or not. This can be set by the include paths or
36 : /// by #pragma gcc system_header. This is an instance of
37 : /// SrcMgr::CharacteristicKind.
38 : unsigned DirInfo : 2;
39 :
40 : /// NumIncludes - This is the number of times the file has been included
41 : /// already.
42 : unsigned short NumIncludes;
43 :
44 : /// ControllingMacro - If this file has a #ifndef XXX (or equivalent) guard
45 : /// that protects the entire contents of the file, this is the identifier
46 : /// for the macro that controls whether or not it has any effect.
47 : ///
48 : /// Note: Most clients should use getControllingMacro() to access
49 : /// the controlling macro of this header, since
50 : /// getControllingMacro() is able to load a controlling macro from
51 : /// external storage.
52 : const IdentifierInfo *ControllingMacro;
53 :
54 : /// \brief The ID number of the controlling macro.
55 : ///
56 : /// This ID number will be non-zero when there is a controlling
57 : /// macro whose IdentifierInfo may not yet have been loaded from
58 : /// external storage.
59 : unsigned ControllingMacroID;
60 :
61 3039: HeaderFileInfo()
62 : : isImport(false), DirInfo(SrcMgr::C_User),
63 3039: NumIncludes(0), ControllingMacro(0), ControllingMacroID(0) {}
64 :
65 : /// \brief Retrieve the controlling macro for this header file, if
66 : /// any.
67 : const IdentifierInfo *getControllingMacro(ExternalIdentifierLookup *External);
68 : };
69 :
70 : /// HeaderSearch - This class encapsulates the information needed to find the
71 : /// file referenced by a #include or #include_next, (sub-)framework lookup, etc.
72 : class HeaderSearch {
73 : FileManager &FileMgr;
74 :
75 : /// #include search path information. Requests for #include "x" search the
76 : /// directory of the #including file first, then each directory in SearchDirs
77 : /// consequtively. Requests for <x> search the current dir first, then each
78 : /// directory in SearchDirs, starting at SystemDirIdx, consequtively. If
79 : /// NoCurDirSearch is true, then the check for the file in the current
80 : /// directory is supressed.
81 : std::vector<DirectoryLookup> SearchDirs;
82 : unsigned SystemDirIdx;
83 : bool NoCurDirSearch;
84 :
85 : /// FileInfo - This contains all of the preprocessor-specific data about files
86 : /// that are included. The vector is indexed by the FileEntry's UID.
87 : ///
88 : std::vector<HeaderFileInfo> FileInfo;
89 :
90 : /// LookupFileCache - This is keeps track of each lookup performed by
91 : /// LookupFile. The first part of the value is the starting index in
92 : /// SearchDirs that the cached search was performed from. If there is a hit
93 : /// and this value doesn't match the current query, the cache has to be
94 : /// ignored. The second value is the entry in SearchDirs that satisfied the
95 : /// query.
96 : llvm::StringMap<std::pair<unsigned, unsigned> > LookupFileCache;
97 :
98 :
99 : /// FrameworkMap - This is a collection mapping a framework or subframework
100 : /// name like "Carbon" to the Carbon.framework directory.
101 : llvm::StringMap<const DirectoryEntry *> FrameworkMap;
102 :
103 : /// HeaderMaps - This is a mapping from FileEntry -> HeaderMap, uniquing
104 : /// headermaps. This vector owns the headermap.
105 : std::vector<std::pair<const FileEntry*, const HeaderMap*> > HeaderMaps;
106 :
107 : /// \brief Entity used to resolve the identifier IDs of controlling
108 : /// macros into IdentifierInfo pointers, as needed.
109 : ExternalIdentifierLookup *ExternalLookup;
110 :
111 : // Various statistics we track for performance analysis.
112 : unsigned NumIncluded;
113 : unsigned NumMultiIncludeFileOptzn;
114 : unsigned NumFrameworkLookups, NumSubFrameworkLookups;
115 :
116 : // HeaderSearch doesn't support default or copy construction.
117 : explicit HeaderSearch();
118 : explicit HeaderSearch(const HeaderSearch&);
119 : void operator=(const HeaderSearch&);
120 : public:
121 : HeaderSearch(FileManager &FM);
122 : ~HeaderSearch();
123 :
124 69638: FileManager &getFileMgr() const { return FileMgr; }
125 :
126 : /// SetSearchPaths - Interface for setting the file search paths.
127 : ///
128 : void SetSearchPaths(const std::vector<DirectoryLookup> &dirs,
129 2520: unsigned systemDirIdx, bool noCurDirSearch) {
130 2520: SearchDirs = dirs;
131 2520: SystemDirIdx = systemDirIdx;
132 2520: NoCurDirSearch = noCurDirSearch;
133 : //LookupFileCache.clear();
134 2520: }
135 :
136 : /// ClearFileInfo - Forget everything we know about headers so far.
137 : void ClearFileInfo() {
138 : FileInfo.clear();
139 : }
140 :
141 80: void SetExternalLookup(ExternalIdentifierLookup *EIL) {
142 80: ExternalLookup = EIL;
143 80: }
144 :
145 : /// LookupFile - Given a "foo" or <foo> reference, look up the indicated file,
146 : /// return null on failure. isAngled indicates whether the file reference is
147 : /// a <> reference. If successful, this returns 'UsedDir', the
148 : /// DirectoryLookup member the file was found in, or null if not applicable.
149 : /// If CurDir is non-null, the file was found in the specified directory
150 : /// search location. This is used to implement #include_next. CurFileEnt, if
151 : /// non-null, indicates where the #including file is, in case a relative
152 : /// search is needed.
153 : const FileEntry *LookupFile(llvm::StringRef Filename, bool isAngled,
154 : const DirectoryLookup *FromDir,
155 : const DirectoryLookup *&CurDir,
156 : const FileEntry *CurFileEnt);
157 :
158 : /// LookupSubframeworkHeader - Look up a subframework for the specified
159 : /// #include file. For example, if #include'ing <HIToolbox/HIToolbox.h> from
160 : /// within ".../Carbon.framework/Headers/Carbon.h", check to see if HIToolbox
161 : /// is a subframework within Carbon.framework. If so, return the FileEntry
162 : /// for the designated file, otherwise return null.
163 : const FileEntry *LookupSubframeworkHeader(llvm::StringRef Filename,
164 : const FileEntry *RelativeFileEnt);
165 :
166 : /// LookupFrameworkCache - Look up the specified framework name in our
167 : /// framework cache, returning the DirectoryEntry it is in if we know,
168 : /// otherwise, return null.
169 0: const DirectoryEntry *&LookupFrameworkCache(llvm::StringRef FWName) {
170 0: return FrameworkMap.GetOrCreateValue(FWName).getValue();
171 : }
172 :
173 : /// ShouldEnterIncludeFile - Mark the specified file as a target of of a
174 : /// #include, #include_next, or #import directive. Return false if #including
175 : /// the file will have no effect or true if we should include it.
176 : bool ShouldEnterIncludeFile(const FileEntry *File, bool isImport);
177 :
178 :
179 : /// getFileDirFlavor - Return whether the specified file is a normal header,
180 : /// a system header, or a C++ friendly system header.
181 568: SrcMgr::CharacteristicKind getFileDirFlavor(const FileEntry *File) {
182 568: return (SrcMgr::CharacteristicKind)getFileInfo(File).DirInfo;
183 : }
184 :
185 : /// MarkFileIncludeOnce - Mark the specified file as a "once only" file, e.g.
186 : /// due to #pragma once.
187 0: void MarkFileIncludeOnce(const FileEntry *File) {
188 0: getFileInfo(File).isImport = true;
189 0: }
190 :
191 : /// MarkFileSystemHeader - Mark the specified file as a system header, e.g.
192 : /// due to #pragma GCC system_header.
193 1: void MarkFileSystemHeader(const FileEntry *File) {
194 1: getFileInfo(File).DirInfo = SrcMgr::C_System;
195 1: }
196 :
197 : /// IncrementIncludeCount - Increment the count for the number of times the
198 : /// specified FileEntry has been entered.
199 2422: void IncrementIncludeCount(const FileEntry *File) {
200 2422: ++getFileInfo(File).NumIncludes;
201 2422: }
202 :
203 : /// SetFileControllingMacro - Mark the specified file as having a controlling
204 : /// macro. This is used by the multiple-include optimization to eliminate
205 : /// no-op #includes.
206 : void SetFileControllingMacro(const FileEntry *File,
207 283: const IdentifierInfo *ControllingMacro) {
208 283: getFileInfo(File).ControllingMacro = ControllingMacro;
209 283: }
210 :
211 : /// CreateHeaderMap - This method returns a HeaderMap for the specified
212 : /// FileEntry, uniquing them through the the 'HeaderMaps' datastructure.
213 : const HeaderMap *CreateHeaderMap(const FileEntry *FE);
214 :
215 0: void IncrementFrameworkLookupCount() { ++NumFrameworkLookups; }
216 :
217 : typedef std::vector<HeaderFileInfo>::iterator header_file_iterator;
218 44: header_file_iterator header_file_begin() { return FileInfo.begin(); }
219 44: header_file_iterator header_file_end() { return FileInfo.end(); }
220 :
221 : // Used by PCHReader.
222 : void setHeaderFileInfoForUID(HeaderFileInfo HFI, unsigned UID);
223 :
224 : void PrintStats();
225 : private:
226 :
227 : /// getFileInfo - Return the HeaderFileInfo structure for the specified
228 : /// FileEntry.
229 : HeaderFileInfo &getFileInfo(const FileEntry *FE);
230 : };
231 :
232 : } // end namespace clang
233 :
234 : #endif
Generated: 2010-02-10 01:31 by zcov