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

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

Issue 1385193002: Bisect clang Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: 246985 Created 5 years, 2 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 | « tools/clang/plugins/CMakeLists.txt ('k') | 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef TOOLS_CLANG_PLUGINS_CHROMECLASSTESTER_H_
6 #define TOOLS_CLANG_PLUGINS_CHROMECLASSTESTER_H_
7
8 #include <set>
9 #include <vector>
10
11 #include "Options.h"
12 #include "clang/AST/ASTConsumer.h"
13 #include "clang/AST/TypeLoc.h"
14 #include "clang/Frontend/CompilerInstance.h"
15
16 // A class on top of ASTConsumer that forwards classes defined in Chromium
17 // headers to subclasses which implement CheckChromeClass().
18 class ChromeClassTester : public clang::ASTConsumer {
19 public:
20 ChromeClassTester(clang::CompilerInstance& instance,
21 const chrome_checker::Options& options);
22 virtual ~ChromeClassTester();
23
24 // clang::ASTConsumer:
25 virtual void HandleTagDeclDefinition(clang::TagDecl* tag);
26 virtual bool HandleTopLevelDecl(clang::DeclGroupRef group_ref);
27
28 void CheckTag(clang::TagDecl*);
29
30 clang::DiagnosticsEngine::Level getErrorLevel();
31
32 protected:
33 clang::CompilerInstance& instance() { return instance_; }
34 clang::DiagnosticsEngine& diagnostic() { return diagnostic_; }
35
36 // Emits a simple warning; this shouldn't be used if you require printf-style
37 // printing.
38 void emitWarning(clang::SourceLocation loc, const char* error);
39
40 // Utility method for subclasses to check if this class is in a banned
41 // namespace.
42 bool InBannedNamespace(const clang::Decl* record);
43
44 // Utility method for subclasses to check if the source location is in a
45 // directory the plugin should ignore.
46 bool InBannedDirectory(clang::SourceLocation loc);
47
48 // Utility method for subclasses to determine the namespace of the
49 // specified record, if any. Unnamed namespaces will be identified as
50 // "<anonymous namespace>".
51 std::string GetNamespace(const clang::Decl* record);
52
53 // Utility method for subclasses to check if this class is within an
54 // implementation (.cc, .cpp, .mm) file.
55 bool InImplementationFile(clang::SourceLocation location);
56
57 // Options.
58 const chrome_checker::Options options_;
59
60 private:
61 void BuildBannedLists();
62
63 // Filtered versions of tags that are only called with things defined in
64 // chrome header files.
65 virtual void CheckChromeClass(clang::SourceLocation record_location,
66 clang::CXXRecordDecl* record) = 0;
67
68 // Filtered versions of enum type that are only called with things defined
69 // in chrome header files.
70 virtual void CheckChromeEnum(clang::SourceLocation enum_location,
71 clang::EnumDecl* enum_decl) {
72 }
73
74 // Utility methods used for filtering out non-chrome classes (and ones we
75 // deliberately ignore) in HandleTagDeclDefinition().
76 std::string GetNamespaceImpl(const clang::DeclContext* context,
77 const std::string& candidate);
78 bool IsIgnoredType(const std::string& base_name);
79
80 // Attempts to determine the filename for the given SourceLocation.
81 // Returns false if the filename could not be determined.
82 bool GetFilename(clang::SourceLocation loc, std::string* filename);
83
84 clang::CompilerInstance& instance_;
85 clang::DiagnosticsEngine& diagnostic_;
86
87 // List of banned namespaces.
88 std::vector<std::string> banned_namespaces_;
89
90 // List of banned directories.
91 std::vector<std::string> banned_directories_;
92
93 // List of types that we don't check.
94 std::set<std::string> ignored_record_names_;
95
96 // List of decls to check once the current top-level decl is parsed.
97 std::vector<clang::TagDecl*> pending_class_decls_;
98 };
99
100 #endif // TOOLS_CLANG_PLUGINS_CHROMECLASSTESTER_H_
OLDNEW
« no previous file with comments | « tools/clang/plugins/CMakeLists.txt ('k') | tools/clang/plugins/ChromeClassTester.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698