Spicy
type-literal.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 
8 #include <hilti/ast/expressions/type.h>
9 
10 #include <spicy/compiler/detail/codegen/production.h>
11 
13 
20 public:
21  TypeLiteral(const std::string& symbol, spicy::Type type, const Location& l = location::None)
22  : ProductionBase(symbol, l), _type(std::move(type)) {}
23 
24  Expression expression() const { return hilti::expression::Type_(_type); }
25  std::optional<spicy::Type> type() const { return _type; }
26  bool nullable() const { return false; }
27  bool eodOk() const { return nullable(); }
28  bool atomic() const { return true; }
29  bool supportsSynchronize() const { return hasSize() && maySynchronize(); }
30  int64_t tokenID() const { return production::tokenID(hilti::util::fmt("%s", _type)); }
31  std::string render() const { return hilti::util::fmt("%s", _type); }
32 
33 private:
34  spicy::Type _type;
35 };
36 
37 } // namespace spicy::detail::codegen::production
Definition: type.h:14
const std::string & symbol() const
Definition: production.h:196
bool maySynchronize() const
Definition: production.h:188
bool hasSize() const
Definition: production.h:185
Definition: production.h:170
Definition: grammar.h:15
Definition: production.h:25
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