handle_pattern_binding.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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/sem_ir/node.h"
  7. namespace Carbon::Check {
  8. auto HandleAddress(Context& context, Parse::Node parse_node) -> bool {
  9. return context.TODO(parse_node, "HandleAddress");
  10. }
  11. auto HandleGenericPatternBinding(Context& context, Parse::Node parse_node)
  12. -> bool {
  13. return context.TODO(parse_node, "GenericPatternBinding");
  14. }
  15. auto HandlePatternBinding(Context& context, Parse::Node parse_node) -> bool {
  16. auto [type_node, parsed_type_id] =
  17. context.node_stack().PopExpressionWithParseNode();
  18. auto cast_type_id = ExpressionAsType(context, type_node, parsed_type_id);
  19. // Get the name.
  20. auto [name_node, name_id] =
  21. context.node_stack().PopWithParseNode<Parse::NodeKind::Name>();
  22. // Allocate a node of the appropriate kind, linked to the name for error
  23. // locations.
  24. switch (auto context_parse_node_kind = context.parse_tree().node_kind(
  25. context.node_stack().PeekParseNode())) {
  26. case Parse::NodeKind::VariableIntroducer:
  27. context.AddNodeAndPush(parse_node, SemIR::Node::VarStorage::Make(
  28. name_node, cast_type_id, name_id));
  29. break;
  30. case Parse::NodeKind::ParameterListStart:
  31. context.AddNodeAndPush(parse_node, SemIR::Node::Parameter::Make(
  32. name_node, cast_type_id, name_id));
  33. break;
  34. default:
  35. CARBON_FATAL() << "Found a pattern binding in unexpected context "
  36. << context_parse_node_kind;
  37. }
  38. return true;
  39. }
  40. auto HandleTemplate(Context& context, Parse::Node parse_node) -> bool {
  41. return context.TODO(parse_node, "HandleTemplate");
  42. }
  43. } // namespace Carbon::Check