summaryrefslogtreecommitdiffstats
path: root/clang/examples/PrintFunctionNames/PrintFunctionNames.cpp
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-11-15 00:27:43 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-11-15 00:27:43 +0000
commit6499e9c625e12feb9d3813cee67810cc08fd2f2e (patch)
tree2a7fe4639a2a400e9a8821c85469d8eae78d1841 /clang/examples/PrintFunctionNames/PrintFunctionNames.cpp
parent9b30eb721f82e6afc02ba192f36ae17ad2a19dc4 (diff)
downloadbcm5719-llvm-6499e9c625e12feb9d3813cee67810cc08fd2f2e.tar.gz
bcm5719-llvm-6499e9c625e12feb9d3813cee67810cc08fd2f2e.zip
Add a trivial example plugin, which prints the names of the top-level decls.
- The build scriptage is about twice as long as the code, which is nice. :) llvm-svn: 88826
Diffstat (limited to 'clang/examples/PrintFunctionNames/PrintFunctionNames.cpp')
-rw-r--r--clang/examples/PrintFunctionNames/PrintFunctionNames.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/clang/examples/PrintFunctionNames/PrintFunctionNames.cpp b/clang/examples/PrintFunctionNames/PrintFunctionNames.cpp
new file mode 100644
index 00000000000..a103c63704a
--- /dev/null
+++ b/clang/examples/PrintFunctionNames/PrintFunctionNames.cpp
@@ -0,0 +1,44 @@
+//===- PrintFunctionNames.cpp ---------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// Example clang-cc plugin which simply prints the names of all the top-level
+// decls in the input file.
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/Frontend/FrontendPluginRegistry.h"
+#include "clang/AST/ASTConsumer.h"
+#include "clang/AST/AST.h"
+#include "llvm/Support/raw_ostream.h"
+using namespace clang;
+
+namespace {
+
+class PrintFunctionsConsumer : public ASTConsumer {
+public:
+ virtual void HandleTopLevelDecl(DeclGroupRef DG) {
+ for (DeclGroupRef::iterator i = DG.begin(), e = DG.end(); i != e; ++i) {
+ const Decl *D = *i;
+ if (const NamedDecl *ND = dyn_cast<NamedDecl>(D))
+ llvm::errs() << "top-level-decl: \"" << ND->getNameAsString() << "\"\n";
+ }
+ }
+};
+
+class PrintFunctionNamesAction : public ASTFrontendAction {
+protected:
+ ASTConsumer *CreateASTConsumer(CompilerInstance &CI, llvm::StringRef) {
+ return new PrintFunctionsConsumer();
+ }
+};
+
+}
+
+FrontendPluginRegistry::Add<PrintFunctionNamesAction>
+X("print-fns", "print function names");
OpenPOWER on IntegriCloud