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

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

Issue 2276813003: Improve accuracy of detecting type trait fields. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@blink-style-definition-outside-of-namespace-node
Patch Set: Created 4 years, 4 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/fields-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 3a19515c190ac61352db73b703e20e33987e67ac..f073c73a713531066575133ae8729e850fc7bdfb 100644
--- a/tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp
+++ b/tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp
@@ -101,17 +101,6 @@ AST_MATCHER_P(clang::OverloadExpr,
return true;
}
-bool IsDeclContextInWTF(const clang::DeclContext* decl_context) {
- auto* namespace_decl = clang::dyn_cast_or_null<clang::NamespaceDecl>(
- decl_context->getEnclosingNamespaceContext());
- if (!namespace_decl)
- return false;
- if (namespace_decl->getParent()->isTranslationUnit() &&
- namespace_decl->getName() == "WTF")
- return true;
- return IsDeclContextInWTF(namespace_decl->getParent());
-}
-
template <typename T>
bool MatchAllOverriddenMethods(
const clang::CXXMethodDecl& decl,
@@ -453,13 +442,23 @@ bool GetNameForDecl(const clang::VarDecl& decl,
bool is_const = IsProbablyConst(decl, context);
if (is_const) {
- // Struct consts in WTF do not become kFoo cuz stuff like type traits
- // should stay as lowercase.
- const clang::DeclContext* decl_context = decl.getDeclContext();
- bool is_in_wtf = IsDeclContextInWTF(decl_context);
- const clang::CXXRecordDecl* parent =
- clang::dyn_cast_or_null<clang::CXXRecordDecl>(decl_context);
- if (is_in_wtf && parent && parent->isStruct())
+ // Given
+ // namespace WTF {
+ // struct TypeTrait {
+ // static const bool value = ...;
+ // };
+ // }
+ // matches |value|.
+ auto type_trait_matcher = varDecl(
+ hasName("value"),
+ hasStaticStorageDuration(),
+ hasType(isConstQualified()),
+ hasType(booleanType()),
+ hasAncestor(recordDecl(hasAncestor(namespaceDecl(
+ hasName("WTF"), hasParent(translationUnitDecl()))))));
dcheng 2016/08/24 21:42:17 Since this is expressed as a matcher now, should w
Łukasz Anforowicz 2016/08/24 21:55:09 Good point. Done. (although this has to go to |v
+
+ // Avoid renaming |value| -> |kValue| in WTF type traits.
+ if (!match(type_trait_matcher, decl, context).empty())
return false;
if (!GetNameForConstant(original_name.str(), name))
« no previous file with comments | « no previous file | tools/clang/rewrite_to_chrome_style/tests/fields-expected.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698