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> |
| 11 |
10 #include "clang/AST/AST.h" | 12 #include "clang/AST/AST.h" |
11 #include "clang/Basic/FileManager.h" | 13 #include "clang/Basic/FileManager.h" |
12 #include "clang/Basic/SourceManager.h" | 14 #include "clang/Basic/SourceManager.h" |
13 | 15 |
14 #ifdef LLVM_ON_UNIX | 16 #ifdef LLVM_ON_UNIX |
15 #include <sys/param.h> | 17 #include <sys/param.h> |
16 #endif | 18 #endif |
17 | 19 |
18 using namespace clang; | 20 using namespace clang; |
19 | 21 |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 return GetNamespaceImpl(context->getParent(), | 227 return GetNamespaceImpl(context->getParent(), |
226 OS.str()); | 228 OS.str()); |
227 } | 229 } |
228 default: { | 230 default: { |
229 return GetNamespaceImpl(context->getParent(), candidate); | 231 return GetNamespaceImpl(context->getParent(), candidate); |
230 } | 232 } |
231 } | 233 } |
232 } | 234 } |
233 | 235 |
234 bool ChromeClassTester::InBannedDirectory(SourceLocation loc) { | 236 bool ChromeClassTester::InBannedDirectory(SourceLocation loc) { |
| 237 if (instance().getSourceManager().isInSystemHeader(loc)) |
| 238 return true; |
| 239 |
235 std::string filename; | 240 std::string filename; |
236 if (!GetFilename(loc, &filename)) { | 241 if (!GetFilename(loc, &filename)) { |
237 // If the filename cannot be determined, simply treat this as a banned | 242 // If the filename cannot be determined, simply treat this as a banned |
238 // location, instead of going through the full lookup process. | 243 // location, instead of going through the full lookup process. |
239 return true; | 244 return true; |
240 } | 245 } |
241 | 246 |
242 // We need to special case scratch space; which is where clang does its | 247 // We need to special case scratch space; which is where clang does its |
243 // macro expansion. We explicitly want to allow people to do otherwise bad | 248 // macro expansion. We explicitly want to allow people to do otherwise bad |
244 // things through macros that were defined due to third party libraries. | 249 // things through macros that were defined due to third party libraries. |
245 if (filename == "<scratch space>") | 250 if (filename == "<scratch space>") |
246 return true; | 251 return true; |
247 | 252 |
248 // Don't complain about autogenerated protobuf files. | 253 // Don't complain about autogenerated protobuf files. |
249 if (ends_with(filename, ".pb.h")) { | 254 if (ends_with(filename, ".pb.h")) { |
250 return true; | 255 return true; |
251 } | 256 } |
252 | 257 |
253 #ifdef LLVM_ON_UNIX | 258 #if defined(LLVM_ON_UNIX) |
254 // We need to munge the paths so that they are relative to the repository | 259 // We need to munge the paths so that they are relative to the repository |
255 // srcroot. We first resolve the symlinktastic relative path and then | 260 // srcroot. We first resolve the symlinktastic relative path and then |
256 // remove our known srcroot from it if needed. | 261 // remove our known srcroot from it if needed. |
257 char resolvedPath[MAXPATHLEN]; | 262 char resolvedPath[MAXPATHLEN]; |
258 if (realpath(filename.c_str(), resolvedPath)) { | 263 if (realpath(filename.c_str(), resolvedPath)) { |
259 filename = resolvedPath; | 264 filename = resolvedPath; |
260 } | 265 } |
261 #endif | 266 #endif |
262 | 267 |
| 268 #if defined(LLVM_ON_WIN32) |
| 269 std::replace(filename.begin(), filename.end(), '\\', '/'); |
| 270 #endif |
| 271 |
263 for (const std::string& banned_dir : banned_directories_) { | 272 for (const std::string& banned_dir : banned_directories_) { |
264 // If any of the banned directories occur as a component in filename, | 273 // If any of the banned directories occur as a component in filename, |
265 // this file is rejected. | 274 // this file is rejected. |
266 assert(banned_dir.front() == '/' && "Banned dir must start with '/'"); | 275 assert(banned_dir.front() == '/' && "Banned dir must start with '/'"); |
267 assert(banned_dir.back() == '/' && "Banned dir must end with '/'"); | 276 assert(banned_dir.back() == '/' && "Banned dir must end with '/'"); |
268 | 277 |
269 if (filename.find(banned_dir) != std::string::npos) | 278 if (filename.find(banned_dir) != std::string::npos) |
270 return true; | 279 return true; |
271 } | 280 } |
272 | 281 |
(...skipping 11 matching lines...) Expand all Loading... |
284 PresumedLoc ploc = source_manager.getPresumedLoc(spelling_location); | 293 PresumedLoc ploc = source_manager.getPresumedLoc(spelling_location); |
285 if (ploc.isInvalid()) { | 294 if (ploc.isInvalid()) { |
286 // If we're in an invalid location, we're looking at things that aren't | 295 // If we're in an invalid location, we're looking at things that aren't |
287 // actually stated in the source. | 296 // actually stated in the source. |
288 return false; | 297 return false; |
289 } | 298 } |
290 | 299 |
291 *filename = ploc.getFilename(); | 300 *filename = ploc.getFilename(); |
292 return true; | 301 return true; |
293 } | 302 } |
OLD | NEW |