Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:56

0001 //===- InstallAPI/Visitor.h -----------------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 ///
0009 /// ASTVisitor Interface for InstallAPI frontend operations.
0010 ///
0011 //===----------------------------------------------------------------------===//
0012 
0013 #ifndef LLVM_CLANG_INSTALLAPI_VISITOR_H
0014 #define LLVM_CLANG_INSTALLAPI_VISITOR_H
0015 
0016 #include "clang/AST/Mangle.h"
0017 #include "clang/AST/RecursiveASTVisitor.h"
0018 #include "clang/Basic/TargetInfo.h"
0019 #include "clang/Frontend/FrontendActions.h"
0020 #include "clang/InstallAPI/Context.h"
0021 #include "llvm/ADT/Twine.h"
0022 
0023 namespace clang {
0024 struct AvailabilityInfo;
0025 namespace installapi {
0026 
0027 /// ASTVisitor for collecting declarations that represent global symbols.
0028 class InstallAPIVisitor final : public ASTConsumer,
0029                                 public RecursiveASTVisitor<InstallAPIVisitor> {
0030 public:
0031   InstallAPIVisitor(ASTContext &ASTCtx, InstallAPIContext &Ctx,
0032                     SourceManager &SrcMgr, Preprocessor &PP)
0033       : Ctx(Ctx), SrcMgr(SrcMgr), PP(PP),
0034         MC(ItaniumMangleContext::create(ASTCtx, ASTCtx.getDiagnostics())),
0035         Layout(ASTCtx.getTargetInfo().getDataLayoutString()) {}
0036   void HandleTranslationUnit(ASTContext &ASTCtx) override;
0037   bool shouldVisitTemplateInstantiations() const { return true; }
0038 
0039   /// Collect global variables.
0040   bool VisitVarDecl(const VarDecl *D);
0041 
0042   /// Collect global functions.
0043   bool VisitFunctionDecl(const FunctionDecl *D);
0044 
0045   /// Collect Objective-C Interface declarations.
0046   /// Every Objective-C class has an interface declaration that lists all the
0047   /// ivars, properties, and methods of the class.
0048   bool VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D);
0049 
0050   /// Collect Objective-C Category/Extension declarations.
0051   ///
0052   /// The class that is being extended might come from a different library and
0053   /// is therefore itself not collected.
0054   bool VisitObjCCategoryDecl(const ObjCCategoryDecl *D);
0055 
0056   /// Collect global c++ declarations.
0057   bool VisitCXXRecordDecl(const CXXRecordDecl *D);
0058 
0059 private:
0060   std::string getMangledName(const NamedDecl *D) const;
0061   std::string getBackendMangledName(llvm::Twine Name) const;
0062   std::string getMangledCXXVTableName(const CXXRecordDecl *D) const;
0063   std::string getMangledCXXThunk(const GlobalDecl &D, const ThunkInfo &Thunk,
0064                                  bool ElideOverrideInfo) const;
0065   std::string getMangledCXXRTTI(const CXXRecordDecl *D) const;
0066   std::string getMangledCXXRTTIName(const CXXRecordDecl *D) const;
0067   std::string getMangledCtorDtor(const CXXMethodDecl *D, int Type) const;
0068 
0069   std::optional<HeaderType> getAccessForDecl(const NamedDecl *D) const;
0070   void recordObjCInstanceVariables(
0071       const ASTContext &ASTCtx, llvm::MachO::ObjCContainerRecord *Record,
0072       StringRef SuperClass,
0073       const llvm::iterator_range<
0074           DeclContext::specific_decl_iterator<ObjCIvarDecl>>
0075           Ivars);
0076   void emitVTableSymbols(const CXXRecordDecl *D, const AvailabilityInfo &Avail,
0077                          const HeaderType Access, bool EmittedVTable = false);
0078 
0079   InstallAPIContext &Ctx;
0080   SourceManager &SrcMgr;
0081   Preprocessor &PP;
0082   std::unique_ptr<clang::ItaniumMangleContext> MC;
0083   StringRef Layout;
0084 };
0085 
0086 } // namespace installapi
0087 } // namespace clang
0088 
0089 #endif // LLVM_CLANG_INSTALLAPI_VISITOR_H