Skip to content

Commit d73efd9

Browse files
committed
[InstallAPI] Add support for C++ headers
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 580af4d commit d73efd9

File tree

6 files changed

+1007
-6
lines changed

6 files changed

+1007
-6
lines changed

clang/include/clang/InstallAPI/Visitor.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#ifndef LLVM_CLANG_INSTALLAPI_VISITOR_H
1414
#define LLVM_CLANG_INSTALLAPI_VISITOR_H
1515

16+
#include "clang/AST/Availability.h"
1617
#include "clang/AST/Mangle.h"
1718
#include "clang/AST/RecursiveASTVisitor.h"
1819
#include "clang/Basic/TargetInfo.h"
@@ -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
@@ -136,9 +136,9 @@ std::unique_ptr<MemoryBuffer> createInputBuffer(InstallAPIContext &Ctx) {
136136
else
137137
OS << "#import ";
138138
if (H.useIncludeName())
139-
OS << "<" << H.getIncludeName() << ">";
139+
OS << "<" << H.getIncludeName() << ">\n";
140140
else
141-
OS << "\"" << H.getPath() << "\"";
141+
OS << "\"" << H.getPath() << "\"\n";
142142

143143
Ctx.addKnownHeader(H);
144144
}

0 commit comments

Comments
 (0)