clang 20.0.0git
Visitor.h
Go to the documentation of this file.
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"
21#include "llvm/ADT/Twine.h"
22
23namespace clang {
24struct AvailabilityInfo;
25namespace installapi {
26
27/// ASTVisitor for collecting declarations that represent global symbols.
28class InstallAPIVisitor final : public ASTConsumer,
29 public RecursiveASTVisitor<InstallAPIVisitor> {
30public:
32 SourceManager &SrcMgr, Preprocessor &PP)
33 : Ctx(Ctx), SrcMgr(SrcMgr), PP(PP),
34 MC(ItaniumMangleContext::create(ASTCtx, 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.
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.
55
56 /// Collect global c++ declarations.
58
59private:
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, const ThunkInfo &Thunk,
64 bool ElideOverrideInfo) 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<
75 Ivars);
76 void emitVTableSymbols(const CXXRecordDecl *D, const AvailabilityInfo &Avail,
77 const HeaderType Access, bool EmittedVTable = false);
78
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
const Decl * D
llvm::MachO::Record Record
Definition: MachO.h:31
ASTConsumer - This is an abstract interface that should be implemented by clients that read ASTs.
Definition: ASTConsumer.h:34
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:187
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:2064
Represents a C++ struct/union/class.
Definition: DeclCXX.h:258
specific_decl_iterator - Iterates over a subrange of declarations stored in a DeclContext,...
Definition: DeclBase.h:2370
Represents a function declaration or definition.
Definition: Decl.h:1932
GlobalDecl - represents a global declaration.
Definition: GlobalDecl.h:56
This represents a decl that may have a name.
Definition: Decl.h:249
ObjCCategoryDecl - Represents a category declaration.
Definition: DeclObjC.h:2328
Represents an ObjC class declaration.
Definition: DeclObjC.h:1153
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Definition: Preprocessor.h:137
A class that does preorder or postorder depth-first traversal on the entire Clang AST and visits each...
This class handles loading and caching of source files into memory.
The base class of the type hierarchy.
Definition: Type.h:1829
Represents a variable declaration or definition.
Definition: Decl.h:879
ASTVisitor for collecting declarations that represent global symbols.
Definition: Visitor.h:29
bool shouldVisitTemplateInstantiations() const
Definition: Visitor.h:37
void HandleTranslationUnit(ASTContext &ASTCtx) override
HandleTranslationUnit - This method is called when the ASTs for entire translation unit have been par...
Definition: Visitor.cpp:78
bool VisitCXXRecordDecl(const CXXRecordDecl *D)
Collect global c++ declarations.
Definition: Visitor.cpp:557
bool VisitFunctionDecl(const FunctionDecl *D)
Collect global functions.
Definition: Visitor.cpp:251
bool VisitVarDecl(const VarDecl *D)
Collect global variables.
Definition: Visitor.cpp:216
bool VisitObjCCategoryDecl(const ObjCCategoryDecl *D)
Collect Objective-C Category/Extension declarations.
Definition: Visitor.cpp:198
InstallAPIVisitor(ASTContext &ASTCtx, InstallAPIContext &Ctx, SourceManager &SrcMgr, Preprocessor &PP)
Definition: Visitor.h:31
bool VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D)
Collect Objective-C Interface declarations.
Definition: Visitor.cpp:166
Defines the clang::TargetInfo interface.
The JSON file list parser is used to communicate input to InstallAPI.
Storage of availability attributes for a declaration.
Definition: Availability.h:64
The this pointer adjustment as well as an optional return adjustment for a thunk.
Definition: Thunk.h:157
Struct used for generating validating InstallAPI.
Definition: Context.h:26