modernize-use-auto NFC fixes

llvm-svn: 289656
This commit is contained in:
Piotr Padlewski 2016-12-14 15:29:23 +00:00
parent facbd35696
commit 08124b110a
31 changed files with 72 additions and 117 deletions

View File

@ -709,7 +709,7 @@ void ChangeNamespaceTool::fixTypeLoc(
return; return;
} }
const Decl *DeclCtx = Result.Nodes.getNodeAs<Decl>("dc"); const auto *DeclCtx = Result.Nodes.getNodeAs<Decl>("dc");
assert(DeclCtx && "Empty decl context."); assert(DeclCtx && "Empty decl context.");
replaceQualifiedSymbolInDeclContext(Result, DeclCtx->getDeclContext(), Start, replaceQualifiedSymbolInDeclContext(Result, DeclCtx->getDeclContext(), Start,
End, FromDecl); End, FromDecl);

View File

@ -124,9 +124,7 @@ static void reportConflict(
bool applyAllReplacements(const std::vector<tooling::Replacement> &Replaces, bool applyAllReplacements(const std::vector<tooling::Replacement> &Replaces,
Rewriter &Rewrite) { Rewriter &Rewrite) {
bool Result = true; bool Result = true;
for (std::vector<tooling::Replacement>::const_iterator I = Replaces.begin(), for (auto I = Replaces.begin(), E = Replaces.end(); I != E; ++I) {
E = Replaces.end();
I != E; ++I) {
if (I->isApplicable()) { if (I->isApplicable()) {
Result = I->apply(Rewrite) && Result; Result = I->apply(Rewrite) && Result;
} else { } else {
@ -293,8 +291,7 @@ RangeVector calculateChangedRanges(
bool writeFiles(const clang::Rewriter &Rewrites) { bool writeFiles(const clang::Rewriter &Rewrites) {
for (Rewriter::const_buffer_iterator BufferI = Rewrites.buffer_begin(), for (auto BufferI = Rewrites.buffer_begin(), BufferE = Rewrites.buffer_end();
BufferE = Rewrites.buffer_end();
BufferI != BufferE; ++BufferI) { BufferI != BufferE; ++BufferI) {
StringRef FileName = StringRef FileName =
Rewrites.getSourceMgr().getFileEntryForID(BufferI->first)->getName(); Rewrites.getSourceMgr().getFileEntryForID(BufferI->first)->getName();

View File

@ -86,14 +86,11 @@ bool MatchQuery::run(llvm::raw_ostream &OS, QuerySession &QS) const {
} }
Finder.matchAST(AST->getASTContext()); Finder.matchAST(AST->getASTContext());
for (std::vector<BoundNodes>::iterator MI = Matches.begin(), for (auto MI = Matches.begin(), ME = Matches.end(); MI != ME; ++MI) {
ME = Matches.end();
MI != ME; ++MI) {
OS << "\nMatch #" << ++MatchCount << ":\n\n"; OS << "\nMatch #" << ++MatchCount << ":\n\n";
for (BoundNodes::IDToNodeMap::const_iterator BI = MI->getMap().begin(), for (auto BI = MI->getMap().begin(), BE = MI->getMap().end(); BI != BE;
BE = MI->getMap().end(); ++BI) {
BI != BE; ++BI) {
switch (QS.OutKind) { switch (QS.OutKind) {
case OK_Diag: { case OK_Diag: {
clang::SourceRange R = BI->second.getSourceRange(); clang::SourceRange R = BI->second.getSourceRange();

View File

@ -158,9 +158,7 @@ QueryRef QueryParser::completeMatcherExpression() {
std::vector<MatcherCompletion> Comps = Parser::completeExpression( std::vector<MatcherCompletion> Comps = Parser::completeExpression(
StringRef(Begin, End - Begin), CompletionPos - Begin, nullptr, StringRef(Begin, End - Begin), CompletionPos - Begin, nullptr,
&QS.NamedValues); &QS.NamedValues);
for (std::vector<MatcherCompletion>::iterator I = Comps.begin(), for (auto I = Comps.begin(), E = Comps.end(); I != E; ++I) {
E = Comps.end();
I != E; ++I) {
Completions.push_back(LineEditor::Completion(I->TypedText, I->MatcherDecl)); Completions.push_back(LineEditor::Completion(I->TypedText, I->MatcherDecl));
} }
return QueryRef(); return QueryRef();

View File

@ -77,17 +77,13 @@ int main(int argc, const char **argv) {
QuerySession QS(ASTs); QuerySession QS(ASTs);
if (!Commands.empty()) { if (!Commands.empty()) {
for (cl::list<std::string>::iterator I = Commands.begin(), for (auto I = Commands.begin(), E = Commands.end(); I != E; ++I) {
E = Commands.end();
I != E; ++I) {
QueryRef Q = QueryParser::parse(*I, QS); QueryRef Q = QueryParser::parse(*I, QS);
if (!Q->run(llvm::outs(), QS)) if (!Q->run(llvm::outs(), QS))
return 1; return 1;
} }
} else if (!CommandFiles.empty()) { } else if (!CommandFiles.empty()) {
for (cl::list<std::string>::iterator I = CommandFiles.begin(), for (auto I = CommandFiles.begin(), E = CommandFiles.end(); I != E; ++I) {
E = CommandFiles.end();
I != E; ++I) {
std::ifstream Input(I->c_str()); std::ifstream Input(I->c_str());
if (!Input.is_open()) { if (!Input.is_open()) {
llvm::errs() << argv[0] << ": cannot open " << *I << "\n"; llvm::errs() << argv[0] << ": cannot open " << *I << "\n";

View File

@ -196,7 +196,7 @@ computeInsertions(const CXXConstructorDecl::init_const_range &Inits,
// Add all fields between current field up until the next intializer. // Add all fields between current field up until the next intializer.
for (; Decl != std::end(OrderedDecls) && *Decl != InitDecl; ++Decl) { for (; Decl != std::end(OrderedDecls) && *Decl != InitDecl; ++Decl) {
if (const T *D = dyn_cast<T>(*Decl)) { if (const auto *D = dyn_cast<T>(*Decl)) {
if (DeclsToInit.count(D) > 0) if (DeclsToInit.count(D) > 0)
Insertions.back().Initializers.emplace_back(getName(D)); Insertions.back().Initializers.emplace_back(getName(D));
} }
@ -208,7 +208,7 @@ computeInsertions(const CXXConstructorDecl::init_const_range &Inits,
// Add remaining decls that require initialization. // Add remaining decls that require initialization.
for (; Decl != std::end(OrderedDecls); ++Decl) { for (; Decl != std::end(OrderedDecls); ++Decl) {
if (const T *D = dyn_cast<T>(*Decl)) { if (const auto *D = dyn_cast<T>(*Decl)) {
if (DeclsToInit.count(D) > 0) if (DeclsToInit.count(D) > 0)
Insertions.back().Initializers.emplace_back(getName(D)); Insertions.back().Initializers.emplace_back(getName(D));
} }

View File

@ -82,8 +82,7 @@ join(ArrayRef<SpecialMemberFunctionsCheck::SpecialMemberFunctionKind> SMFS,
void SpecialMemberFunctionsCheck::check( void SpecialMemberFunctionsCheck::check(
const MatchFinder::MatchResult &Result) { const MatchFinder::MatchResult &Result) {
const CXXRecordDecl *MatchedDecl = const auto *MatchedDecl = Result.Nodes.getNodeAs<CXXRecordDecl>("class-def");
Result.Nodes.getNodeAs<CXXRecordDecl>("class-def");
if (!MatchedDecl) if (!MatchedDecl)
return; return;

View File

@ -75,8 +75,7 @@ static bool isStdInitializerList(QualType Type) {
} }
void ExplicitConstructorCheck::check(const MatchFinder::MatchResult &Result) { void ExplicitConstructorCheck::check(const MatchFinder::MatchResult &Result) {
const CXXConstructorDecl *Ctor = const auto *Ctor = Result.Nodes.getNodeAs<CXXConstructorDecl>("ctor");
Result.Nodes.getNodeAs<CXXConstructorDecl>("ctor");
// Do not be confused: isExplicit means 'explicit' keyword is present, // Do not be confused: isExplicit means 'explicit' keyword is present,
// isImplicit means that it's a compiler-generated constructor. // isImplicit means that it's a compiler-generated constructor.
if (Ctor->isOutOfLine() || Ctor->isImplicit() || Ctor->isDeleted() || if (Ctor->isOutOfLine() || Ctor->isImplicit() || Ctor->isDeleted() ||

View File

@ -56,7 +56,7 @@ void NonConstReferences::check(const MatchFinder::MatchResult &Result) {
if (!Function->isCanonicalDecl()) if (!Function->isCanonicalDecl())
return; return;
if (const CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(Function)) { if (const auto *Method = dyn_cast<CXXMethodDecl>(Function)) {
// Don't warn on implementations of an interface using references. // Don't warn on implementations of an interface using references.
if (Method->begin_overridden_methods() != Method->end_overridden_methods()) if (Method->begin_overridden_methods() != Method->end_overridden_methods())
return; return;

View File

@ -25,7 +25,7 @@ void TwineLocalCheck::registerMatchers(MatchFinder *Finder) {
} }
void TwineLocalCheck::check(const MatchFinder::MatchResult &Result) { void TwineLocalCheck::check(const MatchFinder::MatchResult &Result) {
const VarDecl *VD = Result.Nodes.getNodeAs<VarDecl>("variable"); const auto *VD = Result.Nodes.getNodeAs<VarDecl>("variable");
auto Diag = diag(VD->getLocation(), auto Diag = diag(VD->getLocation(),
"twine variables are prone to use-after-free bugs"); "twine variables are prone to use-after-free bugs");

View File

@ -177,7 +177,7 @@ void ArgumentCommentCheck::checkCallArgs(ASTContext *Ctx,
} }
void ArgumentCommentCheck::check(const MatchFinder::MatchResult &Result) { void ArgumentCommentCheck::check(const MatchFinder::MatchResult &Result) {
const Expr *E = Result.Nodes.getNodeAs<Expr>("expr"); const auto *E = Result.Nodes.getNodeAs<Expr>("expr");
if (const auto *Call = dyn_cast<CallExpr>(E)) { if (const auto *Call = dyn_cast<CallExpr>(E)) {
const FunctionDecl *Callee = Call->getDirectCallee(); const FunctionDecl *Callee = Call->getDirectCallee();
if (!Callee) if (!Callee)

View File

@ -104,8 +104,7 @@ void MoveForwardingReferenceCheck::check(
// Get the FunctionDecl and FunctionTemplateDecl containing the function // Get the FunctionDecl and FunctionTemplateDecl containing the function
// parameter. // parameter.
const FunctionDecl *FuncForParam = const auto *FuncForParam = dyn_cast<FunctionDecl>(ParmVar->getDeclContext());
dyn_cast<FunctionDecl>(ParmVar->getDeclContext());
if (!FuncForParam) if (!FuncForParam)
return; return;
const FunctionTemplateDecl *FuncTemplate = const FunctionTemplateDecl *FuncTemplate =

View File

@ -26,7 +26,7 @@ const Stmt *nextStmt(const MatchFinder::MatchResult &Result, const Stmt *S) {
auto Parents = Result.Context->getParents(*S); auto Parents = Result.Context->getParents(*S);
if (Parents.empty()) if (Parents.empty())
return nullptr; return nullptr;
const Stmt *Parent = Parents[0].get<Stmt>(); const auto *Parent = Parents[0].get<Stmt>();
if (!Parent) if (!Parent)
return nullptr; return nullptr;
const Stmt *Prev = nullptr; const Stmt *Prev = nullptr;

View File

@ -100,10 +100,8 @@ void ThrowByValueCatchByReferenceCheck::diagnoseThrowLocations(
if (CheckAnonymousTemporaries) { if (CheckAnonymousTemporaries) {
bool emit = false; bool emit = false;
auto *currentSubExpr = subExpr->IgnoreImpCasts(); auto *currentSubExpr = subExpr->IgnoreImpCasts();
const DeclRefExpr *variableReference = const auto *variableReference = dyn_cast<DeclRefExpr>(currentSubExpr);
dyn_cast<DeclRefExpr>(currentSubExpr); const auto *constructorCall = dyn_cast<CXXConstructExpr>(currentSubExpr);
const CXXConstructExpr *constructorCall =
dyn_cast<CXXConstructExpr>(currentSubExpr);
// If we have a DeclRefExpr, we flag for emitting a diagnosis message in // If we have a DeclRefExpr, we flag for emitting a diagnosis message in
// case the referenced variable is neither a function parameter nor a // case the referenced variable is neither a function parameter nor a
// variable declared in the catch statement. // variable declared in the catch statement.

View File

@ -26,7 +26,7 @@ const char CastSequence[] = "sequence";
AST_MATCHER(Type, sugaredNullptrType) { AST_MATCHER(Type, sugaredNullptrType) {
const Type *DesugaredType = Node.getUnqualifiedDesugaredType(); const Type *DesugaredType = Node.getUnqualifiedDesugaredType();
if (const BuiltinType *BT = dyn_cast<BuiltinType>(DesugaredType)) if (const auto *BT = dyn_cast<BuiltinType>(DesugaredType))
return BT->getKind() == BuiltinType::NullPtr; return BT->getKind() == BuiltinType::NullPtr;
return false; return false;
} }
@ -188,7 +188,7 @@ public:
// Only VisitStmt is overridden as we shouldn't find other base AST types // Only VisitStmt is overridden as we shouldn't find other base AST types
// within a cast expression. // within a cast expression.
bool VisitStmt(Stmt *S) { bool VisitStmt(Stmt *S) {
CastExpr *C = dyn_cast<CastExpr>(S); auto *C = dyn_cast<CastExpr>(S);
// Catch the castExpr inside cxxDefaultArgExpr. // Catch the castExpr inside cxxDefaultArgExpr.
if (auto *E = dyn_cast<CXXDefaultArgExpr>(S)) if (auto *E = dyn_cast<CXXDefaultArgExpr>(S))
C = dyn_cast<CastExpr>(E->getExpr()); C = dyn_cast<CastExpr>(E->getExpr());

View File

@ -60,7 +60,7 @@ static StringRef GetText(const Token &Tok, const SourceManager &Sources) {
} }
void UseOverrideCheck::check(const MatchFinder::MatchResult &Result) { void UseOverrideCheck::check(const MatchFinder::MatchResult &Result) {
const FunctionDecl *Method = Result.Nodes.getNodeAs<FunctionDecl>("method"); const auto *Method = Result.Nodes.getNodeAs<FunctionDecl>("method");
const SourceManager &Sources = *Result.SourceManager; const SourceManager &Sources = *Result.SourceManager;
assert(Method != nullptr); assert(Method != nullptr);

View File

@ -243,7 +243,7 @@ void TypeMismatchCheck::registerMatchers(MatchFinder *Finder) {
void TypeMismatchCheck::check(const MatchFinder::MatchResult &Result) { void TypeMismatchCheck::check(const MatchFinder::MatchResult &Result) {
static ento::mpi::MPIFunctionClassifier FuncClassifier(*Result.Context); static ento::mpi::MPIFunctionClassifier FuncClassifier(*Result.Context);
const CallExpr *const CE = Result.Nodes.getNodeAs<CallExpr>("CE"); const auto *const CE = Result.Nodes.getNodeAs<CallExpr>("CE");
if (!CE->getDirectCallee()) if (!CE->getDirectCallee())
return; return;

View File

@ -102,7 +102,7 @@ bool areParensNeededForOverloadedOperator(OverloadedOperatorKind OperatorKind) {
} }
bool areParensNeededForStatement(const Stmt *Statement) { bool areParensNeededForStatement(const Stmt *Statement) {
if (const CXXOperatorCallExpr *OverloadedOperatorCall = if (const auto *OverloadedOperatorCall =
llvm::dyn_cast<CXXOperatorCallExpr>(Statement)) { llvm::dyn_cast<CXXOperatorCallExpr>(Statement)) {
return areParensNeededForOverloadedOperator( return areParensNeededForOverloadedOperator(
OverloadedOperatorCall->getOperator()); OverloadedOperatorCall->getOperator());

View File

@ -57,7 +57,7 @@ static std::string getNamespaceComment(const NamespaceDecl *ND,
} }
void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) { void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) {
const NamespaceDecl *ND = Result.Nodes.getNodeAs<NamespaceDecl>("namespace"); const auto *ND = Result.Nodes.getNodeAs<NamespaceDecl>("namespace");
const SourceManager &Sources = *Result.SourceManager; const SourceManager &Sources = *Result.SourceManager;
if (!locationsInSameFile(Sources, ND->getLocStart(), ND->getRBraceLoc())) if (!locationsInSameFile(Sources, ND->getLocStart(), ND->getRBraceLoc()))

View File

@ -24,7 +24,7 @@ void RedundantDeclarationCheck::registerMatchers(MatchFinder *Finder) {
} }
void RedundantDeclarationCheck::check(const MatchFinder::MatchResult &Result) { void RedundantDeclarationCheck::check(const MatchFinder::MatchResult &Result) {
const NamedDecl *D = Result.Nodes.getNodeAs<NamedDecl>("Decl"); const auto *D = Result.Nodes.getNodeAs<NamedDecl>("Decl");
const auto *Prev = D->getPreviousDecl(); const auto *Prev = D->getPreviousDecl();
if (!Prev) if (!Prev)
return; return;

View File

@ -116,8 +116,8 @@ void RedundantSmartptrGetCheck::check(const MatchFinder::MatchResult &Result) {
bool IsPtrToPtr = Result.Nodes.getNodeAs<Decl>("ptr_to_ptr") != nullptr; bool IsPtrToPtr = Result.Nodes.getNodeAs<Decl>("ptr_to_ptr") != nullptr;
bool IsMemberExpr = Result.Nodes.getNodeAs<Expr>("memberExpr") != nullptr; bool IsMemberExpr = Result.Nodes.getNodeAs<Expr>("memberExpr") != nullptr;
const Expr *GetCall = Result.Nodes.getNodeAs<Expr>("redundant_get"); const auto *GetCall = Result.Nodes.getNodeAs<Expr>("redundant_get");
const Expr *Smartptr = Result.Nodes.getNodeAs<Expr>("smart_pointer"); const auto *Smartptr = Result.Nodes.getNodeAs<Expr>("smart_pointer");
if (IsPtrToPtr && IsMemberExpr) { if (IsPtrToPtr && IsMemberExpr) {
// Ignore this case (eg. Foo->get()->DoSomething()); // Ignore this case (eg. Foo->get()->DoSomething());

View File

@ -211,7 +211,7 @@ void FindAllSymbols::run(const MatchFinder::MatchResult &Result) {
return; return;
} }
const NamedDecl *ND = Result.Nodes.getNodeAs<NamedDecl>("decl"); const auto *ND = Result.Nodes.getNodeAs<NamedDecl>("decl");
assert(ND && "Matched declaration must be a NamedDecl!"); assert(ND && "Matched declaration must be a NamedDecl!");
const SourceManager *SM = Result.SourceManager; const SourceManager *SM = Result.SourceManager;

View File

@ -225,8 +225,7 @@ bool CoverageChecker::collectModuleHeaders(const Module &Mod) {
ModuleMapHeadersSet.insert(ModularizeUtilities::getCanonicalPath( ModuleMapHeadersSet.insert(ModularizeUtilities::getCanonicalPath(
Header.Entry->getName())); Header.Entry->getName()));
for (Module::submodule_const_iterator MI = Mod.submodule_begin(), for (auto MI = Mod.submodule_begin(), MIEnd = Mod.submodule_end();
MIEnd = Mod.submodule_end();
MI != MIEnd; ++MI) MI != MIEnd; ++MI)
collectModuleHeaders(**MI); collectModuleHeaders(**MI);

View File

@ -341,9 +341,7 @@ static std::string findInputFile(const CommandLineArguments &CLArgs) {
const unsigned IncludedFlagsBitmask = options::CC1Option; const unsigned IncludedFlagsBitmask = options::CC1Option;
unsigned MissingArgIndex, MissingArgCount; unsigned MissingArgIndex, MissingArgCount;
SmallVector<const char *, 256> Argv; SmallVector<const char *, 256> Argv;
for (CommandLineArguments::const_iterator I = CLArgs.begin(), for (auto I = CLArgs.begin(), E = CLArgs.end(); I != E; ++I)
E = CLArgs.end();
I != E; ++I)
Argv.push_back(I->c_str()); Argv.push_back(I->c_str());
InputArgList Args = Opts->ParseArgs(Argv, MissingArgIndex, MissingArgCount, InputArgList Args = Opts->ParseArgs(Argv, MissingArgIndex, MissingArgCount,
IncludedFlagsBitmask); IncludedFlagsBitmask);

View File

@ -77,7 +77,7 @@ ModularizeUtilities *ModularizeUtilities::createModularizeUtilities(
std::error_code ModularizeUtilities::loadAllHeaderListsAndDependencies() { std::error_code ModularizeUtilities::loadAllHeaderListsAndDependencies() {
typedef std::vector<std::string>::iterator Iter; typedef std::vector<std::string>::iterator Iter;
// For each input file. // For each input file.
for (Iter I = InputFilePaths.begin(), E = InputFilePaths.end(); I != E; ++I) { for (auto I = InputFilePaths.begin(), E = InputFilePaths.end(); I != E; ++I) {
llvm::StringRef InputPath = *I; llvm::StringRef InputPath = *I;
// If it's a module map. // If it's a module map.
if (InputPath.endswith(".modulemap")) { if (InputPath.endswith(".modulemap")) {
@ -345,8 +345,7 @@ bool ModularizeUtilities::collectModuleHeaders(const clang::Module &Mod) {
DependentsVector UmbrellaDependents; DependentsVector UmbrellaDependents;
// Recursively do submodules. // Recursively do submodules.
for (clang::Module::submodule_const_iterator MI = Mod.submodule_begin(), for (auto MI = Mod.submodule_begin(), MIEnd = Mod.submodule_end();
MIEnd = Mod.submodule_end();
MI != MIEnd; ++MI) MI != MIEnd; ++MI)
collectModuleHeaders(**MI); collectModuleHeaders(**MI);

View File

@ -87,17 +87,14 @@ bool Module::output(llvm::raw_fd_ostream &OS, int Indent) {
} }
// Output submodules. // Output submodules.
for (std::vector<Module *>::iterator I = SubModules.begin(), for (auto I = SubModules.begin(), E = SubModules.end(); I != E; ++I) {
E = SubModules.end();
I != E; ++I) {
if (!(*I)->output(OS, Indent)) if (!(*I)->output(OS, Indent))
return false; return false;
} }
// Output header files. // Output header files.
for (std::vector<std::string>::iterator I = HeaderFileNames.begin(), for (auto I = HeaderFileNames.begin(), E = HeaderFileNames.end(); I != E;
E = HeaderFileNames.end(); ++I) {
I != E; ++I) {
OS.indent(Indent); OS.indent(Indent);
if (IsProblem || strstr((*I).c_str(), ".inl")) if (IsProblem || strstr((*I).c_str(), ".inl"))
OS << "exclude header \"" << *I << "\"\n"; OS << "exclude header \"" << *I << "\"\n";
@ -123,9 +120,7 @@ bool Module::output(llvm::raw_fd_ostream &OS, int Indent) {
// Lookup a sub-module. // Lookup a sub-module.
Module *Module::findSubModule(llvm::StringRef SubName) { Module *Module::findSubModule(llvm::StringRef SubName) {
for (std::vector<Module *>::iterator I = SubModules.begin(), for (auto I = SubModules.begin(), E = SubModules.end(); I != E; ++I) {
E = SubModules.end();
I != E; ++I) {
if ((*I)->Name == SubName) if ((*I)->Name == SubName)
return *I; return *I;
} }
@ -227,7 +222,7 @@ static Module *loadModuleDescriptions(
DependencyMap &Dependencies, llvm::StringRef HeaderPrefix) { DependencyMap &Dependencies, llvm::StringRef HeaderPrefix) {
// Create root module. // Create root module.
Module *RootModule = new Module(RootModuleName, false); auto *RootModule = new Module(RootModuleName, false);
llvm::SmallString<256> CurrentDirectory; llvm::SmallString<256> CurrentDirectory;
llvm::sys::fs::current_path(CurrentDirectory); llvm::sys::fs::current_path(CurrentDirectory);

View File

@ -558,9 +558,7 @@ public:
// Check for the presence of a header inclusion path handle entry. // Check for the presence of a header inclusion path handle entry.
// Return false if not found. // Return false if not found.
bool haveInclusionPathHandle(InclusionPathHandle H) { bool haveInclusionPathHandle(InclusionPathHandle H) {
for (std::vector<InclusionPathHandle>::iterator for (auto I = InclusionPathHandles.begin(), E = InclusionPathHandles.end();
I = InclusionPathHandles.begin(),
E = InclusionPathHandles.end();
I != E; ++I) { I != E; ++I) {
if (*I == H) if (*I == H)
return true; return true;
@ -608,8 +606,7 @@ public:
MacroExpansionInstance * MacroExpansionInstance *
findMacroExpansionInstance(StringHandle MacroExpanded, findMacroExpansionInstance(StringHandle MacroExpanded,
PPItemKey &DefinitionLocation) { PPItemKey &DefinitionLocation) {
for (std::vector<MacroExpansionInstance>::iterator for (auto I = MacroExpansionInstances.begin(),
I = MacroExpansionInstances.begin(),
E = MacroExpansionInstances.end(); E = MacroExpansionInstances.end();
I != E; ++I) { I != E; ++I) {
if ((I->MacroExpanded == MacroExpanded) && if ((I->MacroExpanded == MacroExpanded) &&
@ -659,9 +656,7 @@ public:
// Check for the presence of a header inclusion path handle entry. // Check for the presence of a header inclusion path handle entry.
// Return false if not found. // Return false if not found.
bool haveInclusionPathHandle(InclusionPathHandle H) { bool haveInclusionPathHandle(InclusionPathHandle H) {
for (std::vector<InclusionPathHandle>::iterator for (auto I = InclusionPathHandles.begin(), E = InclusionPathHandles.end();
I = InclusionPathHandles.begin(),
E = InclusionPathHandles.end();
I != E; ++I) { I != E; ++I) {
if (*I == H) if (*I == H)
return true; return true;
@ -701,8 +696,7 @@ public:
// Find a matching condition expansion instance. // Find a matching condition expansion instance.
ConditionalExpansionInstance * ConditionalExpansionInstance *
findConditionalExpansionInstance(clang::PPCallbacks::ConditionValueKind ConditionValue) { findConditionalExpansionInstance(clang::PPCallbacks::ConditionValueKind ConditionValue) {
for (std::vector<ConditionalExpansionInstance>::iterator for (auto I = ConditionalExpansionInstances.begin(),
I = ConditionalExpansionInstances.begin(),
E = ConditionalExpansionInstances.end(); E = ConditionalExpansionInstances.end();
I != E; ++I) { I != E; ++I) {
if (I->ConditionValue == ConditionValue) { if (I->ConditionValue == ConditionValue) {
@ -954,9 +948,8 @@ public:
HeaderHandle findHeaderHandle(llvm::StringRef HeaderPath) const { HeaderHandle findHeaderHandle(llvm::StringRef HeaderPath) const {
std::string CanonicalPath = getCanonicalPath(HeaderPath); std::string CanonicalPath = getCanonicalPath(HeaderPath);
HeaderHandle H = 0; HeaderHandle H = 0;
for (std::vector<StringHandle>::const_iterator I = HeaderPaths.begin(), for (auto I = HeaderPaths.begin(), E = HeaderPaths.end(); I != E;
E = HeaderPaths.end(); ++I, ++H) {
I != E; ++I, ++H) {
if (**I == CanonicalPath) if (**I == CanonicalPath)
return H; return H;
} }
@ -1004,9 +997,7 @@ public:
// Check for presence of header handle in the header stack. // Check for presence of header handle in the header stack.
bool isHeaderHandleInStack(HeaderHandle H) const { bool isHeaderHandleInStack(HeaderHandle H) const {
for (std::vector<HeaderHandle>::const_iterator I = HeaderStack.begin(), for (auto I = HeaderStack.begin(), E = HeaderStack.end(); I != E; ++I) {
E = HeaderStack.end();
I != E; ++I) {
if (*I == H) if (*I == H)
return true; return true;
} }
@ -1018,10 +1009,8 @@ public:
InclusionPathHandle InclusionPathHandle
findInclusionPathHandle(const std::vector<HeaderHandle> &Path) const { findInclusionPathHandle(const std::vector<HeaderHandle> &Path) const {
InclusionPathHandle H = 0; InclusionPathHandle H = 0;
for (std::vector<HeaderInclusionPath>::const_iterator for (auto I = InclusionPaths.begin(), E = InclusionPaths.end(); I != E;
I = InclusionPaths.begin(), ++I, ++H) {
E = InclusionPaths.end();
I != E; ++I, ++H) {
if (I->Path == Path) if (I->Path == Path)
return H; return H;
} }
@ -1065,7 +1054,7 @@ public:
StringHandle MacroName = addString(II->getName()); StringHandle MacroName = addString(II->getName());
PPItemKey InstanceKey(PP, MacroName, H, InstanceLoc); PPItemKey InstanceKey(PP, MacroName, H, InstanceLoc);
PPItemKey DefinitionKey(PP, MacroName, H, DefinitionLoc); PPItemKey DefinitionKey(PP, MacroName, H, DefinitionLoc);
MacroExpansionMapIter I = MacroExpansions.find(InstanceKey); auto I = MacroExpansions.find(InstanceKey);
// If existing instance of expansion not found, add one. // If existing instance of expansion not found, add one.
if (I == MacroExpansions.end()) { if (I == MacroExpansions.end()) {
std::string InstanceSourceLine = std::string InstanceSourceLine =
@ -1113,7 +1102,7 @@ public:
return; return;
StringHandle ConditionUnexpandedHandle(addString(ConditionUnexpanded)); StringHandle ConditionUnexpandedHandle(addString(ConditionUnexpanded));
PPItemKey InstanceKey(PP, ConditionUnexpandedHandle, H, InstanceLoc); PPItemKey InstanceKey(PP, ConditionUnexpandedHandle, H, InstanceLoc);
ConditionalExpansionMapIter I = ConditionalExpansions.find(InstanceKey); auto I = ConditionalExpansions.find(InstanceKey);
// If existing instance of condition not found, add one. // If existing instance of condition not found, add one.
if (I == ConditionalExpansions.end()) { if (I == ConditionalExpansions.end()) {
std::string InstanceSourceLine = std::string InstanceSourceLine =
@ -1144,9 +1133,8 @@ public:
bool reportInconsistentMacros(llvm::raw_ostream &OS) override { bool reportInconsistentMacros(llvm::raw_ostream &OS) override {
bool ReturnValue = false; bool ReturnValue = false;
// Walk all the macro expansion trackers in the map. // Walk all the macro expansion trackers in the map.
for (MacroExpansionMapIter I = MacroExpansions.begin(), for (auto I = MacroExpansions.begin(), E = MacroExpansions.end(); I != E;
E = MacroExpansions.end(); ++I) {
I != E; ++I) {
const PPItemKey &ItemKey = I->first; const PPItemKey &ItemKey = I->first;
MacroExpansionTracker &MacroExpTracker = I->second; MacroExpansionTracker &MacroExpTracker = I->second;
// If no mismatch (only one instance value) continue. // If no mismatch (only one instance value) continue.
@ -1162,8 +1150,7 @@ public:
<< "' has different values in this header, depending on how it was " << "' has different values in this header, depending on how it was "
"included.\n"; "included.\n";
// Walk all the instances. // Walk all the instances.
for (std::vector<MacroExpansionInstance>::iterator for (auto IMT = MacroExpTracker.MacroExpansionInstances.begin(),
IMT = MacroExpTracker.MacroExpansionInstances.begin(),
EMT = MacroExpTracker.MacroExpansionInstances.end(); EMT = MacroExpTracker.MacroExpansionInstances.end();
IMT != EMT; ++IMT) { IMT != EMT; ++IMT) {
MacroExpansionInstance &MacroInfo = *IMT; MacroExpansionInstance &MacroInfo = *IMT;
@ -1171,12 +1158,11 @@ public:
<< *MacroInfo.MacroExpanded << *MacroInfo.MacroExpanded
<< "' with respect to these inclusion paths:\n"; << "' with respect to these inclusion paths:\n";
// Walk all the inclusion path hierarchies. // Walk all the inclusion path hierarchies.
for (std::vector<InclusionPathHandle>::iterator for (auto IIP = MacroInfo.InclusionPathHandles.begin(),
IIP = MacroInfo.InclusionPathHandles.begin(),
EIP = MacroInfo.InclusionPathHandles.end(); EIP = MacroInfo.InclusionPathHandles.end();
IIP != EIP; ++IIP) { IIP != EIP; ++IIP) {
const std::vector<HeaderHandle> &ip = getInclusionPath(*IIP); const std::vector<HeaderHandle> &ip = getInclusionPath(*IIP);
int Count = (int)ip.size(); auto Count = (int)ip.size();
for (int Index = 0; Index < Count; ++Index) { for (int Index = 0; Index < Count; ++Index) {
HeaderHandle H = ip[Index]; HeaderHandle H = ip[Index];
OS << std::string((Index * 2) + 4, ' ') << *getHeaderFilePath(H) OS << std::string((Index * 2) + 4, ' ') << *getHeaderFilePath(H)
@ -1205,7 +1191,7 @@ public:
bool reportInconsistentConditionals(llvm::raw_ostream &OS) override { bool reportInconsistentConditionals(llvm::raw_ostream &OS) override {
bool ReturnValue = false; bool ReturnValue = false;
// Walk all the conditional trackers in the map. // Walk all the conditional trackers in the map.
for (ConditionalExpansionMapIter I = ConditionalExpansions.begin(), for (auto I = ConditionalExpansions.begin(),
E = ConditionalExpansions.end(); E = ConditionalExpansions.end();
I != E; ++I) { I != E; ++I) {
const PPItemKey &ItemKey = I->first; const PPItemKey &ItemKey = I->first;
@ -1225,8 +1211,7 @@ public:
<< "' has different values in this header, depending on how it was " << "' has different values in this header, depending on how it was "
"included.\n"; "included.\n";
// Walk all the instances. // Walk all the instances.
for (std::vector<ConditionalExpansionInstance>::iterator for (auto IMT = CondTracker.ConditionalExpansionInstances.begin(),
IMT = CondTracker.ConditionalExpansionInstances.begin(),
EMT = CondTracker.ConditionalExpansionInstances.end(); EMT = CondTracker.ConditionalExpansionInstances.end();
IMT != EMT; ++IMT) { IMT != EMT; ++IMT) {
ConditionalExpansionInstance &MacroInfo = *IMT; ConditionalExpansionInstance &MacroInfo = *IMT;
@ -1234,12 +1219,11 @@ public:
<< ConditionValueKindStrings[MacroInfo.ConditionValue] << ConditionValueKindStrings[MacroInfo.ConditionValue]
<< "' with respect to these inclusion paths:\n"; << "' with respect to these inclusion paths:\n";
// Walk all the inclusion path hierarchies. // Walk all the inclusion path hierarchies.
for (std::vector<InclusionPathHandle>::iterator for (auto IIP = MacroInfo.InclusionPathHandles.begin(),
IIP = MacroInfo.InclusionPathHandles.begin(),
EIP = MacroInfo.InclusionPathHandles.end(); EIP = MacroInfo.InclusionPathHandles.end();
IIP != EIP; ++IIP) { IIP != EIP; ++IIP) {
const std::vector<HeaderHandle> &ip = getInclusionPath(*IIP); const std::vector<HeaderHandle> &ip = getInclusionPath(*IIP);
int Count = (int)ip.size(); auto Count = (int)ip.size();
for (int Index = 0; Index < Count; ++Index) { for (int Index = 0; Index < Count; ++Index) {
HeaderHandle H = ip[Index]; HeaderHandle H = ip[Index];
OS << std::string((Index * 2) + 4, ' ') << *getHeaderFilePath(H) OS << std::string((Index * 2) + 4, ' ') << *getHeaderFilePath(H)

View File

@ -161,8 +161,7 @@ static int outputPPTrace(std::vector<CallbackCall> &CallbackCalls,
const CallbackCall &Callback = *I; const CallbackCall &Callback = *I;
OS << "- Callback: " << Callback.Name << "\n"; OS << "- Callback: " << Callback.Name << "\n";
for (std::vector<Argument>::const_iterator AI = Callback.Arguments.begin(), for (auto AI = Callback.Arguments.begin(), AE = Callback.Arguments.end();
AE = Callback.Arguments.end();
AI != AE; ++AI) { AI != AE; ++AI) {
const Argument &Arg = *AI; const Argument &Arg = *AI;
OS << " " << Arg.Name << ": " << Arg.Value << "\n"; OS << " " << Arg.Name << ": " << Arg.Value << "\n";

View File

@ -14,7 +14,7 @@ public:
Finder->addMatcher(ast_matchers::varDecl().bind("var"), this); Finder->addMatcher(ast_matchers::varDecl().bind("var"), this);
} }
void check(const ast_matchers::MatchFinder::MatchResult &Result) override { void check(const ast_matchers::MatchFinder::MatchResult &Result) override {
const VarDecl *Var = Result.Nodes.getNodeAs<VarDecl>("var"); const auto *Var = Result.Nodes.getNodeAs<VarDecl>("var");
// Add diagnostics in the wrong order. // Add diagnostics in the wrong order.
diag(Var->getLocation(), "variable"); diag(Var->getLocation(), "variable");
diag(Var->getTypeSpecStartLoc(), "type specifier"); diag(Var->getTypeSpecStartLoc(), "type specifier");

View File

@ -31,8 +31,7 @@ public:
if (!Aliaser) if (!Aliaser)
Aliaser.reset(new NamespaceAliaser(*Result.SourceManager)); Aliaser.reset(new NamespaceAliaser(*Result.SourceManager));
const CallExpr *Call = const auto *Call = Result.Nodes.getNodeAs<CallExpr>("foo");
Result.Nodes.getNodeAs<CallExpr>("foo");
assert(Call != nullptr && "Did not find node \"foo\""); assert(Call != nullptr && "Did not find node \"foo\"");
auto Hint = Aliaser->createAlias(*Result.Context, *Call, "::foo::bar", auto Hint = Aliaser->createAlias(*Result.Context, *Call, "::foo::bar",
{"b", "some_alias"}); {"b", "some_alias"});

View File

@ -33,8 +33,7 @@ public:
if (!Inserter) if (!Inserter)
Inserter.reset(new UsingInserter(*Result.SourceManager)); Inserter.reset(new UsingInserter(*Result.SourceManager));
const clang::CallExpr *Call = const auto *Call = Result.Nodes.getNodeAs<clang::CallExpr>("foo");
Result.Nodes.getNodeAs<clang::CallExpr>("foo");
assert(Call != nullptr && "Did not find node \"foo\""); assert(Call != nullptr && "Did not find node \"foo\"");
auto Hint = auto Hint =
Inserter->createUsingDeclaration(*Result.Context, *Call, "::foo::func"); Inserter->createUsingDeclaration(*Result.Context, *Call, "::foo::func");