blob: a103c63704af7df247838e7ec9bd3902e7f5f448 [file] [log] [blame]
Daniel Dunbar9a693872009-11-15 00:27:43 +00001//===- PrintFunctionNames.cpp ---------------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// Example clang-cc plugin which simply prints the names of all the top-level
11// decls in the input file.
12//
13//===----------------------------------------------------------------------===//
14
15#include "clang/Frontend/FrontendPluginRegistry.h"
16#include "clang/AST/ASTConsumer.h"
17#include "clang/AST/AST.h"
18#include "llvm/Support/raw_ostream.h"
19using namespace clang;
20
21namespace {
22
23class PrintFunctionsConsumer : public ASTConsumer {
24public:
25 virtual void HandleTopLevelDecl(DeclGroupRef DG) {
26 for (DeclGroupRef::iterator i = DG.begin(), e = DG.end(); i != e; ++i) {
27 const Decl *D = *i;
28 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D))
29 llvm::errs() << "top-level-decl: \"" << ND->getNameAsString() << "\"\n";
30 }
31 }
32};
33
34class PrintFunctionNamesAction : public ASTFrontendAction {
35protected:
36 ASTConsumer *CreateASTConsumer(CompilerInstance &CI, llvm::StringRef) {
37 return new PrintFunctionsConsumer();
38 }
39};
40
41}
42
43FrontendPluginRegistry::Add<PrintFunctionNamesAction>
44X("print-fns", "print function names");