Skip to content

Commit

Permalink
Emit internal decls record fields depend upon.
Browse files Browse the repository at this point in the history
Default ctors and dtors of records that are implicitly called if a field is one such record may not appear anywhere in its parent AST node.

Fixes the remaining linking error from #12.
  • Loading branch information
Syniurge committed Aug 27, 2015
1 parent 9ffb94e commit e56876f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions dmd2/cpp/calypso.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ class LangPlugin : public ::LangPlugin, public ::ForeignCodeGen
void emitAdditionalClassSymbols(::ClassDeclaration *cd) override;
void toInitClass(TypeClass* tc, LLValue* dst) override;
void toPostNewClass(Loc& loc, TypeClass* tc, DValue* val) override;

void EmitInternalDeclsForFields(const clang::RecordDecl *RD);

// ==== ==== ====
PCH pch;
Expand Down
29 changes: 29 additions & 0 deletions gen/cpp/cpptoir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,29 @@ void LangPlugin::toDefaultInitVarDeclaration(::VarDeclaration* vd)
}
}

void LangPlugin::EmitInternalDeclsForFields(const clang::RecordDecl *RD)
{
auto& Context = getASTContext();
auto& S = pch.AST->getSema();

InternalDeclEmitter Emitter(Context, *CGM);

auto Emit = [&] (clang::CXXMethodDecl *D) {
if (D && !D->isDeleted())
Emitter.Emit(D);
};

for (auto F: RD->fields())
{
auto FTyRec = F->getType()->getAsCXXRecordDecl();
if (!FTyRec)
continue;

Emit(S.LookupDefaultConstructor(FTyRec));
Emit(S.LookupDestructor(FTyRec));
}
}

void LangPlugin::toDefineStruct(::StructDeclaration* sd)
{
auto& S = pch.AST->getSema();
Expand All @@ -712,10 +735,16 @@ void LangPlugin::toDefineStruct(::StructDeclaration* sd)

EmitStructor(S.LookupDefaultConstructor(_RD));
EmitStructor(S.LookupCopyingConstructor(_RD, clang::Qualifiers::Const));

EmitInternalDeclsForFields(RD);
}

void LangPlugin::toDefineClass(::ClassDeclaration* cd)
{
auto c_cd = static_cast<cpp::ClassDeclaration*>(cd);
auto RD = cast<clang::CXXRecordDecl>(c_cd->RD);

EmitInternalDeclsForFields(RD);
}

void LangPlugin::toDefineTemplateInstance(::TemplateInstance *inst)
Expand Down

0 comments on commit e56876f

Please sign in to comment.