aboutsummaryrefslogtreecommitdiff
path: root/include/clang
diff options
context:
space:
mode:
Diffstat (limited to 'include/clang')
-rw-r--r--include/clang/Driver/CC1Options.td2
-rw-r--r--include/clang/Frontend/CompilerInstance.h15
-rw-r--r--include/clang/Frontend/FrontendOptions.h9
-rw-r--r--include/clang/Serialization/GlobalModuleIndex.h119
4 files changed, 141 insertions, 4 deletions
diff --git a/include/clang/Driver/CC1Options.td b/include/clang/Driver/CC1Options.td
index d485303350..77fa82a35d 100644
--- a/include/clang/Driver/CC1Options.td
+++ b/include/clang/Driver/CC1Options.td
@@ -289,6 +289,8 @@ def ast_dump_filter : Separate<["-"], "ast-dump-filter">,
HelpText<"Use with -ast-dump or -ast-print to dump/print only AST declaration"
" nodes having a certain substring in a qualified name. Use"
" -ast-list to list all filterable declaration node names.">;
+def generate_module_index : Flag<["-"], "generate-module-index">,
+ HelpText<"Automatically generate or update the global module index">;
let Group = Action_Group in {
diff --git a/include/clang/Frontend/CompilerInstance.h b/include/clang/Frontend/CompilerInstance.h
index 492a3c57cd..d6b3afad8c 100644
--- a/include/clang/Frontend/CompilerInstance.h
+++ b/include/clang/Frontend/CompilerInstance.h
@@ -112,7 +112,11 @@ class CompilerInstance : public ModuleLoader {
/// \brief The result of the last module import.
///
ModuleLoadResult LastModuleImportResult;
-
+
+ /// \brief Whether we should (re)build the global module index once we
+ /// have finished with this translation unit.
+ bool BuildGlobalModuleIndex;
+
/// \brief Holds information about the output file.
///
/// If TempFilename is not empty we must rename it to Filename at the end.
@@ -186,6 +190,15 @@ public:
/// setInvocation - Replace the current invocation.
void setInvocation(CompilerInvocation *Value);
+ /// \brief Indicates whether we should (re)build the global module index.
+ bool getBuildGlobalModuleIndex() const { return BuildGlobalModuleIndex; }
+
+ /// \brief Set the flag indicating whether we should (re)build the global
+ /// module index.
+ void setBuildGlobalModuleIndex(bool Build) {
+ BuildGlobalModuleIndex = Build;
+ }
+
/// }
/// @name Forwarding Methods
/// {
diff --git a/include/clang/Frontend/FrontendOptions.h b/include/clang/Frontend/FrontendOptions.h
index 00f1dc46d6..bb6da349ba 100644
--- a/include/clang/Frontend/FrontendOptions.h
+++ b/include/clang/Frontend/FrontendOptions.h
@@ -137,7 +137,9 @@ public:
/// speed up parsing in cases you do
/// not need them (e.g. with code
/// completion).
-
+ unsigned GenerateModuleIndex : 1; ///< Whether to auto-generate a
+ ///< global module index when a new
+ ///< module has been built.
CodeCompleteOptions CodeCompleteOpts;
enum {
@@ -209,8 +211,9 @@ public:
ShowStats(false), ShowTimers(false), ShowVersion(false),
FixWhatYouCan(false), FixOnlyWarnings(false), FixAndRecompile(false),
FixToTemporaries(false), ARCMTMigrateEmitARCErrors(false),
- SkipFunctionBodies(false), ARCMTAction(ARCMT_None),
- ObjCMTAction(ObjCMT_None), ProgramAction(frontend::ParseSyntaxOnly)
+ SkipFunctionBodies(false), GenerateModuleIndex(false),
+ ARCMTAction(ARCMT_None), ObjCMTAction(ObjCMT_None),
+ ProgramAction(frontend::ParseSyntaxOnly)
{}
/// getInputKindForExtension - Return the appropriate input kind for a file
diff --git a/include/clang/Serialization/GlobalModuleIndex.h b/include/clang/Serialization/GlobalModuleIndex.h
new file mode 100644
index 0000000000..cac6c3a56e
--- /dev/null
+++ b/include/clang/Serialization/GlobalModuleIndex.h
@@ -0,0 +1,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