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/auto.h>
12 #include <hilti/ast/types/error.h>
13 #include <hilti/ast/types/result.h>
14 
15 namespace hilti {
16 namespace ctor {
17 
19 class Result : public NodeBase, public hilti::trait::isCtor {
20 public:
21  Result(Expression v, Meta m = Meta()) : NodeBase(nodes(type::Result(type::auto_), std::move(v)), m) {}
22 
24  const auto& e = child<Expression>(1);
25 
26  if ( e.type() != type::Error() )
27  return e;
28 
29  return {};
30  }
31 
33  const auto& e = child<Expression>(1);
34 
35  if ( e.type() == type::Error() )
36  return e;
37 
38  return {};
39  }
40 
41  const Type& dereferencedType() const { return childs()[0].as<type::Result>().dereferencedType(); }
42 
43  void setDereferencedType(Type x) { childs()[0] = type::Result(std::move(x)); }
44 
46  const auto& type() const { return child<Type>(0); }
47 
49  bool isConstant() const {
50  if ( auto v = value() )
51  return v->isConstant();
52 
53  return true;
54  }
55 
56  bool operator==(const Result& other) const { return value() == other.value() && error() == other.error(); }
57 
59  auto isLhs() const { return false; }
61  auto isTemporary() const { return true; }
62 
64  auto isEqual(const Ctor& other) const { return node::isEqual(this, other); }
65 
67  auto properties() const { return node::Properties{}; }
68 };
69 
70 } // namespace ctor
71 } // namespace hilti
const auto & type() const
Definition: result.h:46
Definition: error.h:13
auto properties() const
Definition: result.h:67
Definition: meta.h:18
Definition: type.h:159
Definition: optional-ref.h:22
bool isConstant() const
Definition: result.h:49
std::map< std::string, node::detail::PropertyValue > Properties
Definition: node.h:99
auto isTemporary() const
Definition: result.h:61
auto isLhs() const
Definition: result.h:59
Definition: ctor.h:15
const auto & childs() const
Definition: node.h:470
auto isEqual(const Ctor &other) const
Definition: result.h:64
Definition: result.h:19
Definition: result.h:14
Definition: node.h:358