1 //===- ExtractAPI/ExtractAPIVisitor.h ---------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// This file defines the ExtractAPVisitor AST visitation interface.
11 ///
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CLANG_EXTRACTAPI_EXTRACT_API_VISITOR_H
15 #define LLVM_CLANG_EXTRACTAPI_EXTRACT_API_VISITOR_H
16 
17 #include "clang/AST/RecursiveASTVisitor.h"
18 #include "clang/Basic/SourceManager.h"
19 #include "clang/ExtractAPI/API.h"
20 #include "llvm/ADT/FunctionExtras.h"
21 
22 namespace clang {
23 namespace extractapi {
24 
25 /// The RecursiveASTVisitor to traverse symbol declarations and collect API
26 /// information.
27 class ExtractAPIVisitor : public RecursiveASTVisitor<ExtractAPIVisitor> {
28 public:
29   ExtractAPIVisitor(ASTContext &Context,
30                     llvm::unique_function<bool(SourceLocation)> LocationChecker,
31                     APISet &API)
32       : Context(Context), API(API),
33         LocationChecker(std::move(LocationChecker)) {}
34 
35   const APISet &getAPI() const { return API; }
36 
37   bool VisitVarDecl(const VarDecl *Decl);
38 
39   bool VisitFunctionDecl(const FunctionDecl *Decl);
40 
41   bool VisitEnumDecl(const EnumDecl *Decl);
42 
43   bool VisitRecordDecl(const RecordDecl *Decl);
44 
45   bool VisitObjCInterfaceDecl(const ObjCInterfaceDecl *Decl);
46 
47   bool VisitObjCProtocolDecl(const ObjCProtocolDecl *Decl);
48 
49   bool VisitTypedefNameDecl(const TypedefNameDecl *Decl);
50 
51   bool VisitObjCCategoryDecl(const ObjCCategoryDecl *Decl);
52 
53 private:
54   /// Collect API information for the enum constants and associate with the
55   /// parent enum.
56   void recordEnumConstants(EnumRecord *EnumRecord,
57                            const EnumDecl::enumerator_range Constants);
58 
59   /// Collect API information for the struct fields and associate with the
60   /// parent struct.
61   void recordStructFields(StructRecord *StructRecord,
62                           const RecordDecl::field_range Fields);
63 
64   /// Collect API information for the Objective-C methods and associate with the
65   /// parent container.
66   void recordObjCMethods(ObjCContainerRecord *Container,
67                          const ObjCContainerDecl::method_range Methods);
68 
69   void recordObjCProperties(ObjCContainerRecord *Container,
70                             const ObjCContainerDecl::prop_range Properties);
71 
72   void recordObjCInstanceVariables(
73       ObjCContainerRecord *Container,
74       const llvm::iterator_range<
75           DeclContext::specific_decl_iterator<ObjCIvarDecl>>
76           Ivars);
77 
78   void recordObjCProtocols(ObjCContainerRecord *Container,
79                            ObjCInterfaceDecl::protocol_range Protocols);
80   ASTContext &Context;
81   APISet &API;
82   llvm::unique_function<bool(SourceLocation)> LocationChecker;
83 };
84 
85 } // namespace extractapi
86 } // namespace clang
87 
88 #endif // LLVM_CLANG_EXTRACTAPI_EXTRACT_API_VISITOR_H
89