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() || | |
dcheng
2016/03/07 23:44:39
I don't think we need to call the 'base' method he
Dmitry Skiba
2016/03/08 01:16:11
Yes, but it provides the value I "blend" with. I d
| |
151 (ipc_visitor_ && ipc_visitor_->should_visit_template_instantiations()); | |
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; | |
dcheng
2016/03/07 23:44:39
Seems like this should all just be in VisitDecl()
Dmitry Skiba
2016/03/08 01:16:11
VisitDecl() is called on leafs, so I won't be able
| |
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 714 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
870 // one of those, it means there is at least one member after a factory. | 903 // one of those, it means there is at least one member after a factory. |
871 if (weak_ptr_factory_location.isValid() && | 904 if (weak_ptr_factory_location.isValid() && |
872 !param_is_weak_ptr_factory_to_self) { | 905 !param_is_weak_ptr_factory_to_self) { |
873 diagnostic().Report(weak_ptr_factory_location, | 906 diagnostic().Report(weak_ptr_factory_location, |
874 diag_weak_ptr_factory_order_); | 907 diag_weak_ptr_factory_order_); |
875 } | 908 } |
876 } | 909 } |
877 } | 910 } |
878 | 911 |
879 } // namespace chrome_checker | 912 } // namespace chrome_checker |
OLD | NEW |