Skip to content

Commit 2c93bec

Browse files
authored
[InstallAPI] Collect C++ Decls (#84403)
This includes capturing symbols for global variables, functions, classes, and templated defintions. As pre-determing what symbols are generated from C++ declarations can be non-trivial, InstallAPI only parses select declarations for symbol generation when parsing c++. For example, installapi only looks at explicit template instantiations or full template specializations, instead of general function or class templates, for symbol emittion.
1 parent ad8c828 commit 2c93bec

File tree

6 files changed

+1008
-6
lines changed

6 files changed

+1008
-6
lines changed

clang/include/clang/InstallAPI/Visitor.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "llvm/ADT/Twine.h"
2222

2323
namespace clang {
24+
struct AvailabilityInfo;
2425
namespace installapi {
2526

2627
/// ASTVisitor for collecting declarations that represent global symbols.
@@ -33,6 +34,7 @@ class InstallAPIVisitor final : public ASTConsumer,
3334
MC(ItaniumMangleContext::create(ASTCtx, ASTCtx.getDiagnostics())),
3435
Layout(ASTCtx.getTargetInfo().getDataLayoutString()) {}
3536
void HandleTranslationUnit(ASTContext &ASTCtx) override;
37+
bool shouldVisitTemplateInstantiations() const { return true; }
3638

3739
/// Collect global variables.
3840
bool VisitVarDecl(const VarDecl *D);
@@ -51,16 +53,28 @@ class InstallAPIVisitor final : public ASTConsumer,
5153
/// is therefore itself not collected.
5254
bool VisitObjCCategoryDecl(const ObjCCategoryDecl *D);
5355

56+
/// Collect global c++ declarations.
57+
bool VisitCXXRecordDecl(const CXXRecordDecl *D);
58+
5459
private:
5560
std::string getMangledName(const NamedDecl *D) const;
5661
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+
5769
std::optional<HeaderType> getAccessForDecl(const NamedDecl *D) const;
5870
void recordObjCInstanceVariables(
5971
const ASTContext &ASTCtx, llvm::MachO::ObjCContainerRecord *Record,
6072
StringRef SuperClass,
6173
const llvm::iterator_range<
6274
DeclContext::specific_decl_iterator<ObjCIvarDecl>>
6375
Ivars);
76+
void emitVTableSymbols(const CXXRecordDecl *D, const AvailabilityInfo &Avail,
77+
const HeaderType Access, bool EmittedVTable = false);
6478

6579
InstallAPIContext &Ctx;
6680
SourceManager &SrcMgr;

clang/lib/InstallAPI/Frontend.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,9 @@ std::unique_ptr<MemoryBuffer> createInputBuffer(InstallAPIContext &Ctx) {
137137
else
138138
OS << "#import ";
139139
if (H.useIncludeName())
140-
OS << "<" << H.getIncludeName() << ">";
140+
OS << "<" << H.getIncludeName() << ">\n";
141141
else
142-
OS << "\"" << H.getPath() << "\"";
142+
OS << "\"" << H.getPath() << "\"\n";
143143

144144
Ctx.addKnownHeader(H);
145145
}

0 commit comments

Comments
 (0)