summaryrefslogtreecommitdiffstats
path: root/clang/examples/AnnotateFunctions/AnnotateFunctions.cpp
diff options
context:
space:
mode:
authorJohn Brawn <john.brawn@arm.com>2016-03-15 12:51:40 +0000
committerJohn Brawn <john.brawn@arm.com>2016-03-15 12:51:40 +0000
commit6c78974b298d619ec11e243fb6fdea0b16f87a66 (patch)
treea3821d2f102bdc6db560013edefad6cd3f4e983c /clang/examples/AnnotateFunctions/AnnotateFunctions.cpp
parent27fc7a7b47bc9656b5af858432518e81b9d36482 (diff)
downloadbcm5719-llvm-6c78974b298d619ec11e243fb6fdea0b16f87a66.tar.gz
bcm5719-llvm-6c78974b298d619ec11e243fb6fdea0b16f87a66.zip
Make it possible for AST plugins to enable themselves by default
Currently when an AST plugin is loaded it must then be enabled by passing -plugin pluginname or -add-plugin pluginname to the -cc1 command line. This patch adds a method to PluginASTAction which allows it to declare that the action happens before, instead of, or after the main AST action, plus the relevant changes to make the plugin action happen at that time automatically. Differential Revision: http://reviews.llvm.org/D17959 llvm-svn: 263546
Diffstat (limited to 'clang/examples/AnnotateFunctions/AnnotateFunctions.cpp')
-rw-r--r--clang/examples/AnnotateFunctions/AnnotateFunctions.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/clang/examples/AnnotateFunctions/AnnotateFunctions.cpp b/clang/examples/AnnotateFunctions/AnnotateFunctions.cpp
new file mode 100644
index 00000000000..f2e7322183a
--- /dev/null
+++ b/clang/examples/AnnotateFunctions/AnnotateFunctions.cpp
@@ -0,0 +1,52 @@
+//===- AnnotateFunctions.cpp ----------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// Example clang plugin which adds an annotation to every function.
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/Frontend/FrontendPluginRegistry.h"
+#include "clang/AST/AST.h"
+#include "clang/AST/ASTConsumer.h"
+using namespace clang;
+
+namespace {
+
+class AnnotateFunctionsConsumer : public ASTConsumer {
+public:
+ bool HandleTopLevelDecl(DeclGroupRef DG) override {
+ for (auto D : DG)
+ if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
+ FD->addAttr(AnnotateAttr::CreateImplicit(FD->getASTContext(),
+ "example_annotation"));
+ return true;
+ }
+};
+
+class AnnotateFunctionsAction : public PluginASTAction {
+public:
+ std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
+ llvm::StringRef) override {
+ return llvm::make_unique<AnnotateFunctionsConsumer>();
+ }
+
+ bool ParseArgs(const CompilerInstance &CI,
+ const std::vector<std::string> &args) override {
+ return true;
+ }
+
+ PluginASTAction::ActionType getActionType() override {
+ return AddBeforeMainAction;
+ }
+};
+
+}
+
+static FrontendPluginRegistry::Add<AnnotateFunctionsAction>
+X("annotate-fns", "annotate functions");
OpenPOWER on IntegriCloud