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