Files
carbon-lang/executable_semantics/ast/member.cpp
T
Jon Meow ada2be2d16 Switch Member to variant in anticipation of more kinds. (#656)
Note this overlaps a little with #644's Member changes, but not too badly.
2021-07-15 15:23:52 -07:00

35 lines
920 B
C++

// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#include "executable_semantics/ast/member.h"
#include <iostream>
namespace Carbon {
auto Member::MakeFieldMember(int line_num, std::string name,
const Expression* type) -> Member* {
auto m = new Member();
m->line_num = line_num;
m->value = FieldMember({.name = std::move(name), .type = type});
return m;
}
auto Member::GetFieldMember() const -> const FieldMember& {
return std::get<FieldMember>(value);
}
void Member::Print() {
switch (tag()) {
case MemberKind::FieldMember:
const auto& field = GetFieldMember();
std::cout << "var " << field.name << " : ";
PrintExp(field.type);
std::cout << ";" << std::endl;
break;
}
}
} // namespace Carbon