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

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

Issue 150943005: Add a check to the FindBadConstructs.cpp clang plugin for bad enum last values. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 500s Created 6 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « tools/clang/plugins/ChromeClassTester.h ('k') | tools/clang/plugins/FindBadConstructs.cpp » ('j') | 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> 10 #include <sys/param.h>
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 std::string base_name = record->getNameAsString(); 86 std::string base_name = record->getNameAsString();
87 if (IsIgnoredType(base_name)) 87 if (IsIgnoredType(base_name))
88 return; 88 return;
89 89
90 // We ignore all classes that end with "Matcher" because they're probably 90 // We ignore all classes that end with "Matcher" because they're probably
91 // GMock artifacts. 91 // GMock artifacts.
92 if (ends_with(base_name, "Matcher")) 92 if (ends_with(base_name, "Matcher"))
93 return; 93 return;
94 94
95 CheckChromeClass(record_location, record); 95 CheckChromeClass(record_location, record);
96 } else if (EnumDecl* enum_decl = dyn_cast<EnumDecl>(tag)) {
97 SourceLocation enum_location = enum_decl->getInnerLocStart();
98 if (InBannedDirectory(enum_location))
99 return;
100
101 std::string base_name = enum_decl->getNameAsString();
102 if (IsIgnoredType(base_name))
103 return;
104
105 CheckChromeEnum(enum_location, enum_decl);
96 } 106 }
97 } 107 }
98 108
99 void ChromeClassTester::emitWarning(SourceLocation loc, 109 void ChromeClassTester::emitWarning(SourceLocation loc,
100 const char* raw_error) { 110 const char* raw_error) {
101 FullSourceLoc full(loc, instance().getSourceManager()); 111 FullSourceLoc full(loc, instance().getSourceManager());
102 std::string err; 112 std::string err;
103 err = "[chromium-style] "; 113 err = "[chromium-style] ";
104 err += raw_error; 114 err += raw_error;
105 DiagnosticsEngine::Level level = 115 DiagnosticsEngine::Level level =
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 ignored_record_names_.insert("AutocompleteController"); 203 ignored_record_names_.insert("AutocompleteController");
194 ignored_record_names_.insert("HistoryURLProvider"); 204 ignored_record_names_.insert("HistoryURLProvider");
195 205
196 // Because of chrome frame 206 // Because of chrome frame
197 ignored_record_names_.insert("ReliabilityTestSuite"); 207 ignored_record_names_.insert("ReliabilityTestSuite");
198 208
199 // Used over in the net unittests. A large enough bundle of integers with 1 209 // Used over in the net unittests. A large enough bundle of integers with 1
200 // non-pod class member. Probably harmless. 210 // non-pod class member. Probably harmless.
201 ignored_record_names_.insert("MockTransaction"); 211 ignored_record_names_.insert("MockTransaction");
202 212
213 // Enum type with _LAST members where _LAST doesn't mean last enum value.
214 ignored_record_names_.insert("ServerFieldType");
215
203 // Used heavily in ui_unittests and once in views_unittests. Fixing this 216 // Used heavily in ui_unittests and once in views_unittests. Fixing this
204 // isn't worth the overhead of an additional library. 217 // isn't worth the overhead of an additional library.
205 ignored_record_names_.insert("TestAnimationDelegate"); 218 ignored_record_names_.insert("TestAnimationDelegate");
206 219
207 // Part of our public interface that nacl and friends use. (Arguably, this 220 // Part of our public interface that nacl and friends use. (Arguably, this
208 // should mean that this is a higher priority but fixing this looks hard.) 221 // should mean that this is a higher priority but fixing this looks hard.)
209 ignored_record_names_.insert("PluginVersionInfo"); 222 ignored_record_names_.insert("PluginVersionInfo");
210 223
211 // Measured performance improvement on cc_perftests. See 224 // Measured performance improvement on cc_perftests. See
212 // https://codereview.chromium.org/11299290/ 225 // https://codereview.chromium.org/11299290/
213 ignored_record_names_.insert("QuadF"); 226 ignored_record_names_.insert("QuadF");
227
228 // Enum type with _LAST members where _LAST doesn't mean last enum value.
229 ignored_record_names_.insert("ViewID");
214 } 230 }
215 231
216 std::string ChromeClassTester::GetNamespaceImpl(const DeclContext* context, 232 std::string ChromeClassTester::GetNamespaceImpl(const DeclContext* context,
217 const std::string& candidate) { 233 const std::string& candidate) {
218 switch (context->getDeclKind()) { 234 switch (context->getDeclKind()) {
219 case Decl::TranslationUnit: { 235 case Decl::TranslationUnit: {
220 return candidate; 236 return candidate;
221 } 237 }
222 case Decl::Namespace: { 238 case Decl::Namespace: {
223 const NamespaceDecl* decl = dyn_cast<NamespaceDecl>(context); 239 const NamespaceDecl* decl = dyn_cast<NamespaceDecl>(context);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 PresumedLoc ploc = source_manager.getPresumedLoc(spelling_location); 313 PresumedLoc ploc = source_manager.getPresumedLoc(spelling_location);
298 if (ploc.isInvalid()) { 314 if (ploc.isInvalid()) {
299 // If we're in an invalid location, we're looking at things that aren't 315 // If we're in an invalid location, we're looking at things that aren't
300 // actually stated in the source. 316 // actually stated in the source.
301 return false; 317 return false;
302 } 318 }
303 319
304 *filename = ploc.getFilename(); 320 *filename = ploc.getFilename();
305 return true; 321 return true;
306 } 322 }
OLDNEW
« no previous file with comments | « tools/clang/plugins/ChromeClassTester.h ('k') | tools/clang/plugins/FindBadConstructs.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698