OLD | NEW |
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> |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 | 256 |
257 int main(int argc, const char* argv[]) { | 257 int main(int argc, const char* argv[]) { |
258 llvm::cl::OptionCategory category("Remove scoped_refptr conversions"); | 258 llvm::cl::OptionCategory category("Remove scoped_refptr conversions"); |
259 CommonOptionsParser options(argc, argv, category); | 259 CommonOptionsParser options(argc, argv, category); |
260 clang::tooling::ClangTool tool(options.getCompilations(), | 260 clang::tooling::ClangTool tool(options.getCompilations(), |
261 options.getSourcePathList()); | 261 options.getSourcePathList()); |
262 | 262 |
263 MatchFinder match_finder; | 263 MatchFinder match_finder; |
264 Replacements replacements; | 264 Replacements replacements; |
265 | 265 |
266 auto is_scoped_refptr = recordDecl(isSameOrDerivedFrom("::scoped_refptr"), | 266 auto is_scoped_refptr = recordDecl(isSameOrDerivedFrom("::scoped_refptr")); |
267 isTemplateInstantiation()); | |
268 | 267 |
269 // Finds all calls to conversion operator member function. This catches calls | 268 // Finds all calls to conversion operator member function. This catches calls |
270 // to "operator T*", "operator Testable", and "operator bool" equally. | 269 // to "operator T*", "operator Testable", and "operator bool" equally. |
271 auto base_matcher = memberCallExpr(thisPointerType(is_scoped_refptr), | 270 auto base_matcher = memberCallExpr(thisPointerType(is_scoped_refptr), |
272 callee(conversionDecl()), | 271 callee(conversionDecl()), |
273 on(id("arg", expr()))); | 272 on(id("arg", expr()))); |
274 | 273 |
275 // The heuristic for whether or not converting a temporary is 'unsafe'. An | 274 // The heuristic for whether or not converting a temporary is 'unsafe'. An |
276 // unsafe conversion is one where a temporary scoped_refptr<T> is converted to | 275 // unsafe conversion is one where a temporary scoped_refptr<T> is converted to |
277 // another type. The matcher provides an exception for a temporary | 276 // another type. The matcher provides an exception for a temporary |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 for (const auto& r : replacements) { | 418 for (const auto& r : replacements) { |
420 std::string replacement_text = r.getReplacementText().str(); | 419 std::string replacement_text = r.getReplacementText().str(); |
421 std::replace(replacement_text.begin(), replacement_text.end(), '\n', '\0'); | 420 std::replace(replacement_text.begin(), replacement_text.end(), '\n', '\0'); |
422 llvm::outs() << "r:::" << r.getFilePath() << ":::" << r.getOffset() << ":::" | 421 llvm::outs() << "r:::" << r.getFilePath() << ":::" << r.getOffset() << ":::" |
423 << r.getLength() << ":::" << replacement_text << "\n"; | 422 << r.getLength() << ":::" << replacement_text << "\n"; |
424 } | 423 } |
425 llvm::outs() << "==== END EDITS ====\n"; | 424 llvm::outs() << "==== END EDITS ====\n"; |
426 | 425 |
427 return 0; | 426 return 0; |
428 } | 427 } |
OLD | NEW |