Thorin 1.9.0
The Higher ORder INtermediate representation
Loading...
Searching...
No Matches
tok.cpp
Go to the documentation of this file.
1#include "thorin/fe/tok.h"
2
3#include <fe/assert.h>
4
5#include "thorin/lam.h"
6#include "thorin/tuple.h"
7
8namespace thorin {
9
10std::string_view Tok::tag2str(Tok::Tag tag) {
11 switch (tag) {
12#define CODE(t, str) \
13 case Tok::Tag::t: return str;
16#undef CODE
17 case Tag::Nil: fe::unreachable();
18 }
19 fe::unreachable();
20}
21
22/// @name std::ostream operator
23///@{
24std::ostream& operator<<(std::ostream& os, Tok tok) {
25 if (tok.isa(Tok::Tag::M_anx) || tok.isa(Tok::Tag::M_id) || tok.isa(Tok::Tag::M_str)) return os << tok.sym();
26 return os << Tok::tag2str(tok.tag());
27}
28///@}
29
30// clang-format off
31Tok::Prec Tok::prec(const Def* def) {
32 if (def->isa<Pi >()) return Tok::Prec::Arrow;
33 if (def->isa<App >()) return Tok::Prec::App;
34 if (def->isa<Extract>()) return Tok::Prec::Extract;
35 if (def->isa<Lit >()) return Tok::Prec::Lit;
36 return Tok::Prec::Bot;
37}
38// clang-format on
39
40} // namespace thorin
Base class for all Defs.
Definition def.h:222
Extracts from a Sigma or Array-typed Extract::tuple the element at position Extract::index.
Definition tuple.h:118
A dependent function type.
Definition lam.h:11
Sym sym() const
Definition tok.h:192
bool isa(Tag tag) const
Definition tok.h:183
static std::string_view tag2str(Tok::Tag)
Definition tok.cpp:10
static constexpr std::array< Prec, 2 > prec(Prec p)
Definition tok.h:125
Tag tag() const
Definition tok.h:184
Definition cfg.h:11
std::ostream & operator<<(std::ostream &, const CFNode *)
Definition cfg.cpp:25
#define THORIN_KEY(m)
Definition tok.h:14
#define THORIN_TOK(m)
Definition tok.h:55