MimIR
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
tok.cpp
Go to the documentation of this file.
1#include "mim/ast/tok.h"
2
3#include <fe/assert.h>
4
5#include "mim/lam.h"
6#include "mim/tuple.h"
7
8namespace mim::ast {
9
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
22std::string Tok::str() const {
23 std::ostringstream oss;
24 oss << *this;
25 return oss.str();
26}
27
28/// @name std::ostream operator
29///@{
30std::ostream& operator<<(std::ostream& os, Tok tok) {
31 if (tok.has_sym()) return os << tok.sym();
32 return os << Tok::tag2str(tok.tag());
33}
34///@}
35
36} // namespace mim::ast
friend std::ostream & operator<<(std::ostream &, Tok)
Definition tok.cpp:30
bool has_sym() const
Definition tok.h:311
Sym sym() const
Definition tok.h:320
static const char * tag2str(Tok::Tag)
Definition tok.cpp:10
std::string str() const
Definition tok.cpp:22
Tag tag() const
Definition tok.h:310
Definition ast.h:16
#define CODE(name,...)
Definition tok.h:51
#define MIM_TOK(m)
Definition tok.h:128
#define MIM_KEY(m)
Definition tok.h:75