OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 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 "clang/AST/ASTConsumer.h" |
| 9 #include "clang/AST/AST.h" |
| 10 #include "clang/AST/TypeLoc.h" |
| 11 #include "clang/Basic/SourceManager.h" |
| 12 #include "clang/Frontend/CompilerInstance.h" |
| 13 |
| 14 #include <vector> |
| 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 explicit ChromeClassTester(clang::CompilerInstance& instance); |
| 21 virtual ~ChromeClassTester(); |
| 22 |
| 23 // ASTConsumer: |
| 24 virtual void HandleTagDeclDefinition(clang::TagDecl* tag); |
| 25 |
| 26 protected: |
| 27 clang::CompilerInstance& instance() { return instance_; } |
| 28 clang::Diagnostic& diagnostic() { return diagnostic_; } |
| 29 |
| 30 // Emits a simple warning; this shouldn't be used if you require printf-style |
| 31 // printing. |
| 32 void emitWarning(clang::SourceLocation loc, const char* error); |
| 33 |
| 34 private: |
| 35 // Template method which is called with only classes that are defined in |
| 36 // chrome header files. |
| 37 virtual void CheckChromeClass(const clang::SourceLocation& record_location, |
| 38 clang::CXXRecordDecl* record) = 0; |
| 39 |
| 40 // Utility methods used for filtering out non-chrome classes (and ones we |
| 41 // delibrately ignore) in HandleTagDeclDefinition(). |
| 42 bool IsTestCode(clang::Decl* record); |
| 43 bool InBannedNamespace(clang::Decl* record); |
| 44 std::string GetNamespace(clang::Decl* record); |
| 45 std::string GetNamespaceImpl(const clang::DeclContext* context, |
| 46 std::string candidate); |
| 47 bool InBannedDirectory(const clang::SourceLocation& loc); |
| 48 bool IsIgnoredType(clang::RecordDecl* record); |
| 49 |
| 50 clang::CompilerInstance& instance_; |
| 51 clang::Diagnostic& diagnostic_; |
| 52 |
| 53 // List of banned namespaces. |
| 54 std::vector<std::string> banned_namespaces_; |
| 55 |
| 56 // List of banned directories. |
| 57 std::vector<std::string> banned_directories_; |
| 58 |
| 59 // List of types that we don't check. |
| 60 std::vector<std::string> ignored_record_names_; |
| 61 }; |
| 62 |
| 63 #endif // TOOLS_CLANG_PLUGINS_CHROMECLASSTESTER_H_ |
OLD | NEW |