1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/webrtc/trunk/tools/clang/plugins/ChromeClassTester.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,84 @@ 1.4 +// Copyright (c) 2012 The Chromium Authors. All rights reserved. 1.5 +// Use of this source code is governed by a BSD-style license that can be 1.6 +// found in the LICENSE file. 1.7 + 1.8 +#ifndef TOOLS_CLANG_PLUGINS_CHROMECLASSTESTER_H_ 1.9 +#define TOOLS_CLANG_PLUGINS_CHROMECLASSTESTER_H_ 1.10 + 1.11 +#include <set> 1.12 +#include <vector> 1.13 + 1.14 +#include "clang/AST/ASTConsumer.h" 1.15 +#include "clang/AST/TypeLoc.h" 1.16 +#include "clang/Frontend/CompilerInstance.h" 1.17 + 1.18 +// A class on top of ASTConsumer that forwards classes defined in Chromium 1.19 +// headers to subclasses which implement CheckChromeClass(). 1.20 +class ChromeClassTester : public clang::ASTConsumer { 1.21 + public: 1.22 + explicit ChromeClassTester(clang::CompilerInstance& instance); 1.23 + virtual ~ChromeClassTester(); 1.24 + 1.25 + // clang::ASTConsumer: 1.26 + virtual void HandleTagDeclDefinition(clang::TagDecl* tag); 1.27 + virtual bool HandleTopLevelDecl(clang::DeclGroupRef group_ref); 1.28 + 1.29 + protected: 1.30 + clang::CompilerInstance& instance() { return instance_; } 1.31 + clang::DiagnosticsEngine& diagnostic() { return diagnostic_; } 1.32 + 1.33 + // Emits a simple warning; this shouldn't be used if you require printf-style 1.34 + // printing. 1.35 + void emitWarning(clang::SourceLocation loc, const char* error); 1.36 + 1.37 + // Utility method for subclasses to check if this class is in a banned 1.38 + // namespace. 1.39 + bool InBannedNamespace(const clang::Decl* record); 1.40 + 1.41 + // Utility method for subclasses to determine the namespace of the 1.42 + // specified record, if any. Unnamed namespaces will be identified as 1.43 + // "<anonymous namespace>". 1.44 + std::string GetNamespace(const clang::Decl* record); 1.45 + 1.46 + // Utility method for subclasses to check if this class is within an 1.47 + // implementation (.cc, .cpp, .mm) file. 1.48 + bool InImplementationFile(clang::SourceLocation location); 1.49 + 1.50 + private: 1.51 + void BuildBannedLists(); 1.52 + 1.53 + void CheckTag(clang::TagDecl*); 1.54 + 1.55 + // Filtered versions of tags that are only called with things defined in 1.56 + // chrome header files. 1.57 + virtual void CheckChromeClass(clang::SourceLocation record_location, 1.58 + clang::CXXRecordDecl* record) = 0; 1.59 + 1.60 + // Utility methods used for filtering out non-chrome classes (and ones we 1.61 + // deliberately ignore) in HandleTagDeclDefinition(). 1.62 + std::string GetNamespaceImpl(const clang::DeclContext* context, 1.63 + const std::string& candidate); 1.64 + bool InBannedDirectory(clang::SourceLocation loc); 1.65 + bool IsIgnoredType(const std::string& base_name); 1.66 + 1.67 + // Attempts to determine the filename for the given SourceLocation. 1.68 + // Returns false if the filename could not be determined. 1.69 + bool GetFilename(clang::SourceLocation loc, std::string* filename); 1.70 + 1.71 + clang::CompilerInstance& instance_; 1.72 + clang::DiagnosticsEngine& diagnostic_; 1.73 + 1.74 + // List of banned namespaces. 1.75 + std::vector<std::string> banned_namespaces_; 1.76 + 1.77 + // List of banned directories. 1.78 + std::vector<std::string> banned_directories_; 1.79 + 1.80 + // List of types that we don't check. 1.81 + std::set<std::string> ignored_record_names_; 1.82 + 1.83 + // List of decls to check once the current top-level decl is parsed. 1.84 + std::vector<clang::TagDecl*> pending_class_decls_; 1.85 +}; 1.86 + 1.87 +#endif // TOOLS_CLANG_PLUGINS_CHROMECLASSTESTER_H_