Spicy
deferred.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/types/auto.h>
9 #include <hilti/ast/types/result.h>
10 
11 namespace hilti::expression {
12 
19 class Deferred : public NodeBase, public trait::isExpression {
20 public:
21  Deferred(Expression e, Meta m = Meta()) : NodeBase(nodes(std::move(e), type::auto_), std::move(m)) {}
22  Deferred(Expression e, bool catch_exception, Meta m = Meta())
23  : NodeBase(nodes(std::move(e), type::auto_), std::move(m)), _catch_exception(catch_exception) {}
24 
25  const auto& expression() const { return child<Expression>(0); }
26  bool catchException() const { return _catch_exception; }
27 
28  void setType(Type t) {
29  if ( _catch_exception )
30  children()[1] = type::Result(std::move(t));
31  else
32  children()[1] = t;
33  }
34 
35  bool operator==(const Deferred& other) const {
36  return expression() == other.expression() && _catch_exception == other._catch_exception;
37  }
38 
40  bool isLhs() const { return false; }
42  bool isTemporary() const { return true; }
44  const auto& type() const { return child<Type>(1); }
46  auto isConstant() const { return expression().isConstant(); }
48  auto isEqual(const Expression& other) const { return node::isEqual(this, other); }
49 
51  auto properties() const { return node::Properties{{"catch_exception", _catch_exception}}; }
52 
53 private:
54  bool _catch_exception;
55 };
56 
57 } // namespace hilti::expression
const auto & children() const
Definition: node.h:472
bool isLhs() const
Definition: deferred.h:40
bool isTemporary() const
Definition: deferred.h:42
auto isConstant() const
Definition: deferred.h:46
Definition: expression.h:18
Definition: meta.h:19
Definition: type.h:160
auto isEqual(const Expression &other) const
Definition: deferred.h:48
const auto & type() const
Definition: deferred.h:44
std::map< std::string, node::detail::PropertyValue > Properties
Definition: node.h:98
auto properties() const
Definition: deferred.h:51
Definition: deferred.h:19
Definition: result.h:13
Definition: node.h:360
Definition: expression.h:21