本文整理汇总了C++中ModuleDecl::getImportedModules方法的典型用法代码示例。如果您正苦于以下问题:C++ ModuleDecl::getImportedModules方法的具体用法?C++ ModuleDecl::getImportedModules怎么用?C++ ModuleDecl::getImportedModules使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ModuleDecl
的用法示例。
在下文中一共展示了ModuleDecl::getImportedModules方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: assert
ImportDepth::ImportDepth(ASTContext &context, CompilerInvocation &invocation) {
llvm::DenseSet<ModuleDecl *> seen;
std::deque<std::pair<ModuleDecl *, uint8_t>> worklist;
StringRef mainModule = invocation.getModuleName();
auto *main = context.getLoadedModule(context.getIdentifier(mainModule));
assert(main && "missing main module");
worklist.emplace_back(main, uint8_t(0));
// Imports from -import-name such as Playground auxiliary sources are treated
// specially by applying import depth 0.
llvm::StringSet<> auxImports;
for (StringRef moduleName :
invocation.getFrontendOptions().ImplicitImportModuleNames)
auxImports.insert(moduleName);
// Private imports from this module.
// FIXME: only the private imports from the current source file.
ModuleDecl::ImportFilter importFilter;
importFilter |= ModuleDecl::ImportFilterKind::Private;
importFilter |= ModuleDecl::ImportFilterKind::ImplementationOnly;
SmallVector<ModuleDecl::ImportedModule, 16> mainImports;
main->getImportedModules(mainImports, importFilter);
for (auto &import : mainImports) {
uint8_t depth = 1;
if (auxImports.count(import.second->getName().str()))
depth = 0;
worklist.emplace_back(import.second, depth);
}
// Fill depths with BFS over module imports.
while (!worklist.empty()) {
ModuleDecl *module;
uint8_t depth;
std::tie(module, depth) = worklist.front();
worklist.pop_front();
if (!seen.insert(module).second)
continue;
// Insert new module:depth mapping.
const clang::Module *CM = module->findUnderlyingClangModule();
if (CM) {
depths[CM->getFullModuleName()] = depth;
} else {
depths[module->getName().str()] = depth;
}
// Add imports to the worklist.
SmallVector<ModuleDecl::ImportedModule, 16> imports;
module->getImportedModules(imports);
for (auto &import : imports) {
uint8_t next = std::max(depth, uint8_t(depth + 1)); // unsigned wrap
// Implicitly imported sub-modules get the same depth as their parent.
if (const clang::Module *CMI = import.second->findUnderlyingClangModule())
if (CM && CMI->isSubModuleOf(CM))
next = depth;
worklist.emplace_back(import.second, next);
}
}
}