本文整理汇总了C++中ModuleDecl::getFiles方法的典型用法代码示例。如果您正苦于以下问题:C++ ModuleDecl::getFiles方法的具体用法?C++ ModuleDecl::getFiles怎么用?C++ ModuleDecl::getFiles使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ModuleDecl
的用法示例。
在下文中一共展示了ModuleDecl::getFiles方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: isFirstObjectFileInModule
/// Returns true if the object file generated by \p IGM will be the "first"
/// object file in the module. This lets us determine where to put a symbol
/// that must be unique.
static bool isFirstObjectFileInModule(IRGenModule &IGM) {
if (IGM.getSILModule().isWholeModule())
return IGM.IRGen.getPrimaryIGM() == &IGM;
const DeclContext *DC = IGM.getSILModule().getAssociatedContext();
if (!DC)
return false;
assert(!isa<ModuleDecl>(DC) && "that would be a whole module build");
assert(isa<FileUnit>(DC) && "compiling something smaller than a file?");
ModuleDecl *containingModule = cast<FileUnit>(DC)->getParentModule();
return containingModule->getFiles().front() == DC;
}
示例2: addImport
void NameBinder::addImport(
SmallVectorImpl<SourceFile::ImportedModuleDesc> &imports, ImportDecl *ID) {
if (ID->getModulePath().front().first == SF.getParentModule()->getName() &&
ID->getModulePath().size() == 1 && !shouldImportSelfImportClang(ID, SF)) {
// If the imported module name is the same as the current module,
// produce a diagnostic.
StringRef filename = llvm::sys::path::filename(SF.getFilename());
if (filename.empty())
Context.Diags.diagnose(ID, diag::sema_import_current_module,
ID->getModulePath().front().first);
else
Context.Diags.diagnose(ID, diag::sema_import_current_module_with_file,
filename, ID->getModulePath().front().first);
ID->setModule(SF.getParentModule());
return;
}
ModuleDecl *M = getModule(ID->getModulePath());
if (!M) {
SmallString<64> modulePathStr;
interleave(ID->getModulePath(),
[&](ImportDecl::AccessPathElement elem) {
modulePathStr += elem.first.str();
},
[&] { modulePathStr += "."; });
auto diagKind = diag::sema_no_import;
if (SF.Kind == SourceFileKind::REPL || Context.LangOpts.DebuggerSupport)
diagKind = diag::sema_no_import_repl;
diagnose(ID->getLoc(), diagKind, modulePathStr);
if (Context.SearchPathOpts.SDKPath.empty() &&
llvm::Triple(llvm::sys::getProcessTriple()).isMacOSX()) {
diagnose(SourceLoc(), diag::sema_no_import_no_sdk);
diagnose(SourceLoc(), diag::sema_no_import_no_sdk_xcrun);
}
return;
}
ID->setModule(M);
ModuleDecl *topLevelModule;
if (ID->getModulePath().size() == 1) {
topLevelModule = M;
} else {
// If we imported a submodule, import the top-level module as well.
Identifier topLevelName = ID->getModulePath().front().first;
topLevelModule = Context.getLoadedModule(topLevelName);
if (!topLevelModule) {
// Clang can sometimes import top-level modules as if they were
// submodules.
assert(!M->getFiles().empty() &&
isa<ClangModuleUnit>(M->getFiles().front()));
topLevelModule = M;
}
}
auto *testableAttr = ID->getAttrs().getAttribute<TestableAttr>();
if (testableAttr && !topLevelModule->isTestingEnabled() &&
Context.LangOpts.EnableTestableAttrRequiresTestableModule) {
diagnose(ID->getModulePath().front().second, diag::module_not_testable,
topLevelModule->getName());
testableAttr->setInvalid();
}
auto *privateImportAttr = ID->getAttrs().getAttribute<PrivateImportAttr>();
StringRef privateImportFileName;
if (privateImportAttr) {
if (!topLevelModule->arePrivateImportsEnabled()) {
diagnose(ID->getModulePath().front().second,
diag::module_not_compiled_for_private_import,
topLevelModule->getName());
privateImportAttr->setInvalid();
} else {
privateImportFileName = privateImportAttr->getSourceFile();
}
}
ImportOptions options;
if (ID->isExported())
options |= SourceFile::ImportFlags::Exported;
if (testableAttr)
options |= SourceFile::ImportFlags::Testable;
if (privateImportAttr)
options |= SourceFile::ImportFlags::PrivateImport;
auto *implementationOnlyAttr =
ID->getAttrs().getAttribute<ImplementationOnlyAttr>();
if (implementationOnlyAttr) {
if (options.contains(SourceFile::ImportFlags::Exported)) {
diagnose(ID, diag::import_implementation_cannot_be_exported,
topLevelModule->getName())
.fixItRemove(implementationOnlyAttr->getRangeWithAt());
} else {
options |= SourceFile::ImportFlags::ImplementationOnly;
}
}
imports.push_back(SourceFile::ImportedModuleDesc(
{ID->getDeclPath(), M}, options, privateImportFileName));
//.........这里部分代码省略.........
示例3: addModuleDependencies
static void addModuleDependencies(ArrayRef<ModuleDecl::ImportedModule> imports,
StringRef indexStorePath,
bool indexSystemModules,
StringRef targetTriple,
const clang::CompilerInstance &clangCI,
DiagnosticEngine &diags,
IndexUnitWriter &unitWriter,
StringScratchSpace &moduleNameScratch) {
auto &fileMgr = clangCI.getFileManager();
for (auto &import : imports) {
ModuleDecl *mod = import.second;
if (mod->isOnoneSupportModule())
continue; // ignore the Onone support library.
if (mod->isSwiftShimsModule())
continue;
for (auto *FU : mod->getFiles()) {
switch (FU->getKind()) {
case FileUnitKind::Source:
case FileUnitKind::Builtin:
break;
case FileUnitKind::SerializedAST:
case FileUnitKind::DWARFModule:
case FileUnitKind::ClangModule: {
auto *LFU = cast<LoadedFile>(FU);
if (auto *F = fileMgr.getFile(LFU->getFilename())) {
std::string moduleName = mod->getNameStr();
bool withoutUnitName = true;
if (FU->getKind() == FileUnitKind::ClangModule) {
withoutUnitName = false;
auto clangModUnit = cast<ClangModuleUnit>(LFU);
if (auto clangMod = clangModUnit->getUnderlyingClangModule()) {
moduleName = clangMod->getTopLevelModuleName();
// FIXME: clang's -Rremarks do not seem to go through Swift's
// diagnostic emitter.
clang::index::emitIndexDataForModuleFile(clangMod,
clangCI, unitWriter);
}
} else {
// Serialized AST file.
// Only index system modules (essentially stdlib and overlays).
// We don't officially support binary swift modules, so normally
// the index data for user modules would get generated while
// building them.
if (mod->isSystemModule() && indexSystemModules) {
emitDataForSwiftSerializedModule(mod, indexStorePath,
indexSystemModules,
targetTriple, clangCI, diags,
unitWriter);
withoutUnitName = false;
}
}
clang::index::writer::OpaqueModule opaqMod =
moduleNameScratch.createString(moduleName);
unitWriter.addASTFileDependency(F, mod->isSystemModule(), opaqMod,
withoutUnitName);
}
break;
}
}
}
}
}