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

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

Issue 10005022: Check for public dtors on base::RefCounted types (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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>
11 11
12 #include <string>
13
12 #include "clang/Basic/FileManager.h" 14 #include "clang/Basic/FileManager.h"
13 15
14 using namespace clang; 16 using namespace clang;
15 17
16 namespace { 18 namespace {
17 19
18 bool starts_with(const std::string& one, const std::string& two) { 20 bool starts_with(const std::string& one, const std::string& two) {
19 return one.compare(0, two.size(), two) == 0; 21 return one.compare(0, two.size(), two) == 0;
20 } 22 }
21 23
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 bool ChromeClassTester::InBannedNamespace(const Decl* record) { 166 bool ChromeClassTester::InBannedNamespace(const Decl* record) {
165 std::string n = GetNamespace(record); 167 std::string n = GetNamespace(record);
166 if (n != "") { 168 if (n != "") {
167 return std::find(banned_namespaces_.begin(), banned_namespaces_.end(), n) 169 return std::find(banned_namespaces_.begin(), banned_namespaces_.end(), n)
168 != banned_namespaces_.end(); 170 != banned_namespaces_.end();
169 } 171 }
170 172
171 return false; 173 return false;
172 } 174 }
173 175
176 bool ChromeClassTester::InImplementationFile(
177 const SourceLocation& record_location) {
178 const SourceManager &SM = instance().getSourceManager();
179 SourceLocation spelling_location = SM.getSpellingLoc(record_location);
180 PresumedLoc ploc = SM.getPresumedLoc(spelling_location);
181 if (ploc.isInvalid())
182 return false;
183
184 std::string b = ploc.getFilename();
185
186 if (ends_with(b, ".cc") || ends_with(b, ".cpp") || ends_with(b, ".mm"))
187 return true;
188
189 return false;
190 }
191
174 std::string ChromeClassTester::GetNamespace(const Decl* record) { 192 std::string ChromeClassTester::GetNamespace(const Decl* record) {
175 return GetNamespaceImpl(record->getDeclContext(), ""); 193 return GetNamespaceImpl(record->getDeclContext(), "");
176 } 194 }
177 195
178 std::string ChromeClassTester::GetNamespaceImpl(const DeclContext* context, 196 std::string ChromeClassTester::GetNamespaceImpl(const DeclContext* context,
179 std::string candidate) { 197 std::string candidate) {
180 switch (context->getDeclKind()) { 198 switch (context->getDeclKind()) {
181 case Decl::TranslationUnit: { 199 case Decl::TranslationUnit: {
182 return candidate; 200 return candidate;
183 } 201 }
(...skipping 26 matching lines...) Expand all
210 return true; 228 return true;
211 } else { 229 } else {
212 std::string b = ploc.getFilename(); 230 std::string b = ploc.getFilename();
213 231
214 // We need to special case scratch space; which is where clang does its 232 // We need to special case scratch space; which is where clang does its
215 // macro expansion. We explicitly want to allow people to do otherwise bad 233 // macro expansion. We explicitly want to allow people to do otherwise bad
216 // things through macros that were defined due to third party libraries. 234 // things through macros that were defined due to third party libraries.
217 if (b == "<scratch space>") 235 if (b == "<scratch space>")
218 return true; 236 return true;
219 237
220 // Don't complain about these things in implementation files.
221 if (ends_with(b, ".cc") || ends_with(b, ".cpp") || ends_with(b, ".mm")) {
222 return true;
223 }
224
225 // Don't complain about autogenerated protobuf files. 238 // Don't complain about autogenerated protobuf files.
226 if (ends_with(b, ".pb.h")) { 239 if (ends_with(b, ".pb.h")) {
227 return true; 240 return true;
228 } 241 }
229 242
230 // We need to munge the paths so that they are relative to the repository 243 // We need to munge the paths so that they are relative to the repository
231 // srcroot. We first resolve the symlinktastic relative path and then 244 // srcroot. We first resolve the symlinktastic relative path and then
232 // remove our known srcroot from it if needed. 245 // remove our known srcroot from it if needed.
233 char resolvedPath[MAXPATHLEN]; 246 char resolvedPath[MAXPATHLEN];
234 if (realpath(b.c_str(), resolvedPath)) { 247 if (realpath(b.c_str(), resolvedPath)) {
(...skipping 20 matching lines...) Expand all
255 } 268 }
256 } 269 }
257 } 270 }
258 271
259 return false; 272 return false;
260 } 273 }
261 274
262 bool ChromeClassTester::IsIgnoredType(const std::string& base_name) { 275 bool ChromeClassTester::IsIgnoredType(const std::string& base_name) {
263 return ignored_record_names_.find(base_name) != ignored_record_names_.end(); 276 return ignored_record_names_.find(base_name) != ignored_record_names_.end();
264 } 277 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698