Spicy
byte-block.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 
21 public:
22  ByteBlock(const std::string& symbol, Expression e, Production body, const Location& l = location::None)
23  : ProductionBase(symbol, l), _expression(std::move(e)), _body(std::move(body)) {}
24 
25  const Expression& expression() const { return _expression; }
26  const Production& body() const { return _body; }
27 
28  // Production API
29  std::vector<std::vector<Production>> rhss() const { return {{_body}}; }
30  std::optional<spicy::Type> type() const { return {}; }
31  bool nullable() const { return production::nullable(rhss()); }
32  bool eodOk() const { return nullable(); }
33  bool atomic() const { return false; }
34  bool supportsSynchronize() const { return hasSize(); }
35  std::string render() const { return hilti::util::fmt("byte-block(%s): %s", _expression, _body.symbol()); }
36 
37 private:
38  Expression _expression;
39  Production _body;
40 };
41 
42 } // 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