1226586Sdim//===--- ModuleLoader.h - Module Loader Interface ---------------*- C++ -*-===//
2226586Sdim//
3226586Sdim//                     The LLVM Compiler Infrastructure
4226586Sdim//
5226586Sdim// This file is distributed under the University of Illinois Open Source
6226586Sdim// License. See LICENSE.TXT for details.
7226586Sdim//
8226586Sdim//===----------------------------------------------------------------------===//
9226586Sdim//
10226586Sdim//  This file defines the ModuleLoader interface, which is responsible for
11226586Sdim//  loading named modules.
12226586Sdim//
13226586Sdim//===----------------------------------------------------------------------===//
14226586Sdim#ifndef LLVM_CLANG_LEX_MODULE_LOADER_H
15226586Sdim#define LLVM_CLANG_LEX_MODULE_LOADER_H
16226586Sdim
17234353Sdim#include "clang/Basic/Module.h"
18226586Sdim#include "clang/Basic/SourceLocation.h"
19234353Sdim#include "llvm/ADT/ArrayRef.h"
20249423Sdim#include "llvm/ADT/PointerIntPair.h"
21226586Sdim
22226586Sdimnamespace clang {
23226586Sdim
24226586Sdimclass IdentifierInfo;
25249423Sdimclass Module;
26249423Sdim
27234353Sdim/// \brief A sequence of identifier/location pairs used to describe a particular
28234353Sdim/// module or submodule, e.g., std.vector.
29249423Sdimtypedef ArrayRef<std::pair<IdentifierInfo *, SourceLocation> > ModuleIdPath;
30249423Sdim
31249423Sdim/// \brief Describes the result of attempting to load a module.
32249423Sdimclass ModuleLoadResult {
33249423Sdim  llvm::PointerIntPair<Module *, 1, bool> Storage;
34249423Sdim
35249423Sdimpublic:
36249423Sdim  ModuleLoadResult() : Storage() { }
37249423Sdim
38249423Sdim  ModuleLoadResult(Module *module, bool missingExpected)
39249423Sdim    : Storage(module, missingExpected) { }
40249423Sdim
41249423Sdim  operator Module *() const { return Storage.getPointer(); }
42249423Sdim
43249423Sdim  /// \brief Determines whether the module, which failed to load, was
44249423Sdim  /// actually a submodule that we expected to see (based on implying the
45249423Sdim  /// submodule from header structure), but didn't materialize in the actual
46249423Sdim  /// module.
47249423Sdim  bool isMissingExpected() const { return Storage.getInt(); }
48249423Sdim};
49249423Sdim
50226586Sdim/// \brief Abstract interface for a module loader.
51226586Sdim///
52226586Sdim/// This abstract interface describes a module loader, which is responsible
53226586Sdim/// for resolving a module name (e.g., "std") to an actual module file, and
54226586Sdim/// then loading that module.
55226586Sdimclass ModuleLoader {
56226586Sdimpublic:
57263508Sdim  ModuleLoader() : HadFatalFailure(false) {}
58263508Sdim
59226586Sdim  virtual ~ModuleLoader();
60226586Sdim
61226586Sdim  /// \brief Attempt to load the given module.
62226586Sdim  ///
63226586Sdim  /// This routine attempts to load the module described by the given
64226586Sdim  /// parameters.
65226586Sdim  ///
66226586Sdim  /// \param ImportLoc The location of the 'import' keyword.
67226586Sdim  ///
68234353Sdim  /// \param Path The identifiers (and their locations) of the module
69234353Sdim  /// "path", e.g., "std.vector" would be split into "std" and "vector".
70234353Sdim  ///
71234353Sdim  /// \param Visibility The visibility provided for the names in the loaded
72234353Sdim  /// module.
73234353Sdim  ///
74234353Sdim  /// \param IsInclusionDirective Indicates that this module is being loaded
75234353Sdim  /// implicitly, due to the presence of an inclusion directive. Otherwise,
76234353Sdim  /// it is being loaded due to an import declaration.
77234353Sdim  ///
78234353Sdim  /// \returns If successful, returns the loaded module. Otherwise, returns
79234353Sdim  /// NULL to indicate that the module could not be loaded.
80249423Sdim  virtual ModuleLoadResult loadModule(SourceLocation ImportLoc,
81249423Sdim                                      ModuleIdPath Path,
82249423Sdim                                      Module::NameVisibilityKind Visibility,
83249423Sdim                                      bool IsInclusionDirective) = 0;
84249423Sdim
85249423Sdim  /// \brief Make the given module visible.
86249423Sdim  virtual void makeModuleVisible(Module *Mod,
87249423Sdim                                 Module::NameVisibilityKind Visibility,
88249423Sdim                                 SourceLocation ImportLoc,
89249423Sdim                                 bool Complain) = 0;
90263508Sdim
91263508Sdim  bool HadFatalFailure;
92226586Sdim};
93226586Sdim
94226586Sdim}
95226586Sdim
96226586Sdim#endif
97