subpattern.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334
  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. #ifndef CARBON_TOOLCHAIN_CHECK_SUBPATTERN_H_
  5. #define CARBON_TOOLCHAIN_CHECK_SUBPATTERN_H_
  6. #include "toolchain/check/context.h"
  7. #include "toolchain/sem_ir/ids.h"
  8. namespace Carbon::Check {
  9. // Marks the start of a region of insts in a pattern context that might
  10. // represent an expression or a pattern. Typically this is called when
  11. // handling a parse node that can immediately precede a subpattern (such
  12. // as `let` or a `,` in a pattern list), and the handler for the subpattern
  13. // node makes the matching `EndSubpatternAs*` call.
  14. auto BeginSubpattern(Context& context) -> void;
  15. // Ends a region started by BeginSubpattern (in stack order), treating it as
  16. // an expression with the given result, and returns the ID of the region. The
  17. // region will not yet have any control-flow edges into or out of it.
  18. auto EndSubpatternAsExpr(Context& context, SemIR::InstId result_id)
  19. -> SemIR::ExprRegionId;
  20. // Ends a region started by BeginSubpattern (in stack order), asserting that
  21. // it had no expression content.
  22. auto EndSubpatternAsNonExpr(Context& context) -> void;
  23. // TODO: Add EndSubpatternAsPattern, when needed.
  24. } // namespace Carbon::Check
  25. #endif // CARBON_TOOLCHAIN_CHECK_SUBPATTERN_H_