clang API Documentation
00001 //===--- ModuleLoader.h - Module Loader Interface ---------------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file defines the ModuleLoader interface, which is responsible for 00011 // loading named modules. 00012 // 00013 //===----------------------------------------------------------------------===// 00014 #ifndef LLVM_CLANG_LEX_MODULELOADER_H 00015 #define LLVM_CLANG_LEX_MODULELOADER_H 00016 00017 #include "clang/Basic/Module.h" 00018 #include "clang/Basic/SourceLocation.h" 00019 #include "llvm/ADT/ArrayRef.h" 00020 #include "llvm/ADT/PointerIntPair.h" 00021 00022 namespace clang { 00023 00024 class GlobalModuleIndex; 00025 class IdentifierInfo; 00026 class Module; 00027 00028 /// \brief A sequence of identifier/location pairs used to describe a particular 00029 /// module or submodule, e.g., std.vector. 00030 typedef ArrayRef<std::pair<IdentifierInfo *, SourceLocation> > ModuleIdPath; 00031 00032 /// \brief Describes the result of attempting to load a module. 00033 class ModuleLoadResult { 00034 llvm::PointerIntPair<Module *, 1, bool> Storage; 00035 00036 public: 00037 ModuleLoadResult() : Storage() { } 00038 00039 ModuleLoadResult(Module *module, bool missingExpected) 00040 : Storage(module, missingExpected) { } 00041 00042 operator Module *() const { return Storage.getPointer(); } 00043 00044 /// \brief Determines whether the module, which failed to load, was 00045 /// actually a submodule that we expected to see (based on implying the 00046 /// submodule from header structure), but didn't materialize in the actual 00047 /// module. 00048 bool isMissingExpected() const { return Storage.getInt(); } 00049 }; 00050 00051 /// \brief Abstract interface for a module loader. 00052 /// 00053 /// This abstract interface describes a module loader, which is responsible 00054 /// for resolving a module name (e.g., "std") to an actual module file, and 00055 /// then loading that module. 00056 class ModuleLoader { 00057 // Building a module if true. 00058 bool BuildingModule; 00059 public: 00060 explicit ModuleLoader(bool BuildingModule = false) : 00061 BuildingModule(BuildingModule), 00062 HadFatalFailure(false) {} 00063 00064 virtual ~ModuleLoader(); 00065 00066 /// \brief Returns true if this instance is building a module. 00067 bool buildingModule() const { 00068 return BuildingModule; 00069 } 00070 /// \brief Flag indicating whether this instance is building a module. 00071 void setBuildingModule(bool BuildingModuleFlag) { 00072 BuildingModule = BuildingModuleFlag; 00073 } 00074 00075 /// \brief Attempt to load the given module. 00076 /// 00077 /// This routine attempts to load the module described by the given 00078 /// parameters. 00079 /// 00080 /// \param ImportLoc The location of the 'import' keyword. 00081 /// 00082 /// \param Path The identifiers (and their locations) of the module 00083 /// "path", e.g., "std.vector" would be split into "std" and "vector". 00084 /// 00085 /// \param Visibility The visibility provided for the names in the loaded 00086 /// module. 00087 /// 00088 /// \param IsInclusionDirective Indicates that this module is being loaded 00089 /// implicitly, due to the presence of an inclusion directive. Otherwise, 00090 /// it is being loaded due to an import declaration. 00091 /// 00092 /// \returns If successful, returns the loaded module. Otherwise, returns 00093 /// NULL to indicate that the module could not be loaded. 00094 virtual ModuleLoadResult loadModule(SourceLocation ImportLoc, 00095 ModuleIdPath Path, 00096 Module::NameVisibilityKind Visibility, 00097 bool IsInclusionDirective) = 0; 00098 00099 /// \brief Make the given module visible. 00100 virtual void makeModuleVisible(Module *Mod, 00101 Module::NameVisibilityKind Visibility, 00102 SourceLocation ImportLoc, 00103 bool Complain) = 0; 00104 00105 /// \brief Load, create, or return global module. 00106 /// This function returns an existing global module index, if one 00107 /// had already been loaded or created, or loads one if it 00108 /// exists, or creates one if it doesn't exist. 00109 /// Also, importantly, if the index doesn't cover all the modules 00110 /// in the module map, it will be update to do so here, because 00111 /// of its use in searching for needed module imports and 00112 /// associated fixit messages. 00113 /// \param TriggerLoc The location for what triggered the load. 00114 /// \returns Returns null if load failed. 00115 virtual GlobalModuleIndex *loadGlobalModuleIndex( 00116 SourceLocation TriggerLoc) = 0; 00117 00118 /// Check global module index for missing imports. 00119 /// \param Name The symbol name to look for. 00120 /// \param TriggerLoc The location for what triggered the load. 00121 /// \returns Returns true if any modules with that symbol found. 00122 virtual bool lookupMissingImports(StringRef Name, 00123 SourceLocation TriggerLoc) = 0; 00124 00125 bool HadFatalFailure; 00126 }; 00127 00128 } 00129 00130 #endif