From 8769778aca3c3c679066850b26810a433383457d Mon Sep 17 00:00:00 2001 From: Kirill Bobyrev Date: Sun, 4 Sep 2016 22:50:41 +0000 Subject: [clang-rename] Enforce LLVM policy about braces around single line control flow statement body. Although it is not explicitly stated in LLVM Coding Standards, LLVM developers prefer to omit braces around flow control statements with single line body. For example the following piece of code ``` if (condition) std::cout << "Hello, world!" << std::endl; ``` is preferred to ``` if (condition) { std::cout << "Hello, world!" << std::endl; } ``` So far clang-rename has ignored this. This patch makes clang-rename more "LLVM-ish". llvm-svn: 280640 --- clang-tools-extra/clang-rename/USRLocFinder.cpp | 33 +++++++++++-------------- 1 file changed, 14 insertions(+), 19 deletions(-) (limited to 'clang-tools-extra/clang-rename/USRLocFinder.cpp') diff --git a/clang-tools-extra/clang-rename/USRLocFinder.cpp b/clang-tools-extra/clang-rename/USRLocFinder.cpp index c7ce5338d07..60bc1c27c07 100644 --- a/clang-tools-extra/clang-rename/USRLocFinder.cpp +++ b/clang-tools-extra/clang-rename/USRLocFinder.cpp @@ -44,23 +44,20 @@ public: bool VisitCXXConstructorDecl(clang::CXXConstructorDecl *ConstructorDecl) { for (const auto *Initializer : ConstructorDecl->inits()) { - if (!Initializer->isWritten()) { - // Ignore implicit initializers. + // Ignore implicit initializers. + if (!Initializer->isWritten()) continue; - } if (const clang::FieldDecl *FieldDecl = Initializer->getMember()) { - if (USRSet.find(getUSRForDecl(FieldDecl)) != USRSet.end()) { + if (USRSet.find(getUSRForDecl(FieldDecl)) != USRSet.end()) LocationsFound.push_back(Initializer->getSourceLocation()); - } } } return true; } bool VisitNamedDecl(const NamedDecl *Decl) { - if (USRSet.find(getUSRForDecl(Decl)) != USRSet.end()) { + if (USRSet.find(getUSRForDecl(Decl)) != USRSet.end()) checkAndAddLocation(Decl->getLocation()); - } return true; } @@ -92,15 +89,13 @@ public: bool VisitTypeLoc(const TypeLoc Loc) { if (USRSet.find(getUSRForDecl(Loc.getType()->getAsCXXRecordDecl())) != - USRSet.end()) { + USRSet.end()) checkAndAddLocation(Loc.getBeginLoc()); - } if (const auto *TemplateTypeParm = dyn_cast(Loc.getType())) { if (USRSet.find(getUSRForDecl(TemplateTypeParm->getDecl())) != - USRSet.end()) { + USRSet.end()) checkAndAddLocation(Loc.getBeginLoc()); - } } return true; } @@ -118,9 +113,8 @@ public: while (NameLoc) { const NamespaceDecl *Decl = NameLoc.getNestedNameSpecifier()->getAsNamespace(); - if (Decl && USRSet.find(getUSRForDecl(Decl)) != USRSet.end()) { + if (Decl && USRSet.find(getUSRForDecl(Decl)) != USRSet.end()) checkAndAddLocation(NameLoc.getLocalBeginLoc()); - } NameLoc = NameLoc.getPrefix(); } } @@ -134,11 +128,11 @@ private: Lexer::getSourceText(CharSourceRange::getTokenRange(BeginLoc, EndLoc), Context.getSourceManager(), Context.getLangOpts()); size_t Offset = TokenName.find(PrevName); - if (Offset != StringRef::npos) { - // The token of the source location we find actually has the old - // name. + + // The token of the source location we find actually has the old + // name. + if (Offset != StringRef::npos) LocationsFound.push_back(BeginLoc.getLocWithOffset(Offset)); - } } const std::set USRSet; @@ -154,9 +148,10 @@ getLocationsOfUSRs(const std::vector &USRs, StringRef PrevName, USRLocFindingASTVisitor Visitor(USRs, PrevName, Decl->getASTContext()); Visitor.TraverseDecl(Decl); NestedNameSpecifierLocFinder Finder(Decl->getASTContext()); - for (const auto &Location : Finder.getNestedNameSpecifierLocations()) { + + for (const auto &Location : Finder.getNestedNameSpecifierLocations()) Visitor.handleNestedNameSpecifierLoc(Location); - } + return Visitor.getLocationsFound(); } -- cgit v1.2.3