-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathemit.cpp
78 lines (67 loc) · 1.24 KB
/
emit.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// emit.cpp
// Revision 8-sep-2011
#include "emit.h"
Emit::Emit (std::ostream &out) :
o(out),
debug(false),
with_an(true),
pendingf(false),
pendingl(false),
line(0)
{ }
void Emit::setDebug()
{
debug = true;
}
bool Emit::getDebug() const
{
return debug;
}
void Emit::omit_annotations()
{
with_an= false;
}
void Emit::comment(const std::string &msg)
{
o << "# " << msg << '\n';
}
void Emit::boxedcomment(const std::string &msg)
{
const size_t n= msg.size();
comment('+' + std::string(n + 2, '-') + '+');
comment("| " + msg + " |");
comment('+' + std::string(n + 2, '-') + '+');
}
void Emit::preemit()
{
if (pendingf)
{
o << ".annotate 'file', '" << file << "'\n";
pendingf= false;
}
if (pendingl)
{
o << ".annotate 'line', " << line << '\n';
pendingl= false;
}
}
void Emit::annotate(const Token &t)
{
if (with_an)
{
if (t.file() != file)
{
file= t.file();
pendingf= true;
pendingl= false;
line= 0;
}
if (t.linenum() != line)
{
line= t.linenum();
if (line)
pendingl= true;
}
}
}
// End of emit.cpp