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 banned_namespaces_.push_back("blink"); | 207 if (!options_.enforce_overriding_blink) { |
198 banned_namespaces_.push_back("WTF"); | 208 banned_namespaces_.emplace("blink"); |
| 209 banned_namespaces_.emplace("WTF"); |
| 210 } |
199 | 211 |
200 banned_directories_.push_back("/third_party/"); | 212 if (options_.enforce_in_thirdparty_webkit) { |
201 banned_directories_.push_back("/native_client/"); | 213 allowed_directories_.emplace("/third_party/WebKit/"); |
202 banned_directories_.push_back("/breakpad/"); | 214 } |
203 banned_directories_.push_back("/courgette/"); | 215 |
204 banned_directories_.push_back("/pdf/"); | 216 banned_directories_.emplace("/third_party/"); |
205 banned_directories_.push_back("/ppapi/"); | 217 banned_directories_.emplace("/native_client/"); |
206 banned_directories_.push_back("/usr/include/"); | 218 banned_directories_.emplace("/breakpad/"); |
207 banned_directories_.push_back("/usr/lib/"); | 219 banned_directories_.emplace("/courgette/"); |
208 banned_directories_.push_back("/usr/local/include/"); | 220 banned_directories_.emplace("/pdf/"); |
209 banned_directories_.push_back("/usr/local/lib/"); | 221 banned_directories_.emplace("/ppapi/"); |
210 banned_directories_.push_back("/testing/"); | 222 banned_directories_.emplace("/usr/include/"); |
211 banned_directories_.push_back("/v8/"); | 223 banned_directories_.emplace("/usr/lib/"); |
212 banned_directories_.push_back("/dart/"); | 224 banned_directories_.emplace("/usr/local/include/"); |
213 banned_directories_.push_back("/sdch/"); | 225 banned_directories_.emplace("/usr/local/lib/"); |
214 banned_directories_.push_back("/icu4c/"); | 226 banned_directories_.emplace("/testing/"); |
215 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/"); |
216 | 232 |
217 // Don't check autogenerated headers. | 233 // Don't check autogenerated headers. |
218 // Make puts them below $(builddir_name)/.../gen and geni. | 234 // Make puts them below $(builddir_name)/.../gen and geni. |
219 // Ninja puts them below OUTPUT_DIR/.../gen | 235 // Ninja puts them below OUTPUT_DIR/.../gen |
220 // Xcode has a fixed output directory for everything. | 236 // Xcode has a fixed output directory for everything. |
221 banned_directories_.push_back("/gen/"); | 237 banned_directories_.emplace("/gen/"); |
222 banned_directories_.push_back("/geni/"); | 238 banned_directories_.emplace("/geni/"); |
223 banned_directories_.push_back("/xcodebuild/"); | 239 banned_directories_.emplace("/xcodebuild/"); |
224 | |
225 // You are standing in a mazy of twisty dependencies, all resolved by | |
226 // putting everything in the header. | |
227 banned_directories_.push_back("/automation/"); | |
228 | |
229 // Don't check system headers. | |
230 banned_directories_.push_back("/Developer/"); | |
231 | 240 |
232 // 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 |
233 // lined. | 242 // lined. |
234 ignored_record_names_.insert("ThreadLocalBoolean"); | 243 ignored_record_names_.emplace("ThreadLocalBoolean"); |
235 | 244 |
236 // A complicated pickle derived struct that is all packed integers. | 245 // A complicated pickle derived struct that is all packed integers. |
237 ignored_record_names_.insert("Header"); | 246 ignored_record_names_.emplace("Header"); |
238 | 247 |
239 // Part of the GPU system that uses multiple included header | 248 // Part of the GPU system that uses multiple included header |
240 // weirdness. Never getting this right. | 249 // weirdness. Never getting this right. |
241 ignored_record_names_.insert("Validators"); | 250 ignored_record_names_.emplace("Validators"); |
242 | 251 |
243 // Has a UNIT_TEST only constructor. Isn't *terribly* complex... | 252 // Has a UNIT_TEST only constructor. Isn't *terribly* complex... |
244 ignored_record_names_.insert("AutocompleteController"); | 253 ignored_record_names_.emplace("AutocompleteController"); |
245 ignored_record_names_.insert("HistoryURLProvider"); | 254 ignored_record_names_.emplace("HistoryURLProvider"); |
246 | |
247 // Because of chrome frame | |
248 ignored_record_names_.insert("ReliabilityTestSuite"); | |
249 | 255 |
250 // 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 |
251 // non-pod class member. Probably harmless. | 257 // non-pod class member. Probably harmless. |
252 ignored_record_names_.insert("MockTransaction"); | 258 ignored_record_names_.emplace("MockTransaction"); |
253 | 259 |
254 // 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. |
255 ignored_record_names_.insert("ServerFieldType"); | 261 ignored_record_names_.emplace("ServerFieldType"); |
256 | 262 |
257 // 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 |
258 // isn't worth the overhead of an additional library. | 264 // isn't worth the overhead of an additional library. |
259 ignored_record_names_.insert("TestAnimationDelegate"); | 265 ignored_record_names_.emplace("TestAnimationDelegate"); |
260 | 266 |
261 // 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 |
262 // 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.) |
263 ignored_record_names_.insert("PluginVersionInfo"); | 269 ignored_record_names_.emplace("PluginVersionInfo"); |
264 | 270 |
265 // Measured performance improvement on cc_perftests. See | 271 // Measured performance improvement on cc_perftests. See |
266 // https://codereview.chromium.org/11299290/ | 272 // https://codereview.chromium.org/11299290/ |
267 ignored_record_names_.insert("QuadF"); | 273 ignored_record_names_.emplace("QuadF"); |
268 | 274 |
269 // 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. |
270 ignored_record_names_.insert("ViewID"); | 276 ignored_record_names_.emplace("ViewID"); |
271 } | 277 } |
272 | 278 |
273 std::string ChromeClassTester::GetNamespaceImpl(const DeclContext* context, | 279 std::string ChromeClassTester::GetNamespaceImpl(const DeclContext* context, |
274 const std::string& candidate) { | 280 const std::string& candidate) { |
275 switch (context->getDeclKind()) { | 281 switch (context->getDeclKind()) { |
276 case Decl::TranslationUnit: { | 282 case Decl::TranslationUnit: { |
277 return candidate; | 283 return candidate; |
278 } | 284 } |
279 case Decl::Namespace: { | 285 case Decl::Namespace: { |
280 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... |
312 return true; | 318 return true; |
313 } | 319 } |
314 | 320 |
315 DiagnosticsEngine::Level ChromeClassTester::getErrorLevel() { | 321 DiagnosticsEngine::Level ChromeClassTester::getErrorLevel() { |
316 if (options_.warn_only) | 322 if (options_.warn_only) |
317 return DiagnosticsEngine::Warning; | 323 return DiagnosticsEngine::Warning; |
318 | 324 |
319 return diagnostic().getWarningsAsErrors() ? DiagnosticsEngine::Error | 325 return diagnostic().getWarningsAsErrors() ? DiagnosticsEngine::Error |
320 : DiagnosticsEngine::Warning; | 326 : DiagnosticsEngine::Warning; |
321 } | 327 } |
OLD | NEW |