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.

     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  protected:
    27   clang::CompilerInstance& instance() { return instance_; }
    28   clang::DiagnosticsEngine& diagnostic() { return diagnostic_; }
    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);
    34   // Utility method for subclasses to check if this class is in a banned
    35   // namespace.
    36   bool InBannedNamespace(const clang::Decl* record);
    38   // Utility method for subclasses to determine the namespace of the
    39   // specified record, if any. Unnamed namespaces will be identified as
    40   // "<anonymous namespace>".
    41   std::string GetNamespace(const clang::Decl* record);
    43   // Utility method for subclasses to check if this class is within an
    44   // implementation (.cc, .cpp, .mm) file.
    45   bool InImplementationFile(clang::SourceLocation location);
    47  private:
    48   void BuildBannedLists();
    50   void CheckTag(clang::TagDecl*);
    52   // Filtered versions of tags that are only called with things defined in
    53   // chrome header files.
    54   virtual void CheckChromeClass(clang::SourceLocation record_location,
    55                                 clang::CXXRecordDecl* record) = 0;
    57   // Utility methods used for filtering out non-chrome classes (and ones we
    58   // deliberately ignore) in HandleTagDeclDefinition().
    59   std::string GetNamespaceImpl(const clang::DeclContext* context,
    60                                const std::string& candidate);
    61   bool InBannedDirectory(clang::SourceLocation loc);
    62   bool IsIgnoredType(const std::string& base_name);
    64   // Attempts to determine the filename for the given SourceLocation.
    65   // Returns false if the filename could not be determined.
    66   bool GetFilename(clang::SourceLocation loc, std::string* filename);
    68   clang::CompilerInstance& instance_;
    69   clang::DiagnosticsEngine& diagnostic_;
    71   // List of banned namespaces.
    72   std::vector<std::string> banned_namespaces_;
    74   // List of banned directories.
    75   std::vector<std::string> banned_directories_;
    77   // List of types that we don't check.
    78   std::set<std::string> ignored_record_names_;
    80   // List of decls to check once the current top-level decl is parsed.
    81   std::vector<clang::TagDecl*> pending_class_decls_;
    82 };
    84 #endif  // TOOLS_CLANG_PLUGINS_CHROMECLASSTESTER_H_

mercurial