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 // A general interface for filtering and only acting on classes in Chromium C++ | 5 // A general interface for filtering and only acting on classes in Chromium C++ |
6 // code. | 6 // code. |
7 | 7 |
8 #include "ChromeClassTester.h" | 8 #include "ChromeClassTester.h" |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 | 182 |
183 return false; | 183 return false; |
184 } | 184 } |
185 | 185 |
186 std::string ChromeClassTester::GetNamespace(const Decl* record) { | 186 std::string ChromeClassTester::GetNamespace(const Decl* record) { |
187 return GetNamespaceImpl(record->getDeclContext(), ""); | 187 return GetNamespaceImpl(record->getDeclContext(), ""); |
188 } | 188 } |
189 | 189 |
190 bool ChromeClassTester::InImplementationFile(SourceLocation record_location) { | 190 bool ChromeClassTester::InImplementationFile(SourceLocation record_location) { |
191 std::string filename; | 191 std::string filename; |
192 if (!GetFilename(record_location, &filename)) | |
193 return false; | |
194 | 192 |
195 if (ends_with(filename, ".cc") || ends_with(filename, ".cpp") || | 193 if (options_.follow_macro_expansion) { |
196 ends_with(filename, ".mm")) { | 194 // If |record_location| is a macro, check the whole chain of expansions. |
197 return true; | 195 const SourceManager& source_manager = instance_.getSourceManager(); |
| 196 while (true) { |
| 197 if (GetFilename(record_location, &filename)) { |
| 198 if (ends_with(filename, ".cc") || ends_with(filename, ".cpp") || |
| 199 ends_with(filename, ".mm")) { |
| 200 return true; |
| 201 } |
| 202 } |
| 203 if (!record_location.isMacroID()) { |
| 204 break; |
| 205 } |
| 206 record_location = |
| 207 source_manager.getImmediateExpansionRange(record_location).first; |
| 208 } |
| 209 } else { |
| 210 if (!GetFilename(record_location, &filename)) |
| 211 return false; |
| 212 |
| 213 if (ends_with(filename, ".cc") || ends_with(filename, ".cpp") || |
| 214 ends_with(filename, ".mm")) { |
| 215 return true; |
| 216 } |
198 } | 217 } |
199 | 218 |
200 return false; | 219 return false; |
201 } | 220 } |
202 | 221 |
203 void ChromeClassTester::BuildBannedLists() { | 222 void ChromeClassTester::BuildBannedLists() { |
204 banned_namespaces_.emplace("std"); | 223 banned_namespaces_.emplace("std"); |
205 banned_namespaces_.emplace("__gnu_cxx"); | 224 banned_namespaces_.emplace("__gnu_cxx"); |
206 | 225 |
207 if (options_.enforce_in_thirdparty_webkit) { | 226 if (options_.enforce_in_thirdparty_webkit) { |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 } | 329 } |
311 | 330 |
312 *filename = ploc.getFilename(); | 331 *filename = ploc.getFilename(); |
313 return true; | 332 return true; |
314 } | 333 } |
315 | 334 |
316 DiagnosticsEngine::Level ChromeClassTester::getErrorLevel() { | 335 DiagnosticsEngine::Level ChromeClassTester::getErrorLevel() { |
317 return diagnostic().getWarningsAsErrors() ? DiagnosticsEngine::Error | 336 return diagnostic().getWarningsAsErrors() ? DiagnosticsEngine::Error |
318 : DiagnosticsEngine::Warning; | 337 : DiagnosticsEngine::Warning; |
319 } | 338 } |
OLD | NEW |