mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 22:02:52 +01:00
@@ -14,10 +14,10 @@ cc_library(
|
||||
"declaration.h",
|
||||
],
|
||||
deps = [
|
||||
":class_definition",
|
||||
":function_definition",
|
||||
":member",
|
||||
":pattern",
|
||||
":struct_definition",
|
||||
"//common:ostream",
|
||||
"//executable_semantics/common:ptr",
|
||||
"@llvm-project//llvm:Support",
|
||||
@@ -115,8 +115,8 @@ cc_library(
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "struct_definition",
|
||||
hdrs = ["struct_definition.h"],
|
||||
name = "class_definition",
|
||||
hdrs = ["class_definition.h"],
|
||||
deps = [
|
||||
":member",
|
||||
"//common:ostream",
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@
|
||||
|
||||
namespace Carbon {
|
||||
|
||||
struct StructDefinition {
|
||||
struct ClassDefinition {
|
||||
int line_num;
|
||||
std::string name;
|
||||
std::list<Member*> members;
|
||||
@@ -16,11 +16,11 @@ void Declaration::Print(llvm::raw_ostream& out) const {
|
||||
out << cast<FunctionDeclaration>(*this).Definition();
|
||||
break;
|
||||
|
||||
case Kind::StructDeclaration: {
|
||||
const StructDefinition& struct_def =
|
||||
cast<StructDeclaration>(*this).Definition();
|
||||
out << "struct " << struct_def.name << " {\n";
|
||||
for (Member* m : struct_def.members) {
|
||||
case Kind::ClassDeclaration: {
|
||||
const ClassDefinition& class_def =
|
||||
cast<ClassDeclaration>(*this).Definition();
|
||||
out << "class " << class_def.name << " {\n";
|
||||
for (Member* m : class_def.members) {
|
||||
out << *m;
|
||||
}
|
||||
out << "}\n";
|
||||
|
||||
@@ -9,10 +9,10 @@
|
||||
#include <string>
|
||||
|
||||
#include "common/ostream.h"
|
||||
#include "executable_semantics/ast/class_definition.h"
|
||||
#include "executable_semantics/ast/function_definition.h"
|
||||
#include "executable_semantics/ast/member.h"
|
||||
#include "executable_semantics/ast/pattern.h"
|
||||
#include "executable_semantics/ast/struct_definition.h"
|
||||
#include "llvm/Support/Compiler.h"
|
||||
|
||||
namespace Carbon {
|
||||
@@ -29,7 +29,7 @@ class Declaration {
|
||||
public:
|
||||
enum class Kind {
|
||||
FunctionDeclaration,
|
||||
StructDeclaration,
|
||||
ClassDeclaration,
|
||||
ChoiceDeclaration,
|
||||
VariableDeclaration,
|
||||
};
|
||||
@@ -72,22 +72,22 @@ class FunctionDeclaration : public Declaration {
|
||||
const FunctionDefinition* definition;
|
||||
};
|
||||
|
||||
class StructDeclaration : public Declaration {
|
||||
class ClassDeclaration : public Declaration {
|
||||
public:
|
||||
StructDeclaration(int line_num, std::string name, std::list<Member*> members)
|
||||
: Declaration(Kind::StructDeclaration, line_num),
|
||||
ClassDeclaration(int line_num, std::string name, std::list<Member*> members)
|
||||
: Declaration(Kind::ClassDeclaration, line_num),
|
||||
definition({.line_num = line_num,
|
||||
.name = std::move(name),
|
||||
.members = std::move(members)}) {}
|
||||
|
||||
static auto classof(const Declaration* decl) -> bool {
|
||||
return decl->Tag() == Kind::StructDeclaration;
|
||||
return decl->Tag() == Kind::ClassDeclaration;
|
||||
}
|
||||
|
||||
auto Definition() const -> const StructDefinition& { return definition; }
|
||||
auto Definition() const -> const ClassDefinition& { return definition; }
|
||||
|
||||
private:
|
||||
StructDefinition definition;
|
||||
ClassDefinition definition;
|
||||
};
|
||||
|
||||
class ChoiceDeclaration : public Declaration {
|
||||
|
||||
Reference in New Issue
Block a user