media/webrtc/trunk/tools/clang/plugins/ChromeClassTester.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
michael@0 2 // Use of this source code is governed by a BSD-style license that can be
michael@0 3 // found in the LICENSE file.
michael@0 4
michael@0 5 #ifndef TOOLS_CLANG_PLUGINS_CHROMECLASSTESTER_H_
michael@0 6 #define TOOLS_CLANG_PLUGINS_CHROMECLASSTESTER_H_
michael@0 7
michael@0 8 #include <set>
michael@0 9 #include <vector>
michael@0 10
michael@0 11 #include "clang/AST/ASTConsumer.h"
michael@0 12 #include "clang/AST/TypeLoc.h"
michael@0 13 #include "clang/Frontend/CompilerInstance.h"
michael@0 14
michael@0 15 // A class on top of ASTConsumer that forwards classes defined in Chromium
michael@0 16 // headers to subclasses which implement CheckChromeClass().
michael@0 17 class ChromeClassTester : public clang::ASTConsumer {
michael@0 18 public:
michael@0 19 explicit ChromeClassTester(clang::CompilerInstance& instance);
michael@0 20 virtual ~ChromeClassTester();
michael@0 21
michael@0 22 // clang::ASTConsumer:
michael@0 23 virtual void HandleTagDeclDefinition(clang::TagDecl* tag);
michael@0 24 virtual bool HandleTopLevelDecl(clang::DeclGroupRef group_ref);
michael@0 25
michael@0 26 protected:
michael@0 27 clang::CompilerInstance& instance() { return instance_; }
michael@0 28 clang::DiagnosticsEngine& diagnostic() { return diagnostic_; }
michael@0 29
michael@0 30 // Emits a simple warning; this shouldn't be used if you require printf-style
michael@0 31 // printing.
michael@0 32 void emitWarning(clang::SourceLocation loc, const char* error);
michael@0 33
michael@0 34 // Utility method for subclasses to check if this class is in a banned
michael@0 35 // namespace.
michael@0 36 bool InBannedNamespace(const clang::Decl* record);
michael@0 37
michael@0 38 // Utility method for subclasses to determine the namespace of the
michael@0 39 // specified record, if any. Unnamed namespaces will be identified as
michael@0 40 // "<anonymous namespace>".
michael@0 41 std::string GetNamespace(const clang::Decl* record);
michael@0 42
michael@0 43 // Utility method for subclasses to check if this class is within an
michael@0 44 // implementation (.cc, .cpp, .mm) file.
michael@0 45 bool InImplementationFile(clang::SourceLocation location);
michael@0 46
michael@0 47 private:
michael@0 48 void BuildBannedLists();
michael@0 49
michael@0 50 void CheckTag(clang::TagDecl*);
michael@0 51
michael@0 52 // Filtered versions of tags that are only called with things defined in
michael@0 53 // chrome header files.
michael@0 54 virtual void CheckChromeClass(clang::SourceLocation record_location,
michael@0 55 clang::CXXRecordDecl* record) = 0;
michael@0 56
michael@0 57 // Utility methods used for filtering out non-chrome classes (and ones we
michael@0 58 // deliberately ignore) in HandleTagDeclDefinition().
michael@0 59 std::string GetNamespaceImpl(const clang::DeclContext* context,
michael@0 60 const std::string& candidate);
michael@0 61 bool InBannedDirectory(clang::SourceLocation loc);
michael@0 62 bool IsIgnoredType(const std::string& base_name);
michael@0 63
michael@0 64 // Attempts to determine the filename for the given SourceLocation.
michael@0 65 // Returns false if the filename could not be determined.
michael@0 66 bool GetFilename(clang::SourceLocation loc, std::string* filename);
michael@0 67
michael@0 68 clang::CompilerInstance& instance_;
michael@0 69 clang::DiagnosticsEngine& diagnostic_;
michael@0 70
michael@0 71 // List of banned namespaces.
michael@0 72 std::vector<std::string> banned_namespaces_;
michael@0 73
michael@0 74 // List of banned directories.
michael@0 75 std::vector<std::string> banned_directories_;
michael@0 76
michael@0 77 // List of types that we don't check.
michael@0 78 std::set<std::string> ignored_record_names_;
michael@0 79
michael@0 80 // List of decls to check once the current top-level decl is parsed.
michael@0 81 std::vector<clang::TagDecl*> pending_class_decls_;
michael@0 82 };
michael@0 83
michael@0 84 #endif // TOOLS_CLANG_PLUGINS_CHROMECLASSTESTER_H_

mercurial