handle_parameter_list.cpp 1.9 KB

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