pattern.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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_PATTERN_H_
  5. #define CARBON_TOOLCHAIN_CHECK_PATTERN_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. // Information about a created binding pattern.
  24. struct BindingPatternInfo {
  25. SemIR::InstId pattern_id;
  26. SemIR::InstId bind_id;
  27. };
  28. // TODO: Add EndSubpatternAsPattern, when needed.
  29. // Creates a binding pattern. Returns the binding pattern and the bind name
  30. // instruction.
  31. auto AddBindingPattern(Context& context, SemIR::LocId name_loc,
  32. SemIR::NameId name_id, SemIR::TypeId type_id,
  33. SemIR::ExprRegionId type_region_id, bool is_generic,
  34. bool is_template) -> BindingPatternInfo;
  35. } // namespace Carbon::Check
  36. #endif // CARBON_TOOLCHAIN_CHECK_PATTERN_H_