Start populating named entities in relevant locations. (#919)

This starts detecting naming collisions as a consequence of being able to determine when the name is declared twice in a given scope.



Co-authored-by: Geoff Romer <gromer@google.com>
This commit is contained in:
Jon Meow
2021-11-03 08:04:13 -07:00
committed by GitHub
co-authored by Geoff Romer
parent 82a870cfcd
commit 27e084d37a
25 changed files with 586 additions and 30 deletions
+10 -1
View File
@@ -12,6 +12,7 @@
#include "common/ostream.h"
#include "executable_semantics/ast/expression.h"
#include "executable_semantics/ast/source_location.h"
#include "executable_semantics/ast/static_scope.h"
#include "llvm/ADT/ArrayRef.h"
namespace Carbon {
@@ -100,7 +101,7 @@ class AutoPattern : public Pattern {
// A pattern that matches a value of a specified type, and optionally binds
// a name to it.
class BindingPattern : public Pattern {
class BindingPattern : public Pattern, public NamedEntityInterface {
public:
BindingPattern(SourceLocation source_loc, std::optional<std::string> name,
Nonnull<Pattern*> type)
@@ -108,6 +109,14 @@ class BindingPattern : public Pattern {
name_(std::move(name)),
type_(type) {}
auto named_entity_kind() const -> NamedEntityKind override {
return NamedEntityKind::BindingPattern;
}
auto source_loc() const -> SourceLocation override {
return Pattern::source_loc();
}
static auto classof(const Pattern* pattern) -> bool {
return pattern->kind() == Kind::BindingPattern;
}