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> | 10 #include <algorithm> |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 // On Posix, realpath() has made the path absolute. On Windows, this isn't | 143 // On Posix, realpath() has made the path absolute. On Windows, this isn't |
144 // necessarily true, so prepend a '/' to the path to make sure the | 144 // necessarily true, so prepend a '/' to the path to make sure the |
145 // banned_directories_ loop below works correctly. | 145 // banned_directories_ loop below works correctly. |
146 // This turns e.g. "gen/dir/file.cc" to "/gen/dir/file.cc" which lets the | 146 // This turns e.g. "gen/dir/file.cc" to "/gen/dir/file.cc" which lets the |
147 // "/gen/" banned_dir work. | 147 // "/gen/" banned_dir work. |
148 // This seems simpler than converting to utf16, calling GetFullPathNameW(), | 148 // This seems simpler than converting to utf16, calling GetFullPathNameW(), |
149 // and converting back to utf8. | 149 // and converting back to utf8. |
150 filename.insert(filename.begin(), '/'); | 150 filename.insert(filename.begin(), '/'); |
151 #endif | 151 #endif |
152 | 152 |
| 153 for (const std::string& allowed_dir : allowed_directories_) { |
| 154 // If any of the allowed directories occur as a component in filename, |
| 155 // this file is allowed. |
| 156 assert(allowed_dir.front() == '/' && "Allowed dir must start with '/'"); |
| 157 assert(allowed_dir.back() == '/' && "Allowed dir must end with '/'"); |
| 158 |
| 159 if (filename.find(allowed_dir) != std::string::npos) |
| 160 return false; |
| 161 } |
| 162 |
153 for (const std::string& banned_dir : banned_directories_) { | 163 for (const std::string& banned_dir : banned_directories_) { |
154 // If any of the banned directories occur as a component in filename, | 164 // If any of the banned directories occur as a component in filename, |
155 // this file is rejected. | 165 // this file is rejected. |
156 assert(banned_dir.front() == '/' && "Banned dir must start with '/'"); | 166 assert(banned_dir.front() == '/' && "Banned dir must start with '/'"); |
157 assert(banned_dir.back() == '/' && "Banned dir must end with '/'"); | 167 assert(banned_dir.back() == '/' && "Banned dir must end with '/'"); |
158 | 168 |
159 if (filename.find(banned_dir) != std::string::npos) | 169 if (filename.find(banned_dir) != std::string::npos) |
160 return true; | 170 return true; |
161 } | 171 } |
162 | 172 |
(...skipping 21 matching lines...) Expand all Loading... |
184 | 194 |
185 if (ends_with(filename, ".cc") || ends_with(filename, ".cpp") || | 195 if (ends_with(filename, ".cc") || ends_with(filename, ".cpp") || |
186 ends_with(filename, ".mm")) { | 196 ends_with(filename, ".mm")) { |
187 return true; | 197 return true; |
188 } | 198 } |
189 | 199 |
190 return false; | 200 return false; |
191 } | 201 } |
192 | 202 |
193 void ChromeClassTester::BuildBannedLists() { | 203 void ChromeClassTester::BuildBannedLists() { |
194 banned_namespaces_.push_back("std"); | 204 banned_namespaces_.emplace("std"); |
195 banned_namespaces_.push_back("__gnu_cxx"); | 205 banned_namespaces_.emplace("__gnu_cxx"); |
196 | 206 |
197 if (!options_.enforce_blink) { | 207 if (!options_.enforce_overriding_blink) { |
198 banned_namespaces_.push_back("blink"); | 208 banned_namespaces_.emplace("blink"); |
199 banned_namespaces_.push_back("WTF"); | 209 banned_namespaces_.emplace("WTF"); |
200 } | 210 } |
201 | 211 |
202 banned_directories_.push_back("/third_party/"); | 212 if (options_.enforce_in_thirdparty_webkit) { |
203 banned_directories_.push_back("/native_client/"); | 213 allowed_directories_.emplace("/third_party/WebKit/"); |
204 banned_directories_.push_back("/breakpad/"); | 214 } |
205 banned_directories_.push_back("/courgette/"); | 215 |
206 banned_directories_.push_back("/pdf/"); | 216 banned_directories_.emplace("/third_party/"); |
207 banned_directories_.push_back("/ppapi/"); | 217 banned_directories_.emplace("/native_client/"); |
208 banned_directories_.push_back("/usr/include/"); | 218 banned_directories_.emplace("/breakpad/"); |
209 banned_directories_.push_back("/usr/lib/"); | 219 banned_directories_.emplace("/courgette/"); |
210 banned_directories_.push_back("/usr/local/include/"); | 220 banned_directories_.emplace("/pdf/"); |
211 banned_directories_.push_back("/usr/local/lib/"); | 221 banned_directories_.emplace("/ppapi/"); |
212 banned_directories_.push_back("/testing/"); | 222 banned_directories_.emplace("/usr/include/"); |
213 banned_directories_.push_back("/v8/"); | 223 banned_directories_.emplace("/usr/lib/"); |
214 banned_directories_.push_back("/dart/"); | 224 banned_directories_.emplace("/usr/local/include/"); |
215 banned_directories_.push_back("/sdch/"); | 225 banned_directories_.emplace("/usr/local/lib/"); |
216 banned_directories_.push_back("/icu4c/"); | 226 banned_directories_.emplace("/testing/"); |
217 banned_directories_.push_back("/frameworks/"); | 227 banned_directories_.emplace("/v8/"); |
| 228 banned_directories_.emplace("/dart/"); |
| 229 banned_directories_.emplace("/sdch/"); |
| 230 banned_directories_.emplace("/icu4c/"); |
| 231 banned_directories_.emplace("/frameworks/"); |
218 | 232 |
219 // Don't check autogenerated headers. | 233 // Don't check autogenerated headers. |
220 // Make puts them below $(builddir_name)/.../gen and geni. | 234 // Make puts them below $(builddir_name)/.../gen and geni. |
221 // Ninja puts them below OUTPUT_DIR/.../gen | 235 // Ninja puts them below OUTPUT_DIR/.../gen |
222 // Xcode has a fixed output directory for everything. | 236 // Xcode has a fixed output directory for everything. |
223 banned_directories_.push_back("/gen/"); | 237 banned_directories_.emplace("/gen/"); |
224 banned_directories_.push_back("/geni/"); | 238 banned_directories_.emplace("/geni/"); |
225 banned_directories_.push_back("/xcodebuild/"); | 239 banned_directories_.emplace("/xcodebuild/"); |
226 | 240 |
227 // Used in really low level threading code that probably shouldn't be out of | 241 // Used in really low level threading code that probably shouldn't be out of |
228 // lined. | 242 // lined. |
229 ignored_record_names_.insert("ThreadLocalBoolean"); | 243 ignored_record_names_.emplace("ThreadLocalBoolean"); |
230 | 244 |
231 // A complicated pickle derived struct that is all packed integers. | 245 // A complicated pickle derived struct that is all packed integers. |
232 ignored_record_names_.insert("Header"); | 246 ignored_record_names_.emplace("Header"); |
233 | 247 |
234 // Part of the GPU system that uses multiple included header | 248 // Part of the GPU system that uses multiple included header |
235 // weirdness. Never getting this right. | 249 // weirdness. Never getting this right. |
236 ignored_record_names_.insert("Validators"); | 250 ignored_record_names_.emplace("Validators"); |
237 | 251 |
238 // Has a UNIT_TEST only constructor. Isn't *terribly* complex... | 252 // Has a UNIT_TEST only constructor. Isn't *terribly* complex... |
239 ignored_record_names_.insert("AutocompleteController"); | 253 ignored_record_names_.emplace("AutocompleteController"); |
240 ignored_record_names_.insert("HistoryURLProvider"); | 254 ignored_record_names_.emplace("HistoryURLProvider"); |
241 | 255 |
242 // Used over in the net unittests. A large enough bundle of integers with 1 | 256 // Used over in the net unittests. A large enough bundle of integers with 1 |
243 // non-pod class member. Probably harmless. | 257 // non-pod class member. Probably harmless. |
244 ignored_record_names_.insert("MockTransaction"); | 258 ignored_record_names_.emplace("MockTransaction"); |
245 | 259 |
246 // Enum type with _LAST members where _LAST doesn't mean last enum value. | 260 // Enum type with _LAST members where _LAST doesn't mean last enum value. |
247 ignored_record_names_.insert("ServerFieldType"); | 261 ignored_record_names_.emplace("ServerFieldType"); |
248 | 262 |
249 // Used heavily in ui_base_unittests and once in views_unittests. Fixing this | 263 // Used heavily in ui_base_unittests and once in views_unittests. Fixing this |
250 // isn't worth the overhead of an additional library. | 264 // isn't worth the overhead of an additional library. |
251 ignored_record_names_.insert("TestAnimationDelegate"); | 265 ignored_record_names_.emplace("TestAnimationDelegate"); |
252 | 266 |
253 // Part of our public interface that nacl and friends use. (Arguably, this | 267 // Part of our public interface that nacl and friends use. (Arguably, this |
254 // should mean that this is a higher priority but fixing this looks hard.) | 268 // should mean that this is a higher priority but fixing this looks hard.) |
255 ignored_record_names_.insert("PluginVersionInfo"); | 269 ignored_record_names_.emplace("PluginVersionInfo"); |
256 | 270 |
257 // Measured performance improvement on cc_perftests. See | 271 // Measured performance improvement on cc_perftests. See |
258 // https://codereview.chromium.org/11299290/ | 272 // https://codereview.chromium.org/11299290/ |
259 ignored_record_names_.insert("QuadF"); | 273 ignored_record_names_.emplace("QuadF"); |
260 | 274 |
261 // Enum type with _LAST members where _LAST doesn't mean last enum value. | 275 // Enum type with _LAST members where _LAST doesn't mean last enum value. |
262 ignored_record_names_.insert("ViewID"); | 276 ignored_record_names_.emplace("ViewID"); |
263 } | 277 } |
264 | 278 |
265 std::string ChromeClassTester::GetNamespaceImpl(const DeclContext* context, | 279 std::string ChromeClassTester::GetNamespaceImpl(const DeclContext* context, |
266 const std::string& candidate) { | 280 const std::string& candidate) { |
267 switch (context->getDeclKind()) { | 281 switch (context->getDeclKind()) { |
268 case Decl::TranslationUnit: { | 282 case Decl::TranslationUnit: { |
269 return candidate; | 283 return candidate; |
270 } | 284 } |
271 case Decl::Namespace: { | 285 case Decl::Namespace: { |
272 const NamespaceDecl* decl = dyn_cast<NamespaceDecl>(context); | 286 const NamespaceDecl* decl = dyn_cast<NamespaceDecl>(context); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 return true; | 318 return true; |
305 } | 319 } |
306 | 320 |
307 DiagnosticsEngine::Level ChromeClassTester::getErrorLevel() { | 321 DiagnosticsEngine::Level ChromeClassTester::getErrorLevel() { |
308 if (options_.warn_only) | 322 if (options_.warn_only) |
309 return DiagnosticsEngine::Warning; | 323 return DiagnosticsEngine::Warning; |
310 | 324 |
311 return diagnostic().getWarningsAsErrors() ? DiagnosticsEngine::Error | 325 return diagnostic().getWarningsAsErrors() ? DiagnosticsEngine::Error |
312 : DiagnosticsEngine::Warning; | 326 : DiagnosticsEngine::Warning; |
313 } | 327 } |
OLD | NEW |