pattern_match.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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_MATCH_H_
  5. #define CARBON_TOOLCHAIN_CHECK_PATTERN_MATCH_H_
  6. #include "toolchain/check/context.h"
  7. #include "toolchain/sem_ir/ids.h"
  8. namespace Carbon::Check {
  9. // TODO: Find a better place for this overview, once it has stabilized.
  10. //
  11. // The signature pattern of a function call is matched partially by the caller
  12. // and partially by the callee. `ParamPattern` insts mark the boundary
  13. // between the two: pattern insts that are descendants of a `ParamPattern`
  14. // are matched by the callee, and pattern insts that have a `ParamPattern`
  15. // as a descendant are matched by the caller.
  16. // Emits the pattern-match IR for the declaration of a parameterized entity with
  17. // the given implicit and explicit parameter patterns, and the given return
  18. // patterns (any of which may be `None` if not applicable). This IR performs the
  19. // callee side of pattern matching, starting at the `ParamPattern` insts, and
  20. // matching them against the corresponding `Call` parameters (see
  21. // entity_with_params_base.h for the definition of that term).
  22. // Returns the ID of an inst block consisting of references to the `Call`
  23. // parameters of the function.
  24. auto CalleePatternMatch(Context& context,
  25. SemIR::InstBlockId implicit_param_patterns_id,
  26. SemIR::InstBlockId param_patterns_id,
  27. SemIR::InstBlockId return_patterns_id)
  28. -> SemIR::InstBlockId;
  29. // Emits the pattern-match IR for matching the given arguments with the given
  30. // parameter patterns, and returns an inst block of the arguments that should
  31. // be passed to the `Call` inst. `is_operator_syntax` indicates that this call
  32. // was generated from an operator rather than from function call syntax, so
  33. // arguments to `ref` parameters aren't required to have `ref` tags.
  34. auto CallerPatternMatch(Context& context, SemIR::SpecificId specific_id,
  35. SemIR::InstId self_pattern_id,
  36. SemIR::InstBlockId param_patterns_id,
  37. SemIR::InstBlockId return_patterns_id,
  38. SemIR::InstId self_arg_id,
  39. llvm::ArrayRef<SemIR::InstId> arg_refs,
  40. llvm::ArrayRef<SemIR::InstId> return_arg_ids,
  41. bool is_operator_syntax) -> SemIR::InstBlockId;
  42. // Emits the pattern-match IR for a local pattern matching operation with the
  43. // given pattern and scrutinee.
  44. auto LocalPatternMatch(Context& context, SemIR::InstId pattern_id,
  45. SemIR::InstId scrutinee_id) -> void;
  46. } // namespace Carbon::Check
  47. #endif // CARBON_TOOLCHAIN_CHECK_PATTERN_MATCH_H_