Spicy
return.h
1 // Copyright (c) 2020-2021 by the Zeek Project. See LICENSE for details.
2 
3 #pragma once
4 
5 #include <utility>
6 
7 #include <hilti/ast/expression.h>
8 #include <hilti/ast/statement.h>
9 
10 namespace hilti {
11 namespace statement {
12 
14 class Return : public NodeBase, public hilti::trait::isStatement {
15 public:
16  Return(Meta m = Meta()) : NodeBase({}, std::move(m)) {}
17  Return(hilti::Expression e, Meta m = Meta()) : NodeBase({std::move(e)}, std::move(m)) {}
18 
19  std::optional<hilti::Expression> expression() const {
20  if ( ! childs().empty() )
21  return child<::hilti::Expression>(0);
22 
23  return {};
24  }
25 
26  bool operator==(const Return& other) const { return expression() == other.expression(); }
27 
29  auto isEqual(const Statement& other) const { return node::isEqual(this, other); }
30 
32  auto properties() const { return node::Properties{}; }
33 
41  static Statement setExpression(const Return& e, const hilti::Expression& c) {
42  auto x = Statement(e)._clone().as<Return>();
43  x.childs()[0] = c;
44  return x;
45  }
46 };
47 
48 } // namespace statement
49 } // namespace hilti
auto & childs() const
Definition: node.h:445
std::vector< T > childs(int begin, int end) const
Definition: node.h:373
auto isEqual(const Statement &other) const
Definition: return.h:29
Definition: meta.h:18
Definition: return.h:14
Definition: statement.h:14
std::map< std::string, node::detail::PropertyValue > Properties
Definition: node.h:83
auto properties() const
Definition: return.h:32
static Statement setExpression(const Return &e, const hilti::Expression &c)
Definition: return.h:41
Definition: node.h:318