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> |
11 | 11 |
12 #include "clang/AST/AST.h" | 12 #include "clang/AST/AST.h" |
13 #include "clang/Basic/FileManager.h" | 13 #include "clang/Basic/FileManager.h" |
14 #include "clang/Basic/SourceManager.h" | 14 #include "clang/Basic/SourceManager.h" |
15 | 15 |
16 #ifdef LLVM_ON_UNIX | 16 #ifdef LLVM_ON_UNIX |
17 #include <sys/param.h> | 17 #include <sys/param.h> |
18 #endif | 18 #endif |
19 | 19 |
20 using namespace clang; | 20 using namespace clang; |
| 21 using chrome_checker::Options; |
21 | 22 |
22 namespace { | 23 namespace { |
23 | 24 |
24 bool ends_with(const std::string& one, const std::string& two) { | 25 bool ends_with(const std::string& one, const std::string& two) { |
25 if (two.size() > one.size()) | 26 if (two.size() > one.size()) |
26 return false; | 27 return false; |
27 | 28 |
28 return one.compare(one.size() - two.size(), two.size(), two) == 0; | 29 return one.compare(one.size() - two.size(), two.size(), two) == 0; |
29 } | 30 } |
30 | 31 |
31 } // namespace | 32 } // namespace |
32 | 33 |
33 ChromeClassTester::ChromeClassTester(CompilerInstance& instance) | 34 ChromeClassTester::ChromeClassTester(CompilerInstance& instance, |
34 : instance_(instance), | 35 const Options& options) |
| 36 : options_(options), |
| 37 instance_(instance), |
35 diagnostic_(instance.getDiagnostics()) { | 38 diagnostic_(instance.getDiagnostics()) { |
36 BuildBannedLists(); | 39 BuildBannedLists(); |
37 } | 40 } |
38 | 41 |
39 ChromeClassTester::~ChromeClassTester() {} | 42 ChromeClassTester::~ChromeClassTester() {} |
40 | 43 |
41 void ChromeClassTester::HandleTagDeclDefinition(TagDecl* tag) { | 44 void ChromeClassTester::HandleTagDeclDefinition(TagDecl* tag) { |
42 pending_class_decls_.push_back(tag); | 45 pending_class_decls_.push_back(tag); |
43 } | 46 } |
44 | 47 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 CheckChromeEnum(enum_location, enum_decl); | 91 CheckChromeEnum(enum_location, enum_decl); |
89 } | 92 } |
90 } | 93 } |
91 | 94 |
92 void ChromeClassTester::emitWarning(SourceLocation loc, | 95 void ChromeClassTester::emitWarning(SourceLocation loc, |
93 const char* raw_error) { | 96 const char* raw_error) { |
94 FullSourceLoc full(loc, instance().getSourceManager()); | 97 FullSourceLoc full(loc, instance().getSourceManager()); |
95 std::string err; | 98 std::string err; |
96 err = "[chromium-style] "; | 99 err = "[chromium-style] "; |
97 err += raw_error; | 100 err += raw_error; |
98 // TODO(dcheng): Re-enable -Werror for these diagnostics on Windows once all | 101 |
99 // the pre-existing warnings are cleaned up. https://crbug.com/467287 | 102 DiagnosticIDs::Level level = getErrorLevel() == DiagnosticsEngine::Error |
100 DiagnosticIDs::Level level = | 103 ? DiagnosticIDs::Error : DiagnosticIDs::Warning; |
101 #if !defined(LLVM_ON_WIN32) | 104 |
102 diagnostic().getWarningsAsErrors() ? | |
103 DiagnosticIDs::Error : | |
104 #endif | |
105 DiagnosticIDs::Warning; | |
106 unsigned id = diagnostic().getDiagnosticIDs()->getCustomDiagID(level, err); | 105 unsigned id = diagnostic().getDiagnosticIDs()->getCustomDiagID(level, err); |
107 DiagnosticBuilder builder = diagnostic().Report(full, id); | 106 DiagnosticBuilder builder = diagnostic().Report(full, id); |
| 107 |
108 } | 108 } |
109 | 109 |
110 bool ChromeClassTester::InBannedDirectory(SourceLocation loc) { | 110 bool ChromeClassTester::InBannedDirectory(SourceLocation loc) { |
111 if (instance().getSourceManager().isInSystemHeader(loc)) | 111 if (instance().getSourceManager().isInSystemHeader(loc)) |
112 return true; | 112 return true; |
113 | 113 |
114 std::string filename; | 114 std::string filename; |
115 if (!GetFilename(loc, &filename)) { | 115 if (!GetFilename(loc, &filename)) { |
116 // If the filename cannot be determined, simply treat this as a banned | 116 // If the filename cannot be determined, simply treat this as a banned |
117 // location, instead of going through the full lookup process. | 117 // location, instead of going through the full lookup process. |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 PresumedLoc ploc = source_manager.getPresumedLoc(spelling_location); | 297 PresumedLoc ploc = source_manager.getPresumedLoc(spelling_location); |
298 if (ploc.isInvalid()) { | 298 if (ploc.isInvalid()) { |
299 // If we're in an invalid location, we're looking at things that aren't | 299 // If we're in an invalid location, we're looking at things that aren't |
300 // actually stated in the source. | 300 // actually stated in the source. |
301 return false; | 301 return false; |
302 } | 302 } |
303 | 303 |
304 *filename = ploc.getFilename(); | 304 *filename = ploc.getFilename(); |
305 return true; | 305 return true; |
306 } | 306 } |
| 307 |
| 308 DiagnosticsEngine::Level ChromeClassTester::getErrorLevel() { |
| 309 if (options_.warn_only) |
| 310 return DiagnosticsEngine::Warning; |
| 311 |
| 312 return diagnostic().getWarningsAsErrors() ? DiagnosticsEngine::Error |
| 313 : DiagnosticsEngine::Warning; |
| 314 } |
OLD | NEW |