FrontendActions.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- ExtractAPI/FrontendActions.h -----------------------------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. ///
  14. /// \file
  15. /// This file defines the ExtractAPIAction frontend action.
  16. ///
  17. //===----------------------------------------------------------------------===//
  18. #ifndef LLVM_CLANG_EXTRACTAPI_FRONTEND_ACTIONS_H
  19. #define LLVM_CLANG_EXTRACTAPI_FRONTEND_ACTIONS_H
  20. #include "clang/ExtractAPI/API.h"
  21. #include "clang/ExtractAPI/APIIgnoresList.h"
  22. #include "clang/Frontend/FrontendAction.h"
  23. namespace clang {
  24. /// ExtractAPIAction sets up the output file and creates the ExtractAPIVisitor.
  25. class ExtractAPIAction : public ASTFrontendAction {
  26. protected:
  27. std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
  28. StringRef InFile) override;
  29. private:
  30. /// A representation of the APIs this action extracts.
  31. std::unique_ptr<extractapi::APISet> API;
  32. /// A stream to the output file of this action.
  33. std::unique_ptr<raw_pwrite_stream> OS;
  34. /// The product this action is extracting API information for.
  35. std::string ProductName;
  36. /// The synthesized input buffer that contains all the provided input header
  37. /// files.
  38. std::unique_ptr<llvm::MemoryBuffer> Buffer;
  39. /// The list of symbols to ignore during serialization
  40. extractapi::APIIgnoresList IgnoresList;
  41. /// The input file originally provided on the command line.
  42. ///
  43. /// This captures the spelling used to include the file and whether the
  44. /// include is quoted or not.
  45. SmallVector<std::pair<SmallString<32>, bool>> KnownInputFiles;
  46. /// Prepare to execute the action on the given CompilerInstance.
  47. ///
  48. /// This is called before executing the action on any inputs. This generates a
  49. /// single header that includes all of CI's inputs and replaces CI's input
  50. /// list with it before actually executing the action.
  51. bool PrepareToExecuteAction(CompilerInstance &CI) override;
  52. /// Called after executing the action on the synthesized input buffer.
  53. ///
  54. /// Note: Now that we have gathered all the API definitions to surface we can
  55. /// emit them in this callback.
  56. void EndSourceFileAction() override;
  57. static std::unique_ptr<llvm::raw_pwrite_stream>
  58. CreateOutputFile(CompilerInstance &CI, StringRef InFile);
  59. static StringRef getInputBufferName() { return "<extract-api-includes>"; }
  60. };
  61. } // namespace clang
  62. #endif // LLVM_CLANG_EXTRACTAPI_FRONTEND_ACTIONS_H
  63. #ifdef __GNUC__
  64. #pragma GCC diagnostic pop
  65. #endif