ExtractAPIVisitor.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- ExtractAPI/ExtractAPIVisitor.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 ExtractAPVisitor AST visitation interface.
  16. ///
  17. //===----------------------------------------------------------------------===//
  18. #ifndef LLVM_CLANG_EXTRACTAPI_EXTRACT_API_VISITOR_H
  19. #define LLVM_CLANG_EXTRACTAPI_EXTRACT_API_VISITOR_H
  20. #include "clang/AST/RecursiveASTVisitor.h"
  21. #include "clang/Basic/SourceManager.h"
  22. #include "clang/ExtractAPI/API.h"
  23. #include "llvm/ADT/FunctionExtras.h"
  24. namespace clang {
  25. namespace extractapi {
  26. /// The RecursiveASTVisitor to traverse symbol declarations and collect API
  27. /// information.
  28. class ExtractAPIVisitor : public RecursiveASTVisitor<ExtractAPIVisitor> {
  29. public:
  30. ExtractAPIVisitor(ASTContext &Context,
  31. llvm::unique_function<bool(SourceLocation)> LocationChecker,
  32. APISet &API)
  33. : Context(Context), API(API),
  34. LocationChecker(std::move(LocationChecker)) {}
  35. const APISet &getAPI() const { return API; }
  36. bool VisitVarDecl(const VarDecl *Decl);
  37. bool VisitFunctionDecl(const FunctionDecl *Decl);
  38. bool VisitEnumDecl(const EnumDecl *Decl);
  39. bool VisitRecordDecl(const RecordDecl *Decl);
  40. bool VisitObjCInterfaceDecl(const ObjCInterfaceDecl *Decl);
  41. bool VisitObjCProtocolDecl(const ObjCProtocolDecl *Decl);
  42. bool VisitTypedefNameDecl(const TypedefNameDecl *Decl);
  43. bool VisitObjCCategoryDecl(const ObjCCategoryDecl *Decl);
  44. private:
  45. /// Collect API information for the enum constants and associate with the
  46. /// parent enum.
  47. void recordEnumConstants(EnumRecord *EnumRecord,
  48. const EnumDecl::enumerator_range Constants);
  49. /// Collect API information for the struct fields and associate with the
  50. /// parent struct.
  51. void recordStructFields(StructRecord *StructRecord,
  52. const RecordDecl::field_range Fields);
  53. /// Collect API information for the Objective-C methods and associate with the
  54. /// parent container.
  55. void recordObjCMethods(ObjCContainerRecord *Container,
  56. const ObjCContainerDecl::method_range Methods);
  57. void recordObjCProperties(ObjCContainerRecord *Container,
  58. const ObjCContainerDecl::prop_range Properties);
  59. void recordObjCInstanceVariables(
  60. ObjCContainerRecord *Container,
  61. const llvm::iterator_range<
  62. DeclContext::specific_decl_iterator<ObjCIvarDecl>>
  63. Ivars);
  64. void recordObjCProtocols(ObjCContainerRecord *Container,
  65. ObjCInterfaceDecl::protocol_range Protocols);
  66. ASTContext &Context;
  67. APISet &API;
  68. llvm::unique_function<bool(SourceLocation)> LocationChecker;
  69. };
  70. } // namespace extractapi
  71. } // namespace clang
  72. #endif // LLVM_CLANG_EXTRACTAPI_EXTRACT_API_VISITOR_H
  73. #ifdef __GNUC__
  74. #pragma GCC diagnostic pop
  75. #endif