pattern_match.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. struct ParameterBlocks {
  10. // The implicit parameter list.
  11. SemIR::InstBlockId implicit_params_id;
  12. // The explicit parameter list.
  13. SemIR::InstBlockId params_id;
  14. };
  15. // TODO: Find a better place for this overview, once it has stabilized.
  16. //
  17. // The signature pattern of a function call is matched partially by the caller
  18. // and partially by the callee. `ParamPattern` insts mark the boundary
  19. // between the two: pattern insts that are descendants of a `ParamPattern`
  20. // are matched by the callee, and pattern insts that have a `ParamPattern`
  21. // as a descendant are matched by the caller.
  22. //
  23. // "Calling convention arguments" are the values actually passed from caller to
  24. // callee at the semantic IR level, and "calling convention parameters" are
  25. // the corresponding semantic placeholders that they bind to.
  26. // Emits the pattern-match IR for the declaration of a function with the
  27. // given implicit and explicit parameter patterns. This IR performs the callee
  28. // side of pattern matching, starting at the `ParamPattern` insts, and matching
  29. // them against the corresponding calling-convention parameters.
  30. auto CalleePatternMatch(Context& context,
  31. SemIR::InstBlockId implicit_param_patterns_id,
  32. SemIR::InstBlockId param_patterns_id)
  33. -> ParameterBlocks;
  34. // Emits the pattern-match IR for matching the given argument with the given
  35. // parameter pattern, and returns the inst representing the resulting
  36. // calling-convention argument. This IR performs the caller side of pattern
  37. // matching that argument.
  38. //
  39. // TODO: restructure to have this handle the entire signature.
  40. auto CallerPatternMatch(Context& context, SemIR::SpecificId specific_id,
  41. SemIR::InstId param, SemIR::InstId arg)
  42. -> SemIR::InstId;
  43. } // namespace Carbon::Check
  44. #endif // CARBON_TOOLCHAIN_CHECK_PATTERN_MATCH_H_