member.cpp 803 B

12345678910111213141516171819202122232425262728293031
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. #include "executable_semantics/ast/member.h"
  5. #include <iostream>
  6. namespace Carbon {
  7. auto MakeField(int line_num, std::string name, const Expression* type)
  8. -> Member* {
  9. auto m = new Member();
  10. m->line_num = line_num;
  11. m->tag = MemberKind::FieldMember;
  12. m->u.field.name = new std::string(std::move(name));
  13. m->u.field.type = type;
  14. return m;
  15. }
  16. void PrintMember(Member* m) {
  17. switch (m->tag) {
  18. case MemberKind::FieldMember:
  19. std::cout << "var " << *m->u.field.name << " : ";
  20. PrintExp(m->u.field.type);
  21. std::cout << ";" << std::endl;
  22. break;
  23. }
  24. }
  25. } // namespace Carbon