handle_form_literal.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. #include "toolchain/check/convert.h"
  6. #include "toolchain/check/handle.h"
  7. #include "toolchain/check/inst.h"
  8. #include "toolchain/parse/node_category.h"
  9. namespace Carbon::Check {
  10. auto HandleParseNode(Context& context, Parse::RefPrimitiveFormId node_id)
  11. -> bool {
  12. auto [type_node_id, type_inst_id] = context.node_stack().PopExprWithNodeId();
  13. auto type_expr = ExprAsType(context, type_node_id, type_inst_id);
  14. auto inst_id =
  15. AddInst<SemIR::RefForm>(context, node_id,
  16. {.type_id = SemIR::FormType::TypeId,
  17. .type_component_inst_id = type_expr.inst_id});
  18. context.node_stack().Push(node_id, inst_id);
  19. return true;
  20. }
  21. auto HandleParseNode(Context& context, Parse::ValPrimitiveFormId node_id)
  22. -> bool {
  23. auto [type_node_id, type_inst_id] = context.node_stack().PopExprWithNodeId();
  24. auto type_expr = ExprAsType(context, type_node_id, type_inst_id);
  25. auto inst_id =
  26. AddInst<SemIR::ValueForm>(context, node_id,
  27. {.type_id = SemIR::FormType::TypeId,
  28. .type_component_inst_id = type_expr.inst_id});
  29. context.node_stack().Push(node_id, inst_id);
  30. return true;
  31. }
  32. auto HandleParseNode(Context& context, Parse::VarPrimitiveFormId node_id)
  33. -> bool {
  34. auto [type_node_id, type_inst_id] = context.node_stack().PopExprWithNodeId();
  35. auto type_expr = ExprAsType(context, type_node_id, type_inst_id);
  36. auto inst_id =
  37. AddInst<SemIR::InitForm>(context, node_id,
  38. {.type_id = SemIR::FormType::TypeId,
  39. .type_component_inst_id = type_expr.inst_id});
  40. context.node_stack().Push(node_id, inst_id);
  41. return true;
  42. }
  43. auto HandleParseNode(Context& /*context*/,
  44. Parse::FormLiteralKeywordId /*node_id*/) -> bool {
  45. return true;
  46. }
  47. auto HandleParseNode(Context& /*context*/,
  48. Parse::FormLiteralOpenParenId /*node_id*/) -> bool {
  49. return true;
  50. }
  51. auto HandleParseNode(Context& /*context*/, Parse::FormLiteralId /*node_id*/)
  52. -> bool {
  53. return true;
  54. }
  55. } // namespace Carbon::Check