Spicy
for-each.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 
16 public:
17  ForEach(const std::string& symbol, Production body, bool eod_ok, const Location& l = location::None)
18  : ProductionBase(symbol, l), _body(std::move(body)), _eod_ok(eod_ok) {}
19 
20  const Production& body() const { return _body; }
21 
22  // Production API
23  std::vector<std::vector<Production>> rhss() const { return {{_body}}; }
24  std::optional<spicy::Type> type() const { return {}; }
25  bool nullable() const { return production::nullable(rhss()); }
26  bool eodOk() const { return _eod_ok ? _eod_ok : nullable(); }
27  bool atomic() const { return false; }
28  bool supportsSynchronize() const { return hasSize() || _body.supportsSynchronize(); }
29  std::string render() const { return hilti::util::fmt("foreach: %s", _body.symbol()); }
30 
31 private:
32  Production _body;
33  bool _eod_ok;
34 };
35 
36 } // 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