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

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

Issue 1372833002: Update the clang plugin to optionally enforce rules for Blink code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: ooookay, emplace it is Created 5 years, 3 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/FindBadConstructsAction.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 8820407095efd974f3d465f1b87f6edb3337a5e2..9b7793afe3b6380e49768743219c4b42ce2946c9 100644
--- a/tools/clang/plugins/ChromeClassTester.cpp
+++ b/tools/clang/plugins/ChromeClassTester.cpp
@@ -150,6 +150,16 @@ bool ChromeClassTester::InBannedDirectory(SourceLocation loc) {
filename.insert(filename.begin(), '/');
#endif
+ for (const std::string& allowed_dir : allowed_directories_) {
+ // If any of the allowed directories occur as a component in filename,
+ // this file is allowed.
+ assert(allowed_dir.front() == '/' && "Allowed dir must start with '/'");
+ assert(allowed_dir.back() == '/' && "Allowed dir must end with '/'");
+
+ if (filename.find(allowed_dir) != std::string::npos)
+ return false;
+ }
+
for (const std::string& banned_dir : banned_directories_) {
// If any of the banned directories occur as a component in filename,
// this file is rejected.
@@ -191,75 +201,79 @@ bool ChromeClassTester::InImplementationFile(SourceLocation record_location) {
}
void ChromeClassTester::BuildBannedLists() {
- banned_namespaces_.push_back("std");
- banned_namespaces_.push_back("__gnu_cxx");
+ banned_namespaces_.emplace("std");
+ banned_namespaces_.emplace("__gnu_cxx");
+
+ if (!options_.enforce_overriding_blink) {
+ banned_namespaces_.emplace("blink");
+ banned_namespaces_.emplace("WTF");
+ }
- if (!options_.enforce_blink) {
- banned_namespaces_.push_back("blink");
- banned_namespaces_.push_back("WTF");
+ if (options_.enforce_in_thirdparty_webkit) {
+ allowed_directories_.emplace("/third_party/WebKit/");
}
- banned_directories_.push_back("/third_party/");
- banned_directories_.push_back("/native_client/");
- banned_directories_.push_back("/breakpad/");
- banned_directories_.push_back("/courgette/");
- banned_directories_.push_back("/pdf/");
- banned_directories_.push_back("/ppapi/");
- banned_directories_.push_back("/usr/include/");
- banned_directories_.push_back("/usr/lib/");
- banned_directories_.push_back("/usr/local/include/");
- banned_directories_.push_back("/usr/local/lib/");
- banned_directories_.push_back("/testing/");
- banned_directories_.push_back("/v8/");
- banned_directories_.push_back("/dart/");
- banned_directories_.push_back("/sdch/");
- banned_directories_.push_back("/icu4c/");
- banned_directories_.push_back("/frameworks/");
+ banned_directories_.emplace("/third_party/");
+ banned_directories_.emplace("/native_client/");
+ banned_directories_.emplace("/breakpad/");
+ banned_directories_.emplace("/courgette/");
+ banned_directories_.emplace("/pdf/");
+ banned_directories_.emplace("/ppapi/");
+ banned_directories_.emplace("/usr/include/");
+ banned_directories_.emplace("/usr/lib/");
+ banned_directories_.emplace("/usr/local/include/");
+ banned_directories_.emplace("/usr/local/lib/");
+ banned_directories_.emplace("/testing/");
+ banned_directories_.emplace("/v8/");
+ banned_directories_.emplace("/dart/");
+ banned_directories_.emplace("/sdch/");
+ banned_directories_.emplace("/icu4c/");
+ banned_directories_.emplace("/frameworks/");
// Don't check autogenerated headers.
// Make puts them below $(builddir_name)/.../gen and geni.
// Ninja puts them below OUTPUT_DIR/.../gen
// Xcode has a fixed output directory for everything.
- banned_directories_.push_back("/gen/");
- banned_directories_.push_back("/geni/");
- banned_directories_.push_back("/xcodebuild/");
+ banned_directories_.emplace("/gen/");
+ banned_directories_.emplace("/geni/");
+ banned_directories_.emplace("/xcodebuild/");
// Used in really low level threading code that probably shouldn't be out of
// lined.
- ignored_record_names_.insert("ThreadLocalBoolean");
+ ignored_record_names_.emplace("ThreadLocalBoolean");
// A complicated pickle derived struct that is all packed integers.
- ignored_record_names_.insert("Header");
+ ignored_record_names_.emplace("Header");
// Part of the GPU system that uses multiple included header
// weirdness. Never getting this right.
- ignored_record_names_.insert("Validators");
+ ignored_record_names_.emplace("Validators");
// Has a UNIT_TEST only constructor. Isn't *terribly* complex...
- ignored_record_names_.insert("AutocompleteController");
- ignored_record_names_.insert("HistoryURLProvider");
+ ignored_record_names_.emplace("AutocompleteController");
+ ignored_record_names_.emplace("HistoryURLProvider");
// Used over in the net unittests. A large enough bundle of integers with 1
// non-pod class member. Probably harmless.
- ignored_record_names_.insert("MockTransaction");
+ ignored_record_names_.emplace("MockTransaction");
// Enum type with _LAST members where _LAST doesn't mean last enum value.
- ignored_record_names_.insert("ServerFieldType");
+ ignored_record_names_.emplace("ServerFieldType");
// Used heavily in ui_base_unittests and once in views_unittests. Fixing this
// isn't worth the overhead of an additional library.
- ignored_record_names_.insert("TestAnimationDelegate");
+ ignored_record_names_.emplace("TestAnimationDelegate");
// Part of our public interface that nacl and friends use. (Arguably, this
// should mean that this is a higher priority but fixing this looks hard.)
- ignored_record_names_.insert("PluginVersionInfo");
+ ignored_record_names_.emplace("PluginVersionInfo");
// Measured performance improvement on cc_perftests. See
// https://codereview.chromium.org/11299290/
- ignored_record_names_.insert("QuadF");
+ ignored_record_names_.emplace("QuadF");
// Enum type with _LAST members where _LAST doesn't mean last enum value.
- ignored_record_names_.insert("ViewID");
+ ignored_record_names_.emplace("ViewID");
}
std::string ChromeClassTester::GetNamespaceImpl(const DeclContext* context,
« no previous file with comments | « tools/clang/plugins/ChromeClassTester.h ('k') | tools/clang/plugins/FindBadConstructsAction.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698