Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(165)

Unified Diff: tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp

Issue 1642323002: rewrite_to_chrome_style: Fix assert calling getName() when there's none (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rewrite-getname: rebase Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp
diff --git a/tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp b/tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp
index 4942d50dac7ba089567723315df77f6b64bcfd87..3f74b3c2e096d53778bb39d0cb12caab9054f5e8 100644
--- a/tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp
+++ b/tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp
@@ -59,7 +59,7 @@ const char kBlinkStaticMemberPrefix[] = "s_";
bool GetNameForDecl(const clang::FunctionDecl& decl,
const clang::ASTContext& context,
std::string& name) {
- name = decl.getNameAsString();
+ StringRef original_name = decl.getName();
if (const auto* method = clang::dyn_cast<const clang::CXXMethodDecl>(&decl)) {
if (!method->isStatic()) {
@@ -67,12 +67,13 @@ bool GetNameForDecl(const clang::FunctionDecl& decl,
static const char* kBlacklist[] = {"begin", "end", "rbegin", "rend",
"trace"};
for (const auto& b : kBlacklist) {
- if (name == b)
+ if (original_name == b)
return false;
}
}
}
+ name = original_name.str();
name[0] = clang::toUppercase(name[0]);
return true;
}
@@ -244,6 +245,10 @@ class RewriterBase : public MatchFinder::MatchCallback {
std::string new_name;
const DeclNode* decl = result.Nodes.getNodeAs<DeclNode>("decl");
clang::ASTContext* context = result.Context;
+ // If false, there's no name to be renamed.
+ if (!decl->getIdentifier())
+ return;
+ // If false, the name was not suitable for renaming.
if (!GetNameForDecl(*decl, *context, new_name))
return;
llvm::StringRef old_name = decl->getName();
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698