Addressed comments, changed the rest of the loops.
Hi chandlerc,
http://llvm-reviews.chandlerc.com/D2979
CHANGE SINCE LAST DIFF
http://llvm-reviews.chandlerc.com/D2979?vs=7588&id=7589#toc
BRANCH
svn
ARCANIST PROJECT
clang-tools-extra
Files:
clang-tidy/ClangTidy.cpp
clang-tidy/ClangTidyDiagnosticConsumer.cpp
clang-tidy/ClangTidyModule.cpp
Index: clang-tidy/ClangTidy.cpp
===================================================================
--- clang-tidy/ClangTidy.cpp
+++ clang-tidy/ClangTidy.cpp
@@ -66,24 +66,18 @@
void FlushDiagnosticsImpl(std::vector<const ento::PathDiagnostic *> &Diags,
FilesMade *filesMade) override {
- for (std::vector<const ento::PathDiagnostic *>::iterator I = Diags.begin(),
- E = Diags.end();
- I != E; ++I) {
- const ento::PathDiagnostic *PD = *I;
+ for (const ento::PathDiagnostic *PD : Diags) {
SmallString<64> CheckName(AnalyzerCheckNamePrefix);
CheckName += PD->getCheckName();
addRanges(Context.diag(CheckName, PD->getLocation().asLocation(),
PD->getShortDescription()),
PD->path.back()->getRanges());
- ento::PathPieces FlatPath =
- PD->path.flatten(/*ShouldFlattenMacros=*/true);
- for (ento::PathPieces::const_iterator PI = FlatPath.begin(),
- PE = FlatPath.end();
- PI != PE; ++PI) {
- addRanges(Context.diag(CheckName, (*PI)->getLocation().asLocation(),
- (*PI)->getString(), DiagnosticIDs::Note),
- (*PI)->getRanges());
+ for (const auto &DiagPiece :
+ PD->path.flatten(/*ShouldFlattenMacros=*/true)) {
+ addRanges(Context.diag(CheckName, DiagPiece->getLocation().asLocation(),
+ DiagPiece->getString(), DiagnosticIDs::Note),
+ DiagPiece->getRanges());
}
}
}
@@ -98,9 +92,8 @@
// FIXME: Convert to operator<<(DiagnosticBuilder&, ArrayRef<SourceRange>).
static const DiagnosticBuilder &addRanges(const DiagnosticBuilder &DB,
ArrayRef<SourceRange> Ranges) {
- for (ArrayRef<SourceRange>::iterator I = Ranges.begin(), E = Ranges.end();
- I != E; ++I)
- DB << *I;
+ for (const SourceRange &Range : Ranges)
+ DB << Range;
return DB;
}
};
@@ -121,30 +114,24 @@
CheckFactories->createChecks(Filter, Checks);
- for (SmallVectorImpl<ClangTidyCheck *>::iterator I = Checks.begin(),
- E = Checks.end();
- I != E; ++I) {
- (*I)->setContext(&Context);
- (*I)->registerMatchers(&Finder);
+ for (ClangTidyCheck *Check : Checks) {
+ Check->setContext(&Context);
+ Check->registerMatchers(&Finder);
}
}
ClangTidyASTConsumerFactory::~ClangTidyASTConsumerFactory() {
- for (SmallVectorImpl<ClangTidyCheck *>::iterator I = Checks.begin(),
- E = Checks.end();
- I != E; ++I)
- delete *I;
+ for (ClangTidyCheck *Check : Checks)
+ delete Check;
}
clang::ASTConsumer *ClangTidyASTConsumerFactory::CreateASTConsumer(
clang::CompilerInstance &Compiler, StringRef File) {
// FIXME: Move this to a separate method, so that CreateASTConsumer doesn't
// modify Compiler.
Context.setSourceManager(&Compiler.getSourceManager());
- for (SmallVectorImpl<ClangTidyCheck *>::iterator I = Checks.begin(),
- E = Checks.end();
- I != E; ++I)
- (*I)->registerPPCallbacks(Compiler);
+ for (ClangTidyCheck *Check : Checks)
+ Check->registerPPCallbacks(Compiler);
SmallVector<ASTConsumer *, 2> Consumers;
if (!CheckFactories->empty())
@@ -169,34 +156,27 @@
std::vector<std::string> ClangTidyASTConsumerFactory::getCheckNames() {
std::vector<std::string> CheckNames;
- for (ClangTidyCheckFactories::FactoryMap::const_iterator
- I = CheckFactories->begin(),
- E = CheckFactories->end();
- I != E; ++I) {
- if (Filter.IsCheckEnabled(I->first))
- CheckNames.push_back(I->first);
+ for (const auto &CheckFactory : *CheckFactories) {
+ if (Filter.IsCheckEnabled(CheckFactory.first))
+ CheckNames.push_back(CheckFactory.first);
}
- CheckersList AnalyzerChecks = getCheckersControlList();
- for (CheckersList::const_iterator I = AnalyzerChecks.begin(),
- E = AnalyzerChecks.end();
- I != E; ++I)
- CheckNames.push_back(AnalyzerCheckNamePrefix + I->first);
+ for (const auto &AnalyzerCheck : getCheckersControlList())
+ CheckNames.push_back(AnalyzerCheckNamePrefix + AnalyzerCheck.first);
std::sort(CheckNames.begin(), CheckNames.end());
return CheckNames;
}
ClangTidyASTConsumerFactory::CheckersList
ClangTidyASTConsumerFactory::getCheckersControlList() {
CheckersList List;
- ArrayRef<StringRef> Checks(StaticAnalyzerChecks);
bool AnalyzerChecksEnabled = false;
- for (unsigned i = 0; i < Checks.size(); ++i) {
- std::string Checker((AnalyzerCheckNamePrefix + Checks[i]).str());
+ for (StringRef CheckName : StaticAnalyzerChecks) {
+ std::string Checker((AnalyzerCheckNamePrefix + CheckName).str());
AnalyzerChecksEnabled |=
- Filter.IsCheckEnabled(Checker) && !Checks[i].startswith("debug");
+ Filter.IsCheckEnabled(Checker) && !CheckName.startswith("debug");
}
if (AnalyzerChecksEnabled) {
@@ -207,12 +187,12 @@
// Always add all core checkers if any other static analyzer checks are
// enabled. This is currently necessary, as other path sensitive checks
// rely on the core checkers.
- for (unsigned i = 0; i < Checks.size(); ++i) {
- std::string Checker((AnalyzerCheckNamePrefix + Checks[i]).str());
+ for (StringRef CheckName : StaticAnalyzerChecks) {
+ std::string Checker((AnalyzerCheckNamePrefix + CheckName).str());
- if (Checks[i].startswith("core") ||
- (!Checks[i].startswith("debug") && Filter.IsCheckEnabled(Checker)))
- List.push_back(std::make_pair(Checks[i], true));
+ if (CheckName.startswith("core") ||
+ (!CheckName.startswith("debug") && Filter.IsCheckEnabled(Checker)))
+ List.push_back(std::make_pair(CheckName, true));
}
}
return List;
@@ -302,20 +282,18 @@
SourceManager &SourceMgr,
DiagnosticsEngine::Level Level,
DiagnosticsEngine &Diags,
- tooling::Replacements *Fixes = NULL) {
+ const tooling::Replacements *Fixes = NULL) {
SourceLocation Loc =
getLocation(SourceMgr, Message.FilePath, Message.FileOffset);
DiagnosticBuilder Diag = Diags.Report(Loc, Diags.getCustomDiagID(Level, "%0"))
<< Message.Message;
if (Fixes != NULL) {
- for (tooling::Replacements::const_iterator I = Fixes->begin(),
- E = Fixes->end();
- I != E; ++I) {
+ for (const tooling::Replacement &Fix : *Fixes) {
SourceLocation FixLoc =
- getLocation(SourceMgr, I->getFilePath(), I->getOffset());
+ getLocation(SourceMgr, Fix.getFilePath(), Fix.getOffset());
Diag << FixItHint::CreateReplacement(
- SourceRange(FixLoc, FixLoc.getLocWithOffset(I->getLength())),
- I->getReplacementText());
+ SourceRange(FixLoc, FixLoc.getLocWithOffset(Fix.getLength())),
+ Fix.getReplacementText());
}
}
}
@@ -332,15 +310,13 @@
DiagPrinter->BeginSourceFile(LangOpts);
SourceManager SourceMgr(Diags, Files);
Rewriter Rewrite(SourceMgr, LangOpts);
- for (SmallVectorImpl<ClangTidyError>::iterator I = Errors.begin(),
- E = Errors.end();
- I != E; ++I) {
- reportDiagnostic(I->Message, SourceMgr, DiagnosticsEngine::Warning, Diags,
- &I->Fix);
- for (unsigned i = 0, e = I->Notes.size(); i != e; ++i) {
- reportDiagnostic(I->Notes[i], SourceMgr, DiagnosticsEngine::Note, Diags);
- }
- tooling::applyAllReplacements(I->Fix, Rewrite);
+ for (const ClangTidyError &Error : Errors) {
+ reportDiagnostic(Error.Message, SourceMgr, DiagnosticsEngine::Warning, Diags,
+ &Error.Fix);
+ for (const ClangTidyMessage &Note : Error.Notes)
+ reportDiagnostic(Note, SourceMgr, DiagnosticsEngine::Note, Diags);
+
+ tooling::applyAllReplacements(Error.Fix, Rewrite);
}
// FIXME: Run clang-format on changes.
if (Fix)
Index: clang-tidy/ClangTidyDiagnosticConsumer.cpp
===================================================================
--- clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -119,8 +119,8 @@
// Flushes the internal diagnostics buffer to the ClangTidyContext.
void ClangTidyDiagnosticConsumer::finish() {
finalizeLastError();
- for (unsigned i = 0, e = Errors.size(); i != e; ++i)
- Context.storeError(Errors[i]);
+ for (const ClangTidyError &Error : Errors)
+ Context.storeError(Error);
Errors.clear();
}
Index: clang-tidy/ClangTidyModule.cpp
===================================================================
--- clang-tidy/ClangTidyModule.cpp
+++ clang-tidy/ClangTidyModule.cpp
@@ -17,24 +17,21 @@
namespace tidy {
ClangTidyCheckFactories::~ClangTidyCheckFactories() {
- for (FactoryMap::iterator I = Factories.begin(), E = Factories.end(); I != E;
- ++I) {
- delete I->second;
- }
+ for (const auto &Factory : Factories)
+ delete Factory.second;
}
+
void ClangTidyCheckFactories::addCheckFactory(StringRef Name,
CheckFactoryBase *Factory) {
-
Factories[Name] = Factory;
}
void ClangTidyCheckFactories::createChecks(
ChecksFilter &Filter, SmallVectorImpl<ClangTidyCheck *> &Checks) {
- for (FactoryMap::iterator I = Factories.begin(), E = Factories.end(); I != E;
- ++I) {
- if (Filter.IsCheckEnabled(I->first)) {
- ClangTidyCheck *Check = I->second->createCheck();
- Check->setName(I->first);
+ for (const auto &Factory : Factories) {
+ if (Filter.IsCheckEnabled(Factory.first)) {
+ ClangTidyCheck *Check = Factory.second->createCheck();
+ Check->setName(Factory.first);
Checks.push_back(Check);
}
}
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits