From 36c49e3f258dced101949edabd72e9bc3f1dedc4 Mon Sep 17 00:00:00 2001 From: dim Date: Fri, 17 Sep 2010 15:54:40 +0000 Subject: Vendor import of clang r114020 (from the release_28 branch): http://llvm.org/svn/llvm-project/cfe/branches/release_28@114020 Approved by: rpaulo (mentor) --- examples/PrintFunctionNames/PrintFunctionNames.cpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'examples/PrintFunctionNames/PrintFunctionNames.cpp') diff --git a/examples/PrintFunctionNames/PrintFunctionNames.cpp b/examples/PrintFunctionNames/PrintFunctionNames.cpp index 397cf84..cc138f5 100644 --- a/examples/PrintFunctionNames/PrintFunctionNames.cpp +++ b/examples/PrintFunctionNames/PrintFunctionNames.cpp @@ -15,6 +15,7 @@ #include "clang/Frontend/FrontendPluginRegistry.h" #include "clang/AST/ASTConsumer.h" #include "clang/AST/AST.h" +#include "clang/Frontend/CompilerInstance.h" #include "llvm/Support/raw_ostream.h" using namespace clang; @@ -29,7 +30,7 @@ public: llvm::errs() << "top-level-decl: \"" << ND->getNameAsString() << "\"\n"; } } -}; +}; class PrintFunctionNamesAction : public PluginASTAction { protected: @@ -37,15 +38,26 @@ protected: return new PrintFunctionsConsumer(); } - bool ParseArgs(const std::vector& args) { - for (unsigned i=0; i& args) { + for (unsigned i = 0, e = args.size(); i != e; ++i) { llvm::errs() << "PrintFunctionNames arg = " << args[i] << "\n"; + + // Example error handling. + if (args[i] == "-an-error") { + Diagnostic &D = CI.getDiagnostics(); + unsigned DiagID = D.getCustomDiagID( + Diagnostic::Error, "invalid argument '" + args[i] + "'"); + D.Report(DiagID); + return false; + } + } if (args.size() && args[0] == "help") PrintHelp(llvm::errs()); return true; } - void PrintHelp(llvm::raw_ostream& ros) { + void PrintHelp(llvm::raw_ostream& ros) { ros << "Help for PrintFunctionNames plugin goes here\n"; } @@ -53,5 +65,5 @@ protected: } -FrontendPluginRegistry::Add +static FrontendPluginRegistry::Add X("print-fns", "print function names"); -- cgit v1.1