diff options
author | Daniel Dunbar <daniel@zuster.org> | 2010-08-02 15:31:28 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2010-08-02 15:31:28 +0000 |
commit | 2be96746b4c0aaf4a3f812ff0afe39b77bc94bc6 (patch) | |
tree | ee4a8941af9ca18d10b532d2ba01c10f3f42a87a /clang/examples/PrintFunctionNames/PrintFunctionNames.cpp | |
parent | 77558b7d13488fb0766475bc59c7a79b69741cfd (diff) | |
download | bcm5719-llvm-2be96746b4c0aaf4a3f812ff0afe39b77bc94bc6.tar.gz bcm5719-llvm-2be96746b4c0aaf4a3f812ff0afe39b77bc94bc6.zip |
Frontend: Change PluginASTAction::ParseArgs to take a CompilerInstance object
for use in reporting diagnostics.
- We don't want to use the Action's own CompilerInstance, because that is only
initialized during file processing and I like that invariant.
Also, if ParseArgs returns false then abandon execution.
Also, remove unused PluginASTAction::PrintHelp virtual method.
llvm-svn: 110039
Diffstat (limited to 'clang/examples/PrintFunctionNames/PrintFunctionNames.cpp')
-rw-r--r-- | clang/examples/PrintFunctionNames/PrintFunctionNames.cpp | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/clang/examples/PrintFunctionNames/PrintFunctionNames.cpp b/clang/examples/PrintFunctionNames/PrintFunctionNames.cpp index e94b0ed676a..cc138f56dbb 100644 --- a/clang/examples/PrintFunctionNames/PrintFunctionNames.cpp +++ b/clang/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<std::string>& args) { - for (unsigned i=0; i<args.size(); ++i) + bool ParseArgs(const CompilerInstance &CI, + const std::vector<std::string>& 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"; } |