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

Unified Diff: tools/clang/plugins/ChromeClassTester.h

Issue 6368055: Commit my clang plugin and fix up documentation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add makefile for thakis Created 9 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: tools/clang/plugins/ChromeClassTester.h
diff --git a/tools/clang/plugins/ChromeClassTester.h b/tools/clang/plugins/ChromeClassTester.h
new file mode 100644
index 0000000000000000000000000000000000000000..b9985d710d5d73953ba5603ca2b31a8126a714cb
--- /dev/null
+++ b/tools/clang/plugins/ChromeClassTester.h
@@ -0,0 +1,63 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef TOOLS_CLANG_PLUGINS_CHROMECLASSTESTER_H_
+#define TOOLS_CLANG_PLUGINS_CHROMECLASSTESTER_H_
+
+#include "clang/AST/ASTConsumer.h"
+#include "clang/AST/AST.h"
+#include "clang/AST/TypeLoc.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Frontend/CompilerInstance.h"
+
+#include <vector>
+
+// A class on top of ASTConsumer that forwards classes defined in Chromium
+// headers to subclasses which implement CheckChromeClass().
+class ChromeClassTester : public clang::ASTConsumer {
+ public:
+ explicit ChromeClassTester(clang::CompilerInstance& instance);
+ virtual ~ChromeClassTester();
+
+ // ASTConsumer:
+ virtual void HandleTagDeclDefinition(clang::TagDecl* tag);
+
+ protected:
+ clang::CompilerInstance& instance() { return instance_; }
+ clang::Diagnostic& diagnostic() { return diagnostic_; }
+
+ // Emits a simple warning; this shouldn't be used if you require printf-style
+ // printing.
+ void emitWarning(clang::SourceLocation loc, const char* error);
+
+ private:
+ // Template method which is called with only classes that are defined in
+ // chrome header files.
+ virtual void CheckChromeClass(const clang::SourceLocation& record_location,
+ clang::CXXRecordDecl* record) = 0;
+
+ // Utility methods used for filtering out non-chrome classes (and ones we
+ // delibrately ignore) in HandleTagDeclDefinition().
+ bool IsTestCode(clang::Decl* record);
+ bool InBannedNamespace(clang::Decl* record);
+ std::string GetNamespace(clang::Decl* record);
+ std::string GetNamespaceImpl(const clang::DeclContext* context,
+ std::string candidate);
+ bool InBannedDirectory(const clang::SourceLocation& loc);
+ bool IsIgnoredType(clang::RecordDecl* record);
+
+ clang::CompilerInstance& instance_;
+ clang::Diagnostic& diagnostic_;
+
+ // List of banned namespaces.
+ std::vector<std::string> banned_namespaces_;
+
+ // List of banned directories.
+ std::vector<std::string> banned_directories_;
+
+ // List of types that we don't check.
+ std::vector<std::string> ignored_record_names_;
+};
+
+#endif // TOOLS_CLANG_PLUGINS_CHROMECLASSTESTER_H_

Powered by Google App Engine
This is Rietveld 408576698