forked from carbon-language/carbon-lang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpattern_match.h
37 lines (30 loc) · 1.52 KB
/
pattern_match.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#ifndef CARBON_EXPLORER_INTERPRETER_PATTERN_MATCH_H_
#define CARBON_EXPLORER_INTERPRETER_PATTERN_MATCH_H_
#include <optional>
#include "explorer/ast/bindings.h"
#include "explorer/ast/value.h"
#include "explorer/base/nonnull.h"
#include "explorer/base/source_location.h"
namespace Carbon {
class RuntimeScope;
class TraceStream;
class Arena;
// Attempts to match `v` against the pattern `p`, returning whether matching
// is successful. If it is, populates **bindings with the variables bound by
// the match; `bindings` should only be nullopt in contexts where `p`
// is not permitted to bind variables. **bindings may be modified even if the
// match is unsuccessful, so it should typically be created for the
// PatternMatch call and then merged into an existing scope on success.
// The matches for generic variables in the pattern are output in
// `generic_args`.
[[nodiscard]] auto PatternMatch(Nonnull<const Value*> p, ExpressionResult v,
SourceLocation source_loc,
std::optional<Nonnull<RuntimeScope*>> bindings,
BindingMap& generic_args,
Nonnull<TraceStream*> trace_stream,
Nonnull<Arena*> arena) -> bool;
} // namespace Carbon
#endif // CARBON_EXPLORER_INTERPRETER_PATTERN_MATCH_H_