OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "DiagnosticsReporter.h" | 5 #include "DiagnosticsReporter.h" |
6 | 6 |
7 using namespace clang; | 7 using namespace clang; |
8 | 8 |
9 namespace { | 9 namespace { |
10 | 10 |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 " is not permitted to declare a pure-virtual trace method."; | 140 " is not permitted to declare a pure-virtual trace method."; |
141 | 141 |
142 const char kLeftMostBaseMustBePolymorphic[] = | 142 const char kLeftMostBaseMustBePolymorphic[] = |
143 "[blink-gc] Left-most base class %0 of derived class %1" | 143 "[blink-gc] Left-most base class %0 of derived class %1" |
144 " must be polymorphic."; | 144 " must be polymorphic."; |
145 | 145 |
146 const char kBaseClassMustDeclareVirtualTrace[] = | 146 const char kBaseClassMustDeclareVirtualTrace[] = |
147 "[blink-gc] Left-most base class %0 of derived class %1" | 147 "[blink-gc] Left-most base class %0 of derived class %1" |
148 " must define a virtual trace method."; | 148 " must define a virtual trace method."; |
149 | 149 |
150 const char kIteratorToGCManagedCollectionNote[] = | 150 const char kIteratorToGCManagedCollection[] = |
151 "[blink-gc] Iterator field %0 to a GC managed collection declared here:"; | 151 "[blink-gc] Iterator field %0 to a GC managed collection declared here:"; |
152 | 152 |
153 const char kTraceMethodOfStackAllocatedParentNote[] = | 153 const char kTraceMethodOfStackAllocatedParent[] = |
154 "[blink-gc] The stack allocated class %0 provides an unnecessary " | 154 "[blink-gc] The stack allocated class %0 provides an unnecessary " |
155 "trace method:"; | 155 "trace method:"; |
156 | 156 |
| 157 const char kStaticSingletonContainsScriptWrappable[] = |
| 158 "[blink-gc] The static singleton %0 contains one or more unsafe " |
| 159 "ScriptWrappable references"; |
| 160 |
| 161 const char kUnsafeScriptWrappableFieldNote[] = |
| 162 "[blink-gc] Embedded unsafe ScriptWrappable-derived field with type '%1' " |
| 163 "located at '%0'"; |
| 164 |
157 } // namespace | 165 } // namespace |
158 | 166 |
159 DiagnosticBuilder DiagnosticsReporter::ReportDiagnostic( | 167 DiagnosticBuilder DiagnosticsReporter::ReportDiagnostic( |
160 SourceLocation location, | 168 SourceLocation location, |
161 unsigned diag_id) { | 169 unsigned diag_id) { |
162 SourceManager& manager = instance_.getSourceManager(); | 170 SourceManager& manager = instance_.getSourceManager(); |
163 FullSourceLoc full_loc(location, manager); | 171 FullSourceLoc full_loc(location, manager); |
164 return diagnostic_.Report(full_loc, diag_id); | 172 return diagnostic_.Report(full_loc, diag_id); |
165 } | 173 } |
166 | 174 |
| 175 DiagnosticBuilder DiagnosticsReporter::ReportDiagnostic(unsigned diag_id) { |
| 176 return diagnostic_.Report(diag_id); |
| 177 } |
| 178 |
167 DiagnosticsReporter::DiagnosticsReporter( | 179 DiagnosticsReporter::DiagnosticsReporter( |
168 clang::CompilerInstance& instance) | 180 clang::CompilerInstance& instance) |
169 : instance_(instance), | 181 : instance_(instance), |
170 diagnostic_(instance.getDiagnostics()) | 182 diagnostic_(instance.getDiagnostics()) |
171 { | 183 { |
172 // Register warning/error messages. | 184 // Register warning/error messages. |
173 diag_class_must_left_mostly_derive_gc_ = diagnostic_.getCustomDiagID( | 185 diag_class_must_left_mostly_derive_gc_ = diagnostic_.getCustomDiagID( |
174 getErrorLevel(), kClassMustLeftMostlyDeriveGC); | 186 getErrorLevel(), kClassMustLeftMostlyDeriveGC); |
175 diag_class_requires_trace_method_ = | 187 diag_class_requires_trace_method_ = |
176 diagnostic_.getCustomDiagID(getErrorLevel(), kClassRequiresTraceMethod); | 188 diagnostic_.getCustomDiagID(getErrorLevel(), kClassRequiresTraceMethod); |
(...skipping 30 matching lines...) Expand all Loading... |
207 diag_stack_allocated_derives_gc_ = diagnostic_.getCustomDiagID( | 219 diag_stack_allocated_derives_gc_ = diagnostic_.getCustomDiagID( |
208 getErrorLevel(), kStackAllocatedDerivesGarbageCollected); | 220 getErrorLevel(), kStackAllocatedDerivesGarbageCollected); |
209 diag_class_overrides_new_ = | 221 diag_class_overrides_new_ = |
210 diagnostic_.getCustomDiagID(getErrorLevel(), kClassOverridesNew); | 222 diagnostic_.getCustomDiagID(getErrorLevel(), kClassOverridesNew); |
211 diag_class_declares_pure_virtual_trace_ = diagnostic_.getCustomDiagID( | 223 diag_class_declares_pure_virtual_trace_ = diagnostic_.getCustomDiagID( |
212 getErrorLevel(), kClassDeclaresPureVirtualTrace); | 224 getErrorLevel(), kClassDeclaresPureVirtualTrace); |
213 diag_left_most_base_must_be_polymorphic_ = diagnostic_.getCustomDiagID( | 225 diag_left_most_base_must_be_polymorphic_ = diagnostic_.getCustomDiagID( |
214 getErrorLevel(), kLeftMostBaseMustBePolymorphic); | 226 getErrorLevel(), kLeftMostBaseMustBePolymorphic); |
215 diag_base_class_must_declare_virtual_trace_ = diagnostic_.getCustomDiagID( | 227 diag_base_class_must_declare_virtual_trace_ = diagnostic_.getCustomDiagID( |
216 getErrorLevel(), kBaseClassMustDeclareVirtualTrace); | 228 getErrorLevel(), kBaseClassMustDeclareVirtualTrace); |
217 diag_iterator_to_gc_managed_collection_note_ = diagnostic_.getCustomDiagID( | 229 diag_iterator_to_gc_managed_collection_ = diagnostic_.getCustomDiagID( |
218 getErrorLevel(), kIteratorToGCManagedCollectionNote); | 230 getErrorLevel(), kIteratorToGCManagedCollection); |
219 diag_trace_method_of_stack_allocated_parent_ = diagnostic_.getCustomDiagID( | 231 diag_trace_method_of_stack_allocated_parent_ = diagnostic_.getCustomDiagID( |
220 getErrorLevel(), kTraceMethodOfStackAllocatedParentNote); | 232 getErrorLevel(), kTraceMethodOfStackAllocatedParent); |
| 233 diag_static_singleton_with_scriptwrappable_ = diagnostic_.getCustomDiagID( |
| 234 getErrorLevel(), kStaticSingletonContainsScriptWrappable); |
221 | 235 |
222 // Register note messages. | 236 // Register note messages. |
223 diag_base_requires_tracing_note_ = diagnostic_.getCustomDiagID( | 237 diag_base_requires_tracing_note_ = diagnostic_.getCustomDiagID( |
224 DiagnosticsEngine::Note, kBaseRequiresTracingNote); | 238 DiagnosticsEngine::Note, kBaseRequiresTracingNote); |
225 diag_field_requires_tracing_note_ = diagnostic_.getCustomDiagID( | 239 diag_field_requires_tracing_note_ = diagnostic_.getCustomDiagID( |
226 DiagnosticsEngine::Note, kFieldRequiresTracingNote); | 240 DiagnosticsEngine::Note, kFieldRequiresTracingNote); |
227 diag_field_should_not_be_traced_note_ = diagnostic_.getCustomDiagID( | 241 diag_field_should_not_be_traced_note_ = diagnostic_.getCustomDiagID( |
228 DiagnosticsEngine::Note, kFieldShouldNotBeTracedNote); | 242 DiagnosticsEngine::Note, kFieldShouldNotBeTracedNote); |
229 diag_raw_ptr_to_gc_managed_class_note_ = diagnostic_.getCustomDiagID( | 243 diag_raw_ptr_to_gc_managed_class_note_ = diagnostic_.getCustomDiagID( |
230 DiagnosticsEngine::Note, kRawPtrToGCManagedClassNote); | 244 DiagnosticsEngine::Note, kRawPtrToGCManagedClassNote); |
(...skipping 26 matching lines...) Expand all Loading... |
257 diag_user_declared_finalizer_note_ = diagnostic_.getCustomDiagID( | 271 diag_user_declared_finalizer_note_ = diagnostic_.getCustomDiagID( |
258 DiagnosticsEngine::Note, kUserDeclaredFinalizerNote); | 272 DiagnosticsEngine::Note, kUserDeclaredFinalizerNote); |
259 diag_base_requires_finalization_note_ = diagnostic_.getCustomDiagID( | 273 diag_base_requires_finalization_note_ = diagnostic_.getCustomDiagID( |
260 DiagnosticsEngine::Note, kBaseRequiresFinalizationNote); | 274 DiagnosticsEngine::Note, kBaseRequiresFinalizationNote); |
261 diag_field_requires_finalization_note_ = diagnostic_.getCustomDiagID( | 275 diag_field_requires_finalization_note_ = diagnostic_.getCustomDiagID( |
262 DiagnosticsEngine::Note, kFieldRequiresFinalizationNote); | 276 DiagnosticsEngine::Note, kFieldRequiresFinalizationNote); |
263 diag_overridden_non_virtual_trace_note_ = diagnostic_.getCustomDiagID( | 277 diag_overridden_non_virtual_trace_note_ = diagnostic_.getCustomDiagID( |
264 DiagnosticsEngine::Note, kOverriddenNonVirtualTraceNote); | 278 DiagnosticsEngine::Note, kOverriddenNonVirtualTraceNote); |
265 diag_manual_dispatch_method_note_ = diagnostic_.getCustomDiagID( | 279 diag_manual_dispatch_method_note_ = diagnostic_.getCustomDiagID( |
266 DiagnosticsEngine::Note, kManualDispatchMethodNote); | 280 DiagnosticsEngine::Note, kManualDispatchMethodNote); |
| 281 diag_unsafe_scriptwrappable_field_note_ = diagnostic_.getCustomDiagID( |
| 282 DiagnosticsEngine::Note, kUnsafeScriptWrappableFieldNote); |
267 } | 283 } |
268 | 284 |
269 bool DiagnosticsReporter::hasErrorOccurred() const | 285 bool DiagnosticsReporter::hasErrorOccurred() const |
270 { | 286 { |
271 return diagnostic_.hasErrorOccurred(); | 287 return diagnostic_.hasErrorOccurred(); |
272 } | 288 } |
273 | 289 |
274 DiagnosticsEngine::Level DiagnosticsReporter::getErrorLevel() const { | 290 DiagnosticsEngine::Level DiagnosticsReporter::getErrorLevel() const { |
275 return diagnostic_.getWarningsAsErrors() ? DiagnosticsEngine::Error | 291 return diagnostic_.getWarningsAsErrors() ? DiagnosticsEngine::Error |
276 : DiagnosticsEngine::Warning; | 292 : DiagnosticsEngine::Warning; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 note = diag_unique_ptr_to_gc_managed_class_note_; | 364 note = diag_unique_ptr_to_gc_managed_class_note_; |
349 } else if (error.second == CheckFieldsVisitor::kMemberToGCUnmanaged) { | 365 } else if (error.second == CheckFieldsVisitor::kMemberToGCUnmanaged) { |
350 note = diag_member_to_gc_unmanaged_class_note_; | 366 note = diag_member_to_gc_unmanaged_class_note_; |
351 } else if (error.second == CheckFieldsVisitor::kMemberInUnmanaged) { | 367 } else if (error.second == CheckFieldsVisitor::kMemberInUnmanaged) { |
352 note = diag_member_in_unmanaged_class_note_; | 368 note = diag_member_in_unmanaged_class_note_; |
353 } else if (error.second == CheckFieldsVisitor::kPtrFromHeapToStack) { | 369 } else if (error.second == CheckFieldsVisitor::kPtrFromHeapToStack) { |
354 note = diag_stack_allocated_field_note_; | 370 note = diag_stack_allocated_field_note_; |
355 } else if (error.second == CheckFieldsVisitor::kGCDerivedPartObject) { | 371 } else if (error.second == CheckFieldsVisitor::kGCDerivedPartObject) { |
356 note = diag_part_object_to_gc_derived_class_note_; | 372 note = diag_part_object_to_gc_derived_class_note_; |
357 } else if (error.second == CheckFieldsVisitor::kIteratorToGCManaged) { | 373 } else if (error.second == CheckFieldsVisitor::kIteratorToGCManaged) { |
358 note = diag_iterator_to_gc_managed_collection_note_; | 374 note = diag_iterator_to_gc_managed_collection_; |
359 } else { | 375 } else { |
360 assert(false && "Unknown field error"); | 376 assert(false && "Unknown field error"); |
361 } | 377 } |
362 NoteField(error.first, note); | 378 NoteField(error.first, note); |
363 } | 379 } |
364 } | 380 } |
365 | 381 |
366 void DiagnosticsReporter::ClassContainsGCRoots( | 382 void DiagnosticsReporter::ClassContainsGCRoots( |
367 RecordInfo* info, | 383 RecordInfo* info, |
368 const CheckGCRootsVisitor::Errors& errors) { | 384 const CheckGCRootsVisitor::Errors& errors) { |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 } | 522 } |
507 | 523 |
508 void DiagnosticsReporter::TraceMethodForStackAllocatedClass( | 524 void DiagnosticsReporter::TraceMethodForStackAllocatedClass( |
509 RecordInfo* info, | 525 RecordInfo* info, |
510 CXXMethodDecl* trace) { | 526 CXXMethodDecl* trace) { |
511 ReportDiagnostic(trace->getLocStart(), | 527 ReportDiagnostic(trace->getLocStart(), |
512 diag_trace_method_of_stack_allocated_parent_) | 528 diag_trace_method_of_stack_allocated_parent_) |
513 << info->record(); | 529 << info->record(); |
514 } | 530 } |
515 | 531 |
| 532 void DiagnosticsReporter::StaticSingletonContainsScriptWrappable( |
| 533 VarDecl* decl) { |
| 534 ReportDiagnostic(decl->getLocStart(), |
| 535 diag_static_singleton_with_scriptwrappable_) |
| 536 << decl; |
| 537 } |
| 538 |
516 void DiagnosticsReporter::NoteManualDispatchMethod(CXXMethodDecl* dispatch) { | 539 void DiagnosticsReporter::NoteManualDispatchMethod(CXXMethodDecl* dispatch) { |
517 ReportDiagnostic(dispatch->getLocStart(), | 540 ReportDiagnostic(dispatch->getLocStart(), |
518 diag_manual_dispatch_method_note_) | 541 diag_manual_dispatch_method_note_) |
519 << dispatch; | 542 << dispatch; |
520 } | 543 } |
521 | 544 |
522 void DiagnosticsReporter::NoteBaseRequiresTracing(BasePoint* base) { | 545 void DiagnosticsReporter::NoteBaseRequiresTracing(BasePoint* base) { |
523 ReportDiagnostic(base->spec().getLocStart(), | 546 ReportDiagnostic(base->spec().getLocStart(), |
524 diag_base_requires_tracing_note_) | 547 diag_base_requires_tracing_note_) |
525 << base->info()->record(); | 548 << base->info()->record(); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
573 void DiagnosticsReporter::NoteField(FieldDecl* field, unsigned note) { | 596 void DiagnosticsReporter::NoteField(FieldDecl* field, unsigned note) { |
574 ReportDiagnostic(field->getLocStart(), note) << field; | 597 ReportDiagnostic(field->getLocStart(), note) << field; |
575 } | 598 } |
576 | 599 |
577 void DiagnosticsReporter::NoteOverriddenNonVirtualTrace( | 600 void DiagnosticsReporter::NoteOverriddenNonVirtualTrace( |
578 CXXMethodDecl* overridden) { | 601 CXXMethodDecl* overridden) { |
579 ReportDiagnostic(overridden->getLocStart(), | 602 ReportDiagnostic(overridden->getLocStart(), |
580 diag_overridden_non_virtual_trace_note_) | 603 diag_overridden_non_virtual_trace_note_) |
581 << overridden; | 604 << overridden; |
582 } | 605 } |
| 606 |
| 607 void DiagnosticsReporter::NoteUnsafeScriptWrappableField( |
| 608 VarDecl* decl, |
| 609 const std::string& context, |
| 610 const std::string& type_name) { |
| 611 ReportDiagnostic(diag_unsafe_scriptwrappable_field_note_) << context |
| 612 << type_name; |
| 613 } |
OLD | NEW |