Spicy
list.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/list.h>
12 #include <hilti/ast/types/unknown.h>
13 
14 namespace hilti {
15 namespace ctor {
16 
18 class List : public NodeBase, public hilti::trait::isCtor {
19 public:
20  List(std::vector<Expression> e, Meta m = Meta()) : NodeBase(nodes(node::none, e), m) {}
21  List(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 List& other) const {
38  return elementType() == other.elementType() && value() == other.value();
39  }
40 
42  auto type() const { return type::List(elementType(), meta()); }
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 ctor
56 } // namespace hilti
auto & childs() const
Definition: node.h:445
Definition: list.h:18
auto isLhs() const
Definition: list.h:46
const Node none
Definition: node.cc:12
bool isConstant() const
Definition: list.h:44
Definition: meta.h:18
Definition: list.h:52
auto isEqual(const Ctor &other) const
Definition: list.h:50
std::map< std::string, node::detail::PropertyValue > Properties
Definition: node.h:83
Definition: ctor.h:15
auto isTemporary() const
Definition: list.h:48
auto & meta() const
Definition: node.h:449
auto properties() const
Definition: list.h:52
auto type() const
Definition: list.h:42
Definition: node.h:318