/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
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->getParent()->getQualifiedNameAsString() + "::"
+ functionDecl->getReturnType().getAsString() + "-"
+ functionDecl->getNameAsString() + "("; for (const ParmVarDecl *pParmVarDecl : functionDecl->params()) {
s += pParmVarDecl->getType().getAsString();
s += ",";
}
s += ")"; if (functionDecl->isConst()) {
s += "const";
} return s;
}
bool RemoveVirtuals::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;
}
if (!functionDecl->isVirtualAsWritten()) { 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;
} if (functionDecl->isPure()) { if (!removeText(functionDecl->getSourceRange())) {
report(
DiagnosticsEngine::Warning, "Could not remove unused pure virtual method",
functionDecl->getLocStart())
<< functionDecl->getSourceRange();
}
} else {
std::string aOrigText = rewriter->getRewrittenText(functionDecl->getSourceRange());
size_t iVirtualTokenIndex = aOrigText.find_first_of("virtual "); if (iVirtualTokenIndex == std::string::npos) { returntrue;
} if (!replaceText(functionDecl->getSourceRange(), aOrigText.replace(iVirtualTokenIndex, strlen("virtual "), ""))) {
report(
DiagnosticsEngine::Warning, "Could not remove virtual qualifier from method",
functionDecl->getLocStart())
<< 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.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.