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/auto.h>
12 #include <hilti/ast/types/bool.h>
13 #include <hilti/ast/types/set.h>
14 
15 namespace hilti::ctor {
16 
18 class Set : public NodeBase, public hilti::trait::isCtor {
19 public:
20  Set(const std::vector<Expression>& e, Meta m = Meta())
21  : NodeBase(nodes(type::Set(e.size() ? Type(type::auto_) : Type(type::Bool())), e), std::move(m)) {
22  } // Bool is just an arbitrary place-holder type for empty values
23  Set(const Type& t, std::vector<Expression> e, const Meta& m = Meta())
24  : NodeBase(nodes(type::Set(t, m), std::move(e)), m) {}
25 
26  const auto& elementType() const { return children()[0].as<type::Set>().elementType(); }
27  auto value() const { return children<Expression>(1, -1); }
28 
29  void setElementType(const Type& t) { children()[0] = type::Set(t, meta()); }
30 
31  void setValue(const std::vector<Expression>& elems) {
32  children().erase(children().begin() + 1, children().end());
33  for ( auto&& e : elems )
34  children().emplace_back(e);
35  }
36 
37  bool operator==(const Set& other) const { return elementType() == other.elementType() && value() == other.value(); }
38 
40  const auto& type() const { return child<Type>(0); }
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 hilti::ctor
auto isEqual(const Ctor &other) const
Definition: set.h:48
auto isTemporary() const
Definition: set.h:46
auto properties() const
Definition: set.h:50
const auto & children() const
Definition: node.h:471
Definition: meta.h:19
Definition: type.h:160
Definition: set.h:18
Definition: set.h:54
std::map< std::string, node::detail::PropertyValue > Properties
Definition: node.h:97
auto isLhs() const
Definition: set.h:44
Definition: bool.h:12
const auto & type() const
Definition: set.h:40
Definition: ctor.h:15
auto & meta() const
Definition: node.h:475
bool isConstant() const
Definition: set.h:42
Definition: node.h:359