/* -*- 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 VisitFieldDecl( const FieldDecl* 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;
};
bool UnusedFieldsRemove::VisitFieldDecl( const FieldDecl* fieldDecl )
{ if (rewriter == nullptr) { returntrue;
} if (ignoreLocation(fieldDecl)) { returntrue;
} // ignore stuff that forms part of the stable URE interface if (isInUnoIncludeFile(compiler.getSourceManager().getSpellingLoc(
fieldDecl->getCanonicalDecl()->getLocation()))) { returntrue;
}
// don't mess with templates /* if (isa<CXXRecordDecl>(fieldDecl->getParent())) { if (dyn_cast<CXXRecordDecl>(fieldDecl->getParent())->getDescribedClassTemplate() != nullptr) { return true; } }
*/
std::string aNiceName = " " + niceName(fieldDecl) + "\n"; constchar *aNiceNameStr = aNiceName.c_str(); char* found = std::search(mmappedData, mmappedData + mmapFilesize, aNiceNameStr, aNiceNameStr + strlen(aNiceNameStr)); if(!(found < mmappedData + mmapFilesize)) { returntrue;
}
SourceRange replaceRange(fieldDecl->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 field (" + niceName(fieldDecl) + ")",
fieldDecl->getBeginLoc())
<< fieldDecl->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.