clang  3.9.0
ModuleLoader.h
Go to the documentation of this file.
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_MODULELOADER_H
15 #define LLVM_CLANG_LEX_MODULELOADER_H
16 
17 #include "clang/Basic/Module.h"
19 #include "llvm/ADT/ArrayRef.h"
20 #include "llvm/ADT/PointerIntPair.h"
21 
22 namespace clang {
23 
24 class GlobalModuleIndex;
25 class IdentifierInfo;
26 class Module;
27 
28 /// \brief A sequence of identifier/location pairs used to describe a particular
29 /// module or submodule, e.g., std.vector.
31 
32 /// \brief Describes the result of attempting to load a module.
34  llvm::PointerIntPair<Module *, 1, bool> Storage;
35 
36 public:
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.
56 class ModuleLoader {
57  // Building a module if true.
58  bool BuildingModule;
59 public:
60  explicit ModuleLoader(bool BuildingModule = false) :
61  BuildingModule(BuildingModule),
63 
64  virtual ~ModuleLoader();
65 
66  /// \brief Returns true if this instance is building a module.
67  bool buildingModule() const {
68  return BuildingModule;
69  }
70  /// \brief Flag indicating whether this instance is building a module.
71  void setBuildingModule(bool BuildingModuleFlag) {
72  BuildingModule = BuildingModuleFlag;
73  }
74 
75  /// \brief Attempt to load the given module.
76  ///
77  /// This routine attempts to load the module described by the given
78  /// parameters.
79  ///
80  /// \param ImportLoc The location of the 'import' keyword.
81  ///
82  /// \param Path The identifiers (and their locations) of the module
83  /// "path", e.g., "std.vector" would be split into "std" and "vector".
84  ///
85  /// \param Visibility The visibility provided for the names in the loaded
86  /// module.
87  ///
88  /// \param IsInclusionDirective Indicates that this module is being loaded
89  /// implicitly, due to the presence of an inclusion directive. Otherwise,
90  /// it is being loaded due to an import declaration.
91  ///
92  /// \returns If successful, returns the loaded module. Otherwise, returns
93  /// NULL to indicate that the module could not be loaded.
94  virtual ModuleLoadResult loadModule(SourceLocation ImportLoc,
95  ModuleIdPath Path,
97  bool IsInclusionDirective) = 0;
98 
99  /// \brief Make the given module visible.
100  virtual void makeModuleVisible(Module *Mod,
102  SourceLocation ImportLoc) = 0;
103 
104  /// \brief Load, create, or return global module.
105  /// This function returns an existing global module index, if one
106  /// had already been loaded or created, or loads one if it
107  /// exists, or creates one if it doesn't exist.
108  /// Also, importantly, if the index doesn't cover all the modules
109  /// in the module map, it will be update to do so here, because
110  /// of its use in searching for needed module imports and
111  /// associated fixit messages.
112  /// \param TriggerLoc The location for what triggered the load.
113  /// \returns Returns null if load failed.
115  SourceLocation TriggerLoc) = 0;
116 
117  /// Check global module index for missing imports.
118  /// \param Name The symbol name to look for.
119  /// \param TriggerLoc The location for what triggered the load.
120  /// \returns Returns true if any modules with that symbol found.
121  virtual bool lookupMissingImports(StringRef Name,
122  SourceLocation TriggerLoc) = 0;
123 
125 };
126 
127 }
128 
129 #endif
Defines the clang::Module class, which describes a module in the source code.
virtual GlobalModuleIndex * loadGlobalModuleIndex(SourceLocation TriggerLoc)=0
Load, create, or return global module.
class LLVM_ALIGNAS(8) DependentTemplateSpecializationType const IdentifierInfo * Name
Represents a template specialization type whose template cannot be resolved, e.g. ...
Definition: Type.h:4549
bool buildingModule() const
Returns true if this instance is building a module.
Definition: ModuleLoader.h:67
ArrayRef< std::pair< IdentifierInfo *, SourceLocation > > ModuleIdPath
A sequence of identifier/location pairs used to describe a particular module or submodule, e.g., std.vector.
Definition: ModuleLoader.h:26
Describes a module or submodule.
Definition: Basic/Module.h:47
bool isMissingExpected() const
Determines whether the module, which failed to load, was actually a submodule that we expected to see...
Definition: ModuleLoader.h:48
Visibility
Describes the different kinds of visibility that a declaration may have.
Definition: Visibility.h:32
ModuleLoader(bool BuildingModule=false)
Definition: ModuleLoader.h:60
Describes the result of attempting to load a module.
Definition: ModuleLoader.h:33
ModuleLoadResult(Module *module, bool missingExpected)
Definition: ModuleLoader.h:39
virtual bool lookupMissingImports(StringRef Name, SourceLocation TriggerLoc)=0
Check global module index for missing imports.
#define false
Definition: stdbool.h:33
Encodes a location in the source.
A global index for a set of module files, providing information about the identifiers within those mo...
virtual ModuleLoadResult loadModule(SourceLocation ImportLoc, ModuleIdPath Path, Module::NameVisibilityKind Visibility, bool IsInclusionDirective)=0
Attempt to load the given module.
Abstract interface for a module loader.
Definition: ModuleLoader.h:56
Defines the clang::SourceLocation class and associated facilities.
NameVisibilityKind
Describes the visibility of the various names within a particular module.
Definition: Basic/Module.h:206
void setBuildingModule(bool BuildingModuleFlag)
Flag indicating whether this instance is building a module.
Definition: ModuleLoader.h:71
virtual void makeModuleVisible(Module *Mod, Module::NameVisibilityKind Visibility, SourceLocation ImportLoc)=0
Make the given module visible.