Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Side by Side Diff: tools/clang/plugins/ChromeClassTester.cpp

Issue 1069853004: Windows compile fixes for Chrome clang plugin. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <sys/param.h>
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
14 #ifdef LLVM_ON_UNIX
15 #include <sys/param.h>
16 #endif
17
16 using namespace clang; 18 using namespace clang;
17 19
18 namespace { 20 namespace {
19 21
20 bool starts_with(const std::string& one, const std::string& two) { 22 bool starts_with(const std::string& one, const std::string& two) {
21 return one.compare(0, two.size(), two) == 0; 23 return one.compare(0, two.size(), two) == 0;
22 } 24 }
23 25
24 std::string lstrip(const std::string& one, const std::string& two) { 26 std::string lstrip(const std::string& one, const std::string& two) {
25 if (starts_with(one, two)) 27 if (starts_with(one, two))
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 // macro expansion. We explicitly want to allow people to do otherwise bad 253 // macro expansion. We explicitly want to allow people to do otherwise bad
252 // things through macros that were defined due to third party libraries. 254 // things through macros that were defined due to third party libraries.
253 if (filename == "<scratch space>") 255 if (filename == "<scratch space>")
254 return true; 256 return true;
255 257
256 // Don't complain about autogenerated protobuf files. 258 // Don't complain about autogenerated protobuf files.
257 if (ends_with(filename, ".pb.h")) { 259 if (ends_with(filename, ".pb.h")) {
258 return true; 260 return true;
259 } 261 }
260 262
263 #ifdef LLVM_ON_UNIX
261 // We need to munge the paths so that they are relative to the repository 264 // We need to munge the paths so that they are relative to the repository
262 // srcroot. We first resolve the symlinktastic relative path and then 265 // srcroot. We first resolve the symlinktastic relative path and then
263 // remove our known srcroot from it if needed. 266 // remove our known srcroot from it if needed.
264 char resolvedPath[MAXPATHLEN]; 267 char resolvedPath[MAXPATHLEN];
265 if (realpath(filename.c_str(), resolvedPath)) { 268 if (realpath(filename.c_str(), resolvedPath)) {
266 filename = resolvedPath; 269 filename = resolvedPath;
267 } 270 }
271 #endif
268 272
269 for (size_t i = 0; i < banned_directories_.size(); ++i) { 273 for (const std::string& banned_dir : banned_directories_) {
270 // If any of the banned directories occur as a component in filename, 274 // If any of the banned directories occur as a component in filename,
271 // this file is rejected. 275 // this file is rejected.
272 const std::string& banned_dir = banned_directories_[i];
273 assert(banned_dir.front() == '/' && "Banned dir must start with '/'"); 276 assert(banned_dir.front() == '/' && "Banned dir must start with '/'");
274 assert(banned_dir.back() == '/' && "Banned dir must end with '/'"); 277 assert(banned_dir.back() == '/' && "Banned dir must end with '/'");
275 278
276 if (filename.find(banned_dir) != std::string::npos) 279 if (filename.find(banned_dir) != std::string::npos)
277 return true; 280 return true;
278 } 281 }
279 282
280 return false; 283 return false;
281 } 284 }
282 285
283 bool ChromeClassTester::IsIgnoredType(const std::string& base_name) { 286 bool ChromeClassTester::IsIgnoredType(const std::string& base_name) {
284 return ignored_record_names_.find(base_name) != ignored_record_names_.end(); 287 return ignored_record_names_.find(base_name) != ignored_record_names_.end();
285 } 288 }
286 289
287 bool ChromeClassTester::GetFilename(SourceLocation loc, 290 bool ChromeClassTester::GetFilename(SourceLocation loc,
288 std::string* filename) { 291 std::string* filename) {
289 const SourceManager& source_manager = instance_.getSourceManager(); 292 const SourceManager& source_manager = instance_.getSourceManager();
290 SourceLocation spelling_location = source_manager.getSpellingLoc(loc); 293 SourceLocation spelling_location = source_manager.getSpellingLoc(loc);
291 PresumedLoc ploc = source_manager.getPresumedLoc(spelling_location); 294 PresumedLoc ploc = source_manager.getPresumedLoc(spelling_location);
292 if (ploc.isInvalid()) { 295 if (ploc.isInvalid()) {
293 // If we're in an invalid location, we're looking at things that aren't 296 // If we're in an invalid location, we're looking at things that aren't
294 // actually stated in the source. 297 // actually stated in the source.
295 return false; 298 return false;
296 } 299 }
297 300
298 *filename = ploc.getFilename(); 301 *filename = ploc.getFilename();
299 return true; 302 return true;
300 } 303 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698