ModuleLoader.h revision 463d90986ec54c62bf8fe31193ef5db701db48a5
1//===--- ModuleLoader.h - Module Loader Interface ---------------*- 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 ModuleLoader interface, which is responsible for
11//  loading named modules.
12//
13//===----------------------------------------------------------------------===//
14#ifndef LLVM_CLANG_LEX_MODULE_LOADER_H
15#define LLVM_CLANG_LEX_MODULE_LOADER_H
16
17#include "clang/Basic/Module.h"
18#include "clang/Basic/SourceLocation.h"
19#include "llvm/ADT/ArrayRef.h"
20#include "llvm/ADT/PointerIntPair.h"
21
22namespace clang {
23
24class IdentifierInfo;
25class Module;
26
27/// \brief A sequence of identifier/location pairs used to describe a particular
28/// module or submodule, e.g., std.vector.
29typedef llvm::ArrayRef<std::pair<IdentifierInfo*, SourceLocation> >
30  ModuleIdPath;
31
32/// \brief Describes the result of attempting to load a module.
33class ModuleLoadResult {
34  llvm::PointerIntPair<Module *, 1, bool> Storage;
35
36public:
37  ModuleLoadResult() : Storage() { }
38
39  ModuleLoadResult(Module *module, bool missingExpected)
40    : Storage(module, missingExpected) { }
41
42  operator Module *() const { return Storage.getPointer(); }
43
44  /// \brief Determines whether the module, which failed to load, was
45  /// actually a submodule that we expected to see (based on implying the
46  /// submodule from header structure), but didn't materialize in the actual
47  /// module.
48  bool isMissingExpected() const { return Storage.getInt(); }
49};
50
51/// \brief Abstract interface for a module loader.
52///
53/// This abstract interface describes a module loader, which is responsible
54/// for resolving a module name (e.g., "std") to an actual module file, and
55/// then loading that module.
56class ModuleLoader {
57public:
58  virtual ~ModuleLoader();
59
60  /// \brief Attempt to load the given module.
61  ///
62  /// This routine attempts to load the module described by the given
63  /// parameters.
64  ///
65  /// \param ImportLoc The location of the 'import' keyword.
66  ///
67  /// \param Path The identifiers (and their locations) of the module
68  /// "path", e.g., "std.vector" would be split into "std" and "vector".
69  ///
70  /// \param Visibility The visibility provided for the names in the loaded
71  /// module.
72  ///
73  /// \param IsInclusionDirective Indicates that this module is being loaded
74  /// implicitly, due to the presence of an inclusion directive. Otherwise,
75  /// it is being loaded due to an import declaration.
76  ///
77  /// \returns If successful, returns the loaded module. Otherwise, returns
78  /// NULL to indicate that the module could not be loaded.
79  virtual ModuleLoadResult loadModule(SourceLocation ImportLoc,
80                                      ModuleIdPath Path,
81                                      Module::NameVisibilityKind Visibility,
82                                      bool IsInclusionDirective) = 0;
83};
84
85}
86
87#endif
88