1*f4a2713aSLionel Sambuc //===--- Module.cpp - Describe a module -----------------------------------===// 2*f4a2713aSLionel Sambuc // 3*f4a2713aSLionel Sambuc // The LLVM Compiler Infrastructure 4*f4a2713aSLionel Sambuc // 5*f4a2713aSLionel Sambuc // This file is distributed under the University of Illinois Open Source 6*f4a2713aSLionel Sambuc // License. See LICENSE.TXT for details. 7*f4a2713aSLionel Sambuc // 8*f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===// 9*f4a2713aSLionel Sambuc // 10*f4a2713aSLionel Sambuc // This file defines the Module class, which describes a module in the source 11*f4a2713aSLionel Sambuc // code. 12*f4a2713aSLionel Sambuc // 13*f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===// 14*f4a2713aSLionel Sambuc 15*f4a2713aSLionel Sambuc #include "clang/Basic/Module.h" 16*f4a2713aSLionel Sambuc #include "clang/Basic/FileManager.h" 17*f4a2713aSLionel Sambuc #include "clang/Basic/LangOptions.h" 18*f4a2713aSLionel Sambuc #include "clang/Basic/TargetInfo.h" 19*f4a2713aSLionel Sambuc #include "llvm/ADT/ArrayRef.h" 20*f4a2713aSLionel Sambuc #include "llvm/ADT/SmallVector.h" 21*f4a2713aSLionel Sambuc #include "llvm/ADT/StringSwitch.h" 22*f4a2713aSLionel Sambuc #include "llvm/Support/ErrorHandling.h" 23*f4a2713aSLionel Sambuc #include "llvm/Support/raw_ostream.h" 24*f4a2713aSLionel Sambuc 25*f4a2713aSLionel Sambuc using namespace clang; 26*f4a2713aSLionel Sambuc 27*f4a2713aSLionel Sambuc Module::Module(StringRef Name, SourceLocation DefinitionLoc, Module *Parent, 28*f4a2713aSLionel Sambuc bool IsFramework, bool IsExplicit) 29*f4a2713aSLionel Sambuc : Name(Name), DefinitionLoc(DefinitionLoc), Parent(Parent), 30*f4a2713aSLionel Sambuc Umbrella(), ASTFile(0), IsAvailable(true), IsFromModuleFile(false), 31*f4a2713aSLionel Sambuc IsFramework(IsFramework), IsExplicit(IsExplicit), IsSystem(false), 32*f4a2713aSLionel Sambuc InferSubmodules(false), InferExplicitSubmodules(false), 33*f4a2713aSLionel Sambuc InferExportWildcard(false), ConfigMacrosExhaustive(false), 34*f4a2713aSLionel Sambuc NameVisibility(Hidden) 35*f4a2713aSLionel Sambuc { 36*f4a2713aSLionel Sambuc if (Parent) { 37*f4a2713aSLionel Sambuc if (!Parent->isAvailable()) 38*f4a2713aSLionel Sambuc IsAvailable = false; 39*f4a2713aSLionel Sambuc if (Parent->IsSystem) 40*f4a2713aSLionel Sambuc IsSystem = true; 41*f4a2713aSLionel Sambuc 42*f4a2713aSLionel Sambuc Parent->SubModuleIndex[Name] = Parent->SubModules.size(); 43*f4a2713aSLionel Sambuc Parent->SubModules.push_back(this); 44*f4a2713aSLionel Sambuc } 45*f4a2713aSLionel Sambuc } 46*f4a2713aSLionel Sambuc 47*f4a2713aSLionel Sambuc Module::~Module() { 48*f4a2713aSLionel Sambuc for (submodule_iterator I = submodule_begin(), IEnd = submodule_end(); 49*f4a2713aSLionel Sambuc I != IEnd; ++I) { 50*f4a2713aSLionel Sambuc delete *I; 51*f4a2713aSLionel Sambuc } 52*f4a2713aSLionel Sambuc } 53*f4a2713aSLionel Sambuc 54*f4a2713aSLionel Sambuc /// \brief Determine whether a translation unit built using the current 55*f4a2713aSLionel Sambuc /// language options has the given feature. 56*f4a2713aSLionel Sambuc static bool hasFeature(StringRef Feature, const LangOptions &LangOpts, 57*f4a2713aSLionel Sambuc const TargetInfo &Target) { 58*f4a2713aSLionel Sambuc return llvm::StringSwitch<bool>(Feature) 59*f4a2713aSLionel Sambuc .Case("altivec", LangOpts.AltiVec) 60*f4a2713aSLionel Sambuc .Case("blocks", LangOpts.Blocks) 61*f4a2713aSLionel Sambuc .Case("cplusplus", LangOpts.CPlusPlus) 62*f4a2713aSLionel Sambuc .Case("cplusplus11", LangOpts.CPlusPlus11) 63*f4a2713aSLionel Sambuc .Case("objc", LangOpts.ObjC1) 64*f4a2713aSLionel Sambuc .Case("objc_arc", LangOpts.ObjCAutoRefCount) 65*f4a2713aSLionel Sambuc .Case("opencl", LangOpts.OpenCL) 66*f4a2713aSLionel Sambuc .Case("tls", Target.isTLSSupported()) 67*f4a2713aSLionel Sambuc .Default(Target.hasFeature(Feature)); 68*f4a2713aSLionel Sambuc } 69*f4a2713aSLionel Sambuc 70*f4a2713aSLionel Sambuc bool 71*f4a2713aSLionel Sambuc Module::isAvailable(const LangOptions &LangOpts, const TargetInfo &Target, 72*f4a2713aSLionel Sambuc Requirement &Req) const { 73*f4a2713aSLionel Sambuc if (IsAvailable) 74*f4a2713aSLionel Sambuc return true; 75*f4a2713aSLionel Sambuc 76*f4a2713aSLionel Sambuc for (const Module *Current = this; Current; Current = Current->Parent) { 77*f4a2713aSLionel Sambuc for (unsigned I = 0, N = Current->Requirements.size(); I != N; ++I) { 78*f4a2713aSLionel Sambuc if (hasFeature(Current->Requirements[I].first, LangOpts, Target) != 79*f4a2713aSLionel Sambuc Current->Requirements[I].second) { 80*f4a2713aSLionel Sambuc Req = Current->Requirements[I]; 81*f4a2713aSLionel Sambuc return false; 82*f4a2713aSLionel Sambuc } 83*f4a2713aSLionel Sambuc } 84*f4a2713aSLionel Sambuc } 85*f4a2713aSLionel Sambuc 86*f4a2713aSLionel Sambuc llvm_unreachable("could not find a reason why module is unavailable"); 87*f4a2713aSLionel Sambuc } 88*f4a2713aSLionel Sambuc 89*f4a2713aSLionel Sambuc bool Module::isSubModuleOf(Module *Other) const { 90*f4a2713aSLionel Sambuc const Module *This = this; 91*f4a2713aSLionel Sambuc do { 92*f4a2713aSLionel Sambuc if (This == Other) 93*f4a2713aSLionel Sambuc return true; 94*f4a2713aSLionel Sambuc 95*f4a2713aSLionel Sambuc This = This->Parent; 96*f4a2713aSLionel Sambuc } while (This); 97*f4a2713aSLionel Sambuc 98*f4a2713aSLionel Sambuc return false; 99*f4a2713aSLionel Sambuc } 100*f4a2713aSLionel Sambuc 101*f4a2713aSLionel Sambuc const Module *Module::getTopLevelModule() const { 102*f4a2713aSLionel Sambuc const Module *Result = this; 103*f4a2713aSLionel Sambuc while (Result->Parent) 104*f4a2713aSLionel Sambuc Result = Result->Parent; 105*f4a2713aSLionel Sambuc 106*f4a2713aSLionel Sambuc return Result; 107*f4a2713aSLionel Sambuc } 108*f4a2713aSLionel Sambuc 109*f4a2713aSLionel Sambuc std::string Module::getFullModuleName() const { 110*f4a2713aSLionel Sambuc SmallVector<StringRef, 2> Names; 111*f4a2713aSLionel Sambuc 112*f4a2713aSLionel Sambuc // Build up the set of module names (from innermost to outermost). 113*f4a2713aSLionel Sambuc for (const Module *M = this; M; M = M->Parent) 114*f4a2713aSLionel Sambuc Names.push_back(M->Name); 115*f4a2713aSLionel Sambuc 116*f4a2713aSLionel Sambuc std::string Result; 117*f4a2713aSLionel Sambuc for (SmallVectorImpl<StringRef>::reverse_iterator I = Names.rbegin(), 118*f4a2713aSLionel Sambuc IEnd = Names.rend(); 119*f4a2713aSLionel Sambuc I != IEnd; ++I) { 120*f4a2713aSLionel Sambuc if (!Result.empty()) 121*f4a2713aSLionel Sambuc Result += '.'; 122*f4a2713aSLionel Sambuc 123*f4a2713aSLionel Sambuc Result += *I; 124*f4a2713aSLionel Sambuc } 125*f4a2713aSLionel Sambuc 126*f4a2713aSLionel Sambuc return Result; 127*f4a2713aSLionel Sambuc } 128*f4a2713aSLionel Sambuc 129*f4a2713aSLionel Sambuc const DirectoryEntry *Module::getUmbrellaDir() const { 130*f4a2713aSLionel Sambuc if (const FileEntry *Header = getUmbrellaHeader()) 131*f4a2713aSLionel Sambuc return Header->getDir(); 132*f4a2713aSLionel Sambuc 133*f4a2713aSLionel Sambuc return Umbrella.dyn_cast<const DirectoryEntry *>(); 134*f4a2713aSLionel Sambuc } 135*f4a2713aSLionel Sambuc 136*f4a2713aSLionel Sambuc ArrayRef<const FileEntry *> Module::getTopHeaders(FileManager &FileMgr) { 137*f4a2713aSLionel Sambuc if (!TopHeaderNames.empty()) { 138*f4a2713aSLionel Sambuc for (std::vector<std::string>::iterator 139*f4a2713aSLionel Sambuc I = TopHeaderNames.begin(), E = TopHeaderNames.end(); I != E; ++I) { 140*f4a2713aSLionel Sambuc if (const FileEntry *FE = FileMgr.getFile(*I)) 141*f4a2713aSLionel Sambuc TopHeaders.insert(FE); 142*f4a2713aSLionel Sambuc } 143*f4a2713aSLionel Sambuc TopHeaderNames.clear(); 144*f4a2713aSLionel Sambuc } 145*f4a2713aSLionel Sambuc 146*f4a2713aSLionel Sambuc return llvm::makeArrayRef(TopHeaders.begin(), TopHeaders.end()); 147*f4a2713aSLionel Sambuc } 148*f4a2713aSLionel Sambuc 149*f4a2713aSLionel Sambuc void Module::addRequirement(StringRef Feature, bool RequiredState, 150*f4a2713aSLionel Sambuc const LangOptions &LangOpts, 151*f4a2713aSLionel Sambuc const TargetInfo &Target) { 152*f4a2713aSLionel Sambuc Requirements.push_back(Requirement(Feature, RequiredState)); 153*f4a2713aSLionel Sambuc 154*f4a2713aSLionel Sambuc // If this feature is currently available, we're done. 155*f4a2713aSLionel Sambuc if (hasFeature(Feature, LangOpts, Target) == RequiredState) 156*f4a2713aSLionel Sambuc return; 157*f4a2713aSLionel Sambuc 158*f4a2713aSLionel Sambuc if (!IsAvailable) 159*f4a2713aSLionel Sambuc return; 160*f4a2713aSLionel Sambuc 161*f4a2713aSLionel Sambuc SmallVector<Module *, 2> Stack; 162*f4a2713aSLionel Sambuc Stack.push_back(this); 163*f4a2713aSLionel Sambuc while (!Stack.empty()) { 164*f4a2713aSLionel Sambuc Module *Current = Stack.back(); 165*f4a2713aSLionel Sambuc Stack.pop_back(); 166*f4a2713aSLionel Sambuc 167*f4a2713aSLionel Sambuc if (!Current->IsAvailable) 168*f4a2713aSLionel Sambuc continue; 169*f4a2713aSLionel Sambuc 170*f4a2713aSLionel Sambuc Current->IsAvailable = false; 171*f4a2713aSLionel Sambuc for (submodule_iterator Sub = Current->submodule_begin(), 172*f4a2713aSLionel Sambuc SubEnd = Current->submodule_end(); 173*f4a2713aSLionel Sambuc Sub != SubEnd; ++Sub) { 174*f4a2713aSLionel Sambuc if ((*Sub)->IsAvailable) 175*f4a2713aSLionel Sambuc Stack.push_back(*Sub); 176*f4a2713aSLionel Sambuc } 177*f4a2713aSLionel Sambuc } 178*f4a2713aSLionel Sambuc } 179*f4a2713aSLionel Sambuc 180*f4a2713aSLionel Sambuc Module *Module::findSubmodule(StringRef Name) const { 181*f4a2713aSLionel Sambuc llvm::StringMap<unsigned>::const_iterator Pos = SubModuleIndex.find(Name); 182*f4a2713aSLionel Sambuc if (Pos == SubModuleIndex.end()) 183*f4a2713aSLionel Sambuc return 0; 184*f4a2713aSLionel Sambuc 185*f4a2713aSLionel Sambuc return SubModules[Pos->getValue()]; 186*f4a2713aSLionel Sambuc } 187*f4a2713aSLionel Sambuc 188*f4a2713aSLionel Sambuc static void printModuleId(raw_ostream &OS, const ModuleId &Id) { 189*f4a2713aSLionel Sambuc for (unsigned I = 0, N = Id.size(); I != N; ++I) { 190*f4a2713aSLionel Sambuc if (I) 191*f4a2713aSLionel Sambuc OS << "."; 192*f4a2713aSLionel Sambuc OS << Id[I].first; 193*f4a2713aSLionel Sambuc } 194*f4a2713aSLionel Sambuc } 195*f4a2713aSLionel Sambuc 196*f4a2713aSLionel Sambuc void Module::getExportedModules(SmallVectorImpl<Module *> &Exported) const { 197*f4a2713aSLionel Sambuc // All non-explicit submodules are exported. 198*f4a2713aSLionel Sambuc for (std::vector<Module *>::const_iterator I = SubModules.begin(), 199*f4a2713aSLionel Sambuc E = SubModules.end(); 200*f4a2713aSLionel Sambuc I != E; ++I) { 201*f4a2713aSLionel Sambuc Module *Mod = *I; 202*f4a2713aSLionel Sambuc if (!Mod->IsExplicit) 203*f4a2713aSLionel Sambuc Exported.push_back(Mod); 204*f4a2713aSLionel Sambuc } 205*f4a2713aSLionel Sambuc 206*f4a2713aSLionel Sambuc // Find re-exported modules by filtering the list of imported modules. 207*f4a2713aSLionel Sambuc bool AnyWildcard = false; 208*f4a2713aSLionel Sambuc bool UnrestrictedWildcard = false; 209*f4a2713aSLionel Sambuc SmallVector<Module *, 4> WildcardRestrictions; 210*f4a2713aSLionel Sambuc for (unsigned I = 0, N = Exports.size(); I != N; ++I) { 211*f4a2713aSLionel Sambuc Module *Mod = Exports[I].getPointer(); 212*f4a2713aSLionel Sambuc if (!Exports[I].getInt()) { 213*f4a2713aSLionel Sambuc // Export a named module directly; no wildcards involved. 214*f4a2713aSLionel Sambuc Exported.push_back(Mod); 215*f4a2713aSLionel Sambuc 216*f4a2713aSLionel Sambuc continue; 217*f4a2713aSLionel Sambuc } 218*f4a2713aSLionel Sambuc 219*f4a2713aSLionel Sambuc // Wildcard export: export all of the imported modules that match 220*f4a2713aSLionel Sambuc // the given pattern. 221*f4a2713aSLionel Sambuc AnyWildcard = true; 222*f4a2713aSLionel Sambuc if (UnrestrictedWildcard) 223*f4a2713aSLionel Sambuc continue; 224*f4a2713aSLionel Sambuc 225*f4a2713aSLionel Sambuc if (Module *Restriction = Exports[I].getPointer()) 226*f4a2713aSLionel Sambuc WildcardRestrictions.push_back(Restriction); 227*f4a2713aSLionel Sambuc else { 228*f4a2713aSLionel Sambuc WildcardRestrictions.clear(); 229*f4a2713aSLionel Sambuc UnrestrictedWildcard = true; 230*f4a2713aSLionel Sambuc } 231*f4a2713aSLionel Sambuc } 232*f4a2713aSLionel Sambuc 233*f4a2713aSLionel Sambuc // If there were any wildcards, push any imported modules that were 234*f4a2713aSLionel Sambuc // re-exported by the wildcard restriction. 235*f4a2713aSLionel Sambuc if (!AnyWildcard) 236*f4a2713aSLionel Sambuc return; 237*f4a2713aSLionel Sambuc 238*f4a2713aSLionel Sambuc for (unsigned I = 0, N = Imports.size(); I != N; ++I) { 239*f4a2713aSLionel Sambuc Module *Mod = Imports[I]; 240*f4a2713aSLionel Sambuc bool Acceptable = UnrestrictedWildcard; 241*f4a2713aSLionel Sambuc if (!Acceptable) { 242*f4a2713aSLionel Sambuc // Check whether this module meets one of the restrictions. 243*f4a2713aSLionel Sambuc for (unsigned R = 0, NR = WildcardRestrictions.size(); R != NR; ++R) { 244*f4a2713aSLionel Sambuc Module *Restriction = WildcardRestrictions[R]; 245*f4a2713aSLionel Sambuc if (Mod == Restriction || Mod->isSubModuleOf(Restriction)) { 246*f4a2713aSLionel Sambuc Acceptable = true; 247*f4a2713aSLionel Sambuc break; 248*f4a2713aSLionel Sambuc } 249*f4a2713aSLionel Sambuc } 250*f4a2713aSLionel Sambuc } 251*f4a2713aSLionel Sambuc 252*f4a2713aSLionel Sambuc if (!Acceptable) 253*f4a2713aSLionel Sambuc continue; 254*f4a2713aSLionel Sambuc 255*f4a2713aSLionel Sambuc Exported.push_back(Mod); 256*f4a2713aSLionel Sambuc } 257*f4a2713aSLionel Sambuc } 258*f4a2713aSLionel Sambuc 259*f4a2713aSLionel Sambuc void Module::buildVisibleModulesCache() const { 260*f4a2713aSLionel Sambuc assert(VisibleModulesCache.empty() && "cache does not need building"); 261*f4a2713aSLionel Sambuc 262*f4a2713aSLionel Sambuc // This module is visible to itself. 263*f4a2713aSLionel Sambuc VisibleModulesCache.insert(this); 264*f4a2713aSLionel Sambuc 265*f4a2713aSLionel Sambuc // Every imported module is visible. 266*f4a2713aSLionel Sambuc SmallVector<Module *, 16> Stack(Imports.begin(), Imports.end()); 267*f4a2713aSLionel Sambuc while (!Stack.empty()) { 268*f4a2713aSLionel Sambuc Module *CurrModule = Stack.pop_back_val(); 269*f4a2713aSLionel Sambuc 270*f4a2713aSLionel Sambuc // Every module transitively exported by an imported module is visible. 271*f4a2713aSLionel Sambuc if (VisibleModulesCache.insert(CurrModule).second) 272*f4a2713aSLionel Sambuc CurrModule->getExportedModules(Stack); 273*f4a2713aSLionel Sambuc } 274*f4a2713aSLionel Sambuc } 275*f4a2713aSLionel Sambuc 276*f4a2713aSLionel Sambuc void Module::print(raw_ostream &OS, unsigned Indent) const { 277*f4a2713aSLionel Sambuc OS.indent(Indent); 278*f4a2713aSLionel Sambuc if (IsFramework) 279*f4a2713aSLionel Sambuc OS << "framework "; 280*f4a2713aSLionel Sambuc if (IsExplicit) 281*f4a2713aSLionel Sambuc OS << "explicit "; 282*f4a2713aSLionel Sambuc OS << "module " << Name; 283*f4a2713aSLionel Sambuc 284*f4a2713aSLionel Sambuc if (IsSystem) { 285*f4a2713aSLionel Sambuc OS.indent(Indent + 2); 286*f4a2713aSLionel Sambuc OS << " [system]"; 287*f4a2713aSLionel Sambuc } 288*f4a2713aSLionel Sambuc 289*f4a2713aSLionel Sambuc OS << " {\n"; 290*f4a2713aSLionel Sambuc 291*f4a2713aSLionel Sambuc if (!Requirements.empty()) { 292*f4a2713aSLionel Sambuc OS.indent(Indent + 2); 293*f4a2713aSLionel Sambuc OS << "requires "; 294*f4a2713aSLionel Sambuc for (unsigned I = 0, N = Requirements.size(); I != N; ++I) { 295*f4a2713aSLionel Sambuc if (I) 296*f4a2713aSLionel Sambuc OS << ", "; 297*f4a2713aSLionel Sambuc if (!Requirements[I].second) 298*f4a2713aSLionel Sambuc OS << "!"; 299*f4a2713aSLionel Sambuc OS << Requirements[I].first; 300*f4a2713aSLionel Sambuc } 301*f4a2713aSLionel Sambuc OS << "\n"; 302*f4a2713aSLionel Sambuc } 303*f4a2713aSLionel Sambuc 304*f4a2713aSLionel Sambuc if (const FileEntry *UmbrellaHeader = getUmbrellaHeader()) { 305*f4a2713aSLionel Sambuc OS.indent(Indent + 2); 306*f4a2713aSLionel Sambuc OS << "umbrella header \""; 307*f4a2713aSLionel Sambuc OS.write_escaped(UmbrellaHeader->getName()); 308*f4a2713aSLionel Sambuc OS << "\"\n"; 309*f4a2713aSLionel Sambuc } else if (const DirectoryEntry *UmbrellaDir = getUmbrellaDir()) { 310*f4a2713aSLionel Sambuc OS.indent(Indent + 2); 311*f4a2713aSLionel Sambuc OS << "umbrella \""; 312*f4a2713aSLionel Sambuc OS.write_escaped(UmbrellaDir->getName()); 313*f4a2713aSLionel Sambuc OS << "\"\n"; 314*f4a2713aSLionel Sambuc } 315*f4a2713aSLionel Sambuc 316*f4a2713aSLionel Sambuc if (!ConfigMacros.empty() || ConfigMacrosExhaustive) { 317*f4a2713aSLionel Sambuc OS.indent(Indent + 2); 318*f4a2713aSLionel Sambuc OS << "config_macros "; 319*f4a2713aSLionel Sambuc if (ConfigMacrosExhaustive) 320*f4a2713aSLionel Sambuc OS << "[exhaustive]"; 321*f4a2713aSLionel Sambuc for (unsigned I = 0, N = ConfigMacros.size(); I != N; ++I) { 322*f4a2713aSLionel Sambuc if (I) 323*f4a2713aSLionel Sambuc OS << ", "; 324*f4a2713aSLionel Sambuc OS << ConfigMacros[I]; 325*f4a2713aSLionel Sambuc } 326*f4a2713aSLionel Sambuc OS << "\n"; 327*f4a2713aSLionel Sambuc } 328*f4a2713aSLionel Sambuc 329*f4a2713aSLionel Sambuc for (unsigned I = 0, N = NormalHeaders.size(); I != N; ++I) { 330*f4a2713aSLionel Sambuc OS.indent(Indent + 2); 331*f4a2713aSLionel Sambuc OS << "header \""; 332*f4a2713aSLionel Sambuc OS.write_escaped(NormalHeaders[I]->getName()); 333*f4a2713aSLionel Sambuc OS << "\"\n"; 334*f4a2713aSLionel Sambuc } 335*f4a2713aSLionel Sambuc 336*f4a2713aSLionel Sambuc for (unsigned I = 0, N = ExcludedHeaders.size(); I != N; ++I) { 337*f4a2713aSLionel Sambuc OS.indent(Indent + 2); 338*f4a2713aSLionel Sambuc OS << "exclude header \""; 339*f4a2713aSLionel Sambuc OS.write_escaped(ExcludedHeaders[I]->getName()); 340*f4a2713aSLionel Sambuc OS << "\"\n"; 341*f4a2713aSLionel Sambuc } 342*f4a2713aSLionel Sambuc 343*f4a2713aSLionel Sambuc for (unsigned I = 0, N = PrivateHeaders.size(); I != N; ++I) { 344*f4a2713aSLionel Sambuc OS.indent(Indent + 2); 345*f4a2713aSLionel Sambuc OS << "private header \""; 346*f4a2713aSLionel Sambuc OS.write_escaped(PrivateHeaders[I]->getName()); 347*f4a2713aSLionel Sambuc OS << "\"\n"; 348*f4a2713aSLionel Sambuc } 349*f4a2713aSLionel Sambuc 350*f4a2713aSLionel Sambuc for (submodule_const_iterator MI = submodule_begin(), MIEnd = submodule_end(); 351*f4a2713aSLionel Sambuc MI != MIEnd; ++MI) 352*f4a2713aSLionel Sambuc (*MI)->print(OS, Indent + 2); 353*f4a2713aSLionel Sambuc 354*f4a2713aSLionel Sambuc for (unsigned I = 0, N = Exports.size(); I != N; ++I) { 355*f4a2713aSLionel Sambuc OS.indent(Indent + 2); 356*f4a2713aSLionel Sambuc OS << "export "; 357*f4a2713aSLionel Sambuc if (Module *Restriction = Exports[I].getPointer()) { 358*f4a2713aSLionel Sambuc OS << Restriction->getFullModuleName(); 359*f4a2713aSLionel Sambuc if (Exports[I].getInt()) 360*f4a2713aSLionel Sambuc OS << ".*"; 361*f4a2713aSLionel Sambuc } else { 362*f4a2713aSLionel Sambuc OS << "*"; 363*f4a2713aSLionel Sambuc } 364*f4a2713aSLionel Sambuc OS << "\n"; 365*f4a2713aSLionel Sambuc } 366*f4a2713aSLionel Sambuc 367*f4a2713aSLionel Sambuc for (unsigned I = 0, N = UnresolvedExports.size(); I != N; ++I) { 368*f4a2713aSLionel Sambuc OS.indent(Indent + 2); 369*f4a2713aSLionel Sambuc OS << "export "; 370*f4a2713aSLionel Sambuc printModuleId(OS, UnresolvedExports[I].Id); 371*f4a2713aSLionel Sambuc if (UnresolvedExports[I].Wildcard) { 372*f4a2713aSLionel Sambuc if (UnresolvedExports[I].Id.empty()) 373*f4a2713aSLionel Sambuc OS << "*"; 374*f4a2713aSLionel Sambuc else 375*f4a2713aSLionel Sambuc OS << ".*"; 376*f4a2713aSLionel Sambuc } 377*f4a2713aSLionel Sambuc OS << "\n"; 378*f4a2713aSLionel Sambuc } 379*f4a2713aSLionel Sambuc 380*f4a2713aSLionel Sambuc for (unsigned I = 0, N = DirectUses.size(); I != N; ++I) { 381*f4a2713aSLionel Sambuc OS.indent(Indent + 2); 382*f4a2713aSLionel Sambuc OS << "use "; 383*f4a2713aSLionel Sambuc OS << DirectUses[I]->getFullModuleName(); 384*f4a2713aSLionel Sambuc OS << "\n"; 385*f4a2713aSLionel Sambuc } 386*f4a2713aSLionel Sambuc 387*f4a2713aSLionel Sambuc for (unsigned I = 0, N = UnresolvedDirectUses.size(); I != N; ++I) { 388*f4a2713aSLionel Sambuc OS.indent(Indent + 2); 389*f4a2713aSLionel Sambuc OS << "use "; 390*f4a2713aSLionel Sambuc printModuleId(OS, UnresolvedDirectUses[I]); 391*f4a2713aSLionel Sambuc OS << "\n"; 392*f4a2713aSLionel Sambuc } 393*f4a2713aSLionel Sambuc 394*f4a2713aSLionel Sambuc for (unsigned I = 0, N = LinkLibraries.size(); I != N; ++I) { 395*f4a2713aSLionel Sambuc OS.indent(Indent + 2); 396*f4a2713aSLionel Sambuc OS << "link "; 397*f4a2713aSLionel Sambuc if (LinkLibraries[I].IsFramework) 398*f4a2713aSLionel Sambuc OS << "framework "; 399*f4a2713aSLionel Sambuc OS << "\""; 400*f4a2713aSLionel Sambuc OS.write_escaped(LinkLibraries[I].Library); 401*f4a2713aSLionel Sambuc OS << "\""; 402*f4a2713aSLionel Sambuc } 403*f4a2713aSLionel Sambuc 404*f4a2713aSLionel Sambuc for (unsigned I = 0, N = UnresolvedConflicts.size(); I != N; ++I) { 405*f4a2713aSLionel Sambuc OS.indent(Indent + 2); 406*f4a2713aSLionel Sambuc OS << "conflict "; 407*f4a2713aSLionel Sambuc printModuleId(OS, UnresolvedConflicts[I].Id); 408*f4a2713aSLionel Sambuc OS << ", \""; 409*f4a2713aSLionel Sambuc OS.write_escaped(UnresolvedConflicts[I].Message); 410*f4a2713aSLionel Sambuc OS << "\"\n"; 411*f4a2713aSLionel Sambuc } 412*f4a2713aSLionel Sambuc 413*f4a2713aSLionel Sambuc for (unsigned I = 0, N = Conflicts.size(); I != N; ++I) { 414*f4a2713aSLionel Sambuc OS.indent(Indent + 2); 415*f4a2713aSLionel Sambuc OS << "conflict "; 416*f4a2713aSLionel Sambuc OS << Conflicts[I].Other->getFullModuleName(); 417*f4a2713aSLionel Sambuc OS << ", \""; 418*f4a2713aSLionel Sambuc OS.write_escaped(Conflicts[I].Message); 419*f4a2713aSLionel Sambuc OS << "\"\n"; 420*f4a2713aSLionel Sambuc } 421*f4a2713aSLionel Sambuc 422*f4a2713aSLionel Sambuc if (InferSubmodules) { 423*f4a2713aSLionel Sambuc OS.indent(Indent + 2); 424*f4a2713aSLionel Sambuc if (InferExplicitSubmodules) 425*f4a2713aSLionel Sambuc OS << "explicit "; 426*f4a2713aSLionel Sambuc OS << "module * {\n"; 427*f4a2713aSLionel Sambuc if (InferExportWildcard) { 428*f4a2713aSLionel Sambuc OS.indent(Indent + 4); 429*f4a2713aSLionel Sambuc OS << "export *\n"; 430*f4a2713aSLionel Sambuc } 431*f4a2713aSLionel Sambuc OS.indent(Indent + 2); 432*f4a2713aSLionel Sambuc OS << "}\n"; 433*f4a2713aSLionel Sambuc } 434*f4a2713aSLionel Sambuc 435*f4a2713aSLionel Sambuc OS.indent(Indent); 436*f4a2713aSLionel Sambuc OS << "}\n"; 437*f4a2713aSLionel Sambuc } 438*f4a2713aSLionel Sambuc 439*f4a2713aSLionel Sambuc void Module::dump() const { 440*f4a2713aSLionel Sambuc print(llvm::errs()); 441*f4a2713aSLionel Sambuc } 442*f4a2713aSLionel Sambuc 443*f4a2713aSLionel Sambuc 444