Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / tools / clang / plugins / ChromeClassTester.h
blobed65050d499d76424af42a19877829e5598f2cd9
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.
5 #ifndef TOOLS_CLANG_PLUGINS_CHROMECLASSTESTER_H_
6 #define TOOLS_CLANG_PLUGINS_CHROMECLASSTESTER_H_
8 #include <set>
9 #include <vector>
11 #include "clang/AST/ASTConsumer.h"
12 #include "clang/AST/TypeLoc.h"
13 #include "clang/Frontend/CompilerInstance.h"
15 // A class on top of ASTConsumer that forwards classes defined in Chromium
16 // headers to subclasses which implement CheckChromeClass().
17 class ChromeClassTester : public clang::ASTConsumer {
18 public:
19 explicit ChromeClassTester(clang::CompilerInstance& instance);
20 virtual ~ChromeClassTester();
22 // clang::ASTConsumer:
23 virtual void HandleTagDeclDefinition(clang::TagDecl* tag);
24 virtual bool HandleTopLevelDecl(clang::DeclGroupRef group_ref);
26 void CheckTag(clang::TagDecl*);
28 protected:
29 clang::CompilerInstance& instance() { return instance_; }
30 clang::DiagnosticsEngine& diagnostic() { return diagnostic_; }
32 // Emits a simple warning; this shouldn't be used if you require printf-style
33 // printing.
34 void emitWarning(clang::SourceLocation loc, const char* error);
36 // Utility method for subclasses to check if this class is in a banned
37 // namespace.
38 bool InBannedNamespace(const clang::Decl* record);
40 // Utility method for subclasses to check if the source location is in a
41 // directory the plugin should ignore.
42 bool InBannedDirectory(clang::SourceLocation loc);
44 // Utility method for subclasses to determine the namespace of the
45 // specified record, if any. Unnamed namespaces will be identified as
46 // "<anonymous namespace>".
47 std::string GetNamespace(const clang::Decl* record);
49 // Utility method for subclasses to check if this class is within an
50 // implementation (.cc, .cpp, .mm) file.
51 bool InImplementationFile(clang::SourceLocation location);
53 private:
54 void BuildBannedLists();
56 // Filtered versions of tags that are only called with things defined in
57 // chrome header files.
58 virtual void CheckChromeClass(clang::SourceLocation record_location,
59 clang::CXXRecordDecl* record) = 0;
61 // Filtered versions of enum type that are only called with things defined
62 // in chrome header files.
63 virtual void CheckChromeEnum(clang::SourceLocation enum_location,
64 clang::EnumDecl* enum_decl) {
67 // Utility methods used for filtering out non-chrome classes (and ones we
68 // deliberately ignore) in HandleTagDeclDefinition().
69 std::string GetNamespaceImpl(const clang::DeclContext* context,
70 const std::string& candidate);
71 bool IsIgnoredType(const std::string& base_name);
73 // Attempts to determine the filename for the given SourceLocation.
74 // Returns false if the filename could not be determined.
75 bool GetFilename(clang::SourceLocation loc, std::string* filename);
77 clang::CompilerInstance& instance_;
78 clang::DiagnosticsEngine& diagnostic_;
80 // List of banned namespaces.
81 std::vector<std::string> banned_namespaces_;
83 // List of banned directories.
84 std::vector<std::string> banned_directories_;
86 // List of types that we don't check.
87 std::set<std::string> ignored_record_names_;
89 // List of decls to check once the current top-level decl is parsed.
90 std::vector<clang::TagDecl*> pending_class_decls_;
93 #endif // TOOLS_CLANG_PLUGINS_CHROMECLASSTESTER_H_