ModuleMap.h revision 65f3b5e99009f49d51eb00a859dbd2c2ee660718
1//===--- ModuleMap.h - Describe the layout of modules -----------*- 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 ModuleMap interface, which describes the layout of a 11// module as it relates to headers. 12// 13//===----------------------------------------------------------------------===// 14 15 16#ifndef LLVM_CLANG_LEX_MODULEMAP_H 17#define LLVM_CLANG_LEX_MODULEMAP_H 18 19#include "clang/Basic/LangOptions.h" 20#include "clang/Basic/SourceManager.h" 21#include "llvm/ADT/DenseMap.h" 22#include "llvm/ADT/IntrusiveRefCntPtr.h" 23#include "llvm/ADT/SmallVector.h" 24#include "llvm/ADT/StringRef.h" 25#include "llvm/ADT/StringMap.h" 26#include <string> 27 28namespace clang { 29 30class FileEntry; 31class FileManager; 32class DiagnosticConsumer; 33class DiagnosticsEngine; 34class ModuleMapParser; 35 36class ModuleMap { 37public: 38 /// \brief Describes a module or submodule. 39 struct Module { 40 /// \brief The name of this module. 41 std::string Name; 42 43 /// \brief The location of the module definition. 44 SourceLocation DefinitionLoc; 45 46 /// \brief The parent of this module. This will be NULL for the top-level 47 /// module. 48 Module *Parent; 49 50 /// \brief The umbrella header, if any. 51 /// 52 /// Only the top-level module can have an umbrella header. 53 const FileEntry *UmbrellaHeader; 54 55 /// \brief The submodules of this module, indexed by name. 56 llvm::StringMap<Module *> SubModules; 57 58 /// \brief The headers that are part of this module. 59 llvm::SmallVector<const FileEntry *, 2> Headers; 60 61 /// \brief Whether this is an explicit submodule. 62 bool IsExplicit; 63 64 /// \brief Construct a top-level module. 65 explicit Module(StringRef Name, SourceLocation DefinitionLoc) 66 : Name(Name), DefinitionLoc(DefinitionLoc), Parent(0), UmbrellaHeader(0), 67 IsExplicit(false) { } 68 69 /// \brief Construct a new module or submodule. 70 Module(StringRef Name, SourceLocation DefinitionLoc, Module *Parent, 71 bool IsExplicit) 72 : Name(Name), DefinitionLoc(DefinitionLoc), Parent(Parent), 73 UmbrellaHeader(0), IsExplicit(IsExplicit) { 74 } 75 76 /// \brief Determine whether this module is a submodule. 77 bool isSubModule() const { return Parent != 0; } 78 79 /// \brief Retrieve the full name of this module, including the path from 80 /// its top-level module. 81 std::string getFullModuleName() const; 82 83 /// \brief Retrieve the name of the top-level module. 84 StringRef getTopLevelModuleName() const; 85 }; 86 87private: 88 SourceManager *SourceMgr; 89 llvm::IntrusiveRefCntPtr<DiagnosticsEngine> Diags; 90 LangOptions LangOpts; 91 92 /// \brief The top-level modules that are known 93 llvm::StringMap<Module *> Modules; 94 95 /// \brief Mapping from each header to the module that owns the contents of the 96 /// that header. 97 llvm::DenseMap<const FileEntry *, Module *> Headers; 98 99 friend class ModuleMapParser; 100 101public: 102 /// \brief Construct a new module map. 103 /// 104 /// \param FileMgr The file manager used to find module files and headers. 105 /// This file manager should be shared with the header-search mechanism, since 106 /// they will refer to the same headers. 107 /// 108 /// \param DC A diagnostic consumer that will be cloned for use in generating 109 /// diagnostics. 110 ModuleMap(FileManager &FileMgr, const DiagnosticConsumer &DC); 111 112 /// \brief Destroy the module map. 113 /// 114 ~ModuleMap(); 115 116 /// \brief Retrieve the module that owns the given header file, if any. 117 /// 118 /// \param File The header file that is likely to be included. 119 /// 120 /// \returns The module that owns the given header file, or null to indicate 121 /// that no module owns this header file. 122 Module *findModuleForHeader(const FileEntry *File); 123 124 /// \brief Parse the given module map file, and record any modules we 125 /// encounter. 126 /// 127 /// \param File The file to be parsed. 128 /// 129 /// \returns true if an error occurred, false otherwise. 130 bool parseModuleMapFile(const FileEntry *File); 131 132 /// \brief Dump the contents of the module map, for debugging purposes. 133 void dump(); 134}; 135 136} 137#endif 138