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  int64_t tokenID() const { return static_cast<int64_t>(production::tokenID(hilti::util::fmt("%s", _type))); }
30  std::string render() const { return hilti::util::fmt("%s", _type); }
31 
32 private:
33  spicy::Type _type;
34 };
35 
36 } // namespace spicy::detail::codegen::production
Definition: type.h:13
const std::string & symbol() const
Definition: production.h:191
Definition: production.h:170
Definition: grammar.h:15
Definition: production.h:25
Definition: type.h:160
Definition: location.h:18
ProductionBase(std::string symbol, Location l=location::None)
Definition: production.h:181