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

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

Issue 1504033010: Follow macro invocations when checking if a violation happened in a .cc file. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkcr
Patch Set: Check every file in the macro instantiation chain. Created 5 years 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
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 <algorithm> 10 #include <algorithm>
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 182
183 return false; 183 return false;
184 } 184 }
185 185
186 std::string ChromeClassTester::GetNamespace(const Decl* record) { 186 std::string ChromeClassTester::GetNamespace(const Decl* record) {
187 return GetNamespaceImpl(record->getDeclContext(), ""); 187 return GetNamespaceImpl(record->getDeclContext(), "");
188 } 188 }
189 189
190 bool ChromeClassTester::InImplementationFile(SourceLocation record_location) { 190 bool ChromeClassTester::InImplementationFile(SourceLocation record_location) {
191 std::string filename; 191 std::string filename;
192 if (!GetFilename(record_location, &filename))
193 return false;
194 192
195 if (ends_with(filename, ".cc") || ends_with(filename, ".cpp") || 193 if (options_.follow_macro_expansion) {
196 ends_with(filename, ".mm")) { 194 // If |record_location| is a macro, check the whole chain of expansions.
197 return true; 195 const SourceManager& source_manager = instance_.getSourceManager();
196 while (true) {
197 if (GetFilename(record_location, &filename)) {
198 if (ends_with(filename, ".cc") || ends_with(filename, ".cpp") ||
199 ends_with(filename, ".mm")) {
200 return true;
201 }
202 }
203 if (!record_location.isMacroID()) {
204 break;
205 }
206 record_location =
207 source_manager.getImmediateExpansionRange(record_location).first;
208 }
209 } else {
210 if (!GetFilename(record_location, &filename))
211 return false;
212
213 if (ends_with(filename, ".cc") || ends_with(filename, ".cpp") ||
214 ends_with(filename, ".mm")) {
215 return true;
216 }
198 } 217 }
199 218
200 return false; 219 return false;
201 } 220 }
202 221
203 void ChromeClassTester::BuildBannedLists() { 222 void ChromeClassTester::BuildBannedLists() {
204 banned_namespaces_.emplace("std"); 223 banned_namespaces_.emplace("std");
205 banned_namespaces_.emplace("__gnu_cxx"); 224 banned_namespaces_.emplace("__gnu_cxx");
206 225
207 if (options_.enforce_in_thirdparty_webkit) { 226 if (options_.enforce_in_thirdparty_webkit) {
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 } 329 }
311 330
312 *filename = ploc.getFilename(); 331 *filename = ploc.getFilename();
313 return true; 332 return true;
314 } 333 }
315 334
316 DiagnosticsEngine::Level ChromeClassTester::getErrorLevel() { 335 DiagnosticsEngine::Level ChromeClassTester::getErrorLevel() {
317 return diagnostic().getWarningsAsErrors() ? DiagnosticsEngine::Error 336 return diagnostic().getWarningsAsErrors() ? DiagnosticsEngine::Error
318 : DiagnosticsEngine::Warning; 337 : DiagnosticsEngine::Warning;
319 } 338 }
OLDNEW
« no previous file with comments | « no previous file | tools/clang/plugins/FindBadConstructsAction.cpp » ('j') | tools/clang/plugins/tests/inline_ctor.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698