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

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: 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 9123f5527b8b6411a510dda0371e251cb9248078..4f3badd740e70beea4c876ba33b6391c64990089 100644
--- a/tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp
+++ b/tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp
@@ -59,7 +59,10 @@ constexpr char kBlinkStaticMemberPrefix[] = "s_";
bool GetNameForDecl(const clang::FunctionDecl& decl,
const clang::ASTContext& context,
std::string& name) {
- name = decl.getNameAsString();
+ // If there's no name to change, return.
+ if (!decl.getIdentifier())
+ return false;
+ StringRef original_name = decl.getName();
if (const auto* method = clang::dyn_cast<const clang::CXXMethodDecl>(&decl)) {
if (!method->isStatic()) {
@@ -67,12 +70,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;
}
@@ -114,6 +118,9 @@ std::string CamelCaseToUnderscoreCase(StringRef input) {
bool GetNameForDecl(const clang::FieldDecl& decl,
const clang::ASTContext& context,
std::string& name) {
+ // If there's no name to change, return.
+ if (!decl.getIdentifier())
+ return false;
StringRef original_name = decl.getName();
// Blink style field names are prefixed with `m_`. If this prefix isn't
// present, assume it's already been converted to Google style.
@@ -158,6 +165,9 @@ bool IsProbablyConst(const clang::VarDecl& decl,
bool GetNameForDecl(const clang::VarDecl& decl,
const clang::ASTContext& context,
std::string& name) {
+ // If there's no name to change, return.
+ if (!decl.getIdentifier())
dcheng 2016/01/29 01:13:05 Does it makes sense to move this into RewriteBase:
danakj 2016/01/29 01:15:05 Hm ya sure.
+ return false;
StringRef original_name = decl.getName();
// Nothing to do for unnamed parameters.
« 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