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

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

Issue 10005022: Check for public dtors on base::RefCounted types (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Just RefCounted 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 #ifndef TOOLS_CLANG_PLUGINS_CHROMECLASSTESTER_H_ 5 #ifndef TOOLS_CLANG_PLUGINS_CHROMECLASSTESTER_H_
6 #define TOOLS_CLANG_PLUGINS_CHROMECLASSTESTER_H_ 6 #define TOOLS_CLANG_PLUGINS_CHROMECLASSTESTER_H_
7 7
8 #include "clang/AST/ASTConsumer.h" 8 #include "clang/AST/ASTConsumer.h"
9 #include "clang/AST/AST.h" 9 #include "clang/AST/AST.h"
10 #include "clang/AST/TypeLoc.h" 10 #include "clang/AST/TypeLoc.h"
11 #include "clang/Basic/SourceManager.h" 11 #include "clang/Basic/SourceManager.h"
12 #include "clang/Frontend/CompilerInstance.h" 12 #include "clang/Frontend/CompilerInstance.h"
13 13
14 #include <set> 14 #include <set>
15 #include <vector> 15 #include <vector>
16 16
17 // A class on top of ASTConsumer that forwards classes defined in Chromium 17 // A class on top of ASTConsumer that forwards classes defined in Chromium
18 // headers to subclasses which implement CheckChromeClass(). 18 // headers to subclasses which implement CheckChromeClass().
19 class ChromeClassTester : public clang::ASTConsumer { 19 class ChromeClassTester : public clang::ASTConsumer {
20 public: 20 public:
21 explicit ChromeClassTester(clang::CompilerInstance& instance); 21 explicit ChromeClassTester(clang::CompilerInstance& instance);
22 virtual ~ChromeClassTester(); 22 virtual ~ChromeClassTester();
23 23
24 void BuildBannedLists();
25
26 // ASTConsumer: 24 // ASTConsumer:
27 virtual void HandleTagDeclDefinition(clang::TagDecl* tag); 25 virtual void HandleTagDeclDefinition(clang::TagDecl* tag);
28 26
29 protected: 27 protected:
30 clang::CompilerInstance& instance() { return instance_; } 28 clang::CompilerInstance& instance() { return instance_; }
31 clang::DiagnosticsEngine& diagnostic() { return diagnostic_; } 29 clang::DiagnosticsEngine& diagnostic() { return diagnostic_; }
32 30
33 // Emits a simple warning; this shouldn't be used if you require printf-style 31 // Emits a simple warning; this shouldn't be used if you require printf-style
34 // printing. 32 // printing.
35 void emitWarning(clang::SourceLocation loc, const char* error); 33 void emitWarning(const clang::SourceLocation& loc, const char* error);
36
37 // Utility method for subclasses to check if testing details are in this
38 // class. Some tests won't care if a class has a ::testing member and others
39 // will.
40 bool InTestingNamespace(const clang::Decl* record);
41 34
42 // Utility method for subclasses to check if this class is in a banned 35 // Utility method for subclasses to check if this class is in a banned
43 // namespace. 36 // namespace.
44 bool InBannedNamespace(const clang::Decl* record); 37 bool InBannedNamespace(const clang::Decl* record);
45 38
39 // Utility method for subclasses to determine the namespace of the
40 // specified record, if any. Unnamed namespaces will be identified as
41 // "<anonymous namespace>".
42 std::string GetNamespace(const clang::Decl* record);
43
44 // Utility method for subclasses to check if this class is within an
45 // implementation (.cc, .cpp, .mm) file.
46 bool InImplementationFile(const clang::SourceLocation& location);
47
46 private: 48 private:
49 void BuildBannedLists();
50
47 // Filtered versions of tags that are only called with things defined in 51 // Filtered versions of tags that are only called with things defined in
48 // chrome header files. 52 // chrome header files.
49 virtual void CheckChromeClass(const clang::SourceLocation& record_location, 53 virtual void CheckChromeClass(const clang::SourceLocation& record_location,
50 clang::CXXRecordDecl* record) = 0; 54 clang::CXXRecordDecl* record) = 0;
51 55
52 // Utility methods used for filtering out non-chrome classes (and ones we 56 // Utility methods used for filtering out non-chrome classes (and ones we
53 // deliberately ignore) in HandleTagDeclDefinition(). 57 // deliberately ignore) in HandleTagDeclDefinition().
54 std::string GetNamespace(const clang::Decl* record);
55 std::string GetNamespaceImpl(const clang::DeclContext* context, 58 std::string GetNamespaceImpl(const clang::DeclContext* context,
56 std::string candidate); 59 const std::string& candidate);
57 bool InBannedDirectory(clang::SourceLocation loc); 60 bool InBannedDirectory(const clang::SourceLocation& loc);
Nico 2012/04/11 22:27:26 a sourcelocation is an int, passing these by value
58 bool IsIgnoredType(const std::string& base_name); 61 bool IsIgnoredType(const std::string& base_name);
59 62
63 // Attempts to determine the filename for the given SourceLocation.
64 // Returns false if the filename could not be determined.
65 bool GetFilename(const clang::SourceLocation& loc,
Nico 2012/04/11 22:27:26 ditto
66 std::string* filename);
67
60 clang::CompilerInstance& instance_; 68 clang::CompilerInstance& instance_;
61 clang::DiagnosticsEngine& diagnostic_; 69 clang::DiagnosticsEngine& diagnostic_;
62 70
63 // List of banned namespaces. 71 // List of banned namespaces.
64 std::vector<std::string> banned_namespaces_; 72 std::vector<std::string> banned_namespaces_;
65 73
66 // List of banned directories. 74 // List of banned directories.
67 std::vector<std::string> banned_directories_; 75 std::vector<std::string> banned_directories_;
68 76
69 // List of types that we don't check. 77 // List of types that we don't check.
70 std::set<std::string> ignored_record_names_; 78 std::set<std::string> ignored_record_names_;
71 }; 79 };
72 80
73 #endif // TOOLS_CLANG_PLUGINS_CHROMECLASSTESTER_H_ 81 #endif // TOOLS_CLANG_PLUGINS_CHROMECLASSTESTER_H_
OLDNEW
« no previous file with comments | « no previous file | tools/clang/plugins/ChromeClassTester.cpp » ('j') | tools/clang/plugins/ChromeClassTester.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698