summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-rename/USRLocFinder.cpp
diff options
context:
space:
mode:
authorKirill Bobyrev <omtcyfz@gmail.com>2016-09-04 22:50:41 +0000
committerKirill Bobyrev <omtcyfz@gmail.com>2016-09-04 22:50:41 +0000
commit8769778aca3c3c679066850b26810a433383457d (patch)
treedc30b98dd2a30114033a0cd68b04142c0d6304b4 /clang-tools-extra/clang-rename/USRLocFinder.cpp
parent9504e3a4f04612d76bcd77012221293c21f31bd6 (diff)
downloadbcm5719-llvm-8769778aca3c3c679066850b26810a433383457d.tar.gz
bcm5719-llvm-8769778aca3c3c679066850b26810a433383457d.zip
[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
Diffstat (limited to 'clang-tools-extra/clang-rename/USRLocFinder.cpp')
-rw-r--r--clang-tools-extra/clang-rename/USRLocFinder.cpp33
1 files changed, 14 insertions, 19 deletions
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<TemplateTypeParmType>(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<std::string> USRSet;
@@ -154,9 +148,10 @@ getLocationsOfUSRs(const std::vector<std::string> &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();
}
OpenPOWER on IntegriCloud