本文整理汇总了C++中Mangler::bindGenericParameters方法的典型用法代码示例。如果您正苦于以下问题:C++ Mangler::bindGenericParameters方法的具体用法?C++ Mangler::bindGenericParameters怎么用?C++ Mangler::bindGenericParameters使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mangler
的用法示例。
在下文中一共展示了Mangler::bindGenericParameters方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: printDeclUSR
bool ide::printDeclUSR(const ValueDecl *D, raw_ostream &OS) {
using namespace Mangle;
if (!isa<FuncDecl>(D) && !D->hasName())
return true; // Ignore.
if (D->getModuleContext()->isBuiltinModule())
return true; // Ignore.
ValueDecl *VD = const_cast<ValueDecl *>(D);
auto interpretAsClangNode = [](const ValueDecl *D)->ClangNode {
ClangNode ClangN = D->getClangNode();
if (auto ClangD = ClangN.getAsDecl()) {
// NSErrorDomain causes the clang enum to be imported like this:
//
// struct MyError {
// enum Code : Int32 {
// case errFirst
// case errSecond
// }
// static var errFirst: MyError.Code { get }
// static var errSecond: MyError.Code { get }
// }
//
// The clang enum and enum constants are associated with both the
// struct/nested enum, and the static vars/enum cases.
// But we want unique USRs for the above symbols, so use the clang USR
// for the enum and enum cases, and the Swift USR for the struct and vars.
//
if (isa<clang::EnumDecl>(ClangD)) {
if (ClangD->hasAttr<clang::NSErrorDomainAttr>() && isa<StructDecl>(D))
return ClangNode();
} else if (auto *ClangEnumConst = dyn_cast<clang::EnumConstantDecl>(ClangD)) {
if (auto *ClangEnum = dyn_cast<clang::EnumDecl>(ClangEnumConst->getDeclContext())) {
if (ClangEnum->hasAttr<clang::NSErrorDomainAttr>() && isa<VarDecl>(D))
return ClangNode();
}
}
}
return ClangN;
};
if (ClangNode ClangN = interpretAsClangNode(D)) {
llvm::SmallString<128> Buf;
if (auto ClangD = ClangN.getAsDecl()) {
bool Ignore = clang::index::generateUSRForDecl(ClangD, Buf);
if (!Ignore)
OS << Buf.str();
return Ignore;
}
auto &Importer = *D->getASTContext().getClangModuleLoader();
auto ClangMacroInfo = ClangN.getAsMacro();
auto PPRecord = Importer.getClangPreprocessor().getPreprocessingRecord();
assert(PPRecord && "Clang importer should be created with "
"-detailed-preprocessing-record option");
auto ClangMacroDef = PPRecord->findMacroDefinition(ClangMacroInfo);
bool Ignore = clang::index::generateUSRForMacro(
ClangMacroDef, Importer.getClangASTContext().getSourceManager(), Buf);
if (!Ignore)
OS << Buf.str();
return Ignore;
}
if (!D->hasType())
return true;
// FIXME: mangling 'self' in destructors crashes in mangler.
if (isa<ParamDecl>(VD) && isa<DestructorDecl>(VD->getDeclContext()))
return true;
OS << getUSRSpacePrefix();
Mangler Mangler;
Mangler.bindGenericParameters(VD->getDeclContext());
if (auto Ctor = dyn_cast<ConstructorDecl>(VD)) {
Mangler.mangleConstructorEntity(Ctor, /*isAllocating=*/false,
/*uncurryingLevel=*/0);
} else if (auto Dtor = dyn_cast<DestructorDecl>(VD)) {
Mangler.mangleDestructorEntity(Dtor, /*isDeallocating=*/false);
} else if (auto NTD = dyn_cast<NominalTypeDecl>(VD)) {
Mangler.mangleNominalType(NTD);
} else if (isa<TypeAliasDecl>(VD) || isa<AssociatedTypeDecl>(VD)) {
Mangler.mangleContextOf(VD);
Mangler.mangleDeclName(VD);
} else {
Mangler.mangleEntity(VD, /*uncurryingLevel=*/0);
}
Mangler.finalize(OS);
return false;
}