function_definition.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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() = default;
  20. FunctionDefinition(int line_num, std::string name,
  21. std::vector<GenericBinding> deduced_params,
  22. const TuplePattern* param_pattern,
  23. const Pattern* return_type, bool is_omitted_return_type,
  24. const Statement* body)
  25. : line_num(line_num),
  26. name(std::move(name)),
  27. deduced_parameters(deduced_params),
  28. param_pattern(param_pattern),
  29. return_type(return_type),
  30. is_omitted_return_type(is_omitted_return_type),
  31. body(body) {}
  32. void Print(llvm::raw_ostream& out) const { PrintDepth(-1, out); }
  33. void PrintDepth(int depth, llvm::raw_ostream& out) const;
  34. LLVM_DUMP_METHOD void Dump() const { Print(llvm::errs()); }
  35. int line_num;
  36. std::string name;
  37. std::vector<GenericBinding> deduced_parameters;
  38. const TuplePattern* param_pattern;
  39. const Pattern* return_type;
  40. bool is_omitted_return_type;
  41. const Statement* body;
  42. };
  43. } // namespace Carbon
  44. #endif // EXECUTABLE_SEMANTICS_AST_FUNCTION_DEFINITION_H_