pattern_match.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637
  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_EXPLORER_INTERPRETER_PATTERN_MATCH_H_
  5. #define CARBON_EXPLORER_INTERPRETER_PATTERN_MATCH_H_
  6. #include <optional>
  7. #include "explorer/ast/bindings.h"
  8. #include "explorer/ast/value.h"
  9. #include "explorer/base/nonnull.h"
  10. #include "explorer/base/source_location.h"
  11. namespace Carbon {
  12. class RuntimeScope;
  13. class TraceStream;
  14. class Arena;
  15. // Attempts to match `v` against the pattern `p`, returning whether matching
  16. // is successful. If it is, populates **bindings with the variables bound by
  17. // the match; `bindings` should only be nullopt in contexts where `p`
  18. // is not permitted to bind variables. **bindings may be modified even if the
  19. // match is unsuccessful, so it should typically be created for the
  20. // PatternMatch call and then merged into an existing scope on success.
  21. // The matches for generic variables in the pattern are output in
  22. // `generic_args`.
  23. [[nodiscard]] auto PatternMatch(Nonnull<const Value*> p, ExpressionResult v,
  24. SourceLocation source_loc,
  25. std::optional<Nonnull<RuntimeScope*>> bindings,
  26. BindingMap& generic_args,
  27. Nonnull<TraceStream*> trace_stream,
  28. Nonnull<Arena*> arena) -> bool;
  29. } // namespace Carbon
  30. #endif // CARBON_EXPLORER_INTERPRETER_PATTERN_MATCH_H_