function_definition.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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/pattern.h"
  9. #include "executable_semantics/ast/statement.h"
  10. #include "llvm/Support/Compiler.h"
  11. namespace Carbon {
  12. // TODO: expand the kinds of things that can be deduced parameters.
  13. // For now, only generic parameters are supported.
  14. struct GenericBinding {
  15. std::string name;
  16. const Expression* type;
  17. };
  18. struct FunctionDefinition {
  19. FunctionDefinition(int line_num, std::string name,
  20. std::vector<GenericBinding> deduced_params,
  21. const TuplePattern* param_pattern,
  22. const Pattern* return_type, bool is_omitted_return_type,
  23. const Statement* body)
  24. : line_num(line_num),
  25. name(std::move(name)),
  26. deduced_parameters(deduced_params),
  27. param_pattern(param_pattern),
  28. return_type(return_type),
  29. is_omitted_return_type(is_omitted_return_type),
  30. body(body) {}
  31. void Print(llvm::raw_ostream& out) const { PrintDepth(-1, out); }
  32. void PrintDepth(int depth, llvm::raw_ostream& out) const;
  33. LLVM_DUMP_METHOD void Dump() const { Print(llvm::errs()); }
  34. int line_num;
  35. std::string name;
  36. std::vector<GenericBinding> deduced_parameters;
  37. const TuplePattern* param_pattern;
  38. const Pattern* return_type;
  39. bool is_omitted_return_type;
  40. const Statement* body;
  41. };
  42. } // namespace Carbon
  43. #endif // EXECUTABLE_SEMANTICS_AST_FUNCTION_DEFINITION_H_