MCPcopy Create free account
hub / github.com/KDAB/codebrowser / getReferenceAndTitle

Method getReferenceAndTitle

generator/annotator.cpp:897–938  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

895
896
897std::pair< std::string, std::string > Annotator::getReferenceAndTitle(clang::NamedDecl* decl)
898{
899 clang::Decl* canonDecl = decl->getCanonicalDecl();
900 auto &cached = mangle_cache[canonDecl];
901 if (cached.first.empty()) {
902 decl = getSpecializedCursorTemplate(decl);
903
904 std::string qualName = decl->getQualifiedNameAsString();
905 if (llvm::isa<clang::FunctionDecl>(decl) && mangle->shouldMangleDeclName(decl)
906 //workaround crash in clang while trying to mangle some buitins types
907 && !llvm::StringRef(qualName).startswith("__")) {
908 llvm::raw_string_ostream s(cached.first);
909 if (llvm::isa<clang::CXXDestructorDecl>(decl)) {
910 mangle->mangleCXXDtor(llvm::cast<clang::CXXDestructorDecl>(decl), clang::Dtor_Complete, s);
911 } else if (llvm::isa<clang::CXXConstructorDecl>(decl)) {
912 mangle->mangleCXXCtor(llvm::cast<clang::CXXConstructorDecl>(decl), clang::Ctor_Complete, s);
913 } else {
914 mangle->mangleName(decl, s);
915 }
916 } else if (clang::FieldDecl *d = llvm::dyn_cast<clang::FieldDecl>(decl)) {
917 cached.first = getReferenceAndTitle(d->getParent()).first + "::" + decl->getName().str();
918 } else {
919 cached.first = qualName;
920 cached.first.erase(std::remove(cached.first.begin(), cached.first.end(), ' '),
921 cached.first.end());
922 // replace < and > because alse jquery can't match them.
923 std::replace(cached.first.begin(), cached.first.end(), '<' , '{');
924 std::replace(cached.first.begin(), cached.first.end(), '>' , '}');
925 }
926 llvm::SmallString<64> buffer;
927 cached.second = Generator::escapeAttr(qualName, buffer);
928
929 if (cached.first.size() > 170) {
930 // If the name is too big, turncate it and add the hash at the end.
931 auto hash = std::hash<std::string>()(cached.first) & 0x00ffffff;
932 cached.first.resize(150);
933 buffer.clear();
934 cached.first += llvm::Twine(hash).toStringRef(buffer);
935 }
936 }
937 return cached;
938}
939
940
941std::string Annotator::getTypeRef(clang::QualType type)

Callers

nothing calls this directly

Calls 3

TwineClass · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected