MimIR
0.1
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
8
namespace
mim::ast
{
9
10
const
char
*
Tok::tag2str
(
Tok::Tag
tag) {
11
switch
(
tag
) {
12
#define CODE(t, str) \
13
case Tok::Tag::t: return str;
14
MIM_KEY
(
CODE
)
15
MIM_TOK
(
CODE
)
16
#undef CODE
17
case
Tag::Nil: fe::unreachable();
18
}
19
fe::unreachable();
20
}
21
22
std::string
Tok::str
()
const
{
23
std::ostringstream oss;
24
oss << *
this
;
25
return
oss.str();
26
}
27
28
/// @name std::ostream operator
29
///@{
30
std::ostream&
operator<<
(std::ostream& os,
Tok
tok) {
31
if
(tok.
isa
(Tok::Tag::M_anx) || tok.
isa
(Tok::Tag::M_id) || tok.
isa
(Tok::Tag::L_str))
return
os << tok.
sym
();
32
return
os <<
Tok::tag2str
(tok.
tag
());
33
}
34
///@}
35
36
}
// namespace mim::ast
mim::ast::Tok
Definition
tok.h:120
mim::ast::Tok::sym
Sym sym() const
Definition
tok.h:177
mim::ast::Tok::isa
bool isa(Tag tag) const
Definition
tok.h:168
mim::ast::Tok::tag2str
static const char * tag2str(Tok::Tag)
Definition
tok.cpp:10
mim::ast::Tok::str
std::string str() const
Definition
tok.cpp:22
mim::ast::Tok::Tag
Tag
Definition
tok.h:124
mim::ast::Tok::Tag::CODE
CODE(t, str)
mim::ast::Tok::tag
Tag tag() const
Definition
tok.h:169
lam.h
mim::ast
Definition
ast.h:14
mim::ast::operator<<
std::ostream & operator<<(std::ostream &os, Tok tok)
Definition
tok.cpp:30
tok.h
MIM_TOK
#define MIM_TOK(m)
Definition
tok.h:57
MIM_KEY
#define MIM_KEY(m)
Definition
tok.h:13
tuple.h
src
mim
ast
tok.cpp
Generated by
1.12.0