function_definition.cpp 920 B

12345678910111213141516171819202122232425262728293031323334353637
  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/function_definition.h"
  5. namespace Carbon {
  6. void FunctionDefinition::PrintDepth(int depth, llvm::raw_ostream& out) const {
  7. out << "fn " << name_ << " ";
  8. if (!deduced_parameters_.empty()) {
  9. out << "[";
  10. unsigned int i = 0;
  11. for (const auto& deduced : deduced_parameters_) {
  12. if (i != 0) {
  13. out << ", ";
  14. }
  15. out << deduced.name << ":! ";
  16. deduced.type->Print(out);
  17. ++i;
  18. }
  19. out << "]";
  20. }
  21. out << *param_pattern_;
  22. if (!is_omitted_return_type_) {
  23. out << " -> " << *return_type_;
  24. }
  25. if (body_) {
  26. out << " {\n";
  27. (*body_)->PrintDepth(depth, out);
  28. out << "\n}\n";
  29. } else {
  30. out << ";\n";
  31. }
  32. }
  33. } // namespace Carbon