handle_param_list.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 HandleParamList(Context& context, Parse::NodeId parse_node) -> bool {
  24. auto refs_id = context.ParamOrArgEnd(Parse::NodeKind::ParamListStart);
  25. context.PopScope();
  26. context.node_stack()
  27. .PopAndDiscardSoloParseNode<Parse::NodeKind::ParamListStart>();
  28. context.node_stack().Push(parse_node, refs_id);
  29. return true;
  30. }
  31. auto HandleParamListComma(Context& context, Parse::NodeId /*parse_node*/)
  32. -> bool {
  33. context.ParamOrArgComma();
  34. return true;
  35. }
  36. auto HandleParamListStart(Context& context, Parse::NodeId parse_node) -> bool {
  37. // A parameter list following an implicit parameter list shares the same
  38. // scope.
  39. //
  40. // TODO: For a declaration like
  41. //
  42. // fn A(T:! type).B(U:! T).C(x: X(U)) { ... }
  43. //
  44. // ... all the earlier parameter should be in scope in the later parameter
  45. // lists too.
  46. if (!context.node_stack().PeekIs<Parse::NodeKind::ImplicitParamList>()) {
  47. context.PushScope();
  48. }
  49. context.node_stack().Push(parse_node);
  50. context.ParamOrArgStart();
  51. return true;
  52. }
  53. } // namespace Carbon::Check