mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 21:51:12 +01:00
Switch Member to variant in anticipation of more kinds. (#656)
Note this overlaps a little with #644's Member changes, but not too badly.
This commit is contained in:
@@ -300,12 +300,12 @@ auto ChoiceDeclaration::InitGlobals(Env& globals) const -> void {
|
||||
auto StructDeclaration::InitGlobals(Env& globals) const -> void {
|
||||
VarValues fields;
|
||||
VarValues methods;
|
||||
for (auto i = definition.members->begin(); i != definition.members->end();
|
||||
++i) {
|
||||
switch ((*i)->tag) {
|
||||
for (Member* m : *definition.members) {
|
||||
switch (m->tag()) {
|
||||
case MemberKind::FieldMember: {
|
||||
auto t = InterpExp(Env(), (*i)->u.field.type);
|
||||
fields.push_back(make_pair(*(*i)->u.field.name, t));
|
||||
const auto& field = m->GetFieldMember();
|
||||
auto t = InterpExp(Env(), field.type);
|
||||
fields.push_back({field.name, t});
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -681,10 +681,13 @@ auto TypeOfStructDef(const StructDefinition* sd, TypeEnv /*types*/, Env ct_top)
|
||||
-> const Value* {
|
||||
VarValues fields;
|
||||
VarValues methods;
|
||||
for (auto m = sd->members->begin(); m != sd->members->end(); ++m) {
|
||||
if ((*m)->tag == MemberKind::FieldMember) {
|
||||
auto t = InterpExp(ct_top, (*m)->u.field.type);
|
||||
fields.push_back(std::make_pair(*(*m)->u.field.name, t));
|
||||
for (Member* m : *sd->members) {
|
||||
switch (m->tag()) {
|
||||
case MemberKind::FieldMember:
|
||||
const auto& field = m->GetFieldMember();
|
||||
auto t = InterpExp(ct_top, field.type);
|
||||
fields.push_back(std::make_pair(field.name, t));
|
||||
break;
|
||||
}
|
||||
}
|
||||
return Value::MakeStructType(*sd->name, std::move(fields),
|
||||
@@ -705,10 +708,12 @@ auto VariableDeclaration::Name() const -> std::string { return name; }
|
||||
auto StructDeclaration::TypeChecked(TypeEnv types, Env values) const
|
||||
-> Declaration {
|
||||
auto fields = new std::list<Member*>();
|
||||
for (auto& m : *definition.members) {
|
||||
if (m->tag == MemberKind::FieldMember) {
|
||||
// TODO: Interpret the type expression and store the result.
|
||||
fields->push_back(m);
|
||||
for (Member* m : *definition.members) {
|
||||
switch (m->tag()) {
|
||||
case MemberKind::FieldMember:
|
||||
// TODO: Interpret the type expression and store the result.
|
||||
fields->push_back(m);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return StructDeclaration(definition.line_num, *definition.name, fields);
|
||||
|
||||
Reference in New Issue
Block a user