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

Unified Diff: tools/clang/plugins/ChromeClassTester.cpp

Issue 1108173002: Roll //build, //native_client, and a few more targets of opportunity. Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Test fix 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/clang/plugins/ChromeClassTester.h ('k') | tools/clang/plugins/FindBadConstructsConsumer.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/clang/plugins/ChromeClassTester.cpp
diff --git a/tools/clang/plugins/ChromeClassTester.cpp b/tools/clang/plugins/ChromeClassTester.cpp
index 48d6a735f272c3db2331e7f21703fedaa265e0a2..931da02f3ff54e352a1cbec4337433abb38e449f 100644
--- a/tools/clang/plugins/ChromeClassTester.cpp
+++ b/tools/clang/plugins/ChromeClassTester.cpp
@@ -7,26 +7,20 @@
#include "ChromeClassTester.h"
-#include <sys/param.h>
+#include <algorithm>
#include "clang/AST/AST.h"
#include "clang/Basic/FileManager.h"
#include "clang/Basic/SourceManager.h"
+#ifdef LLVM_ON_UNIX
+#include <sys/param.h>
+#endif
+
using namespace clang;
namespace {
-bool starts_with(const std::string& one, const std::string& two) {
- return one.compare(0, two.size(), two) == 0;
-}
-
-std::string lstrip(const std::string& one, const std::string& two) {
- if (starts_with(one, two))
- return one.substr(two.size());
- return one;
-}
-
bool ends_with(const std::string& one, const std::string& two) {
if (two.size() > one.size())
return false;
@@ -101,14 +95,67 @@ void ChromeClassTester::emitWarning(SourceLocation loc,
std::string err;
err = "[chromium-style] ";
err += raw_error;
+ // TODO(dcheng): Re-enable -Werror for these diagnostics on Windows once all
+ // the pre-existing warnings are cleaned up. https://crbug.com/467287
DiagnosticIDs::Level level =
+#if !defined(LLVM_ON_WIN32)
diagnostic().getWarningsAsErrors() ?
DiagnosticIDs::Error :
+#endif
DiagnosticIDs::Warning;
unsigned id = diagnostic().getDiagnosticIDs()->getCustomDiagID(level, err);
DiagnosticBuilder builder = diagnostic().Report(full, id);
}
+bool ChromeClassTester::InBannedDirectory(SourceLocation loc) {
+ if (instance().getSourceManager().isInSystemHeader(loc))
+ return true;
+
+ std::string filename;
+ if (!GetFilename(loc, &filename)) {
+ // If the filename cannot be determined, simply treat this as a banned
+ // location, instead of going through the full lookup process.
+ return true;
+ }
+
+ // We need to special case scratch space; which is where clang does its
+ // macro expansion. We explicitly want to allow people to do otherwise bad
+ // things through macros that were defined due to third party libraries.
+ if (filename == "<scratch space>")
+ return true;
+
+ // Don't complain about autogenerated protobuf files.
+ if (ends_with(filename, ".pb.h")) {
+ return true;
+ }
+
+#if defined(LLVM_ON_UNIX)
+ // We need to munge the paths so that they are relative to the repository
+ // srcroot. We first resolve the symlinktastic relative path and then
+ // remove our known srcroot from it if needed.
+ char resolvedPath[MAXPATHLEN];
+ if (realpath(filename.c_str(), resolvedPath)) {
+ filename = resolvedPath;
+ }
+#endif
+
+#if defined(LLVM_ON_WIN32)
+ std::replace(filename.begin(), filename.end(), '\\', '/');
+#endif
+
+ for (const std::string& banned_dir : banned_directories_) {
+ // If any of the banned directories occur as a component in filename,
+ // this file is rejected.
+ assert(banned_dir.front() == '/' && "Banned dir must start with '/'");
+ assert(banned_dir.back() == '/' && "Banned dir must end with '/'");
+
+ if (filename.find(banned_dir) != std::string::npos)
+ return true;
+ }
+
+ return false;
+}
+
bool ChromeClassTester::InBannedNamespace(const Decl* record) {
std::string n = GetNamespace(record);
if (!n.empty()) {
@@ -239,47 +286,6 @@ std::string ChromeClassTester::GetNamespaceImpl(const DeclContext* context,
}
}
-bool ChromeClassTester::InBannedDirectory(SourceLocation loc) {
- std::string filename;
- if (!GetFilename(loc, &filename)) {
- // If the filename cannot be determined, simply treat this as a banned
- // location, instead of going through the full lookup process.
- return true;
- }
-
- // We need to special case scratch space; which is where clang does its
- // macro expansion. We explicitly want to allow people to do otherwise bad
- // things through macros that were defined due to third party libraries.
- if (filename == "<scratch space>")
- return true;
-
- // Don't complain about autogenerated protobuf files.
- if (ends_with(filename, ".pb.h")) {
- return true;
- }
-
- // We need to munge the paths so that they are relative to the repository
- // srcroot. We first resolve the symlinktastic relative path and then
- // remove our known srcroot from it if needed.
- char resolvedPath[MAXPATHLEN];
- if (realpath(filename.c_str(), resolvedPath)) {
- filename = resolvedPath;
- }
-
- for (size_t i = 0; i < banned_directories_.size(); ++i) {
- // If any of the banned directories occur as a component in filename,
- // this file is rejected.
- const std::string& banned_dir = banned_directories_[i];
- assert(banned_dir.front() == '/' && "Banned dir must start with '/'");
- assert(banned_dir.back() == '/' && "Banned dir must end with '/'");
-
- if (filename.find(banned_dir) != std::string::npos)
- return true;
- }
-
- return false;
-}
-
bool ChromeClassTester::IsIgnoredType(const std::string& base_name) {
return ignored_record_names_.find(base_name) != ignored_record_names_.end();
}
« no previous file with comments | « tools/clang/plugins/ChromeClassTester.h ('k') | tools/clang/plugins/FindBadConstructsConsumer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698