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