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

Side by Side Diff: tools/clang/BindMigrate/Transform.cpp

Issue 7886056: Clang plugin that rewrites PostTask(_, NewRunnableMethod(...)) to PostTask(_, base::Bind(...)); (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix lifetime issue where BindMigrateAction is deleted before the ASTConsumer is finished. Created 9 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « tools/clang/BindMigrate/Transform.h ('k') | tools/clang/BindMigrate/Util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "Transform.h"
6
7 #include "clang/Basic/FileManager.h"
8
9 namespace clang {
10
11 TransformApplier::TransformApplier(const Transform::TransformList& transforms)
12 : transforms_(transforms) {
13 }
14
15 bool TransformApplier::VisitStmt(Stmt *statement) {
16 for (Transform::TransformList::iterator it = transforms_.begin(),
17 end = transforms_.end(); it != end; ++it) {
18 if ((*it)->WouldTransformStmt(statement)) {
19 (*it)->TransformStmt(statement);
20 }
21 }
22
23 return RecursiveASTVisitor<TransformApplier>::VisitStmt(statement);
24 }
25
26 bool TransformApplier::VisitDecl(Decl *decl) {
27 for (Transform::TransformList::iterator it = transforms_.begin(),
28 end = transforms_.end(); it != end; ++it) {
29 if ((*it)->WouldTransformDecl(decl)) {
30 (*it)->TransformDecl(decl);
31 }
32 }
33
34 return RecursiveASTVisitor<TransformApplier>::VisitDecl(decl);
35 }
36
37 bool TransformApplier::VisitType(Type* type) {
38 for (Transform::TransformList::iterator it = transforms_.begin(),
39 end = transforms_.end(); it != end; ++it) {
40 if ((*it)->WouldTransformType(type)) {
41 (*it)->TransformType(type);
42 }
43 }
44
45 return RecursiveASTVisitor<TransformApplier>::VisitType(type);
46 }
47
48 TransformCandidatePrinter::TransformCandidatePrinter(
49 const Transform::TransformList& transforms,
50 SourceManager* source_manager)
51 : transforms_(transforms),
52 source_manager_(source_manager) {
53 }
54
55 TransformCandidatePrinter::~TransformCandidatePrinter() {
56 for (std::set<std::string>::const_iterator it = filenames_.begin();
57 it != filenames_.end(); ++it) {
58 llvm::outs() << *it << "\n";
59 }
60 }
61
62 bool TransformCandidatePrinter::VisitStmt(Stmt *statement) {
63 for (Transform::TransformList::iterator it = transforms_.begin(),
64 end = transforms_.end(); it != end; ++it) {
65 if ((*it)->WouldTransformStmt(statement)) {
66 AddFileForLocation(statement->getLocStart());
67 }
68 }
69
70 return RecursiveASTVisitor<TransformCandidatePrinter>::VisitStmt(
71 statement);
72 }
73
74 bool TransformCandidatePrinter::VisitDecl(Decl *decl) {
75 for (Transform::TransformList::iterator it = transforms_.begin(),
76 end = transforms_.end(); it != end; ++it) {
77 if ((*it)->WouldTransformDecl(decl)) {
78 AddFileForLocation(decl->getLocStart());
79 }
80 }
81
82 return RecursiveASTVisitor<TransformCandidatePrinter>::VisitDecl(decl);
83 }
84
85 bool TransformCandidatePrinter::VisitType(Type* type) {
86 // We will find it in Decls and Statements already.
87 return RecursiveASTVisitor<TransformCandidatePrinter>::VisitType(type);
88 }
89
90 void TransformCandidatePrinter::AddFileForLocation(SourceLocation location) {
91 const FileEntry* file_entry = GetValidFile(*source_manager_, location);
92 if (!file_entry) {
93 return;
94 }
95
96 filenames_.insert(file_entry->getName());
97 }
98
99 } // namespace clang
OLDNEW
« no previous file with comments | « tools/clang/BindMigrate/Transform.h ('k') | tools/clang/BindMigrate/Util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698