Spicy
vector.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/vector.h>
14 
15 namespace hilti::ctor {
16 
18 class Vector : public NodeBase, public hilti::trait::isCtor {
19 public:
20  Vector(const std::vector<Expression>& e, Meta m = Meta())
21  : NodeBase(nodes(type::Vector(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  Vector(const Type& t, std::vector<Expression> e, const Meta& m = Meta())
24  : NodeBase(nodes(type::Vector(t, m), std::move(e)), m) {}
25 
26  const auto& elementType() const { return children()[0].as<type::Vector>().elementType(); }
27  auto value() const { return children<Expression>(1, -1); }
28 
29  void setElementType(const Type& t) { children()[0] = type::Vector(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 Vector& other) const {
38  return elementType() == other.elementType() && value() == other.value();
39  }
40 
42  const auto& type() const { return child<Type>(0); }
44  bool isConstant() const { return false; }
46  auto isLhs() const { return false; }
48  auto isTemporary() const { return true; }
50  auto isEqual(const Ctor& other) const { return node::isEqual(this, other); }
52  auto properties() const { return node::Properties{}; }
53 };
54 
55 } // namespace hilti::ctor
const auto & children() const
Definition: node.h:471
Definition: meta.h:19
auto properties() const
Definition: vector.h:52
Definition: type.h:160
bool isConstant() const
Definition: vector.h:44
auto isEqual(const Ctor &other) const
Definition: vector.h:50
const auto & type() const
Definition: vector.h:42
Definition: vector.h:18
std::map< std::string, node::detail::PropertyValue > Properties
Definition: node.h:97
Definition: bool.h:12
Definition: ctor.h:15
Definition: vector.h:54
auto isTemporary() const
Definition: vector.h:48
auto & meta() const
Definition: node.h:475
auto isLhs() const
Definition: vector.h:46
Definition: node.h:359