pattern_match.h 2.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. #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 IDs of inst blocks consisting of references to the `Call`
  23. // parameter patterns and `Call` parameters of the function.
  24. struct CalleePatternMatchResults {
  25. SemIR::InstBlockId call_param_patterns_id;
  26. SemIR::InstBlockId call_params_id;
  27. };
  28. auto CalleePatternMatch(Context& context,
  29. SemIR::InstBlockId implicit_param_patterns_id,
  30. SemIR::InstBlockId param_patterns_id,
  31. SemIR::InstBlockId return_patterns_id)
  32. -> CalleePatternMatchResults;
  33. // Emits the pattern-match IR for matching the given arguments with the given
  34. // parameter patterns, and returns an inst block of the arguments that should
  35. // be passed to the `Call` inst. `is_operator_syntax` indicates that this call
  36. // was generated from an operator rather than from function call syntax, so
  37. // arguments to `ref` parameters aren't required to have `ref` tags.
  38. auto CallerPatternMatch(Context& context, SemIR::SpecificId specific_id,
  39. SemIR::InstId self_pattern_id,
  40. SemIR::InstBlockId param_patterns_id,
  41. SemIR::InstBlockId return_patterns_id,
  42. SemIR::InstId self_arg_id,
  43. llvm::ArrayRef<SemIR::InstId> arg_refs,
  44. llvm::ArrayRef<SemIR::InstId> return_arg_ids,
  45. bool is_operator_syntax) -> SemIR::InstBlockId;
  46. // Emits the pattern-match IR for a local pattern matching operation with the
  47. // given pattern and scrutinee.
  48. auto LocalPatternMatch(Context& context, SemIR::InstId pattern_id,
  49. SemIR::InstId scrutinee_id) -> void;
  50. } // namespace Carbon::Check
  51. #endif // CARBON_TOOLCHAIN_CHECK_PATTERN_MATCH_H_