mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 09:41:05 +01:00
Initial support for interop with class/struct/union fields. (#5849)
Add a new type, `custom_layout_type`, representing a struct type whose
size, alignment, and field offsets can be manually controlled. Use this
as the object representation type for imported C++ class types (which
also includes struct and union types), allowing us to model C++ class
type layouts. In passing, also add support for incomplete C++ class
types, mapping them into incomplete Carbon class types.
Map C++ fields into Carbon field declarations, allowing direct access to
C++ fields from Carbon. So far, no support is added for base classes nor
anonymous struct or union declarations; those will be added in
subsequent PRs. Also, we don't map C++ access control into Carbon yet,
so all C++ fields are accessible regardless of their access control.
For now we still use a `struct_type` as the object representation for
empty C++ classes, in order to continue to support our existing tests
that convert `{}` to empty C++ class types. This is temporary and should
be removed once we support interop with C++ class initialization.
This commit is contained in:
@@ -299,6 +299,12 @@ class Stringifier {
|
||||
step_stack_->PushInstId(inst.inner_id);
|
||||
}
|
||||
|
||||
auto StringifyInst(InstId /*inst_id*/, CustomLayoutType inst) -> void {
|
||||
auto layout = sem_ir_->custom_layouts().Get(inst.layout_id);
|
||||
*out_ << "<size " << layout[CustomLayoutId::SizeIndex] << ", align "
|
||||
<< layout[CustomLayoutId::AlignIndex] << ">";
|
||||
}
|
||||
|
||||
auto StringifyInst(InstId /*inst_id*/, FacetAccessType inst) -> void {
|
||||
// Given `T:! I`, print `T as type` as simply `T`.
|
||||
step_stack_->PushInstId(inst.facet_value_inst_id);
|
||||
|
||||
Reference in New Issue
Block a user