| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 } |
| OLD | NEW |