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 {
12 namespace expression {
13 
20 class Deferred : public NodeBase, public trait::isExpression {
21 public:
22  Deferred(Expression e, Meta m = Meta()) : NodeBase(nodes(std::move(e), type::auto_), std::move(m)) {}
23  Deferred(Expression e, bool catch_exception, Meta m = Meta())
24  : NodeBase(nodes(e, type::auto_), m), _catch_exception(catch_exception) {}
25 
26  const auto& expression() const { return child<Expression>(0); }
27  bool catchException() const { return _catch_exception; }
28 
29  void setType(Type t) {
30  if ( _catch_exception )
31  children()[1] = type::Result(std::move(t));
32  else
33  children()[1] = std::move(t);
34  }
35 
36  bool operator==(const Deferred& other) const {
37  return expression() == other.expression() && _catch_exception == other._catch_exception;
38  }
39 
41  bool isLhs() const { return false; }
43  bool isTemporary() const { return true; }
45  const auto& type() const { return child<Type>(1); }
47  auto isConstant() const { return expression().isConstant(); }
49  auto isEqual(const Expression& other) const { return node::isEqual(this, other); }
50 
52  auto properties() const { return node::Properties{{"catch_exception", _catch_exception}}; }
53 
54 private:
55  bool _catch_exception;
56 };
57 
58 } // namespace expression
59 } // namespace hilti
const auto & children() const
Definition: node.h:470
bool isLhs() const
Definition: deferred.h:41
bool isTemporary() const
Definition: deferred.h:43
auto isConstant() const
Definition: deferred.h:47
Definition: expression.h:17
Definition: meta.h:18
Definition: type.h:159
auto isEqual(const Expression &other) const
Definition: deferred.h:49
const auto & type() const
Definition: deferred.h:45
std::map< std::string, node::detail::PropertyValue > Properties
Definition: node.h:99
auto properties() const
Definition: deferred.h:52
Definition: deferred.h:20
Definition: result.h:14
Definition: node.h:358