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

Side by Side Diff: tools/clang/rewrite_scoped_refptr/RewriteScopedRefptr.cpp

Issue 754433003: Update from https://crrev.com/305340 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 // This implements a Clang tool to rewrite all instances of 5 // This implements a Clang tool to rewrite all instances of
6 // scoped_refptr<T>'s implicit cast to T (operator T*) to an explicit call to 6 // scoped_refptr<T>'s implicit cast to T (operator T*) to an explicit call to
7 // the .get() method. 7 // the .get() method.
8 8
9 #include <assert.h> 9 #include <assert.h>
10 #include <algorithm> 10 #include <algorithm>
11 #include <memory> 11 #include <memory>
12 #include <string> 12 #include <string>
13 13
14 #include "clang/AST/ASTContext.h" 14 #include "clang/AST/ASTContext.h"
15 #include "clang/ASTMatchers/ASTMatchers.h" 15 #include "clang/ASTMatchers/ASTMatchers.h"
16 #include "clang/ASTMatchers/ASTMatchersMacros.h" 16 #include "clang/ASTMatchers/ASTMatchersMacros.h"
17 #include "clang/ASTMatchers/ASTMatchFinder.h" 17 #include "clang/ASTMatchers/ASTMatchFinder.h"
18 #include "clang/Basic/SourceManager.h" 18 #include "clang/Basic/SourceManager.h"
19 #include "clang/Frontend/FrontendActions.h" 19 #include "clang/Frontend/FrontendActions.h"
20 #include "clang/Lex/Lexer.h" 20 #include "clang/Lex/Lexer.h"
21 #include "clang/Tooling/CommonOptionsParser.h" 21 #include "clang/Tooling/CommonOptionsParser.h"
22 #include "clang/Tooling/Refactoring.h" 22 #include "clang/Tooling/Refactoring.h"
23 #include "clang/Tooling/Tooling.h" 23 #include "clang/Tooling/Tooling.h"
24 #include "llvm/Support/CommandLine.h" 24 #include "llvm/Support/CommandLine.h"
25 #include "llvm/support/TargetSelect.h"
25 26
26 using namespace clang::ast_matchers; 27 using namespace clang::ast_matchers;
27 using clang::tooling::CommonOptionsParser; 28 using clang::tooling::CommonOptionsParser;
28 using clang::tooling::Replacement; 29 using clang::tooling::Replacement;
29 using clang::tooling::Replacements; 30 using clang::tooling::Replacements;
30 using llvm::StringRef; 31 using llvm::StringRef;
31 32
32 namespace clang { 33 namespace clang {
33 namespace ast_matchers { 34 namespace ast_matchers {
34 35
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 const clang::Expr* const expr = result.Nodes.getNodeAs<clang::Expr>("expr"); 249 const clang::Expr* const expr = result.Nodes.getNodeAs<clang::Expr>("expr");
249 assert(expr && "Unexpected match! No Expr captured!"); 250 assert(expr && "Unexpected match! No Expr captured!");
250 replacements_->insert(RewriteImplicitToExplicitConversion(result, expr)); 251 replacements_->insert(RewriteImplicitToExplicitConversion(result, expr));
251 } 252 }
252 253
253 } // namespace 254 } // namespace
254 255
255 static llvm::cl::extrahelp common_help(CommonOptionsParser::HelpMessage); 256 static llvm::cl::extrahelp common_help(CommonOptionsParser::HelpMessage);
256 257
257 int main(int argc, const char* argv[]) { 258 int main(int argc, const char* argv[]) {
259 // TODO(dcheng): Clang tooling should do this itself.
260 // http://llvm.org/bugs/show_bug.cgi?id=21627
261 llvm::InitializeNativeTarget();
262 llvm::InitializeNativeTargetAsmParser();
258 llvm::cl::OptionCategory category("Remove scoped_refptr conversions"); 263 llvm::cl::OptionCategory category("Remove scoped_refptr conversions");
259 CommonOptionsParser options(argc, argv, category); 264 CommonOptionsParser options(argc, argv, category);
260 clang::tooling::ClangTool tool(options.getCompilations(), 265 clang::tooling::ClangTool tool(options.getCompilations(),
261 options.getSourcePathList()); 266 options.getSourcePathList());
262 267
263 MatchFinder match_finder; 268 MatchFinder match_finder;
264 Replacements replacements; 269 Replacements replacements;
265 270
266 auto is_scoped_refptr = recordDecl(isSameOrDerivedFrom("::scoped_refptr"), 271 auto is_scoped_refptr = recordDecl(isSameOrDerivedFrom("::scoped_refptr"),
267 isTemplateInstantiation()); 272 isTemplateInstantiation());
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 for (const auto& r : replacements) { 424 for (const auto& r : replacements) {
420 std::string replacement_text = r.getReplacementText().str(); 425 std::string replacement_text = r.getReplacementText().str();
421 std::replace(replacement_text.begin(), replacement_text.end(), '\n', '\0'); 426 std::replace(replacement_text.begin(), replacement_text.end(), '\n', '\0');
422 llvm::outs() << "r:::" << r.getFilePath() << ":::" << r.getOffset() << ":::" 427 llvm::outs() << "r:::" << r.getFilePath() << ":::" << r.getOffset() << ":::"
423 << r.getLength() << ":::" << replacement_text << "\n"; 428 << r.getLength() << ":::" << replacement_text << "\n";
424 } 429 }
425 llvm::outs() << "==== END EDITS ====\n"; 430 llvm::outs() << "==== END EDITS ====\n";
426 431
427 return 0; 432 return 0;
428 } 433 }
OLDNEW
« no previous file with comments | « tools/clang/rewrite_scoped_refptr/CMakeLists.txt ('k') | tools/clang/scripts/generate_win_compdb.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698