OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "FindBadConstructsAction.h" | 5 #include "FindBadConstructsAction.h" |
6 | 6 |
| 7 #include "clang/AST/ASTConsumer.h" |
7 #include "clang/Frontend/FrontendPluginRegistry.h" | 8 #include "clang/Frontend/FrontendPluginRegistry.h" |
8 | 9 |
9 #include "FindBadConstructsConsumer.h" | 10 #include "FindBadConstructsConsumer.h" |
10 | 11 |
11 using namespace clang; | 12 using namespace clang; |
12 | 13 |
13 namespace chrome_checker { | 14 namespace chrome_checker { |
14 | 15 |
| 16 namespace { |
| 17 |
| 18 class PluginConsumer : public ASTConsumer { |
| 19 public: |
| 20 PluginConsumer(CompilerInstance* instance, const Options& options) |
| 21 : visitor_(*instance, options) {} |
| 22 |
| 23 void HandleTranslationUnit(clang::ASTContext& context) override { |
| 24 visitor_.TraverseDecl(context.getTranslationUnitDecl()); |
| 25 } |
| 26 |
| 27 private: |
| 28 FindBadConstructsConsumer visitor_; |
| 29 }; |
| 30 |
| 31 } // namespace |
| 32 |
15 FindBadConstructsAction::FindBadConstructsAction() { | 33 FindBadConstructsAction::FindBadConstructsAction() { |
16 } | 34 } |
17 | 35 |
18 std::unique_ptr<ASTConsumer> FindBadConstructsAction::CreateASTConsumer( | 36 std::unique_ptr<ASTConsumer> FindBadConstructsAction::CreateASTConsumer( |
19 CompilerInstance& instance, | 37 CompilerInstance& instance, |
20 llvm::StringRef ref) { | 38 llvm::StringRef ref) { |
| 39 if (options_.with_ast_visitor) |
| 40 return llvm::make_unique<PluginConsumer>(&instance, options_); |
21 return llvm::make_unique<FindBadConstructsConsumer>(instance, options_); | 41 return llvm::make_unique<FindBadConstructsConsumer>(instance, options_); |
22 } | 42 } |
23 | 43 |
24 bool FindBadConstructsAction::ParseArgs(const CompilerInstance& instance, | 44 bool FindBadConstructsAction::ParseArgs(const CompilerInstance& instance, |
25 const std::vector<std::string>& args) { | 45 const std::vector<std::string>& args) { |
26 bool parsed = true; | 46 bool parsed = true; |
27 | 47 |
28 for (size_t i = 0; i < args.size() && parsed; ++i) { | 48 for (size_t i = 0; i < args.size() && parsed; ++i) { |
29 if (args[i] == "check-base-classes") { | 49 if (args[i] == "check-base-classes") { |
30 // TODO(rsleevi): Remove this once http://crbug.com/123295 is fixed. | 50 // TODO(rsleevi): Remove this once http://crbug.com/123295 is fixed. |
31 options_.check_base_classes = true; | 51 options_.check_base_classes = true; |
32 } else if (args[i] == "check-weak-ptr-factory-order") { | 52 } else if (args[i] == "check-weak-ptr-factory-order") { |
33 // TODO(dmichael): Remove this once http://crbug.com/303818 is fixed. | 53 // TODO(dmichael): Remove this once http://crbug.com/303818 is fixed. |
34 options_.check_weak_ptr_factory_order = true; | 54 options_.check_weak_ptr_factory_order = true; |
35 } else if (args[i] == "check-enum-last-value") { | 55 } else if (args[i] == "check-enum-last-value") { |
36 // TODO(tsepez): Enable this by default once http://crbug.com/356815 | 56 // TODO(tsepez): Enable this by default once http://crbug.com/356815 |
37 // and http://crbug.com/356816 are fixed. | 57 // and http://crbug.com/356816 are fixed. |
38 options_.check_enum_last_value = true; | 58 options_.check_enum_last_value = true; |
39 } else if (args[i] == "strict-virtual-specifiers") { | 59 } else if (args[i] == "strict-virtual-specifiers") { |
40 options_.strict_virtual_specifiers = true; | 60 options_.strict_virtual_specifiers = true; |
| 61 } else if (args[i] == "with-ast-visitor") { |
| 62 options_.with_ast_visitor = true; |
41 } else { | 63 } else { |
42 parsed = false; | 64 parsed = false; |
43 llvm::errs() << "Unknown clang plugin argument: " << args[i] << "\n"; | 65 llvm::errs() << "Unknown clang plugin argument: " << args[i] << "\n"; |
44 } | 66 } |
45 } | 67 } |
46 | 68 |
47 return parsed; | 69 return parsed; |
48 } | 70 } |
49 | 71 |
50 } // namespace chrome_checker | 72 } // namespace chrome_checker |
51 | 73 |
52 static FrontendPluginRegistry::Add<chrome_checker::FindBadConstructsAction> X( | 74 static FrontendPluginRegistry::Add<chrome_checker::FindBadConstructsAction> X( |
53 "find-bad-constructs", | 75 "find-bad-constructs", |
54 "Finds bad C++ constructs"); | 76 "Finds bad C++ constructs"); |
OLD | NEW |