handle_pattern_list.cpp 1.9 KB

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