function_definition.h 2.0 KB

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