diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2013-02-19 19:34:40 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2013-02-19 19:34:40 +0000 |
commit | 21a0004d80f50808ee343ae70092f6260a4c9477 (patch) | |
tree | dbcf4e5b9a04a939b1f144822420be582087df18 /lib/Basic/Module.cpp | |
parent | cc9bdcb720931961bac55e321a3e51b9804ca900 (diff) |
[modules] Refactor code from ASTReader::makeModuleVisible() into a new function,
Module::getExportedModules() so it can be reused.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175548 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Basic/Module.cpp')
-rw-r--r-- | lib/Basic/Module.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/lib/Basic/Module.cpp b/lib/Basic/Module.cpp index 5e5e431d31..65deac1b4a 100644 --- a/lib/Basic/Module.cpp +++ b/lib/Basic/Module.cpp @@ -175,6 +175,59 @@ static void printModuleId(raw_ostream &OS, const ModuleId &Id) { } } +void Module::getExportedModules(SmallVectorImpl<Module *> &Exported) const { + bool AnyWildcard = false; + bool UnrestrictedWildcard = false; + SmallVector<Module *, 4> WildcardRestrictions; + for (unsigned I = 0, N = Exports.size(); I != N; ++I) { + Module *Mod = Exports[I].getPointer(); + if (!Exports[I].getInt()) { + // Export a named module directly; no wildcards involved. + Exported.push_back(Mod); + + continue; + } + + // Wildcard export: export all of the imported modules that match + // the given pattern. + AnyWildcard = true; + if (UnrestrictedWildcard) + continue; + + if (Module *Restriction = Exports[I].getPointer()) + WildcardRestrictions.push_back(Restriction); + else { + WildcardRestrictions.clear(); + UnrestrictedWildcard = true; + } + } + + // If there were any wildcards, push any imported modules that were + // re-exported by the wildcard restriction. + if (!AnyWildcard) + return; + + for (unsigned I = 0, N = Imports.size(); I != N; ++I) { + Module *Mod = Imports[I]; + bool Acceptable = UnrestrictedWildcard; + if (!Acceptable) { + // Check whether this module meets one of the restrictions. + for (unsigned R = 0, NR = WildcardRestrictions.size(); R != NR; ++R) { + Module *Restriction = WildcardRestrictions[R]; + if (Mod == Restriction || Mod->isSubModuleOf(Restriction)) { + Acceptable = true; + break; + } + } + } + + if (!Acceptable) + continue; + + Exported.push_back(Mod); + } +} + void Module::print(raw_ostream &OS, unsigned Indent) const { OS.indent(Indent); if (IsFramework) |