mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-29 08:14:57 +01:00
Move pattern interpretation to compile time (#904)
Co-authored-by: Jon Meow <46229924+jonmeow@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
co-authored by
Jon Meow
parent
629cfb8c4d
commit
79e3d284b4
@@ -60,6 +60,18 @@ class Pattern {
|
||||
// and after typechecking it's guaranteed to be true.
|
||||
auto has_static_type() const -> bool { return static_type_.has_value(); }
|
||||
|
||||
// The value of this pattern. Cannot be called before typechecking.
|
||||
auto value() const -> const Value& { return **value_; }
|
||||
|
||||
// Sets the value of this pattern. Can only be called once, during
|
||||
// typechecking.
|
||||
void set_value(Nonnull<const Value*> value) { value_ = value; }
|
||||
|
||||
// Returns whether the value has been set. Should only be called
|
||||
// during typechecking: before typechecking it's guaranteed to be false,
|
||||
// and after typechecking it's guaranteed to be true.
|
||||
auto has_value() const -> bool { return value_.has_value(); }
|
||||
|
||||
protected:
|
||||
// Constructs a Pattern representing syntax at the given line number.
|
||||
// `kind` must be the enumerator corresponding to the most-derived type being
|
||||
@@ -72,6 +84,7 @@ class Pattern {
|
||||
SourceLocation source_loc_;
|
||||
|
||||
std::optional<Nonnull<const Value*>> static_type_;
|
||||
std::optional<Nonnull<const Value*>> value_;
|
||||
};
|
||||
|
||||
// A pattern consisting of the `auto` keyword.
|
||||
|
||||
Reference in New Issue
Block a user