1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
//===--- GlobalModuleIndex.h - Global Module Index --------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines the GlobalModuleIndex class, which manages a global index
// containing all of the identifiers with namespace-scope bindings attached to
// them as well as all of the selectors that name methods, across all of the
// modules within a given subdirectory of the module cache. It is used to
// improve the performance of queries such as "does this identifier have any
// top-level bindings in any module?"
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_SERIALIZATION_GLOBAL_MODULE_INDEX_H
#define LLVM_CLANG_SERIALIZATION_GLOBAL_MODULE_INDEX_H
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include <utility>
namespace clang {
class DeclarationName;
class DirectoryEntry;
class FileEntry;
class FileManager;
using llvm::SmallVector;
using llvm::SmallVectorImpl;
using llvm::StringRef;
/// \brief A global index for a set of module files, providing information about
/// the top-level identifiers and selectors within those module files.
///
/// The global index is an aid for name lookup into modules, offering a central
/// place where one can look for identifiers or selectors to determine which
/// module files contain a namespace-scope identity with that identifier or
/// a method with that selector, respectively. This allows the client to
/// restrict the search to only those module files known to have a binding for
/// that identifier or selector, improving performance. Moreover, the global
/// module index may know about module files that have not been imported, and
/// can be queried to determine which modules the currently translation could
/// or should load to fix a problem.
class GlobalModuleIndex {
/// \brief Internal constructor. Use \c readIndex() to read an index.
explicit GlobalModuleIndex(FileManager &FileMgr);
public:
/// \brief An error code returned when trying to read an index.
enum ErrorCode {
/// \brief No error occurred.
EC_None,
/// \brief The index found was out-of-date, meaning that some of the
/// module files are newer than the index.
///
/// This error code is not actually fatal, because if the index is
/// up-to-date for any module files, it is
EC_OutOfDate,
/// \brief No index was found.
EC_NotFound,
/// \brief Some other process is currently building the index; it is not
/// available yet.
EC_Building,
/// \brief There was an unspecified I/O error reading or writing the index.
EC_IOError
};
/// \brief Read a global index file for the given directory.
///
/// \param FileMgr The file manager to use for reading files.
///
/// \param Path The path to the specific module cache where the module files
/// for the intended configuration reside.
///
/// \returns A pair containing the global module index (if it exists) and
/// the error code.
static std::pair<GlobalModuleIndex *, ErrorCode>
readIndex(FileManager &FileMgr, StringRef Path);
/// \brief Retrieve the set of modules that have up-to-date indexes.
///
/// \param ModuleFiles Will be populated with the set of module files that
/// have been indexed.
void getKnownModules(SmallVectorImpl<const FileEntry *> &ModuleFiles);
/// \brief Retrieve the set of module files on which the given module file
/// directly depends.
void getModuleDependencies(const FileEntry *ModuleFile,
SmallVectorImpl<const FileEntry *> &Dependencies);
/// \brief Look for all of the module files with a namespace-scope binding
/// for the given name, e.g., a global function, variable, or type with that
/// name, or declare a method with the selector.
///
/// \param Name The name or selector to look for.
///
/// \param DeclaringModuleFiles Will be populated with the list of module
/// files that declare entities with the given name.
///
/// \returns true if any module files were found, false otherwise.
bool lookupName(DeclarationName Name,
SmallVectorImpl<const FileEntry *> &DeclaringModuleFiles);
/// \brief Write a global index into the given
///
/// \param FileMgr The file manager to use to load module files.
///
/// \param Path The path to the directory containing module files, into
/// which the global index will be written.
static ErrorCode writeIndex(FileManager &FileMgr, StringRef Path);
};
}
#endif
|