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::ctor {
16 
18 class Result : public NodeBase, public hilti::trait::isCtor {
19 public:
20  Result(Expression v, Meta m = Meta()) : NodeBase(nodes(type::Result(type::auto_), std::move(v)), std::move(m)) {}
21 
23  const auto& e = child<Expression>(1);
24 
25  if ( e.type() != type::Error() )
26  return e;
27 
28  return {};
29  }
30 
32  const auto& e = child<Expression>(1);
33 
34  if ( e.type() == type::Error() )
35  return e;
36 
37  return {};
38  }
39 
40  const Type& dereferencedType() const { return children()[0].as<type::Result>().dereferencedType(); }
41 
42  void setDereferencedType(Type x) { children()[0] = type::Result(std::move(x)); }
43 
45  const auto& type() const { return child<Type>(0); }
46 
48  bool isConstant() const {
49  if ( auto v = value() )
50  return v->isConstant();
51 
52  return true;
53  }
54 
55  bool operator==(const Result& other) const { return value() == other.value() && error() == other.error(); }
56 
58  auto isLhs() const { return false; }
60  auto isTemporary() const { return true; }
61 
63  auto isEqual(const Ctor& other) const { return node::isEqual(this, other); }
64 
66  auto properties() const { return node::Properties{}; }
67 };
68 
69 } // namespace hilti::ctor
const auto & type() const
Definition: result.h:45
Definition: error.h:12
const auto & children() const
Definition: node.h:471
auto properties() const
Definition: result.h:66
Definition: meta.h:19
Definition: type.h:160
Definition: optional-ref.h:22
bool isConstant() const
Definition: result.h:48
std::map< std::string, node::detail::PropertyValue > Properties
Definition: node.h:97
auto isTemporary() const
Definition: result.h:60
auto isLhs() const
Definition: result.h:58
Definition: ctor.h:15
auto isEqual(const Ctor &other) const
Definition: result.h:63
Definition: result.h:18
Definition: result.h:13
Definition: node.h:359