handle_pattern_binding.cpp 1.9 KB

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