mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 13:31:06 +01:00
Use resolved names in typechecker (#974)
As a byproduct, replace NamedEntity with a type-erasing wrapper NamedEntityView, eliminate virtual inheritance from the AST, and eliminate interfaces from gen_rtti.
This commit is contained in:
@@ -29,7 +29,7 @@ namespace Carbon {
|
||||
// every concrete derived class must have a corresponding enumerator
|
||||
// in `Kind`; see https://llvm.org/docs/HowToSetUpLLVMStyleRTTI.html for
|
||||
// details.
|
||||
class Declaration : public virtual AstNode {
|
||||
class Declaration : public AstNode {
|
||||
public:
|
||||
~Declaration() override = 0;
|
||||
|
||||
@@ -65,7 +65,8 @@ class Declaration : public virtual AstNode {
|
||||
// Constructs a Declaration representing syntax at the given line number.
|
||||
// `kind` must be the enumerator corresponding to the most-derived type being
|
||||
// constructed.
|
||||
Declaration() = default;
|
||||
Declaration(AstNodeKind kind, SourceLocation source_loc)
|
||||
: AstNode(kind, source_loc) {}
|
||||
|
||||
private:
|
||||
std::optional<Nonnull<const Value*>> static_type_;
|
||||
@@ -73,8 +74,10 @@ class Declaration : public virtual AstNode {
|
||||
|
||||
// TODO: expand the kinds of things that can be deduced parameters.
|
||||
// For now, only generic parameters are supported.
|
||||
struct GenericBinding : public virtual AstNode, public NamedEntity {
|
||||
class GenericBinding : public AstNode {
|
||||
public:
|
||||
using ImplementsCarbonNamedEntity = void;
|
||||
|
||||
GenericBinding(SourceLocation source_loc, std::string name,
|
||||
Nonnull<Expression*> type)
|
||||
: AstNode(AstNodeKind::GenericBinding, source_loc),
|
||||
@@ -188,14 +191,16 @@ class ReturnTerm {
|
||||
SourceLocation source_loc_;
|
||||
};
|
||||
|
||||
class FunctionDeclaration : public Declaration, public NamedEntity {
|
||||
class FunctionDeclaration : public Declaration {
|
||||
public:
|
||||
using ImplementsCarbonNamedEntity = void;
|
||||
|
||||
FunctionDeclaration(SourceLocation source_loc, std::string name,
|
||||
std::vector<Nonnull<GenericBinding*>> deduced_params,
|
||||
Nonnull<TuplePattern*> param_pattern,
|
||||
ReturnTerm return_term,
|
||||
std::optional<Nonnull<Block*>> body)
|
||||
: AstNode(AstNodeKind::FunctionDeclaration, source_loc),
|
||||
: Declaration(AstNodeKind::FunctionDeclaration, source_loc),
|
||||
name_(std::move(name)),
|
||||
deduced_parameters_(std::move(deduced_params)),
|
||||
param_pattern_(param_pattern),
|
||||
@@ -231,11 +236,13 @@ class FunctionDeclaration : public Declaration, public NamedEntity {
|
||||
std::optional<Nonnull<Block*>> body_;
|
||||
};
|
||||
|
||||
class ClassDeclaration : public Declaration, public NamedEntity {
|
||||
class ClassDeclaration : public Declaration {
|
||||
public:
|
||||
using ImplementsCarbonNamedEntity = void;
|
||||
|
||||
ClassDeclaration(SourceLocation source_loc, std::string name,
|
||||
std::vector<Nonnull<Member*>> members)
|
||||
: AstNode(AstNodeKind::ClassDeclaration, source_loc),
|
||||
: Declaration(AstNodeKind::ClassDeclaration, source_loc),
|
||||
name_(std::move(name)),
|
||||
members_(std::move(members)) {}
|
||||
|
||||
@@ -251,7 +258,7 @@ class ClassDeclaration : public Declaration, public NamedEntity {
|
||||
std::vector<Nonnull<Member*>> members_;
|
||||
};
|
||||
|
||||
class AlternativeSignature : public virtual AstNode {
|
||||
class AlternativeSignature : public AstNode {
|
||||
public:
|
||||
AlternativeSignature(SourceLocation source_loc, std::string name,
|
||||
Nonnull<Expression*> signature)
|
||||
@@ -274,11 +281,13 @@ class AlternativeSignature : public virtual AstNode {
|
||||
Nonnull<Expression*> signature_;
|
||||
};
|
||||
|
||||
class ChoiceDeclaration : public Declaration, public NamedEntity {
|
||||
class ChoiceDeclaration : public Declaration {
|
||||
public:
|
||||
using ImplementsCarbonNamedEntity = void;
|
||||
|
||||
ChoiceDeclaration(SourceLocation source_loc, std::string name,
|
||||
std::vector<Nonnull<AlternativeSignature*>> alternatives)
|
||||
: AstNode(AstNodeKind::ChoiceDeclaration, source_loc),
|
||||
: Declaration(AstNodeKind::ChoiceDeclaration, source_loc),
|
||||
name_(std::move(name)),
|
||||
alternatives_(std::move(alternatives)) {}
|
||||
|
||||
@@ -306,7 +315,7 @@ class VariableDeclaration : public Declaration {
|
||||
VariableDeclaration(SourceLocation source_loc,
|
||||
Nonnull<BindingPattern*> binding,
|
||||
Nonnull<Expression*> initializer)
|
||||
: AstNode(AstNodeKind::VariableDeclaration, source_loc),
|
||||
: Declaration(AstNodeKind::VariableDeclaration, source_loc),
|
||||
binding_(binding),
|
||||
initializer_(initializer) {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user