Chromium Code Reviews| 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 025fbdcc3d0389ad6ef5603228142beee8ec1841..3f44b500b524a064725f763f76d2448ec0907b92 100644 |
| --- a/tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp |
| +++ b/tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp |
| @@ -51,6 +51,8 @@ namespace { |
| const char kBlinkFieldPrefix[] = "m_"; |
| const char kBlinkStaticMemberPrefix[] = "s_"; |
| const char kGeneratedFileRegex[] = "^gen/|/gen/"; |
| +const char kGeneratedFileExclusionRegex[] = |
| + "(^gen/|/gen/).*/ComputedStyleBase\\.h$"; |
| const char kGMockMethodNamePrefix[] = "gmock_"; |
| const char kMethodBlocklistParamName[] = "method-blocklist"; |
| @@ -497,6 +499,41 @@ AST_MATCHER(clang::VarDecl, isKnownTraitName) { |
| return IsKnownTraitName(Node.getName()); |
| } |
| +AST_MATCHER(clang::Decl, isDeclInGeneratedFile) { |
| + // This matcher mimics the built-in isExpansionInFileMatching matcher from |
| + // llvm/tools/clang/include/clang/ASTMatchers/ASTMatchers.h, except: |
| + // - It special cases some files (e.g. doesn't skip renaming of identifiers |
| + // from gen/blink/core/ComputedStyleBase.h) |
| + |
| + const clang::SourceManager& source_manager = |
| + Node.getASTContext().getSourceManager(); |
| + |
| + // TODO(lukasza): Consider using getSpellingLoc below. |
| + // The built-in isExpansionInFileMatching matcher uses getExpansionLoc below. |
| + // We could consider using getSpellingLoc (which properly handles things like |
| + // SETTINGS_GETTERS_AND_SETTERS macro which is defined in generated code |
| + // (gen/blink/core/SettingsMacros.h), but expanded in non-generated code |
| + // (third_party/WebKit/Source/core/frame/Settings.h). |
|
Łukasz Anforowicz
2017/02/02 01:06:16
This TODO is probably not that important. Things
|
| + clang::SourceLocation loc = |
| + source_manager.getExpansionLoc(Node.getLocStart()); |
| + |
| + // TODO(lukasza): jump out of scratch space if token concatenation was used. |
| + if (loc.isInvalid()) |
| + return false; |
| + |
| + const clang::FileEntry* file_entry = |
| + source_manager.getFileEntryForID(source_manager.getFileID(loc)); |
| + if (!file_entry) |
| + return false; |
| + |
| + static llvm::Regex exclusion_regex(kGeneratedFileExclusionRegex); |
| + if (exclusion_regex.match(file_entry->getName())) |
| + return false; |
| + |
| + static llvm::Regex generated_file_regex(kGeneratedFileRegex); |
| + return generated_file_regex.match(file_entry->getName()); |
| +} |
| + |
| // Helper to convert from a camelCaseName to camel_case_name. It uses some |
| // heuristics to try to handle acronyms in camel case names correctly. |
| std::string CamelCaseToUnderscoreCase(StringRef input) { |
| @@ -1469,7 +1506,7 @@ int main(int argc, const char* argv[]) { |
| auto in_blink_namespace = decl( |
| anyOf(decl_under_blink_namespace, decl_has_qualifier_to_blink_namespace, |
| hasAncestor(decl_has_qualifier_to_blink_namespace)), |
| - unless(hasCanonicalDecl(isExpansionInFileMatching(kGeneratedFileRegex)))); |
| + unless(hasCanonicalDecl(isDeclInGeneratedFile()))); |
| // Field, variable, and enum declarations ======== |
| // Given |