Commit 7370c566 authored by dcheng's avatar dcheng Committed by Commit bot

rewrite_to_chrome_style: skip nodes expanded from macros

Since the tool wasn't using the "spelling" location, replacements would
be emitted using source locations into an unnamed input buffer. As a
result, the emitted replacements would never apply since the file name
would never match.

However, it ends up still being included in the symbol dump for the
rebase tool. Since these identifiers aren't being renamed, just skip
processing anything inside a macro.

BUG=581902

Review URL: https://codereview.chromium.org/1641703003

Cr-Commit-Position: refs/heads/master@{#372203}
parent 00403eb7
...@@ -241,20 +241,21 @@ class RewriterBase : public MatchFinder::MatchCallback { ...@@ -241,20 +241,21 @@ class RewriterBase : public MatchFinder::MatchCallback {
: replacements_(replacements) {} : replacements_(replacements) {}
void run(const MatchFinder::MatchResult& result) override { void run(const MatchFinder::MatchResult& result) override {
std::string name; std::string new_name;
const DeclNode* decl = result.Nodes.getNodeAs<DeclNode>("decl"); const DeclNode* decl = result.Nodes.getNodeAs<DeclNode>("decl");
clang::ASTContext* context = result.Context; clang::ASTContext* context = result.Context;
if (!GetNameForDecl(*decl, *context, name)) if (!GetNameForDecl(*decl, *context, new_name))
return; return;
auto r = replacements_->emplace( llvm::StringRef old_name = decl->getName();
*result.SourceManager, TargetNodeTraits<TargetNode>::GetRange( if (old_name == new_name)
*result.Nodes.getNodeAs<TargetNode>( return;
TargetNodeTraits<TargetNode>::kName)), clang::CharSourceRange range = TargetNodeTraits<TargetNode>::GetRange(
name); *result.Nodes.getNodeAs<TargetNode>(
auto from = decl->getNameAsString(); TargetNodeTraits<TargetNode>::kName));
auto to = r.first->getReplacementText().str(); if (range.getBegin().isMacroID() || range.getEnd().isMacroID())
if (from != to) return;
replacement_names_.emplace(std::move(from), std::move(to)); replacements_->emplace(*result.SourceManager, range, new_name);
replacement_names_.emplace(old_name.str(), std::move(new_name));
} }
const std::unordered_map<std::string, std::string>& replacement_names() const std::unordered_map<std::string, std::string>& replacement_names()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment