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