handle_pattern_list.cpp 2.1 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. namespace Carbon::Check {
  6. auto HandleImplicitParamListStart(Context& context,
  7. Parse::ImplicitParamListStartId parse_node)
  8. -> bool {
  9. context.PushScope();
  10. context.node_stack().Push(parse_node);
  11. context.ParamOrArgStart();
  12. return true;
  13. }
  14. auto HandleImplicitParamList(Context& context,
  15. Parse::ImplicitParamListId parse_node) -> bool {
  16. auto refs_id = context.ParamOrArgEnd(Parse::NodeKind::ImplicitParamListStart);
  17. context.node_stack()
  18. .PopAndDiscardSoloParseNode<Parse::NodeKind::ImplicitParamListStart>();
  19. context.node_stack().Push(parse_node, refs_id);
  20. // The implicit parameter list's scope extends to the end of the following
  21. // parameter list.
  22. return true;
  23. }
  24. auto HandleTuplePatternStart(Context& context,
  25. Parse::TuplePatternStartId parse_node) -> bool {
  26. // A tuple pattern following an implicit parameter list shares the same
  27. // scope.
  28. //
  29. // TODO: For a declaration like
  30. //
  31. // fn A(T:! type).B(U:! T).C(x: X(U)) { ... }
  32. //
  33. // ... all the earlier parameter should be in scope in the later parameter
  34. // lists too.
  35. if (!context.node_stack().PeekIs<Parse::NodeKind::ImplicitParamList>()) {
  36. context.PushScope();
  37. }
  38. context.node_stack().Push(parse_node);
  39. context.ParamOrArgStart();
  40. return true;
  41. }
  42. auto HandlePatternListComma(Context& context,
  43. Parse::PatternListCommaId /*parse_node*/) -> bool {
  44. context.ParamOrArgComma();
  45. return true;
  46. }
  47. auto HandleTuplePattern(Context& context, Parse::TuplePatternId parse_node)
  48. -> bool {
  49. auto refs_id = context.ParamOrArgEnd(Parse::NodeKind::TuplePatternStart);
  50. context.PopScope();
  51. context.node_stack()
  52. .PopAndDiscardSoloParseNode<Parse::NodeKind::TuplePatternStart>();
  53. context.node_stack().Push(parse_node, refs_id);
  54. return true;
  55. }
  56. } // namespace Carbon::Check