Spicy
result.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/ctor.h>
8 #include <hilti/ast/ctors/null.h>
9 #include <hilti/ast/expressions/ctor.h>
10 #include <hilti/ast/types/any.h>
11 #include <hilti/ast/types/error.h>
12 #include <hilti/ast/types/result.h>
13 
14 namespace hilti {
15 namespace ctor {
16 
18 class Result : public NodeBase, public hilti::trait::isCtor {
19 public:
20  Result(Expression v, Meta m = Meta()) : NodeBase({std::move(v)}, std::move(m)) {}
21 
22  std::optional<Expression> value() const {
23  auto e = child<Expression>(0);
24 
25  if ( e.type() != type::Error() )
26  return std::move(e);
27 
28  return {};
29  }
30 
31  std::optional<Expression> error() const {
32  auto e = child<Expression>(0);
33 
34  if ( e.type() == type::Error() )
35  return std::move(e);
36 
37  return {};
38  }
39 
40  std::optional<Type> dereferencedType() const {
41  if ( auto x = value() )
42  return x->type();
43 
44  return {};
45  }
46 
47  bool operator==(const Result& other) const { return value() == other.value() && error() == other.error(); }
48 
50  Type type() const {
51  if ( auto v = value() )
52  return type::Result(v->type(), meta());
53 
54  return type::Result(type::Any(), meta());
55  }
56 
58  bool isConstant() const {
59  if ( auto v = value() )
60  return v->isConstant();
61 
62  return true;
63  }
64 
66  auto isLhs() const { return false; }
68  auto isTemporary() const { return true; }
69 
71  auto isEqual(const Ctor& other) const { return node::isEqual(this, other); }
72 
74  auto properties() const { return node::Properties{}; }
75 };
76 
77 } // namespace ctor
78 } // namespace hilti
Definition: error.h:13
auto properties() const
Definition: result.h:74
Definition: meta.h:18
bool isConstant() const
Definition: result.h:58
Definition: any.h:13
std::map< std::string, node::detail::PropertyValue > Properties
Definition: node.h:83
auto isTemporary() const
Definition: result.h:68
auto isLhs() const
Definition: result.h:66
Type type() const
Definition: result.h:50
Definition: ctor.h:15
auto isEqual(const Ctor &other) const
Definition: result.h:71
Definition: result.h:18
auto & meta() const
Definition: node.h:449
Definition: result.h:13
Definition: node.h:318