return.h 971 B

1234567891011121314151617181920212223242526272829303132
  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 CARBON_TOOLCHAIN_SEMANTICS_NODES_RETURN_H_
  5. #define CARBON_TOOLCHAIN_SEMANTICS_NODES_RETURN_H_
  6. #include "common/ostream.h"
  7. #include "toolchain/parser/parse_tree.h"
  8. #include "toolchain/semantics/meta_node.h"
  9. namespace Carbon::Semantics {
  10. // Represents `return [expr];`
  11. class Return {
  12. public:
  13. static constexpr StatementKind MetaNodeKind = StatementKind::Return;
  14. Return(ParseTree::Node node, llvm::Optional<Expression> expr)
  15. : node_(node), expr_(expr) {}
  16. auto node() const -> ParseTree::Node { return node_; }
  17. auto expression() const -> const llvm::Optional<Expression>& { return expr_; }
  18. private:
  19. ParseTree::Node node_;
  20. llvm::Optional<Expression> expr_;
  21. };
  22. } // namespace Carbon::Semantics
  23. #endif // CARBON_TOOLCHAIN_SEMANTICS_NODES_RETURN_H_