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

Side by Side Diff: tools/clang/value_cleanup/ListValueRewriter.cpp

Issue 2036413003: Fix value_cleanup to handle cases where arg_expr is a macro. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 unified diff | Download patch
« no previous file with comments | « no previous file | tools/clang/value_cleanup/tests/list-value-append-expected.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ListValueRewriter.h" 5 #include "ListValueRewriter.h"
6 6
7 #include <assert.h> 7 #include <assert.h>
8 #include <algorithm> 8 #include <algorithm>
9 9
10 #include "clang/AST/ASTContext.h" 10 #include "clang/AST/ASTContext.h"
(...skipping 14 matching lines...) Expand all
25 25
26 ListValueRewriter::AppendCallback::AppendCallback(Replacements* replacements) 26 ListValueRewriter::AppendCallback::AppendCallback(Replacements* replacements)
27 : replacements_(replacements) {} 27 : replacements_(replacements) {}
28 28
29 void ListValueRewriter::AppendCallback::run( 29 void ListValueRewriter::AppendCallback::run(
30 const MatchFinder::MatchResult& result) { 30 const MatchFinder::MatchResult& result) {
31 // Delete `new base::*Value(' and `)'. 31 // Delete `new base::*Value(' and `)'.
32 auto* newExpr = result.Nodes.getNodeAs<clang::CXXNewExpr>("newExpr"); 32 auto* newExpr = result.Nodes.getNodeAs<clang::CXXNewExpr>("newExpr");
33 auto* argExpr = result.Nodes.getNodeAs<clang::Expr>("argExpr"); 33 auto* argExpr = result.Nodes.getNodeAs<clang::Expr>("argExpr");
34 34
35 // Note that for the end loc, we use the expansion loc: the argument might be
36 // a macro like true and false.
35 clang::CharSourceRange pre_arg_range = clang::CharSourceRange::getCharRange( 37 clang::CharSourceRange pre_arg_range = clang::CharSourceRange::getCharRange(
36 newExpr->getLocStart(), argExpr->getLocStart()); 38 newExpr->getLocStart(),
39 result.SourceManager->getExpansionLoc(argExpr->getLocStart()));
37 replacements_->emplace(*result.SourceManager, pre_arg_range, ""); 40 replacements_->emplace(*result.SourceManager, pre_arg_range, "");
38 41
39 clang::CharSourceRange post_arg_range = 42 clang::CharSourceRange post_arg_range =
40 clang::CharSourceRange::getTokenRange(newExpr->getLocEnd()); 43 clang::CharSourceRange::getTokenRange(newExpr->getLocEnd());
41 replacements_->emplace(*result.SourceManager, post_arg_range, ""); 44 replacements_->emplace(*result.SourceManager, post_arg_range, "");
42 } 45 }
43 46
44 ListValueRewriter::AppendBooleanCallback::AppendBooleanCallback( 47 ListValueRewriter::AppendBooleanCallback::AppendBooleanCallback(
45 Replacements* replacements) 48 Replacements* replacements)
46 : AppendCallback(replacements) {} 49 : AppendCallback(replacements) {}
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 hasArgument( 185 hasArgument(
183 0, ignoringParenImpCasts(id( 186 0, ignoringParenImpCasts(id(
184 "newExpr", 187 "newExpr",
185 cxxNewExpr(has(cxxConstructExpr( 188 cxxNewExpr(has(cxxConstructExpr(
186 hasDeclaration(cxxMethodDecl( 189 hasDeclaration(cxxMethodDecl(
187 hasName("::base::StringValue::StringValue"))), 190 hasName("::base::StringValue::StringValue"))),
188 argumentCountIs(1), 191 argumentCountIs(1),
189 hasArgument(0, id("argExpr", expr())))))))))), 192 hasArgument(0, id("argExpr", expr())))))))))),
190 &append_string_callback_); 193 &append_string_callback_);
191 } 194 }
OLDNEW
« no previous file with comments | « no previous file | tools/clang/value_cleanup/tests/list-value-append-expected.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698