1 | //===- InstallAPI/Visitor.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 | /// ASTVisitor Interface for InstallAPI frontend operations. |
10 | /// |
11 | //===----------------------------------------------------------------------===// |
12 | |
13 | #ifndef LLVM_CLANG_INSTALLAPI_VISITOR_H |
14 | #define LLVM_CLANG_INSTALLAPI_VISITOR_H |
15 | |
16 | #include "clang/AST/Mangle.h" |
17 | #include "clang/AST/RecursiveASTVisitor.h" |
18 | #include "clang/Basic/TargetInfo.h" |
19 | #include "clang/Frontend/FrontendActions.h" |
20 | #include "clang/InstallAPI/Context.h" |
21 | #include "llvm/ADT/Twine.h" |
22 | |
23 | namespace clang { |
24 | struct AvailabilityInfo; |
25 | namespace installapi { |
26 | |
27 | /// ASTVisitor for collecting declarations that represent global symbols. |
28 | class InstallAPIVisitor final : public ASTConsumer, |
29 | public RecursiveASTVisitor<InstallAPIVisitor> { |
30 | public: |
31 | InstallAPIVisitor(ASTContext &ASTCtx, InstallAPIContext &Ctx, |
32 | SourceManager &SrcMgr, Preprocessor &PP) |
33 | : Ctx(Ctx), SrcMgr(SrcMgr), PP(PP), |
34 | MC(ItaniumMangleContext::create(Context&: ASTCtx, Diags&: ASTCtx.getDiagnostics())), |
35 | Layout(ASTCtx.getTargetInfo().getDataLayoutString()) {} |
36 | void HandleTranslationUnit(ASTContext &ASTCtx) override; |
37 | bool shouldVisitTemplateInstantiations() const { return true; } |
38 | |
39 | /// Collect global variables. |
40 | bool VisitVarDecl(const VarDecl *D); |
41 | |
42 | /// Collect global functions. |
43 | bool VisitFunctionDecl(const FunctionDecl *D); |
44 | |
45 | /// Collect Objective-C Interface declarations. |
46 | /// Every Objective-C class has an interface declaration that lists all the |
47 | /// ivars, properties, and methods of the class. |
48 | bool VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D); |
49 | |
50 | /// Collect Objective-C Category/Extension declarations. |
51 | /// |
52 | /// The class that is being extended might come from a different library and |
53 | /// is therefore itself not collected. |
54 | bool VisitObjCCategoryDecl(const ObjCCategoryDecl *D); |
55 | |
56 | /// Collect global c++ declarations. |
57 | bool VisitCXXRecordDecl(const CXXRecordDecl *D); |
58 | |
59 | private: |
60 | std::string getMangledName(const NamedDecl *D) const; |
61 | std::string getBackendMangledName(llvm::Twine Name) const; |
62 | std::string getMangledCXXVTableName(const CXXRecordDecl *D) const; |
63 | std::string getMangledCXXThunk(const GlobalDecl &D, |
64 | const ThunkInfo &Thunk) const; |
65 | std::string getMangledCXXRTTI(const CXXRecordDecl *D) const; |
66 | std::string getMangledCXXRTTIName(const CXXRecordDecl *D) const; |
67 | std::string getMangledCtorDtor(const CXXMethodDecl *D, int Type) const; |
68 | |
69 | std::optional<HeaderType> getAccessForDecl(const NamedDecl *D) const; |
70 | void recordObjCInstanceVariables( |
71 | const ASTContext &ASTCtx, llvm::MachO::ObjCContainerRecord *Record, |
72 | StringRef SuperClass, |
73 | const llvm::iterator_range< |
74 | DeclContext::specific_decl_iterator<ObjCIvarDecl>> |
75 | Ivars); |
76 | void (const CXXRecordDecl *D, const AvailabilityInfo &Avail, |
77 | const HeaderType Access, bool EmittedVTable = false); |
78 | |
79 | InstallAPIContext &Ctx; |
80 | SourceManager &SrcMgr; |
81 | Preprocessor &PP; |
82 | std::unique_ptr<clang::ItaniumMangleContext> MC; |
83 | StringRef Layout; |
84 | }; |
85 | |
86 | } // namespace installapi |
87 | } // namespace clang |
88 | |
89 | #endif // LLVM_CLANG_INSTALLAPI_VISITOR_H |
90 | |