-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathTracer.h
231 lines (196 loc) · 6.63 KB
/
Tracer.h
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
/* $Id: Tracer.h,v 1.39 2002-10-12 09:47:55 pgr Exp $ */
#ifndef COM_JAXO_YAXX_TRACER_H_INCLUDED
#define COM_JAXO_YAXX_TRACER_H_INCLUDED
/*---------+
| Includes |
+---------*/
#include "CodeBuffer.h"
#include "../toolslib/uccompos.h"
#ifdef YAXX_NAMESPACE
namespace YAXX_NAMESPACE {
#endif
class RecoverableException;
class RexxString;
/*------------------------------------------------------------ class Location +
| |
+----------------------------------------------------------------------------*/
class Location {
public:
int m_lineno; // line number
int m_nesting; // nesting level
RexxString m_path; // current file path
RexxString m_contents; // contents
};
/*------------------------------------------------------------- class Tracer -+
| |
+----------------------------------------------------------------------------*/
class Tracer {
public:
Tracer(Location const & loc, UnicodeComposer & erh);
~Tracer();
bool isMyselfInteractive() const;
bool isTracingClausesOrLabels() const;
bool isTracingClauses() const;
bool isTracingResults() const;
bool isTracingIntermediates() const;
bool mustPause();
RexxString getTraceSetting() const;
bool setTraceSetting(RexxString & value, bool denySkipCount);
void startInterpret(bool isInteractiveTrace);
void endInterpret();
void startRoutine();
void endRoutine();
void traceResults(RexxString ** ppStr, int iMax) const;
void traceMonadicOp(RexxString const & value) const;
void traceDyadicOp(RexxString const & value) const;
void traceAssign(RexxString const & value) const;
void traceVariable(RexxString const & value) const;
void traceFunction(RexxString const & value) const;
void traceLiteral(RexxString const & value) const;
void tracePlaceholder(RexxString const & value) const;
void traceCompound(RexxString const & strStem, RexxString const & strTail) const;
void traceNotLabelClause();
void traceClause();
void traceBadRc(int rc) const;
void traceInteractiveError(RecoverableException const & e);
static void traceError(
MemStream & out,
UnicodeComposer::Message const & msg,
Location const & loc
);
static void traceWarning(UnicodeComposer::Message const & msg);
private:
class Setting {
public:
Setting();
bool isInteractive() const;
bool isTracingBadRc() const;
bool isTracingClausesOrLabels() const;
bool isTracingClauses() const;
bool isTracingResults() const;
bool isTracingIntermediates() const;
bool set(RexxString & pVal, int & skipClauseCount, bool denySkipCount);
RexxString get() const;
private:
enum {
_BADRC = 1,
OFF = 0, // Nothing is traced
NORMAL = (1 << 1) + _BADRC, // Host: Failure host
FAILURE = (2 << 1) + _BADRC, // (same as NORMAL)
ERROR = (3 << 1) + _BADRC, // Host: Failure + Error
COMMANDS = (4 << 1) + _BADRC, // Host: Failure + Error + Exec
LABELS = (5 << 1) , // Label
ALL = (6 << 1) , // Clauses: Exec
RESULTS = (7 << 1) + _BADRC, // Clauses: Exec + Results
INTERMEDIATES = (8 << 1) + _BADRC // Clauses: Exec + Results + Itmdtes
} m_setval;
bool m_isInteractive;
};
enum { INC = 20 };
UnicodeComposer & m_erh;
Location const & m_loc;
bool m_isClauseShown;
int m_levelInteractive;
Setting m_setting;
int m_size;
int m_skipPauseCount;
int m_ix;
void * m_buf;
void traceFormat(char c, RexxString const & value) const;
static void showSourceLine(Location const & loc, ostream & out);
void makeRoom();
};
/* -- INLINES -- */
inline Tracer::Setting::Setting() {
m_setval = NORMAL;
m_isInteractive = false;
}
inline bool Tracer::Setting::isInteractive() const {
return m_isInteractive;
}
inline bool Tracer::Setting::isTracingBadRc() const {
return (m_setval & _BADRC);
}
inline bool Tracer::Setting::isTracingClausesOrLabels() const {
return (m_setval >= LABELS);
}
inline bool Tracer::Setting::isTracingClauses() const {
return (m_setval >= ALL);
}
inline bool Tracer::Setting::isTracingResults() const {
return m_setval >= RESULTS;
}
inline bool Tracer::Setting::isTracingIntermediates() const {
return m_setval >= INTERMEDIATES;
}
inline void Tracer::traceMonadicOp(RexxString const & value) const {
traceFormat('P', value);
}
inline void Tracer::traceDyadicOp(RexxString const & value) const {
traceFormat('O', value);
}
inline void Tracer::traceAssign(RexxString const & value) const {
traceFormat('=', value);
}
inline void Tracer::traceVariable(RexxString const & value) const {
traceFormat('V', value);
}
inline void Tracer::traceFunction(RexxString const & value) const {
traceFormat('F', value);
}
inline void Tracer::traceLiteral(RexxString const & value) const {
traceFormat('L', value);
}
inline void Tracer::tracePlaceholder(RexxString const & value) const {
traceFormat('.', value);
}
inline void Tracer::startInterpret(bool isInteractiveTrace) {
if ((isInteractiveTrace) || (m_levelInteractive)) {
++m_levelInteractive;
if (isInteractiveTrace) m_skipPauseCount = 0; // stop b4 clause
}
}
inline void Tracer::endInterpret() {
if (m_levelInteractive) --m_levelInteractive;
}
inline void Tracer::startRoutine() {
if (m_ix >= m_size) makeRoom();
((Setting *)m_buf)[m_ix++] = m_setting;
}
inline void Tracer::endRoutine() {
m_setting = ((Setting *)m_buf)[--m_ix];
}
inline bool Tracer::isTracingIntermediates() const {
return (m_setting.isTracingIntermediates());
}
inline bool Tracer::isTracingResults() const {
return (m_setting.isTracingResults());
}
inline bool Tracer::isMyselfInteractive() const {
return ((m_levelInteractive==0) && m_setting.isInteractive());
}
inline bool Tracer::isTracingClausesOrLabels() const {
return (m_setting.isTracingClausesOrLabels());
}
inline bool Tracer::isTracingClauses() const {
return (m_setting.isTracingClauses());
}
inline bool Tracer::mustPause() {
if (isMyselfInteractive() && (m_skipPauseCount == 0)) {
m_skipPauseCount = -1;
return true;
}else {
return false;
}
}
inline void Tracer::traceNotLabelClause() {
if (isTracingClauses()) traceClause(); // only if tracing clauses
}
inline RexxString Tracer::getTraceSetting() const {
return m_setting.get(); // delegate
}
#ifdef YAXX_NAMESPACE
}
#endif
#endif
/*===========================================================================*/