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

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

Issue 1117163002: Clang style plugin: add warn-only option and use it on Windows (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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
11 #include "Options.h"
11 #include "clang/AST/ASTConsumer.h" 12 #include "clang/AST/ASTConsumer.h"
12 #include "clang/AST/TypeLoc.h" 13 #include "clang/AST/TypeLoc.h"
13 #include "clang/Frontend/CompilerInstance.h" 14 #include "clang/Frontend/CompilerInstance.h"
14 15
15 // A class on top of ASTConsumer that forwards classes defined in Chromium 16 // A class on top of ASTConsumer that forwards classes defined in Chromium
16 // headers to subclasses which implement CheckChromeClass(). 17 // headers to subclasses which implement CheckChromeClass().
17 class ChromeClassTester : public clang::ASTConsumer { 18 class ChromeClassTester : public clang::ASTConsumer {
18 public: 19 public:
19 explicit ChromeClassTester(clang::CompilerInstance& instance); 20 ChromeClassTester(clang::CompilerInstance& instance,
21 const chrome_checker::Options& options);
20 virtual ~ChromeClassTester(); 22 virtual ~ChromeClassTester();
21 23
22 // clang::ASTConsumer: 24 // clang::ASTConsumer:
23 virtual void HandleTagDeclDefinition(clang::TagDecl* tag); 25 virtual void HandleTagDeclDefinition(clang::TagDecl* tag);
24 virtual bool HandleTopLevelDecl(clang::DeclGroupRef group_ref); 26 virtual bool HandleTopLevelDecl(clang::DeclGroupRef group_ref);
25 27
26 void CheckTag(clang::TagDecl*); 28 void CheckTag(clang::TagDecl*);
27 29
30 clang::DiagnosticsEngine::Level getErrorLevel();
31
28 protected: 32 protected:
29 clang::CompilerInstance& instance() { return instance_; } 33 clang::CompilerInstance& instance() { return instance_; }
30 clang::DiagnosticsEngine& diagnostic() { return diagnostic_; } 34 clang::DiagnosticsEngine& diagnostic() { return diagnostic_; }
31 35
32 // Emits a simple warning; this shouldn't be used if you require printf-style 36 // Emits a simple warning; this shouldn't be used if you require printf-style
33 // printing. 37 // printing.
34 void emitWarning(clang::SourceLocation loc, const char* error); 38 void emitWarning(clang::SourceLocation loc, const char* error);
35 39
36 // Utility method for subclasses to check if this class is in a banned 40 // Utility method for subclasses to check if this class is in a banned
37 // namespace. 41 // namespace.
38 bool InBannedNamespace(const clang::Decl* record); 42 bool InBannedNamespace(const clang::Decl* record);
39 43
40 // Utility method for subclasses to check if the source location is in a 44 // Utility method for subclasses to check if the source location is in a
41 // directory the plugin should ignore. 45 // directory the plugin should ignore.
42 bool InBannedDirectory(clang::SourceLocation loc); 46 bool InBannedDirectory(clang::SourceLocation loc);
43 47
44 // Utility method for subclasses to determine the namespace of the 48 // Utility method for subclasses to determine the namespace of the
45 // specified record, if any. Unnamed namespaces will be identified as 49 // specified record, if any. Unnamed namespaces will be identified as
46 // "<anonymous namespace>". 50 // "<anonymous namespace>".
47 std::string GetNamespace(const clang::Decl* record); 51 std::string GetNamespace(const clang::Decl* record);
48 52
49 // Utility method for subclasses to check if this class is within an 53 // Utility method for subclasses to check if this class is within an
50 // implementation (.cc, .cpp, .mm) file. 54 // implementation (.cc, .cpp, .mm) file.
51 bool InImplementationFile(clang::SourceLocation location); 55 bool InImplementationFile(clang::SourceLocation location);
52 56
57 // Options.
58 const chrome_checker::Options options_;
59
53 private: 60 private:
54 void BuildBannedLists(); 61 void BuildBannedLists();
55 62
56 // Filtered versions of tags that are only called with things defined in 63 // Filtered versions of tags that are only called with things defined in
57 // chrome header files. 64 // chrome header files.
58 virtual void CheckChromeClass(clang::SourceLocation record_location, 65 virtual void CheckChromeClass(clang::SourceLocation record_location,
59 clang::CXXRecordDecl* record) = 0; 66 clang::CXXRecordDecl* record) = 0;
60 67
61 // Filtered versions of enum type that are only called with things defined 68 // Filtered versions of enum type that are only called with things defined
62 // in chrome header files. 69 // in chrome header files.
(...skipping 21 matching lines...) Expand all
84 std::vector<std::string> banned_directories_; 91 std::vector<std::string> banned_directories_;
85 92
86 // List of types that we don't check. 93 // List of types that we don't check.
87 std::set<std::string> ignored_record_names_; 94 std::set<std::string> ignored_record_names_;
88 95
89 // List of decls to check once the current top-level decl is parsed. 96 // List of decls to check once the current top-level decl is parsed.
90 std::vector<clang::TagDecl*> pending_class_decls_; 97 std::vector<clang::TagDecl*> pending_class_decls_;
91 }; 98 };
92 99
93 #endif // TOOLS_CLANG_PLUGINS_CHROMECLASSTESTER_H_ 100 #endif // TOOLS_CLANG_PLUGINS_CHROMECLASSTESTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698