member.cpp 793 B

123456789101112131415161718192021222324252627282930
  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, Expression* type) -> Member* {
  8. auto m = new Member();
  9. m->line_num = line_num;
  10. m->tag = MemberKind::FieldMember;
  11. m->u.field.name = new std::string(std::move(name));
  12. m->u.field.type = type;
  13. return m;
  14. }
  15. void PrintMember(Member* m) {
  16. switch (m->tag) {
  17. case MemberKind::FieldMember:
  18. std::cout << "var " << *m->u.field.name << " : ";
  19. PrintExp(m->u.field.type);
  20. std::cout << ";" << std::endl;
  21. break;
  22. }
  23. }
  24. } // namespace Carbon