Module.h revision 63a726870b486e0470c3a4b11cf62bab8be00b73
11a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor//===--- Module.h - Describe a module ---------------------------*- C++ -*-===// 21a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor// 31a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor// The LLVM Compiler Infrastructure 41a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor// 51a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor// This file is distributed under the University of Illinois Open Source 61a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor// License. See LICENSE.TXT for details. 71a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor// 81a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor//===----------------------------------------------------------------------===// 92f7f5b1f5ff023cb8c4008ae53a12b09e3ea2622James Dennett/// 102f7f5b1f5ff023cb8c4008ae53a12b09e3ea2622James Dennett/// \file 112f7f5b1f5ff023cb8c4008ae53a12b09e3ea2622James Dennett/// \brief Defines the clang::Module class, which describes a module in the 122f7f5b1f5ff023cb8c4008ae53a12b09e3ea2622James Dennett/// source code. 132f7f5b1f5ff023cb8c4008ae53a12b09e3ea2622James Dennett/// 141a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor//===----------------------------------------------------------------------===// 151a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor#ifndef LLVM_CLANG_BASIC_MODULE_H 161a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor#define LLVM_CLANG_BASIC_MODULE_H 171a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor 181a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor#include "clang/Basic/SourceLocation.h" 1990db26000aefe9335370013eec64c85232d80227Douglas Gregor#include "llvm/ADT/PointerIntPair.h" 2010694cee2588442bee1e717f5042c58ffee25279Douglas Gregor#include "llvm/ADT/PointerUnion.h" 2130a2e16f6c27f888dd11eba6bbbae1e980078fcbChandler Carruth#include "llvm/ADT/SetVector.h" 221a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor#include "llvm/ADT/SmallVector.h" 231a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor#include "llvm/ADT/StringMap.h" 241a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor#include "llvm/ADT/StringRef.h" 251a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor#include <string> 2690db26000aefe9335370013eec64c85232d80227Douglas Gregor#include <utility> 27b7a7819473709c01ea024a2dc15e99d38f0f8760Douglas Gregor#include <vector> 281a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor 291a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregornamespace llvm { 301a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor class raw_ostream; 311a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor} 321a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor 331a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregornamespace clang { 341a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor 3510694cee2588442bee1e717f5042c58ffee25279Douglas Gregorclass DirectoryEntry; 3651f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregorclass FileEntry; 37c1d22393628a145e54396c0ac66e9625d13a7658Argyrios Kyrtzidisclass FileManager; 3851f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregorclass LangOptions; 39dc58aa71026cce539ca9b5c2c52cc4efc7bd77feDouglas Gregorclass TargetInfo; 4010694cee2588442bee1e717f5042c58ffee25279Douglas Gregor 4190db26000aefe9335370013eec64c85232d80227Douglas Gregor/// \brief Describes the name of a module. 42cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenkotypedef SmallVector<std::pair<std::string, SourceLocation>, 2> ModuleId; 4390db26000aefe9335370013eec64c85232d80227Douglas Gregor 441a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor/// \brief Describes a module or submodule. 451a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregorclass Module { 461a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregorpublic: 471a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor /// \brief The name of this module. 481a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor std::string Name; 491a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor 501a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor /// \brief The location of the module definition. 511a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor SourceLocation DefinitionLoc; 521a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor 531a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor /// \brief The parent of this module. This will be NULL for the top-level 541a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor /// module. 551a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor Module *Parent; 561a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor 5710694cee2588442bee1e717f5042c58ffee25279Douglas Gregor /// \brief The umbrella header or directory. 5810694cee2588442bee1e717f5042c58ffee25279Douglas Gregor llvm::PointerUnion<const DirectoryEntry *, const FileEntry *> Umbrella; 591a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor 60b7a7819473709c01ea024a2dc15e99d38f0f8760Douglas Gregorprivate: 611a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor /// \brief The submodules of this module, indexed by name. 62b7a7819473709c01ea024a2dc15e99d38f0f8760Douglas Gregor std::vector<Module *> SubModules; 631a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor 64b7a7819473709c01ea024a2dc15e99d38f0f8760Douglas Gregor /// \brief A mapping from the submodule name to the index into the 65b7a7819473709c01ea024a2dc15e99d38f0f8760Douglas Gregor /// \c SubModules vector at which that submodule resides. 66b7a7819473709c01ea024a2dc15e99d38f0f8760Douglas Gregor llvm::StringMap<unsigned> SubModuleIndex; 67e2ac16b09ea66ad955752381b82fb8719d003e5eArgyrios Kyrtzidis 68e2ac16b09ea66ad955752381b82fb8719d003e5eArgyrios Kyrtzidis /// \brief The AST file if this is a top-level module which has a 69e2ac16b09ea66ad955752381b82fb8719d003e5eArgyrios Kyrtzidis /// corresponding serialized AST file, or null otherwise. 70e2ac16b09ea66ad955752381b82fb8719d003e5eArgyrios Kyrtzidis const FileEntry *ASTFile; 71c1d22393628a145e54396c0ac66e9625d13a7658Argyrios Kyrtzidis 72c1d22393628a145e54396c0ac66e9625d13a7658Argyrios Kyrtzidis /// \brief The top-level headers associated with this module. 73c1d22393628a145e54396c0ac66e9625d13a7658Argyrios Kyrtzidis llvm::SmallSetVector<const FileEntry *, 2> TopHeaders; 74c1d22393628a145e54396c0ac66e9625d13a7658Argyrios Kyrtzidis 75c1d22393628a145e54396c0ac66e9625d13a7658Argyrios Kyrtzidis /// \brief top-level header filenames that aren't resolved to FileEntries yet. 76c1d22393628a145e54396c0ac66e9625d13a7658Argyrios Kyrtzidis std::vector<std::string> TopHeaderNames; 77c1d22393628a145e54396c0ac66e9625d13a7658Argyrios Kyrtzidis 78b7a7819473709c01ea024a2dc15e99d38f0f8760Douglas Gregorpublic: 791a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor /// \brief The headers that are part of this module. 80cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko SmallVector<const FileEntry *, 2> Headers; 8151f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor 822b49d1f0ad790a8a5d514af1be211591a746cb73Douglas Gregor /// \brief The headers that are explicitly excluded from this module. 83cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko SmallVector<const FileEntry *, 2> ExcludedHeaders; 842b49d1f0ad790a8a5d514af1be211591a746cb73Douglas Gregor 8551f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor /// \brief The set of language features required to use this module. 8651f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor /// 8751f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor /// If any of these features is not present, the \c IsAvailable bit 8851f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor /// will be false to indicate that this (sub)module is not 8951f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor /// available. 90cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko SmallVector<std::string, 2> Requires; 9151f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor 9251f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor /// \brief Whether this module is available in the current 9351f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor /// translation unit. 9451f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor unsigned IsAvailable : 1; 9551f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor 96305dc3ebaa0bea5f3b789e4b54afc79c25907615Douglas Gregor /// \brief Whether this module was loaded from a module file. 97305dc3ebaa0bea5f3b789e4b54afc79c25907615Douglas Gregor unsigned IsFromModuleFile : 1; 98305dc3ebaa0bea5f3b789e4b54afc79c25907615Douglas Gregor 991a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor /// \brief Whether this is a framework module. 1001e12368db12005ddd92fd9188c86383fe30ef443Douglas Gregor unsigned IsFramework : 1; 1011a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor 1021a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor /// \brief Whether this is an explicit submodule. 1031e12368db12005ddd92fd9188c86383fe30ef443Douglas Gregor unsigned IsExplicit : 1; 1041e12368db12005ddd92fd9188c86383fe30ef443Douglas Gregor 105a1f1fad8b60e1cb9d21a40a37f2e03150bcbeb6fDouglas Gregor /// \brief Whether this is a "system" module (which assumes that all 106a1f1fad8b60e1cb9d21a40a37f2e03150bcbeb6fDouglas Gregor /// headers in it are system headers). 107a1f1fad8b60e1cb9d21a40a37f2e03150bcbeb6fDouglas Gregor unsigned IsSystem : 1; 108a1f1fad8b60e1cb9d21a40a37f2e03150bcbeb6fDouglas Gregor 1091e12368db12005ddd92fd9188c86383fe30ef443Douglas Gregor /// \brief Whether we should infer submodules for this module based on 1101e12368db12005ddd92fd9188c86383fe30ef443Douglas Gregor /// the headers. 1111e12368db12005ddd92fd9188c86383fe30ef443Douglas Gregor /// 1121e12368db12005ddd92fd9188c86383fe30ef443Douglas Gregor /// Submodules can only be inferred for modules with an umbrella header. 1131e12368db12005ddd92fd9188c86383fe30ef443Douglas Gregor unsigned InferSubmodules : 1; 1141e12368db12005ddd92fd9188c86383fe30ef443Douglas Gregor 1151e12368db12005ddd92fd9188c86383fe30ef443Douglas Gregor /// \brief Whether, when inferring submodules, the inferred submodules 1161e12368db12005ddd92fd9188c86383fe30ef443Douglas Gregor /// should be explicit. 1171e12368db12005ddd92fd9188c86383fe30ef443Douglas Gregor unsigned InferExplicitSubmodules : 1; 1181e12368db12005ddd92fd9188c86383fe30ef443Douglas Gregor 1191e12368db12005ddd92fd9188c86383fe30ef443Douglas Gregor /// \brief Whether, when inferring submodules, the inferr submodules should 1201e12368db12005ddd92fd9188c86383fe30ef443Douglas Gregor /// export all modules they import (e.g., the equivalent of "export *"). 1211e12368db12005ddd92fd9188c86383fe30ef443Douglas Gregor unsigned InferExportWildcard : 1; 12263a726870b486e0470c3a4b11cf62bab8be00b73Douglas Gregor 12363a726870b486e0470c3a4b11cf62bab8be00b73Douglas Gregor /// \brief Whether the set of configuration macros is exhaustive. 12463a726870b486e0470c3a4b11cf62bab8be00b73Douglas Gregor /// 12563a726870b486e0470c3a4b11cf62bab8be00b73Douglas Gregor /// When the set of configuration macros is exhaustive, meaning 12663a726870b486e0470c3a4b11cf62bab8be00b73Douglas Gregor /// that no identifier not in this list should affect how the module is 12763a726870b486e0470c3a4b11cf62bab8be00b73Douglas Gregor /// built. 12863a726870b486e0470c3a4b11cf62bab8be00b73Douglas Gregor unsigned ConfigMacrosExhaustive : 1; 12963a726870b486e0470c3a4b11cf62bab8be00b73Douglas Gregor 1305e35693721364673f8196e4f5a370f56b92e6053Douglas Gregor /// \brief Describes the visibility of the various names within a 1315e35693721364673f8196e4f5a370f56b92e6053Douglas Gregor /// particular module. 1325e35693721364673f8196e4f5a370f56b92e6053Douglas Gregor enum NameVisibilityKind { 1335e35693721364673f8196e4f5a370f56b92e6053Douglas Gregor /// \brief All of the names in this module are hidden. 1345e35693721364673f8196e4f5a370f56b92e6053Douglas Gregor /// 1355e35693721364673f8196e4f5a370f56b92e6053Douglas Gregor Hidden, 1365e35693721364673f8196e4f5a370f56b92e6053Douglas Gregor /// \brief Only the macro names in this module are visible. 1375e35693721364673f8196e4f5a370f56b92e6053Douglas Gregor MacrosVisible, 1385e35693721364673f8196e4f5a370f56b92e6053Douglas Gregor /// \brief All of the names in this module are visible. 1395e35693721364673f8196e4f5a370f56b92e6053Douglas Gregor AllVisible 1405e35693721364673f8196e4f5a370f56b92e6053Douglas Gregor }; 1415e35693721364673f8196e4f5a370f56b92e6053Douglas Gregor 1425e35693721364673f8196e4f5a370f56b92e6053Douglas Gregor ///\ brief The visibility of names within this particular module. 1435e35693721364673f8196e4f5a370f56b92e6053Douglas Gregor NameVisibilityKind NameVisibility; 14455988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor 1451e12368db12005ddd92fd9188c86383fe30ef443Douglas Gregor /// \brief The location of the inferred submodule. 1461e12368db12005ddd92fd9188c86383fe30ef443Douglas Gregor SourceLocation InferredSubmoduleLoc; 1471e12368db12005ddd92fd9188c86383fe30ef443Douglas Gregor 14855988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor /// \brief The set of modules imported by this module, and on which this 14955988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor /// module depends. 150cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko SmallVector<Module *, 2> Imports; 1515e35693721364673f8196e4f5a370f56b92e6053Douglas Gregor 15290db26000aefe9335370013eec64c85232d80227Douglas Gregor /// \brief Describes an exported module. 15390db26000aefe9335370013eec64c85232d80227Douglas Gregor /// 15490db26000aefe9335370013eec64c85232d80227Douglas Gregor /// The pointer is the module being re-exported, while the bit will be true 15590db26000aefe9335370013eec64c85232d80227Douglas Gregor /// to indicate that this is a wildcard export. 15690db26000aefe9335370013eec64c85232d80227Douglas Gregor typedef llvm::PointerIntPair<Module *, 1, bool> ExportDecl; 15790db26000aefe9335370013eec64c85232d80227Douglas Gregor 15890db26000aefe9335370013eec64c85232d80227Douglas Gregor /// \brief The set of export declarations. 159cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko SmallVector<ExportDecl, 2> Exports; 16090db26000aefe9335370013eec64c85232d80227Douglas Gregor 16190db26000aefe9335370013eec64c85232d80227Douglas Gregor /// \brief Describes an exported module that has not yet been resolved 1622f7f5b1f5ff023cb8c4008ae53a12b09e3ea2622James Dennett /// (perhaps because the module it refers to has not yet been loaded). 16390db26000aefe9335370013eec64c85232d80227Douglas Gregor struct UnresolvedExportDecl { 16490db26000aefe9335370013eec64c85232d80227Douglas Gregor /// \brief The location of the 'export' keyword in the module map file. 16590db26000aefe9335370013eec64c85232d80227Douglas Gregor SourceLocation ExportLoc; 16690db26000aefe9335370013eec64c85232d80227Douglas Gregor 16790db26000aefe9335370013eec64c85232d80227Douglas Gregor /// \brief The name of the module. 16890db26000aefe9335370013eec64c85232d80227Douglas Gregor ModuleId Id; 16990db26000aefe9335370013eec64c85232d80227Douglas Gregor 17090db26000aefe9335370013eec64c85232d80227Douglas Gregor /// \brief Whether this export declaration ends in a wildcard, indicating 17190db26000aefe9335370013eec64c85232d80227Douglas Gregor /// that all of its submodules should be exported (rather than the named 17290db26000aefe9335370013eec64c85232d80227Douglas Gregor /// module itself). 17390db26000aefe9335370013eec64c85232d80227Douglas Gregor bool Wildcard; 17490db26000aefe9335370013eec64c85232d80227Douglas Gregor }; 17590db26000aefe9335370013eec64c85232d80227Douglas Gregor 17690db26000aefe9335370013eec64c85232d80227Douglas Gregor /// \brief The set of export declarations that have yet to be resolved. 177cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko SmallVector<UnresolvedExportDecl, 2> UnresolvedExports; 178b6cbe517237c3c223beb064d60d5b49e56d65c06Douglas Gregor 179b6cbe517237c3c223beb064d60d5b49e56d65c06Douglas Gregor /// \brief A library or framework to link against when an entity from this 180b6cbe517237c3c223beb064d60d5b49e56d65c06Douglas Gregor /// module is used. 181b6cbe517237c3c223beb064d60d5b49e56d65c06Douglas Gregor struct LinkLibrary { 182b6cbe517237c3c223beb064d60d5b49e56d65c06Douglas Gregor LinkLibrary() : IsFramework(false) { } 183b6cbe517237c3c223beb064d60d5b49e56d65c06Douglas Gregor LinkLibrary(const std::string &Library, bool IsFramework) 184b6cbe517237c3c223beb064d60d5b49e56d65c06Douglas Gregor : Library(Library), IsFramework(IsFramework) { } 185b6cbe517237c3c223beb064d60d5b49e56d65c06Douglas Gregor 186b6cbe517237c3c223beb064d60d5b49e56d65c06Douglas Gregor /// \brief The library to link against. 187b6cbe517237c3c223beb064d60d5b49e56d65c06Douglas Gregor /// 188b6cbe517237c3c223beb064d60d5b49e56d65c06Douglas Gregor /// This will typically be a library or framework name, but can also 189b6cbe517237c3c223beb064d60d5b49e56d65c06Douglas Gregor /// be an absolute path to the library or framework. 190b6cbe517237c3c223beb064d60d5b49e56d65c06Douglas Gregor std::string Library; 191b6cbe517237c3c223beb064d60d5b49e56d65c06Douglas Gregor 192b6cbe517237c3c223beb064d60d5b49e56d65c06Douglas Gregor /// \brief Whether this is a framework rather than a library. 193b6cbe517237c3c223beb064d60d5b49e56d65c06Douglas Gregor bool IsFramework; 194b6cbe517237c3c223beb064d60d5b49e56d65c06Douglas Gregor }; 195b6cbe517237c3c223beb064d60d5b49e56d65c06Douglas Gregor 196b6cbe517237c3c223beb064d60d5b49e56d65c06Douglas Gregor /// \brief The set of libraries or frameworks to link against when 197b6cbe517237c3c223beb064d60d5b49e56d65c06Douglas Gregor /// an entity from this module is used. 198b6cbe517237c3c223beb064d60d5b49e56d65c06Douglas Gregor llvm::SmallVector<LinkLibrary, 2> LinkLibraries; 199b6cbe517237c3c223beb064d60d5b49e56d65c06Douglas Gregor 20063a726870b486e0470c3a4b11cf62bab8be00b73Douglas Gregor /// \brief The set of "configuration macros", which are macros that 20163a726870b486e0470c3a4b11cf62bab8be00b73Douglas Gregor /// (intentionally) change how this module is built. 20263a726870b486e0470c3a4b11cf62bab8be00b73Douglas Gregor std::vector<std::string> ConfigMacros; 20363a726870b486e0470c3a4b11cf62bab8be00b73Douglas Gregor 2041a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor /// \brief Construct a top-level module. 2051a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor explicit Module(StringRef Name, SourceLocation DefinitionLoc, 2061a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor bool IsFramework) 207e2ac16b09ea66ad955752381b82fb8719d003e5eArgyrios Kyrtzidis : Name(Name), DefinitionLoc(DefinitionLoc), Parent(0),Umbrella(),ASTFile(0), 20851f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor IsAvailable(true), IsFromModuleFile(false), IsFramework(IsFramework), 209a1f1fad8b60e1cb9d21a40a37f2e03150bcbeb6fDouglas Gregor IsExplicit(false), IsSystem(false), 210a1f1fad8b60e1cb9d21a40a37f2e03150bcbeb6fDouglas Gregor InferSubmodules(false), InferExplicitSubmodules(false), 21163a726870b486e0470c3a4b11cf62bab8be00b73Douglas Gregor InferExportWildcard(false), ConfigMacrosExhaustive(false), 21263a726870b486e0470c3a4b11cf62bab8be00b73Douglas Gregor NameVisibility(Hidden) { } 2131a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor 214a1f1fad8b60e1cb9d21a40a37f2e03150bcbeb6fDouglas Gregor /// \brief Construct a new module or submodule. 2151a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor Module(StringRef Name, SourceLocation DefinitionLoc, Module *Parent, 216b7a7819473709c01ea024a2dc15e99d38f0f8760Douglas Gregor bool IsFramework, bool IsExplicit); 2171a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor 2181a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor ~Module(); 2191a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor 22051f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor /// \brief Determine whether this module is available for use within the 22151f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor /// current translation unit. 22251f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor bool isAvailable() const { return IsAvailable; } 22351f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor 22451f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor /// \brief Determine whether this module is available for use within the 22551f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor /// current translation unit. 22651f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor /// 22751f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor /// \param LangOpts The language options used for the current 22851f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor /// translation unit. 22951f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor /// 230dc58aa71026cce539ca9b5c2c52cc4efc7bd77feDouglas Gregor /// \param Target The target options used for the current translation unit. 231dc58aa71026cce539ca9b5c2c52cc4efc7bd77feDouglas Gregor /// 23251f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor /// \param Feature If this module is unavailable, this parameter 23351f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor /// will be set to one of the features that is required for use of 23451f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor /// this module (but is not available). 235dc58aa71026cce539ca9b5c2c52cc4efc7bd77feDouglas Gregor bool isAvailable(const LangOptions &LangOpts, 236dc58aa71026cce539ca9b5c2c52cc4efc7bd77feDouglas Gregor const TargetInfo &Target, 237dc58aa71026cce539ca9b5c2c52cc4efc7bd77feDouglas Gregor StringRef &Feature) const; 23851f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor 2391a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor /// \brief Determine whether this module is a submodule. 2401a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor bool isSubModule() const { return Parent != 0; } 2411a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor 2420adaa880993ad23186c87c7f98e7a3fd2697742cDouglas Gregor /// \brief Determine whether this module is a submodule of the given other 2430adaa880993ad23186c87c7f98e7a3fd2697742cDouglas Gregor /// module. 2440adaa880993ad23186c87c7f98e7a3fd2697742cDouglas Gregor bool isSubModuleOf(Module *Other) const; 2450adaa880993ad23186c87c7f98e7a3fd2697742cDouglas Gregor 2461a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor /// \brief Determine whether this module is a part of a framework, 2471a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor /// either because it is a framework module or because it is a submodule 2481a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor /// of a framework module. 2491a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor bool isPartOfFramework() const { 2501a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor for (const Module *Mod = this; Mod; Mod = Mod->Parent) 2511a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor if (Mod->IsFramework) 2521a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor return true; 2531a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor 2541a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor return false; 2551a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor } 2568767dc29ec23f96e71658f760333bdf5d87283d5Douglas Gregor 2578767dc29ec23f96e71658f760333bdf5d87283d5Douglas Gregor /// \brief Determine whether this module is a subframework of another 2588767dc29ec23f96e71658f760333bdf5d87283d5Douglas Gregor /// framework. 2598767dc29ec23f96e71658f760333bdf5d87283d5Douglas Gregor bool isSubFramework() const { 2608767dc29ec23f96e71658f760333bdf5d87283d5Douglas Gregor return IsFramework && Parent && Parent->isPartOfFramework(); 2618767dc29ec23f96e71658f760333bdf5d87283d5Douglas Gregor } 2628767dc29ec23f96e71658f760333bdf5d87283d5Douglas Gregor 2631a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor /// \brief Retrieve the full name of this module, including the path from 2641a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor /// its top-level module. 2651a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor std::string getFullModuleName() const; 2661e12368db12005ddd92fd9188c86383fe30ef443Douglas Gregor 2671e12368db12005ddd92fd9188c86383fe30ef443Douglas Gregor /// \brief Retrieve the top-level module for this (sub)module, which may 2681e12368db12005ddd92fd9188c86383fe30ef443Douglas Gregor /// be this module. 2691e12368db12005ddd92fd9188c86383fe30ef443Douglas Gregor Module *getTopLevelModule() { 2701e12368db12005ddd92fd9188c86383fe30ef443Douglas Gregor return const_cast<Module *>( 2711e12368db12005ddd92fd9188c86383fe30ef443Douglas Gregor const_cast<const Module *>(this)->getTopLevelModule()); 2721e12368db12005ddd92fd9188c86383fe30ef443Douglas Gregor } 2731e12368db12005ddd92fd9188c86383fe30ef443Douglas Gregor 2741e12368db12005ddd92fd9188c86383fe30ef443Douglas Gregor /// \brief Retrieve the top-level module for this (sub)module, which may 2751e12368db12005ddd92fd9188c86383fe30ef443Douglas Gregor /// be this module. 2761e12368db12005ddd92fd9188c86383fe30ef443Douglas Gregor const Module *getTopLevelModule() const; 2771a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor 2781a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor /// \brief Retrieve the name of the top-level module. 2791a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor /// 2801e12368db12005ddd92fd9188c86383fe30ef443Douglas Gregor StringRef getTopLevelModuleName() const { 2811e12368db12005ddd92fd9188c86383fe30ef443Douglas Gregor return getTopLevelModule()->Name; 2821e12368db12005ddd92fd9188c86383fe30ef443Douglas Gregor } 283e2ac16b09ea66ad955752381b82fb8719d003e5eArgyrios Kyrtzidis 284e2ac16b09ea66ad955752381b82fb8719d003e5eArgyrios Kyrtzidis /// \brief The serialized AST file for this module, if one was created. 285e2ac16b09ea66ad955752381b82fb8719d003e5eArgyrios Kyrtzidis const FileEntry *getASTFile() const { 286e2ac16b09ea66ad955752381b82fb8719d003e5eArgyrios Kyrtzidis return getTopLevelModule()->ASTFile; 287e2ac16b09ea66ad955752381b82fb8719d003e5eArgyrios Kyrtzidis } 288e2ac16b09ea66ad955752381b82fb8719d003e5eArgyrios Kyrtzidis 289e2ac16b09ea66ad955752381b82fb8719d003e5eArgyrios Kyrtzidis /// \brief Set the serialized AST file for the top-level module of this module. 290e2ac16b09ea66ad955752381b82fb8719d003e5eArgyrios Kyrtzidis void setASTFile(const FileEntry *File) { 291e2ac16b09ea66ad955752381b82fb8719d003e5eArgyrios Kyrtzidis assert((getASTFile() == 0 || getASTFile() == File) && "file path changed"); 292e2ac16b09ea66ad955752381b82fb8719d003e5eArgyrios Kyrtzidis getTopLevelModule()->ASTFile = File; 293e2ac16b09ea66ad955752381b82fb8719d003e5eArgyrios Kyrtzidis } 294e2ac16b09ea66ad955752381b82fb8719d003e5eArgyrios Kyrtzidis 29510694cee2588442bee1e717f5042c58ffee25279Douglas Gregor /// \brief Retrieve the directory for which this module serves as the 29610694cee2588442bee1e717f5042c58ffee25279Douglas Gregor /// umbrella. 29710694cee2588442bee1e717f5042c58ffee25279Douglas Gregor const DirectoryEntry *getUmbrellaDir() const; 29810694cee2588442bee1e717f5042c58ffee25279Douglas Gregor 29910694cee2588442bee1e717f5042c58ffee25279Douglas Gregor /// \brief Retrieve the header that serves as the umbrella header for this 30010694cee2588442bee1e717f5042c58ffee25279Douglas Gregor /// module. 30110694cee2588442bee1e717f5042c58ffee25279Douglas Gregor const FileEntry *getUmbrellaHeader() const { 30210694cee2588442bee1e717f5042c58ffee25279Douglas Gregor return Umbrella.dyn_cast<const FileEntry *>(); 30310694cee2588442bee1e717f5042c58ffee25279Douglas Gregor } 30410694cee2588442bee1e717f5042c58ffee25279Douglas Gregor 3056a1db484f32eb791840dd55a8d45c86ff5bd0834Douglas Gregor /// \brief Determine whether this module has an umbrella directory that is 3066a1db484f32eb791840dd55a8d45c86ff5bd0834Douglas Gregor /// not based on an umbrella header. 3076a1db484f32eb791840dd55a8d45c86ff5bd0834Douglas Gregor bool hasUmbrellaDir() const { 3086a1db484f32eb791840dd55a8d45c86ff5bd0834Douglas Gregor return Umbrella && Umbrella.is<const DirectoryEntry *>(); 3096a1db484f32eb791840dd55a8d45c86ff5bd0834Douglas Gregor } 31051f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor 311c1d22393628a145e54396c0ac66e9625d13a7658Argyrios Kyrtzidis /// \brief Add a top-level header associated with this module. 312c1d22393628a145e54396c0ac66e9625d13a7658Argyrios Kyrtzidis void addTopHeader(const FileEntry *File) { 313c1d22393628a145e54396c0ac66e9625d13a7658Argyrios Kyrtzidis assert(File); 314c1d22393628a145e54396c0ac66e9625d13a7658Argyrios Kyrtzidis TopHeaders.insert(File); 315c1d22393628a145e54396c0ac66e9625d13a7658Argyrios Kyrtzidis } 316c1d22393628a145e54396c0ac66e9625d13a7658Argyrios Kyrtzidis 317c1d22393628a145e54396c0ac66e9625d13a7658Argyrios Kyrtzidis /// \brief Add a top-level header filename associated with this module. 318c1d22393628a145e54396c0ac66e9625d13a7658Argyrios Kyrtzidis void addTopHeaderFilename(StringRef Filename) { 319c1d22393628a145e54396c0ac66e9625d13a7658Argyrios Kyrtzidis TopHeaderNames.push_back(Filename); 320c1d22393628a145e54396c0ac66e9625d13a7658Argyrios Kyrtzidis } 321c1d22393628a145e54396c0ac66e9625d13a7658Argyrios Kyrtzidis 322c1d22393628a145e54396c0ac66e9625d13a7658Argyrios Kyrtzidis /// \brief The top-level headers associated with this module. 323c1d22393628a145e54396c0ac66e9625d13a7658Argyrios Kyrtzidis ArrayRef<const FileEntry *> getTopHeaders(FileManager &FileMgr); 324c1d22393628a145e54396c0ac66e9625d13a7658Argyrios Kyrtzidis 325c9e4b4b091e9bec50d8918a02ea155220b513d47James Dennett /// \brief Add the given feature requirement to the list of features 32651f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor /// required by this module. 32751f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor /// 32851f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor /// \param Feature The feature that is required by this module (and 32951f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor /// its submodules). 33051f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor /// 33151f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor /// \param LangOpts The set of language options that will be used to 33251f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor /// evaluate the availability of this feature. 333dc58aa71026cce539ca9b5c2c52cc4efc7bd77feDouglas Gregor /// 334dc58aa71026cce539ca9b5c2c52cc4efc7bd77feDouglas Gregor /// \param Target The target options that will be used to evaluate the 335dc58aa71026cce539ca9b5c2c52cc4efc7bd77feDouglas Gregor /// availability of this feature. 336dc58aa71026cce539ca9b5c2c52cc4efc7bd77feDouglas Gregor void addRequirement(StringRef Feature, const LangOptions &LangOpts, 337dc58aa71026cce539ca9b5c2c52cc4efc7bd77feDouglas Gregor const TargetInfo &Target); 33851f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor 339b7a7819473709c01ea024a2dc15e99d38f0f8760Douglas Gregor /// \brief Find the submodule with the given name. 340b7a7819473709c01ea024a2dc15e99d38f0f8760Douglas Gregor /// 341b7a7819473709c01ea024a2dc15e99d38f0f8760Douglas Gregor /// \returns The submodule if found, or NULL otherwise. 342b7a7819473709c01ea024a2dc15e99d38f0f8760Douglas Gregor Module *findSubmodule(StringRef Name) const; 34363a726870b486e0470c3a4b11cf62bab8be00b73Douglas Gregor 344b7a7819473709c01ea024a2dc15e99d38f0f8760Douglas Gregor typedef std::vector<Module *>::iterator submodule_iterator; 345b7a7819473709c01ea024a2dc15e99d38f0f8760Douglas Gregor typedef std::vector<Module *>::const_iterator submodule_const_iterator; 346b7a7819473709c01ea024a2dc15e99d38f0f8760Douglas Gregor 347b7a7819473709c01ea024a2dc15e99d38f0f8760Douglas Gregor submodule_iterator submodule_begin() { return SubModules.begin(); } 348b7a7819473709c01ea024a2dc15e99d38f0f8760Douglas Gregor submodule_const_iterator submodule_begin() const {return SubModules.begin();} 349b7a7819473709c01ea024a2dc15e99d38f0f8760Douglas Gregor submodule_iterator submodule_end() { return SubModules.end(); } 350b7a7819473709c01ea024a2dc15e99d38f0f8760Douglas Gregor submodule_const_iterator submodule_end() const { return SubModules.end(); } 35121a0004d80f50808ee343ae70092f6260a4c9477Argyrios Kyrtzidis 35221a0004d80f50808ee343ae70092f6260a4c9477Argyrios Kyrtzidis /// \brief Returns the exported modules based on the wildcard restrictions. 35321a0004d80f50808ee343ae70092f6260a4c9477Argyrios Kyrtzidis void getExportedModules(SmallVectorImpl<Module *> &Exported) const; 35421a0004d80f50808ee343ae70092f6260a4c9477Argyrios Kyrtzidis 3552a857180050fb78b356c17931e311eef7f2daf3eArgyrios Kyrtzidis static StringRef getModuleInputBufferName() { 3562a857180050fb78b356c17931e311eef7f2daf3eArgyrios Kyrtzidis return "<module-includes>"; 3572a857180050fb78b356c17931e311eef7f2daf3eArgyrios Kyrtzidis } 3582a857180050fb78b356c17931e311eef7f2daf3eArgyrios Kyrtzidis 3591a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor /// \brief Print the module map for this module to the given stream. 3601a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor /// 361cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko void print(raw_ostream &OS, unsigned Indent = 0) const; 3621a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor 3631a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor /// \brief Dump the contents of this module to the given output stream. 3641a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor void dump() const; 3651a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor}; 3661a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor 3671a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor} // end namespace clang 3681a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor 3691a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor 3701a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor#endif // LLVM_CLANG_BASIC_MODULE_H 371