Spicy
tuple.h
1 // Copyright (c) 2020-2021 by the Zeek Project. See LICENSE for details.
2 
3 #pragma once
4 
5 #include <algorithm>
6 #include <utility>
7 #include <vector>
8 
9 #include <hilti/ast/ctor.h>
10 #include <hilti/ast/expression.h>
11 #include <hilti/ast/types/tuple.h>
12 #include <hilti/ast/types/unknown.h>
13 
14 namespace hilti {
15 namespace ctor {
16 
18 class Tuple : public NodeBase, public hilti::trait::isCtor {
19 public:
20  Tuple(std::vector<Expression> v, Meta m = Meta()) : NodeBase(nodes(std::move(v)), std::move(m)) {}
21 
22  auto value() const { return childs<Expression>(0, -1); }
23 
24  bool operator==(const Tuple& other) const { return value() == other.value(); }
25 
27  Type type() const {
28  auto v1 = value();
29  auto v2 = std::vector<Type>{};
30  bool is_unknown = false;
31  std::transform(v1.begin(), v1.end(), std::back_inserter(v2), [&is_unknown](const Expression& e) {
32  if ( e.type() == type::unknown )
33  is_unknown = true;
34 
35  return e.type();
36  });
37 
38  if ( is_unknown )
39  return type::unknown;
40  else
41  return type::Tuple(v2, meta());
42  }
43 
45  bool isConstant() const { return true; }
46 
48  auto isLhs() const {
49  if ( value().empty() )
50  return false;
51 
52  for ( const auto& e : value() ) {
53  if ( ! e.isLhs() )
54  return false;
55  }
56 
57  return true;
58  }
59 
61  auto isTemporary() const { return true; }
63  auto isEqual(const Ctor& other) const { return node::isEqual(this, other); }
65  auto properties() const { return node::Properties{}; }
66 };
67 
68 } // namespace ctor
69 } // namespace hilti
Type type() const
Definition: tuple.h:27
auto isLhs() const
Definition: tuple.h:48
Definition: meta.h:18
auto isTemporary() const
Definition: tuple.h:61
auto properties() const
Definition: tuple.h:65
std::map< std::string, node::detail::PropertyValue > Properties
Definition: node.h:83
bool isConstant() const
Definition: tuple.h:45
Definition: ctor.h:15
Definition: tuple.h:15
auto isEqual(const Ctor &other) const
Definition: tuple.h:63
auto & meta() const
Definition: node.h:449
Definition: tuple.h:18
Definition: node.h:318