Merge ClassDefinition and ClassDeclaration (#940)

This commit is contained in:
Jon Meow
2021-11-09 15:24:22 -08:00
committed by GitHub
parent 73eea8e47a
commit e8d9b7675b
8 changed files with 34 additions and 84 deletions
+11 -5
View File
@@ -10,7 +10,6 @@
#include <vector>
#include "common/ostream.h"
#include "executable_semantics/ast/class_definition.h"
#include "executable_semantics/ast/member.h"
#include "executable_semantics/ast/pattern.h"
#include "executable_semantics/ast/source_location.h"
@@ -160,17 +159,24 @@ class ClassDeclaration : public Declaration {
ClassDeclaration(SourceLocation source_loc, std::string name,
std::vector<Nonnull<Member*>> members)
: Declaration(Kind::ClassDeclaration, source_loc),
definition_(source_loc, std::move(name), std::move(members)) {}
name_(std::move(name)),
members_(std::move(members)) {}
static auto classof(const Declaration* decl) -> bool {
return decl->kind() == Kind::ClassDeclaration;
}
auto definition() const -> const ClassDefinition& { return definition_; }
auto definition() -> ClassDefinition& { return definition_; }
auto name() const -> const std::string& { return name_; }
auto members() const -> llvm::ArrayRef<Nonnull<Member*>> { return members_; }
// Contains class members. Scoped variables are in the body.
auto static_scope() const -> const StaticScope& { return static_scope_; }
auto static_scope() -> StaticScope& { return static_scope_; }
private:
ClassDefinition definition_;
std::string name_;
std::vector<Nonnull<Member*>> members_;
StaticScope static_scope_;
};
class ChoiceDeclaration : public Declaration {