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

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: 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
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 kNotIgnored,
47 kBlink,
48 kIgnored,
Nico 2017/04/06 19:03:13 kNotIgnored, kIgnored, kBlink sounds a bit like TR
dcheng 2017/04/11 08:38:40 Done.
49 };
50 LocationType ClassifyLocation(clang::SourceLocation loc);
44 51
45 // Utility method for subclasses to determine the namespace of the 52 // Utility method for subclasses to determine the namespace of the
46 // specified record, if any. Unnamed namespaces will be identified as 53 // specified record, if any. Unnamed namespaces will be identified as
47 // "<anonymous namespace>". 54 // "<anonymous namespace>".
48 std::string GetNamespace(const clang::Decl* record); 55 std::string GetNamespace(const clang::Decl* record);
49 56
50 // Utility method to check whether the given record has any of the ignored 57 // Utility method to check whether the given record has any of the ignored
51 // base classes. 58 // base classes.
52 bool HasIgnoredBases(const clang::CXXRecordDecl* record); 59 bool HasIgnoredBases(const clang::CXXRecordDecl* record);
53 60
54 // Utility method for subclasses to check if this class is within an 61 // Utility method for subclasses to check if this class is within an
55 // implementation (.cc, .cpp, .mm) file. 62 // implementation (.cc, .cpp, .mm) file.
56 bool InImplementationFile(clang::SourceLocation location); 63 bool InImplementationFile(clang::SourceLocation location);
57 64
58 // Options. 65 // Options.
59 const chrome_checker::Options options_; 66 const chrome_checker::Options options_;
60 67
61 private: 68 private:
62 void BuildBannedLists(); 69 void BuildBannedLists();
63 70
64 // Filtered versions of tags that are only called with things defined in 71 // Filtered versions of tags that are only called with things defined in
65 // chrome header files. 72 // chrome header files.
66 virtual void CheckChromeClass(clang::SourceLocation record_location, 73 virtual void CheckChromeClass(LocationType location_type,
74 clang::SourceLocation record_location,
67 clang::CXXRecordDecl* record) = 0; 75 clang::CXXRecordDecl* record) = 0;
68 76
69 // Filtered versions of enum type that are only called with things defined 77 // Filtered versions of enum type that are only called with things defined
70 // in chrome header files. 78 // in chrome header files.
71 virtual void CheckChromeEnum(clang::SourceLocation enum_location, 79 virtual void CheckChromeEnum(LocationType location_type,
72 clang::EnumDecl* enum_decl) { 80 clang::SourceLocation enum_location,
73 } 81 clang::EnumDecl* enum_decl) = 0;
74 82
75 // Utility methods used for filtering out non-chrome classes (and ones we 83 // Utility methods used for filtering out non-chrome classes (and ones we
76 // deliberately ignore) in HandleTagDeclDefinition(). 84 // deliberately ignore) in HandleTagDeclDefinition().
77 std::string GetNamespaceImpl(const clang::DeclContext* context, 85 std::string GetNamespaceImpl(const clang::DeclContext* context,
78 const std::string& candidate); 86 const std::string& candidate);
79 bool IsIgnoredType(const std::string& base_name); 87 bool IsIgnoredType(const std::string& base_name);
80 88
81 // Attempts to determine the filename for the given SourceLocation. 89 // Attempts to determine the filename for the given SourceLocation.
82 // Returns false if the filename could not be determined. 90 // Returns false if the filename could not be determined.
83 bool GetFilename(clang::SourceLocation loc, std::string* filename); 91 bool GetFilename(clang::SourceLocation loc, std::string* filename);
84 92
85 clang::CompilerInstance& instance_; 93 clang::CompilerInstance& instance_;
86 clang::DiagnosticsEngine& diagnostic_; 94 clang::DiagnosticsEngine& diagnostic_;
87 95
88 // List of banned namespaces. 96 // List of banned namespaces.
89 std::set<std::string> banned_namespaces_; 97 std::set<std::string> banned_namespaces_;
90 98
91 // List of directories allowed even though their parent directories are in 99 // List of Blink directories.
92 // |banned_directories_|, below. 100 std::set<std::string> blink_directories_;
93 std::set<std::string> allowed_directories_;
94 101
95 // List of banned directories. 102 // List of banned directories.
96 std::set<std::string> banned_directories_; 103 std::set<std::string> banned_directories_;
97 104
98 // List of types that we don't check. 105 // List of types that we don't check.
99 std::set<std::string> ignored_record_names_; 106 std::set<std::string> ignored_record_names_;
100 107
101 // List of base classes that we skip when checking complex class ctors/dtors. 108 // List of base classes that we skip when checking complex class ctors/dtors.
102 std::set<std::string> ignored_base_classes_; 109 std::set<std::string> ignored_base_classes_;
103 }; 110 };
104 111
105 #endif // TOOLS_CLANG_PLUGINS_CHROMECLASSTESTER_H_ 112 #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