bool VisitCXXMethodDecl( const CXXMethodDecl* var ); private: // I use a brute-force approach - mmap the results file and do a linear search on it // It works surprisingly well, because the file is small enough to fit into L2 cache on modern CPU's
size_t mmapFilesize; int mmapFD; char* mmappedData;
};
std::string niceName(const CXXMethodDecl* functionDecl)
{
std::string s =
functionDecl->getReturnType().getCanonicalType().getAsString()
+ " " + functionDecl->getParent()->getQualifiedNameAsString()
+ "::" + functionDecl->getNameAsString()
+ "("; bool bFirst = true; for (const ParmVarDecl *pParmVarDecl : functionDecl->parameters()) { if (bFirst)
bFirst = false; else
s += ",";
s += pParmVarDecl->getType().getCanonicalType().getAsString();
}
s += ")"; if (functionDecl->isConst()) {
s += " const";
} return s;
}
bool UnusedMethodsRemove::VisitCXXMethodDecl( const CXXMethodDecl* functionDecl )
{ if (rewriter == nullptr) { returntrue;
} if (ignoreLocation(functionDecl)) { returntrue;
} // ignore stuff that forms part of the stable URE interface if (isInUnoIncludeFile(functionDecl)) { returntrue;
}
// don't mess with templates if (functionDecl->getParent()->getDescribedClassTemplate() != nullptr) { returntrue;
} if (functionDecl->getTemplatedKind() != FunctionDecl::TK_NonTemplate) { returntrue;
}
std::string aNiceName = "\n" + niceName(functionDecl) + "\n"; constchar *aNiceNameStr = aNiceName.c_str(); char* found = std::search(mmappedData, mmappedData + mmapFilesize, aNiceNameStr, aNiceNameStr + strlen(aNiceNameStr)); if(!(found < mmappedData + mmapFilesize)) { returntrue;
}
SourceRange replaceRange(functionDecl->getSourceRange()); // sometimes the declaration has a semicolon just after it, and it's much neater to remove that too. if (rewriter->getRewrittenText(SourceRange(replaceRange.getEnd(), replaceRange.getEnd().getLocWithOffset(1))) == ";") {
replaceRange.setEnd(replaceRange.getEnd().getLocWithOffset(1));
} // remove leading spaces while (rewriter->getRewrittenText(SourceRange(replaceRange.getBegin().getLocWithOffset(-1), replaceRange.getBegin())) == " ")
{
replaceRange.setBegin(replaceRange.getBegin().getLocWithOffset(-1));
} if (!replaceText(replaceRange, "")) {
report(
DiagnosticsEngine::Warning, "Could not remove unused method (" + niceName(functionDecl) + ")",
functionDecl->getBeginLoc())
<< functionDecl->getSourceRange();
} returntrue;
}
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.11Bemerkung:
(vorverarbeitet am 2026-09-29)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.