Add name accessor to NamedEntityView (#994)

This required changing BindingPattern::name() to return `"_"` instead of nullopt when representing a `"_"` binding.

Semi-related drive-by fixes:
- Update BindingPlaceholderValue to expose a NamedEntity instead of a string name, and stop exposing its type.
- Drop the unused SourceLocation parameter of ValueEqual
This commit is contained in:
Geoff Romer
2022-01-04 15:53:11 -08:00
committed by GitHub
parent 3f12316d6b
commit 50263483d8
13 changed files with 88 additions and 71 deletions
+6 -4
View File
@@ -101,7 +101,7 @@ class BindingPattern : public Pattern {
public:
using ImplementsCarbonNamedEntity = void;
BindingPattern(SourceLocation source_loc, std::optional<std::string> name,
BindingPattern(SourceLocation source_loc, std::string name,
Nonnull<Pattern*> type)
: Pattern(AstNodeKind::BindingPattern, source_loc),
name_(std::move(name)),
@@ -111,8 +111,10 @@ class BindingPattern : public Pattern {
return InheritsFromBindingPattern(node->kind());
}
// The name this pattern binds, if any.
auto name() const -> const std::optional<std::string>& { return name_; }
// The name this pattern binds, if any. If equal to AnonymousName, indicates
// that this BindingPattern does not bind a name, which in turn means it
// should not be used as a NamedEntity.
auto name() const -> const std::string& { return name_; }
// The pattern specifying the type of values that this pattern matches.
auto type() const -> const Pattern& { return *type_; }
@@ -121,7 +123,7 @@ class BindingPattern : public Pattern {
auto value_category() const -> ValueCategory { return ValueCategory::Var; }
private:
std::optional<std::string> name_;
std::string name_;
Nonnull<Pattern*> type_;
};