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::expression {
10 
12 class Ternary : public NodeBase, public trait::isExpression {
13 public:
14  Ternary(Expression cond, Expression true_, Expression false_, Meta m = Meta())
15  : NodeBase({std::move(cond), std::move(true_), std::move(false_)}, std::move(m)) {}
16 
17  const auto& condition() const { return child<Expression>(0); }
18  const auto& true_() const { return child<Expression>(1); }
19  const auto& false_() const { return child<Expression>(2); }
20 
21  bool operator==(const Ternary& other) const {
22  return condition() == other.condition() && true_() == other.true_() && false_() == other.false_();
23  }
24 
25  void setFalse(const Expression& expr) { children()[2] = expr; }
26 
28  bool isLhs() const { return false; }
30  bool isTemporary() const { return true_().isTemporary() || false_().isTemporary(); }
32  const Type& type() const {
33  return true_().type();
34  } // TODO(robin): Currentluy we enforce both having the same type; we might need to coerce to target type though
36  auto isConstant() const { return false; }
38  auto isEqual(const Expression& other) const { return node::isEqual(this, other); }
39 
41  auto properties() const { return node::Properties{}; }
42 };
43 
44 } // namespace hilti::expression
auto isEqual(const Expression &other) const
Definition: ternary.h:38
bool isTemporary() const
Definition: ternary.h:30
bool isLhs() const
Definition: ternary.h:28
const auto & children() const
Definition: node.h:471
Definition: expression.h:18
auto properties() const
Definition: ternary.h:41
Definition: meta.h:19
auto isConstant() const
Definition: ternary.h:36
Definition: type.h:158
std::map< std::string, node::detail::PropertyValue > Properties
Definition: node.h:97
Definition: ternary.h:12
const Type & type() const
Definition: ternary.h:32
Definition: node.h:359
Definition: expression.h:21