Spicy
set.h
1 // Copyright (c) 2020-2021 by the Zeek Project. See LICENSE for details.
2 
3 #pragma once
4 
5 #include <utility>
6 #include <vector>
7 
8 #include <hilti/ast/builder/type.h>
9 #include <hilti/ast/ctor.h>
10 #include <hilti/ast/expression.h>
11 #include <hilti/ast/types/set.h>
12 #include <hilti/ast/types/unknown.h>
13 
14 namespace hilti {
15 namespace ctor {
16 
18 class Set : public NodeBase, public hilti::trait::isCtor {
19 public:
20  Set(const std::vector<Expression>& e, const Meta& m = Meta()) : NodeBase(nodes(node::none, e), m) {}
21  Set(Type t, std::vector<Expression> e, Meta m = Meta())
22  : NodeBase(nodes(std::move(t), std::move(e)), std::move(m)) {}
23 
24  auto elementType() const {
25  if ( auto t = childs()[0].tryAs<Type>() )
26  return type::effectiveType(*t);
27  else {
28  if ( childs().size() < 2 )
29  return type::unknown;
30 
31  return childs()[1].as<Expression>().type();
32  }
33  }
34 
35  auto value() const { return childs<Expression>(1, -1); }
36 
37  bool operator==(const Set& other) const { return elementType() == other.elementType() && value() == other.value(); }
38 
40  auto type() const { return type::Set(elementType(), meta()); }
42  bool isConstant() const { return false; }
44  auto isLhs() const { return false; }
46  auto isTemporary() const { return true; }
48  auto isEqual(const Ctor& other) const { return node::isEqual(this, other); }
50  auto properties() const { return node::Properties{}; }
51 };
52 
53 } // namespace ctor
54 } // namespace hilti
auto & childs() const
Definition: node.h:445
auto isEqual(const Ctor &other) const
Definition: set.h:48
auto isTemporary() const
Definition: set.h:46
const Node none
Definition: node.cc:12
auto properties() const
Definition: set.h:50
Definition: meta.h:18
Definition: set.h:18
Definition: set.h:56
std::map< std::string, node::detail::PropertyValue > Properties
Definition: node.h:83
auto isLhs() const
Definition: set.h:44
Definition: ctor.h:15
auto & meta() const
Definition: node.h:449
bool isConstant() const
Definition: set.h:42
auto type() const
Definition: set.h:40
Definition: node.h:318