ModuleLoader.h revision 3b7deda7137e62810a810ce25b062927a9fc7c71
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 ArrayRef<std::pair<IdentifierInfo *, SourceLocation> > ModuleIdPath;
30
31/// \brief Describes the result of attempting to load a module.
32class ModuleLoadResult {
33  llvm::PointerIntPair<Module *, 1, bool> Storage;
34
35public:
36  ModuleLoadResult() : Storage() { }
37
38  ModuleLoadResult(Module *module, bool missingExpected)
39    : Storage(module, missingExpected) { }
40
41  operator Module *() const { return Storage.getPointer(); }
42
43  /// \brief Determines whether the module, which failed to load, was
44  /// actually a submodule that we expected to see (based on implying the
45  /// submodule from header structure), but didn't materialize in the actual
46  /// module.
47  bool isMissingExpected() const { return Storage.getInt(); }
48};
49
50/// \brief Abstract interface for a module loader.
51///
52/// This abstract interface describes a module loader, which is responsible
53/// for resolving a module name (e.g., "std") to an actual module file, and
54/// then loading that module.
55class ModuleLoader {
56public:
57  ModuleLoader() : HadFatalFailure(false) {}
58
59  virtual ~ModuleLoader();
60
61  /// \brief Attempt to load the given module.
62  ///
63  /// This routine attempts to load the module described by the given
64  /// parameters.
65  ///
66  /// \param ImportLoc The location of the 'import' keyword.
67  ///
68  /// \param Path The identifiers (and their locations) of the module
69  /// "path", e.g., "std.vector" would be split into "std" and "vector".
70  ///
71  /// \param Visibility The visibility provided for the names in the loaded
72  /// module.
73  ///
74  /// \param IsInclusionDirective Indicates that this module is being loaded
75  /// implicitly, due to the presence of an inclusion directive. Otherwise,
76  /// it is being loaded due to an import declaration.
77  ///
78  /// \returns If successful, returns the loaded module. Otherwise, returns
79  /// NULL to indicate that the module could not be loaded.
80  virtual ModuleLoadResult loadModule(SourceLocation ImportLoc,
81                                      ModuleIdPath Path,
82                                      Module::NameVisibilityKind Visibility,
83                                      bool IsInclusionDirective) = 0;
84
85  /// \brief Make the given module visible.
86  virtual void makeModuleVisible(Module *Mod,
87                                 Module::NameVisibilityKind Visibility,
88                                 SourceLocation ImportLoc,
89                                 bool Complain) = 0;
90
91  bool HadFatalFailure;
92};
93
94}
95
96#endif
97