You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

plugin.cc 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*-
  2. * Copyright 2016 Vsevolod Stakhov
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include "clang/Frontend/FrontendPluginRegistry.h"
  17. #include "clang/AST/AST.h"
  18. #include "clang/AST/ASTConsumer.h"
  19. #include "clang/Frontend/CompilerInstance.h"
  20. #include "clang/Sema/Sema.h"
  21. #include "llvm/Support/raw_ostream.h"
  22. #include "printf_check.h"
  23. using namespace clang;
  24. namespace rspamd {
  25. class RspamdASTConsumer : public ASTConsumer {
  26. CompilerInstance &Instance;
  27. public:
  28. RspamdASTConsumer (CompilerInstance &Instance)
  29. : Instance (Instance)
  30. {
  31. }
  32. void HandleTranslationUnit (ASTContext &context) override
  33. {
  34. rspamd::PrintfCheckVisitor v(&context, Instance);
  35. v.TraverseDecl (context.getTranslationUnitDecl ());
  36. }
  37. };
  38. class RspamdASTAction : public PluginASTAction {
  39. protected:
  40. std::unique_ptr <ASTConsumer> CreateASTConsumer (CompilerInstance &CI,
  41. llvm::StringRef) override
  42. {
  43. return llvm::make_unique<RspamdASTConsumer> (CI);
  44. }
  45. bool ParseArgs (const CompilerInstance &CI,
  46. const std::vector <std::string> &args) override
  47. {
  48. return true;
  49. }
  50. void PrintHelp (llvm::raw_ostream &ros)
  51. {
  52. ros << "Nothing here\n";
  53. }
  54. };
  55. }
  56. static FrontendPluginRegistry::Add <rspamd::RspamdASTAction>
  57. X ("rspamd-ast", "rspamd ast checker");