handle_tuple_literal.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. #include "toolchain/check/context.h"
  5. namespace Carbon::Check {
  6. auto HandleTupleLiteralStart(Context& context,
  7. Parse::TupleLiteralStartId node_id) -> bool {
  8. context.node_stack().Push(node_id);
  9. context.param_and_arg_refs_stack().Push();
  10. return true;
  11. }
  12. auto HandleTupleLiteralComma(Context& context,
  13. Parse::TupleLiteralCommaId /*node_id*/) -> bool {
  14. context.param_and_arg_refs_stack().ApplyComma();
  15. return true;
  16. }
  17. auto HandleTupleLiteral(Context& context, Parse::TupleLiteralId node_id)
  18. -> bool {
  19. auto refs_id = context.param_and_arg_refs_stack().EndAndPop(
  20. Parse::NodeKind::TupleLiteralStart);
  21. context.node_stack()
  22. .PopAndDiscardSoloNodeId<Parse::NodeKind::TupleLiteralStart>();
  23. const auto& inst_block = context.inst_blocks().Get(refs_id);
  24. llvm::SmallVector<SemIR::TypeId> type_ids;
  25. type_ids.reserve(inst_block.size());
  26. for (auto inst : inst_block) {
  27. type_ids.push_back(context.insts().Get(inst).type_id());
  28. }
  29. auto type_id = context.GetTupleType(type_ids);
  30. auto value_id =
  31. context.AddInst({node_id, SemIR::TupleLiteral{type_id, refs_id}});
  32. context.node_stack().Push(node_id, value_id);
  33. return true;
  34. }
  35. } // namespace Carbon::Check