Spicy
counter.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  Counter(const std::string& symbol, Expression e, Production body, const Location& l = location::None)
21  : ProductionBase(symbol, l), _expression(std::move(e)), _body(std::move(body)) {}
22 
23  const Expression& expression() const { return _expression; }
24  const Production& body() const { return _body; }
25 
26  // Production API
27  std::vector<std::vector<Production>> rhss() const { return {{_body}}; }
28  std::optional<spicy::Type> type() const { return {}; }
29  bool nullable() const { return production::nullable(rhss()); }
30  bool eodOk() const { return nullable(); }
31  bool atomic() const { return false; }
32  bool supportsSynchronize() const { return hasSize(); }
33  std::string render() const { return hilti::util::fmt("counter(%s): %s", _expression, _body.symbol()); }
34 
35 private:
36  Expression _expression;
37  Production _body;
38 };
39 
40 } // namespace spicy::detail::codegen::production
Definition: production.h:24
Definition: production.h:120
const std::string & symbol() const
Definition: production.h:196
bool hasSize() const
Definition: production.h:185
Definition: production.h:170
Definition: grammar.h:15
std::string fmt(const char *fmt, const Args &... args)
Definition: util.h:80
Definition: location.h:17
ProductionBase(std::string symbol, Location l=location::None)
Definition: production.h:181