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

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

Issue 2780113002: Refactor banned directory checking so Blink can opt into certain checks. (Closed)
Patch Set: better enum names Created 3 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
« no previous file with comments | « no previous file | tools/clang/plugins/ChromeClassTester.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 #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 <set> 8 #include <set>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 14 matching lines...) Expand all
25 void CheckTag(clang::TagDecl*); 25 void CheckTag(clang::TagDecl*);
26 26
27 clang::DiagnosticsEngine::Level getErrorLevel(); 27 clang::DiagnosticsEngine::Level getErrorLevel();
28 28
29 protected: 29 protected:
30 clang::CompilerInstance& instance() { return instance_; } 30 clang::CompilerInstance& instance() { return instance_; }
31 clang::DiagnosticsEngine& diagnostic() { return diagnostic_; } 31 clang::DiagnosticsEngine& diagnostic() { return diagnostic_; }
32 32
33 // Emits a simple warning; this shouldn't be used if you require printf-style 33 // Emits a simple warning; this shouldn't be used if you require printf-style
34 // printing. 34 // printing.
35 // TODO(dcheng): This will be removed. Do not add new usage.
35 void emitWarning(clang::SourceLocation loc, const char* error); 36 void emitWarning(clang::SourceLocation loc, const char* error);
36 37
37 // Utility method for subclasses to check if this class is in a banned 38 // Utility method for subclasses to check if this class is in a banned
38 // namespace. 39 // namespace.
39 bool InBannedNamespace(const clang::Decl* record); 40 bool InBannedNamespace(const clang::Decl* record);
40 41
41 // Utility method for subclasses to check if the source location is in a 42 // Utility method for subclasses to check how a certain SourceLocation should
42 // directory the plugin should ignore. 43 // be handled. The main criteria for classification is the SourceLocation's
43 bool InBannedDirectory(clang::SourceLocation loc); 44 // path (e.g. whether it's in //third_party).
45 enum class LocationType {
46 // Enforce all default checks.
47 kChrome,
48 // Enforces a subset of checks for Blink code. This is hopefully a
49 // transitional stage, as more plugin checks are gradually enabled in Blink.
50 kBlink,
51 // Skip all checks. Typically, this is third-party or generated code where
52 // it doesn't make sense to enforce Chrome's custom diagnostics.
53 kThirdParty,
54 };
55 LocationType ClassifyLocation(clang::SourceLocation loc);
44 56
45 // Utility method for subclasses to determine the namespace of the 57 // Utility method for subclasses to determine the namespace of the
46 // specified record, if any. Unnamed namespaces will be identified as 58 // specified record, if any. Unnamed namespaces will be identified as
47 // "<anonymous namespace>". 59 // "<anonymous namespace>".
48 std::string GetNamespace(const clang::Decl* record); 60 std::string GetNamespace(const clang::Decl* record);
49 61
50 // Utility method to check whether the given record has any of the ignored 62 // Utility method to check whether the given record has any of the ignored
51 // base classes. 63 // base classes.
52 bool HasIgnoredBases(const clang::CXXRecordDecl* record); 64 bool HasIgnoredBases(const clang::CXXRecordDecl* record);
53 65
54 // Utility method for subclasses to check if this class is within an 66 // Utility method for subclasses to check if this class is within an
55 // implementation (.cc, .cpp, .mm) file. 67 // implementation (.cc, .cpp, .mm) file.
56 bool InImplementationFile(clang::SourceLocation location); 68 bool InImplementationFile(clang::SourceLocation location);
57 69
58 // Options. 70 // Options.
59 const chrome_checker::Options options_; 71 const chrome_checker::Options options_;
60 72
61 private: 73 private:
62 void BuildBannedLists(); 74 void BuildBannedLists();
63 75
64 // Filtered versions of tags that are only called with things defined in 76 // Filtered versions of tags that are only called with things defined in
65 // chrome header files. 77 // chrome header files.
66 virtual void CheckChromeClass(clang::SourceLocation record_location, 78 virtual void CheckChromeClass(LocationType location_type,
79 clang::SourceLocation record_location,
67 clang::CXXRecordDecl* record) = 0; 80 clang::CXXRecordDecl* record) = 0;
68 81
69 // Filtered versions of enum type that are only called with things defined 82 // Filtered versions of enum type that are only called with things defined
70 // in chrome header files. 83 // in chrome header files.
71 virtual void CheckChromeEnum(clang::SourceLocation enum_location, 84 virtual void CheckChromeEnum(LocationType location_type,
72 clang::EnumDecl* enum_decl) { 85 clang::SourceLocation enum_location,
73 } 86 clang::EnumDecl* enum_decl) = 0;
74 87
75 // Utility methods used for filtering out non-chrome classes (and ones we 88 // Utility methods used for filtering out non-chrome classes (and ones we
76 // deliberately ignore) in HandleTagDeclDefinition(). 89 // deliberately ignore) in HandleTagDeclDefinition().
77 std::string GetNamespaceImpl(const clang::DeclContext* context, 90 std::string GetNamespaceImpl(const clang::DeclContext* context,
78 const std::string& candidate); 91 const std::string& candidate);
79 bool IsIgnoredType(const std::string& base_name); 92 bool IsIgnoredType(const std::string& base_name);
80 93
81 // Attempts to determine the filename for the given SourceLocation. 94 // Attempts to determine the filename for the given SourceLocation.
82 // Returns false if the filename could not be determined. 95 // Returns false if the filename could not be determined.
83 bool GetFilename(clang::SourceLocation loc, std::string* filename); 96 bool GetFilename(clang::SourceLocation loc, std::string* filename);
84 97
85 clang::CompilerInstance& instance_; 98 clang::CompilerInstance& instance_;
86 clang::DiagnosticsEngine& diagnostic_; 99 clang::DiagnosticsEngine& diagnostic_;
87 100
88 // List of banned namespaces. 101 // List of banned namespaces.
89 std::set<std::string> banned_namespaces_; 102 std::set<std::string> banned_namespaces_;
90 103
91 // List of directories allowed even though their parent directories are in 104 // List of Blink directories.
92 // |banned_directories_|, below. 105 std::set<std::string> blink_directories_;
93 std::set<std::string> allowed_directories_;
94 106
95 // List of banned directories. 107 // List of banned directories.
96 std::set<std::string> banned_directories_; 108 std::set<std::string> banned_directories_;
97 109
98 // List of types that we don't check. 110 // List of types that we don't check.
99 std::set<std::string> ignored_record_names_; 111 std::set<std::string> ignored_record_names_;
100 112
101 // List of base classes that we skip when checking complex class ctors/dtors. 113 // List of base classes that we skip when checking complex class ctors/dtors.
102 std::set<std::string> ignored_base_classes_; 114 std::set<std::string> ignored_base_classes_;
103 }; 115 };
104 116
105 #endif // TOOLS_CLANG_PLUGINS_CHROMECLASSTESTER_H_ 117 #endif // TOOLS_CLANG_PLUGINS_CHROMECLASSTESTER_H_
OLDNEW
« no previous file with comments | « no previous file | tools/clang/plugins/ChromeClassTester.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698