function_definition.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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, 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. body(body) {}
  30. void Print(llvm::raw_ostream& out) const { PrintDepth(-1, out); }
  31. void PrintDepth(int depth, llvm::raw_ostream& out) const;
  32. LLVM_DUMP_METHOD void Dump() const { Print(llvm::errs()); }
  33. int line_num;
  34. std::string name;
  35. std::vector<GenericBinding> deduced_parameters;
  36. const TuplePattern* param_pattern;
  37. const Pattern* return_type;
  38. const Statement* body;
  39. };
  40. } // namespace Carbon
  41. #endif // EXECUTABLE_SEMANTICS_AST_FUNCTION_DEFINITION_H_