Skip to content

Commit

Permalink
cg: Resurrect record decl emition.
Browse files Browse the repository at this point in the history
  • Loading branch information
xlauko committed Apr 24, 2024
1 parent f9a7d0b commit 7e369dc
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
20 changes: 20 additions & 0 deletions include/vast/CodeGen/DefaultDeclVisitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ VAST_RELAX_WARNINGS
VAST_UNRELAX_WARNINGS

#include "vast/CodeGen/CodeGenVisitorBase.hpp"
#include "vast/CodeGen/CodeGenMembers.hpp"

namespace vast::cg {

Expand Down Expand Up @@ -41,6 +42,25 @@ namespace vast::cg {
operation VisitCXXRecordDecl(const clang::CXXRecordDecl *decl);
operation VisitAccessSpecDecl(const clang::AccessSpecDecl *decl);
operation VisitFieldDecl(const clang::FieldDecl *decl) ;

operation mk_incomplete_decl(const clang::RecordDecl *decl);

template< typename RecordDeclOp >
operation mk_record_decl(const clang::RecordDecl *decl) {
auto field_builder = [&] (auto &/* bld */, auto /* loc */) {
auto gen = mk_scoped_generator< members_generator >(
self.scope, bld, self
);

gen.emit(decl);
};

return bld.compose< RecordDeclOp >()
.bind(self.location(decl))
.bind(self.symbol(decl))
.bind(field_builder)
.freeze();
}
};

} // namespace vast::cg
20 changes: 19 additions & 1 deletion lib/vast/CodeGen/DefaultDeclVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,15 @@ namespace vast::cg
}

operation default_decl_visitor::VisitRecordDecl(const clang::RecordDecl *decl) {
return {};
if (!decl->isCompleteDefinition()) {
return mk_incomplete_decl(decl);
}

if (decl->isUnion()) {
return mk_record_decl< hl::UnionDeclOp >(decl);
} else {
return mk_record_decl< hl::StructDeclOp >(decl);
}
}

operation default_decl_visitor::VisitCXXRecordDecl(const clang::CXXRecordDecl *decl) {
Expand All @@ -358,4 +366,14 @@ namespace vast::cg
operation default_decl_visitor::VisitFieldDecl(const clang::FieldDecl *decl) {
return {};
}

operation default_decl_visitor::mk_incomplete_decl(const clang::RecordDecl *decl) {
return declare([&] {
return bld.compose< hl::TypeDeclOp >()
.bind(self.location(decl))
.bind(self.symbol(decl))
.freeze();
});
}

} // namespace vast::hl

0 comments on commit 7e369dc

Please sign in to comment.