Spicy
ternary.h
1 // Copyright (c) 2020-2021 by the Zeek Project. See LICENSE for details.
2 
3 #pragma once
4 
5 #include <utility>
6 
7 #include <hilti/ast/expression.h>
8 
9 namespace hilti {
10 namespace expression {
11 
13 class Ternary : public NodeBase, public trait::isExpression {
14 public:
15  Ternary(Expression cond, Expression true_, Expression false_, Meta m = Meta())
16  : NodeBase({std::move(cond), std::move(true_), std::move(false_)}, std::move(m)) {}
17 
18  const auto& condition() const { return child<Expression>(0); }
19  const auto& true_() const { return child<Expression>(1); }
20  const auto& false_() const { return child<Expression>(2); }
21 
22  bool operator==(const Ternary& other) const {
23  return condition() == other.condition() && true_() == other.true_() && false_() == other.false_();
24  }
25 
27  bool isLhs() const { return false; }
29  bool isTemporary() const { return true_().isTemporary() || false_().isTemporary(); }
31  const Type& type() const {
32  return true_().type();
33  } // TODO(robin): Currentluy we enforce both having the same type; we might need to coerce to target type though
35  auto isConstant() const { return false; }
37  auto isEqual(const Expression& other) const { return node::isEqual(this, other); }
38 
40  auto properties() const { return node::Properties{}; }
41 };
42 
43 } // namespace expression
44 } // namespace hilti
auto isEqual(const Expression &other) const
Definition: ternary.h:37
bool isTemporary() const
Definition: ternary.h:29
bool isLhs() const
Definition: ternary.h:27
Definition: expression.h:17
auto properties() const
Definition: ternary.h:40
Definition: meta.h:18
auto isConstant() const
Definition: ternary.h:35
Definition: type.h:159
std::map< std::string, node::detail::PropertyValue > Properties
Definition: node.h:99
Definition: ternary.h:13
const Type & type() const
Definition: ternary.h:31
Definition: node.h:358