Spicy
boolean.h
1 // Copyright (c) 2020-2021 by the Zeek Project. See LICENSE for details.
2 
3 #pragma once
4 
5 #include <string>
6 #include <utility>
7 #include <vector>
8 
9 #include <spicy/ast/types/unit.h>
10 #include <spicy/compiler/detail/codegen/production.h>
11 
13 
19 public:
20  Boolean(const std::string& symbol, Expression e, Production alt1, Production alt2,
21  const Location& l = location::None)
22  : ProductionBase(symbol, l),
23  _expression(std::move(e)),
24  _alternatives(std::make_pair(std::move(alt1), std::move(alt2))) {}
25 
26  const Expression& expression() const { return _expression; }
27  const std::pair<Production, Production>& alternatives() const { return _alternatives; }
28 
29  // Production API
30  std::vector<std::vector<Production>> rhss() const { return {{_alternatives.first}, {_alternatives.second}}; }
31  std::optional<spicy::Type> type() const { return {}; }
32  bool nullable() const { return production::nullable(rhss()); }
33  bool eodOk() const {
34  // Always false. If one of the branches is ok with no data, it will
35  // indicate so itself.
36  return false;
37  }
38  bool atomic() const { return false; }
39  std::string render() const {
40  return hilti::util::fmt("true: %s / false: %s", _alternatives.first.symbol(), _alternatives.second.symbol());
41  }
42 
43 private:
44  Expression _expression;
45  std::pair<Production, Production> _alternatives;
46 };
47 
48 } // namespace spicy::detail::codegen::production
Definition: production.h:24
Definition: production.h:120
const std::string & symbol() const
Definition: production.h:191
Definition: production.h:170
Definition: grammar.h:15
Definition: location.h:18
ProductionBase(std::string symbol, Location l=location::None)
Definition: production.h:181