Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
dwblaikie committed Nov 12, 2024
1 parent 8335d1e commit 1439655
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
4 changes: 2 additions & 2 deletions MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions common/array_stack.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ class ArrayStack {
return llvm::ArrayRef(values_).slice(array_offsets_.back());
}

// Returns the top array from the stack in such a way that the array's
// contents can be modified by the caller.
auto PeekMutableArray() -> llvm::MutableArrayRef<ValueT> {
CARBON_CHECK(!array_offsets_.empty());
return llvm::MutableArrayRef(values_).slice(array_offsets_.back());
}

// Returns the array at a specific index.
auto PeekArrayAt(int index) const -> llvm::ArrayRef<ValueT> {
auto ref = llvm::ArrayRef(values_).slice(array_offsets_[index]);
Expand Down
9 changes: 5 additions & 4 deletions toolchain/check/handle_class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,8 @@ auto HandleParseNode(Context& context, Parse::ClassDefinitionStartId node_id)
context.inst_block_stack().Push();
context.node_stack().Push(node_id, class_id);
context.struct_type_fields_stack().PushArray();
context.struct_type_fields_stack().AppendToTop(
{.name_id = SemIR::NameId::Vptr, .type_id = context.GetTupleType({})});

// TODO: Handle the case where there's control flow in the class body. For
// example:
Expand Down Expand Up @@ -668,10 +670,9 @@ static auto CheckCompleteClassType(Context& context, Parse::NodeId node_id,
}

if (defining_vtable_ptr) {
context.struct_type_fields_stack().PrependToTop(
{.name_id = SemIR::NameId::Vptr,
.type_id = context.GetPointerType(
context.GetBuiltinType(SemIR::BuiltinInstKind::VtableType))});
context.struct_type_fields_stack().PeekMutableArray().front().type_id =
context.GetPointerType(
context.GetBuiltinType(SemIR::BuiltinInstKind::VtableType));
}

auto fields_id = context.struct_type_fields().AddCanonical(
Expand Down

0 comments on commit 1439655

Please sign in to comment.