function_definition.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. #ifndef EXECUTABLE_SEMANTICS_AST_FUNCTION_DEFINITION_H_
  5. #define EXECUTABLE_SEMANTICS_AST_FUNCTION_DEFINITION_H_
  6. #include "common/ostream.h"
  7. #include "executable_semantics/ast/expression.h"
  8. #include "executable_semantics/ast/statement.h"
  9. namespace Carbon {
  10. // TODO: expand the kinds of things that can be deduced parameters.
  11. // For now, only generic parameters are supported.
  12. struct GenericBinding {
  13. std::string name;
  14. const Expression* type;
  15. };
  16. struct FunctionDefinition {
  17. FunctionDefinition() = default;
  18. FunctionDefinition(int line_num, std::string name,
  19. std::vector<GenericBinding> deduced_params,
  20. const Expression* param_pattern,
  21. const Expression* return_type, const Statement* body)
  22. : line_num(line_num),
  23. name(std::move(name)),
  24. deduced_parameters(deduced_params),
  25. param_pattern(param_pattern),
  26. return_type(return_type),
  27. body(body) {}
  28. void Print(llvm::raw_ostream& out) const { PrintDepth(-1, out); }
  29. void PrintDepth(int depth, llvm::raw_ostream& out) const;
  30. int line_num;
  31. std::string name;
  32. std::vector<GenericBinding> deduced_parameters;
  33. const Expression* param_pattern;
  34. const Expression* return_type;
  35. const Statement* body;
  36. };
  37. } // namespace Carbon
  38. #endif // EXECUTABLE_SEMANTICS_AST_FUNCTION_DEFINITION_H_