mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 12:31:04 +01:00
Migrate Declaration to newer property style, class-ify ClassDefinition (#859)
This commit is contained in:
@@ -107,10 +107,10 @@ auto Interpreter::EvalPrim(Operator op,
|
||||
}
|
||||
|
||||
void Interpreter::InitEnv(const Declaration& d, Env* env) {
|
||||
switch (d.Tag()) {
|
||||
switch (d.kind()) {
|
||||
case Declaration::Kind::FunctionDeclaration: {
|
||||
const FunctionDefinition& func_def =
|
||||
cast<FunctionDeclaration>(d).Definition();
|
||||
cast<FunctionDeclaration>(d).definition();
|
||||
Env new_env = *env;
|
||||
// Bring the deduced parameters into scope.
|
||||
for (const auto& deduced : func_def.deduced_parameters()) {
|
||||
@@ -125,10 +125,10 @@ void Interpreter::InitEnv(const Declaration& d, Env* env) {
|
||||
}
|
||||
|
||||
case Declaration::Kind::ClassDeclaration: {
|
||||
const ClassDefinition& class_def = cast<ClassDeclaration>(d).Definition();
|
||||
const ClassDefinition& class_def = cast<ClassDeclaration>(d).definition();
|
||||
VarValues fields;
|
||||
VarValues methods;
|
||||
for (Nonnull<const Member*> m : class_def.members) {
|
||||
for (Nonnull<const Member*> m : class_def.members()) {
|
||||
switch (m->Tag()) {
|
||||
case Member::Kind::FieldMember: {
|
||||
Nonnull<const BindingPattern*> binding =
|
||||
@@ -141,23 +141,23 @@ void Interpreter::InitEnv(const Declaration& d, Env* env) {
|
||||
}
|
||||
}
|
||||
}
|
||||
auto st = arena->New<ClassType>(class_def.name, std::move(fields),
|
||||
auto st = arena->New<ClassType>(class_def.name(), std::move(fields),
|
||||
std::move(methods));
|
||||
auto a = heap.AllocateValue(st);
|
||||
env->Set(class_def.name, a);
|
||||
env->Set(class_def.name(), a);
|
||||
break;
|
||||
}
|
||||
|
||||
case Declaration::Kind::ChoiceDeclaration: {
|
||||
const auto& choice = cast<ChoiceDeclaration>(d);
|
||||
VarValues alts;
|
||||
for (const auto& alternative : choice.Alternatives()) {
|
||||
for (const auto& alternative : choice.alternatives()) {
|
||||
auto t = InterpExp(Env(arena), &alternative.signature());
|
||||
alts.push_back(make_pair(alternative.name(), t));
|
||||
}
|
||||
auto ct = arena->New<ChoiceType>(choice.Name(), std::move(alts));
|
||||
auto ct = arena->New<ChoiceType>(choice.name(), std::move(alts));
|
||||
auto a = heap.AllocateValue(ct);
|
||||
env->Set(choice.Name(), a);
|
||||
env->Set(choice.name(), a);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -165,9 +165,9 @@ void Interpreter::InitEnv(const Declaration& d, Env* env) {
|
||||
const auto& var = cast<VariableDeclaration>(d);
|
||||
// Adds an entry in `globals` mapping the variable's name to the
|
||||
// result of evaluating the initializer.
|
||||
auto v = InterpExp(*env, var.Initializer());
|
||||
auto v = InterpExp(*env, &var.initializer());
|
||||
Address a = heap.AllocateValue(v);
|
||||
env->Set(*var.Binding()->Name(), a);
|
||||
env->Set(*var.binding().Name(), a);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user