OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 clang plugin checks various invariants of the Blink garbage | 5 // This clang plugin checks various invariants of the Blink garbage |
6 // collection infrastructure. | 6 // collection infrastructure. |
7 // | 7 // |
8 // Errors are described at: | 8 // Errors are described at: |
9 // http://www.chromium.org/developers/blink-gc-plugin-errors | 9 // http://www.chromium.org/developers/blink-gc-plugin-errors |
10 | 10 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 "[blink-gc] Field %0 requiring finalization declared here:"; | 104 "[blink-gc] Field %0 requiring finalization declared here:"; |
105 | 105 |
106 const char kManualDispatchMethodNote[] = | 106 const char kManualDispatchMethodNote[] = |
107 "[blink-gc] Manual dispatch %0 declared here:"; | 107 "[blink-gc] Manual dispatch %0 declared here:"; |
108 | 108 |
109 const char kDerivesNonStackAllocated[] = | 109 const char kDerivesNonStackAllocated[] = |
110 "[blink-gc] Stack-allocated class %0 derives class %1" | 110 "[blink-gc] Stack-allocated class %0 derives class %1" |
111 " which is not stack allocated."; | 111 " which is not stack allocated."; |
112 | 112 |
113 struct BlinkGCPluginOptions { | 113 struct BlinkGCPluginOptions { |
114 BlinkGCPluginOptions() : enable_oilpan(false), detect_cycles(false) {} | 114 BlinkGCPluginOptions() : enable_oilpan(false), dump_graph(false) {} |
115 bool enable_oilpan; | 115 bool enable_oilpan; |
116 bool detect_cycles; | 116 bool dump_graph; |
117 std::set<std::string> ignored_classes; | 117 std::set<std::string> ignored_classes; |
118 std::set<std::string> checked_namespaces; | 118 std::set<std::string> checked_namespaces; |
119 std::vector<std::string> ignored_directories; | 119 std::vector<std::string> ignored_directories; |
120 }; | 120 }; |
121 | 121 |
122 typedef std::vector<CXXRecordDecl*> RecordVector; | 122 typedef std::vector<CXXRecordDecl*> RecordVector; |
123 typedef std::vector<CXXMethodDecl*> MethodVector; | 123 typedef std::vector<CXXMethodDecl*> MethodVector; |
124 | 124 |
125 // Test if a template specialization is an instantiation. | 125 // Test if a template specialization is an instantiation. |
126 static bool IsTemplateInstantiation(CXXRecordDecl* record) { | 126 static bool IsTemplateInstantiation(CXXRecordDecl* record) { |
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 diag_overridden_non_virtual_trace_note_ = diagnostic_.getCustomDiagID( | 561 diag_overridden_non_virtual_trace_note_ = diagnostic_.getCustomDiagID( |
562 DiagnosticsEngine::Note, kOverriddenNonVirtualTraceNote); | 562 DiagnosticsEngine::Note, kOverriddenNonVirtualTraceNote); |
563 diag_manual_dispatch_method_note_ = diagnostic_.getCustomDiagID( | 563 diag_manual_dispatch_method_note_ = diagnostic_.getCustomDiagID( |
564 DiagnosticsEngine::Note, kManualDispatchMethodNote); | 564 DiagnosticsEngine::Note, kManualDispatchMethodNote); |
565 } | 565 } |
566 | 566 |
567 virtual void HandleTranslationUnit(ASTContext& context) { | 567 virtual void HandleTranslationUnit(ASTContext& context) { |
568 CollectVisitor visitor; | 568 CollectVisitor visitor; |
569 visitor.TraverseDecl(context.getTranslationUnitDecl()); | 569 visitor.TraverseDecl(context.getTranslationUnitDecl()); |
570 | 570 |
571 if (options_.detect_cycles) { | 571 if (options_.dump_graph) { |
572 string err; | 572 string err; |
573 // TODO: Make createDefaultOutputFile or a shorter createOutputFile work. | 573 // TODO: Make createDefaultOutputFile or a shorter createOutputFile work. |
574 json_ = JsonWriter::from(instance_.createOutputFile( | 574 json_ = JsonWriter::from(instance_.createOutputFile( |
575 "", // OutputPath | 575 "", // OutputPath |
576 err, // Errors | 576 err, // Errors |
577 true, // Binary | 577 true, // Binary |
578 true, // RemoveFileOnSignal | 578 true, // RemoveFileOnSignal |
579 instance_.getFrontendOpts().OutputFile, // BaseInput | 579 instance_.getFrontendOpts().OutputFile, // BaseInput |
580 "graph.json", // Extension | 580 "graph.json", // Extension |
581 false, // UseTemporary | 581 false, // UseTemporary |
(...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1284 return new BlinkGCPluginConsumer(instance, options_); | 1284 return new BlinkGCPluginConsumer(instance, options_); |
1285 } | 1285 } |
1286 | 1286 |
1287 virtual bool ParseArgs(const CompilerInstance& instance, | 1287 virtual bool ParseArgs(const CompilerInstance& instance, |
1288 const std::vector<string>& args) { | 1288 const std::vector<string>& args) { |
1289 bool parsed = true; | 1289 bool parsed = true; |
1290 | 1290 |
1291 for (size_t i = 0; i < args.size() && parsed; ++i) { | 1291 for (size_t i = 0; i < args.size() && parsed; ++i) { |
1292 if (args[i] == "enable-oilpan") { | 1292 if (args[i] == "enable-oilpan") { |
1293 options_.enable_oilpan = true; | 1293 options_.enable_oilpan = true; |
1294 } else if (args[i] == "detect-cycles") { | 1294 } else if (args[i] == "dump-graph") { |
1295 options_.detect_cycles = true; | 1295 options_.dump_graph = true; |
1296 } else { | 1296 } else { |
1297 parsed = false; | 1297 parsed = false; |
1298 llvm::errs() << "Unknown blink-gc-plugin argument: " << args[i] << "\n"; | 1298 llvm::errs() << "Unknown blink-gc-plugin argument: " << args[i] << "\n"; |
1299 } | 1299 } |
1300 } | 1300 } |
1301 | 1301 |
1302 return parsed; | 1302 return parsed; |
1303 } | 1303 } |
1304 | 1304 |
1305 private: | 1305 private: |
1306 BlinkGCPluginOptions options_; | 1306 BlinkGCPluginOptions options_; |
1307 }; | 1307 }; |
1308 | 1308 |
1309 } // namespace | 1309 } // namespace |
1310 | 1310 |
1311 static FrontendPluginRegistry::Add<BlinkGCPluginAction> X( | 1311 static FrontendPluginRegistry::Add<BlinkGCPluginAction> X( |
1312 "blink-gc-plugin", | 1312 "blink-gc-plugin", |
1313 "Check Blink GC invariants"); | 1313 "Check Blink GC invariants"); |
OLD | NEW |