mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-06 08:44:41 +01:00
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:
committed by
GitHub
co-authored by
Geoff Romer
parent
82a870cfcd
commit
27e084d37a
@@ -11,6 +11,7 @@
|
||||
#include "executable_semantics/ast/expression.h"
|
||||
#include "executable_semantics/ast/pattern.h"
|
||||
#include "executable_semantics/ast/source_location.h"
|
||||
#include "executable_semantics/ast/static_scope.h"
|
||||
#include "executable_semantics/common/arena.h"
|
||||
#include "llvm/ADT/ArrayRef.h"
|
||||
#include "llvm/Support/Compiler.h"
|
||||
@@ -18,6 +19,7 @@
|
||||
namespace Carbon {
|
||||
|
||||
class FunctionDeclaration;
|
||||
class StaticScope;
|
||||
|
||||
class Statement {
|
||||
public:
|
||||
@@ -75,8 +77,12 @@ class Block : public Statement {
|
||||
return statements_;
|
||||
}
|
||||
|
||||
auto static_scope() const -> const StaticScope& { return static_scope_; }
|
||||
auto static_scope() -> StaticScope& { return static_scope_; }
|
||||
|
||||
private:
|
||||
std::vector<Nonnull<Statement*>> statements_;
|
||||
StaticScope static_scope_;
|
||||
};
|
||||
|
||||
class ExpressionStatement : public Statement {
|
||||
@@ -293,9 +299,15 @@ class Match : public Statement {
|
||||
auto statement() const -> const Statement& { return *statement_; }
|
||||
auto statement() -> Statement& { return *statement_; }
|
||||
|
||||
// Contains names for the pattern and statement. Note that when the
|
||||
// statement is a block, it gains its own scope.
|
||||
auto static_scope() const -> const StaticScope& { return static_scope_; }
|
||||
auto static_scope() -> StaticScope& { return static_scope_; }
|
||||
|
||||
private:
|
||||
Nonnull<Pattern*> pattern_;
|
||||
Nonnull<Statement*> statement_;
|
||||
StaticScope static_scope_;
|
||||
};
|
||||
|
||||
Match(SourceLocation source_loc, Nonnull<Expression*> expression,
|
||||
@@ -323,7 +335,7 @@ class Match : public Statement {
|
||||
// __continuation <continuation_variable> {
|
||||
// <body>
|
||||
// }
|
||||
class Continuation : public Statement {
|
||||
class Continuation : public Statement, public NamedEntityInterface {
|
||||
public:
|
||||
Continuation(SourceLocation source_loc, std::string continuation_variable,
|
||||
Nonnull<Block*> body)
|
||||
@@ -331,6 +343,14 @@ class Continuation : public Statement {
|
||||
continuation_variable_(std::move(continuation_variable)),
|
||||
body_(body) {}
|
||||
|
||||
auto named_entity_kind() const -> NamedEntityKind override {
|
||||
return NamedEntityKind::Continuation;
|
||||
}
|
||||
|
||||
auto source_loc() const -> SourceLocation override {
|
||||
return Statement::source_loc();
|
||||
}
|
||||
|
||||
static auto classof(const Statement* stmt) -> bool {
|
||||
return stmt->kind() == Kind::Continuation;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user