Skip to content

Commit

Permalink
[InstallAPI] Collect C++ Decls (#84403)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cyndyishida committed Mar 11, 2024
1 parent ad8c828 commit 2c93bec
Show file tree
Hide file tree
Showing 6 changed files with 1,008 additions and 6 deletions.
14 changes: 14 additions & 0 deletions clang/include/clang/InstallAPI/Visitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "llvm/ADT/Twine.h"

namespace clang {
struct AvailabilityInfo;
namespace installapi {

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

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

/// Collect global c++ declarations.
bool VisitCXXRecordDecl(const CXXRecordDecl *D);

private:
std::string getMangledName(const NamedDecl *D) const;
std::string getBackendMangledName(llvm::Twine Name) const;
std::string getMangledCXXVTableName(const CXXRecordDecl *D) const;
std::string getMangledCXXThunk(const GlobalDecl &D,
const ThunkInfo &Thunk) const;
std::string getMangledCXXRTTI(const CXXRecordDecl *D) const;
std::string getMangledCXXRTTIName(const CXXRecordDecl *D) const;
std::string getMangledCtorDtor(const CXXMethodDecl *D, int Type) const;

std::optional<HeaderType> getAccessForDecl(const NamedDecl *D) const;
void recordObjCInstanceVariables(
const ASTContext &ASTCtx, llvm::MachO::ObjCContainerRecord *Record,
StringRef SuperClass,
const llvm::iterator_range<
DeclContext::specific_decl_iterator<ObjCIvarDecl>>
Ivars);
void emitVTableSymbols(const CXXRecordDecl *D, const AvailabilityInfo &Avail,
const HeaderType Access, bool EmittedVTable = false);

InstallAPIContext &Ctx;
SourceManager &SrcMgr;
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/InstallAPI/Frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ std::unique_ptr<MemoryBuffer> createInputBuffer(InstallAPIContext &Ctx) {
else
OS << "#import ";
if (H.useIncludeName())
OS << "<" << H.getIncludeName() << ">";
OS << "<" << H.getIncludeName() << ">\n";
else
OS << "\"" << H.getPath() << "\"";
OS << "\"" << H.getPath() << "\"\n";

Ctx.addKnownHeader(H);
}
Expand Down

0 comments on commit 2c93bec

Please sign in to comment.