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

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

Issue 1839573002: rewrite_to_chrome_style: making globals great again. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments Created 4 years, 9 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 | tools/clang/rewrite_to_chrome_style/tests/variables-expected.cc » ('j') | 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 3607731f3699aefa6ff2f897e5f272e4f838a26e..e91153a4646bd26418b14a2eeaaab37f4ed2bcb2 100644
--- a/tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp
+++ b/tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp
@@ -375,6 +375,13 @@ bool GetNameForDecl(const clang::VarDecl& decl,
name[1] = clang::toUppercase(name[1]);
} else {
name = CamelCaseToUnderscoreCase(original_name);
+
+ // Non-const variables with static storage duration at namespace scope are
+ // prefixed with `g_' to reduce the likelihood of a naming collision.
+ const clang::DeclContext* decl_context = decl.getDeclContext();
+ if (name.find("g_") != 0 && decl.hasGlobalStorage() &&
+ decl_context->isNamespace())
+ name.insert(0, "g_");
}
// Static members end with _ just like other members, but constants should
« no previous file with comments | « no previous file | tools/clang/rewrite_to_chrome_style/tests/variables-expected.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698