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 "FindBadConstructsConsumer.h" | 5 #include "FindBadConstructsConsumer.h" |
6 | 6 |
7 #include "clang/Frontend/CompilerInstance.h" | 7 #include "clang/Frontend/CompilerInstance.h" |
8 #include "clang/AST/Attr.h" | 8 #include "clang/AST/Attr.h" |
9 #include "clang/Lex/Lexer.h" | 9 #include "clang/Lex/Lexer.h" |
10 #include "llvm/Support/raw_ostream.h" | 10 #include "llvm/Support/raw_ostream.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 record.getDescribedClassTemplate() || | 96 record.getDescribedClassTemplate() || |
97 record.getTemplateSpecializationKind() || | 97 record.getTemplateSpecializationKind() || |
98 record.isDependentType(); | 98 record.isDependentType(); |
99 } | 99 } |
100 | 100 |
101 } // namespace | 101 } // namespace |
102 | 102 |
103 FindBadConstructsConsumer::FindBadConstructsConsumer(CompilerInstance& instance, | 103 FindBadConstructsConsumer::FindBadConstructsConsumer(CompilerInstance& instance, |
104 const Options& options) | 104 const Options& options) |
105 : ChromeClassTester(instance, options) { | 105 : ChromeClassTester(instance, options) { |
| 106 if (options.check_ipc) { |
| 107 ipc_visitor_.reset(new CheckIPCVisitor(instance)); |
| 108 } |
| 109 |
106 // Messages for virtual method specifiers. | 110 // Messages for virtual method specifiers. |
107 diag_method_requires_override_ = | 111 diag_method_requires_override_ = |
108 diagnostic().getCustomDiagID(getErrorLevel(), kMethodRequiresOverride); | 112 diagnostic().getCustomDiagID(getErrorLevel(), kMethodRequiresOverride); |
109 diag_redundant_virtual_specifier_ = | 113 diag_redundant_virtual_specifier_ = |
110 diagnostic().getCustomDiagID(getErrorLevel(), kRedundantVirtualSpecifier); | 114 diagnostic().getCustomDiagID(getErrorLevel(), kRedundantVirtualSpecifier); |
111 diag_base_method_virtual_and_final_ = | 115 diag_base_method_virtual_and_final_ = |
112 diagnostic().getCustomDiagID(getErrorLevel(), kBaseMethodVirtualAndFinal); | 116 diagnostic().getCustomDiagID(getErrorLevel(), kBaseMethodVirtualAndFinal); |
113 | 117 |
114 // Messages for destructors. | 118 // Messages for destructors. |
115 diag_no_explicit_dtor_ = | 119 diag_no_explicit_dtor_ = |
(...skipping 13 matching lines...) Expand all Loading... |
129 diag_note_inheritance_ = | 133 diag_note_inheritance_ = |
130 diagnostic().getCustomDiagID(DiagnosticsEngine::Note, kNoteInheritance); | 134 diagnostic().getCustomDiagID(DiagnosticsEngine::Note, kNoteInheritance); |
131 diag_note_implicit_dtor_ = | 135 diag_note_implicit_dtor_ = |
132 diagnostic().getCustomDiagID(DiagnosticsEngine::Note, kNoteImplicitDtor); | 136 diagnostic().getCustomDiagID(DiagnosticsEngine::Note, kNoteImplicitDtor); |
133 diag_note_public_dtor_ = | 137 diag_note_public_dtor_ = |
134 diagnostic().getCustomDiagID(DiagnosticsEngine::Note, kNotePublicDtor); | 138 diagnostic().getCustomDiagID(DiagnosticsEngine::Note, kNotePublicDtor); |
135 diag_note_protected_non_virtual_dtor_ = diagnostic().getCustomDiagID( | 139 diag_note_protected_non_virtual_dtor_ = diagnostic().getCustomDiagID( |
136 DiagnosticsEngine::Note, kNoteProtectedNonVirtualDtor); | 140 DiagnosticsEngine::Note, kNoteProtectedNonVirtualDtor); |
137 } | 141 } |
138 | 142 |
| 143 void FindBadConstructsConsumer::Visit(ASTContext& context) { |
| 144 if (ipc_visitor_) ipc_visitor_->set_context(&context); |
| 145 RecursiveASTVisitor::TraverseDecl(context.getTranslationUnitDecl()); |
| 146 if (ipc_visitor_) ipc_visitor_->set_context(nullptr); |
| 147 } |
| 148 |
| 149 bool FindBadConstructsConsumer::shouldVisitTemplateInstantiations() const { |
| 150 return RecursiveASTVisitor::shouldVisitTemplateInstantiations() || |
| 151 (ipc_visitor_ && ipc_visitor_->shouldVisitTemplateInstantiations()); |
| 152 } |
| 153 |
| 154 bool FindBadConstructsConsumer::TraverseDecl(Decl* decl) { |
| 155 if (ipc_visitor_) ipc_visitor_->BeginDecl(decl); |
| 156 bool result = RecursiveASTVisitor::TraverseDecl(decl); |
| 157 if (ipc_visitor_) ipc_visitor_->EndDecl(); |
| 158 return result; |
| 159 } |
| 160 |
139 bool FindBadConstructsConsumer::VisitDecl(clang::Decl* decl) { | 161 bool FindBadConstructsConsumer::VisitDecl(clang::Decl* decl) { |
140 clang::TagDecl* tag_decl = dyn_cast<clang::TagDecl>(decl); | 162 clang::TagDecl* tag_decl = dyn_cast<clang::TagDecl>(decl); |
141 if (tag_decl && tag_decl->isCompleteDefinition()) | 163 if (tag_decl && tag_decl->isCompleteDefinition()) |
142 CheckTag(tag_decl); | 164 CheckTag(tag_decl); |
143 return true; | 165 return true; |
144 } | 166 } |
145 | 167 |
| 168 bool FindBadConstructsConsumer::VisitTemplateSpecializationType( |
| 169 TemplateSpecializationType* spec) { |
| 170 if (ipc_visitor_) ipc_visitor_->VisitTemplateSpecializationType(spec); |
| 171 return true; |
| 172 } |
| 173 |
| 174 bool FindBadConstructsConsumer::VisitCallExpr(CallExpr* call_expr) { |
| 175 if (ipc_visitor_) ipc_visitor_->VisitCallExpr(call_expr); |
| 176 return true; |
| 177 } |
| 178 |
146 void FindBadConstructsConsumer::CheckChromeClass(SourceLocation record_location, | 179 void FindBadConstructsConsumer::CheckChromeClass(SourceLocation record_location, |
147 CXXRecordDecl* record) { | 180 CXXRecordDecl* record) { |
148 // By default, the clang checker doesn't check some types (templates, etc). | 181 // By default, the clang checker doesn't check some types (templates, etc). |
149 // That was only a mistake; once Chromium code passes these checks, we should | 182 // That was only a mistake; once Chromium code passes these checks, we should |
150 // remove the "check-templates" option and remove this code. | 183 // remove the "check-templates" option and remove this code. |
151 // See crbug.com/441916 | 184 // See crbug.com/441916 |
152 if (!options_.check_templates && IsPodOrTemplateType(*record)) | 185 if (!options_.check_templates && IsPodOrTemplateType(*record)) |
153 return; | 186 return; |
154 | 187 |
155 bool implementation_file = InImplementationFile(record_location); | 188 bool implementation_file = InImplementationFile(record_location); |
(...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
866 // one of those, it means there is at least one member after a factory. | 899 // one of those, it means there is at least one member after a factory. |
867 if (weak_ptr_factory_location.isValid() && | 900 if (weak_ptr_factory_location.isValid() && |
868 !param_is_weak_ptr_factory_to_self) { | 901 !param_is_weak_ptr_factory_to_self) { |
869 diagnostic().Report(weak_ptr_factory_location, | 902 diagnostic().Report(weak_ptr_factory_location, |
870 diag_weak_ptr_factory_order_); | 903 diag_weak_ptr_factory_order_); |
871 } | 904 } |
872 } | 905 } |
873 } | 906 } |
874 | 907 |
875 } // namespace chrome_checker | 908 } // namespace chrome_checker |
OLD | NEW |