declaration.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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/declaration.h"
  5. #include <iostream>
  6. namespace Carbon {
  7. void FunctionDeclaration::Print() const { PrintFunDef(definition); }
  8. void StructDeclaration::Print() const {
  9. std::cout << "struct " << *definition.name << " {" << std::endl;
  10. for (auto& member : *definition.members) {
  11. PrintMember(member);
  12. }
  13. std::cout << "}" << std::endl;
  14. }
  15. void ChoiceDeclaration::Print() const {
  16. std::cout << "choice " << name << " {" << std::endl;
  17. for (auto& alternative : alternatives) {
  18. std::cout << "alt " << alternative.first << " ";
  19. PrintExp(alternative.second);
  20. std::cout << ";" << std::endl;
  21. }
  22. std::cout << "}" << std::endl;
  23. }
  24. // Print a global variable declaration to standard out.
  25. void VariableDeclaration::Print() const {
  26. std::cout << "var ";
  27. PrintExp(type);
  28. std::cout << " : " << name << " = ";
  29. PrintExp(initializer);
  30. std::cout << std::endl;
  31. }
  32. } // namespace Carbon