xo-interpreter2: scaffold repl + alloc measurement frameowkr
This commit is contained in:
parent
8ed5f5b995
commit
221402fcbc
1 changed files with 0 additions and 151 deletions
|
|
@ -255,157 +255,6 @@ namespace xo {
|
|||
// instead of post-processing, rely on newline-aware log_streambuf
|
||||
// to indent in advance
|
||||
|
||||
#ifdef OBSOLETE
|
||||
log_streambuf_type * sbuf2 = this->p_sbuf_phase2_.get();
|
||||
|
||||
/* often sbuf contains one line of output.
|
||||
* if it contains multiple newlines, need to indent
|
||||
* after each one.
|
||||
*
|
||||
* will scan output in *sbuf1, post-process to *sbuf2,
|
||||
* then write *sbuf2 to output stream
|
||||
*
|
||||
* note: we inherit .lpos from prec call to .flush2sbuf(),
|
||||
* in the unlikely event that it's non-zero
|
||||
*/
|
||||
char const * s = sbuf1->lo();
|
||||
|
||||
char const * e = s + sbuf1->pos();
|
||||
char const * p = s;
|
||||
|
||||
/* point to first space following a non-space character.
|
||||
* will indent to just after this space
|
||||
*/
|
||||
char const * space_after_nonspace = nullptr;
|
||||
|
||||
/* true on VT100 color escape (\033); in which case false on terminating char (m)
|
||||
* don't advance lpos during escape
|
||||
*/
|
||||
bool in_color_escape = false;
|
||||
|
||||
while(true) {
|
||||
bool have_nonspace = false;
|
||||
|
||||
/* invariant: s<=p<=e */
|
||||
|
||||
/* for indenting, looking for first 'space following non-space, on first line', if any */
|
||||
|
||||
#ifdef OBSOLETE
|
||||
// ..multiline input should have already been indented by custom log_streambuf.
|
||||
// may need to extend to recognize terminal control sequences like below
|
||||
|
||||
std::size_t lpos_on_newline = 0;
|
||||
#endif
|
||||
|
||||
#ifdef OBSOLETE
|
||||
while(p < e) {
|
||||
if(space_after_nonspace) {
|
||||
;
|
||||
} else {
|
||||
if(*p != ' ')
|
||||
have_nonspace = true;
|
||||
|
||||
if(have_nonspace && (*p == ' ')) {
|
||||
space_after_nonspace = p;
|
||||
}
|
||||
}
|
||||
|
||||
if (in_color_escape && (*p != '\n')) {
|
||||
/* in color escape -> don't advance .lpos */
|
||||
if (*p == 'm')
|
||||
in_color_escape = false;
|
||||
++p;
|
||||
} else if (*p == '\033') {
|
||||
/* begin color escape sequence */
|
||||
in_color_escape = true;
|
||||
++p;
|
||||
} else if (*p == '\n') {
|
||||
/* reset .pos on newline; also drop any (incomplete + ill-formed) color escape */
|
||||
|
||||
in_color_escape = false;
|
||||
|
||||
#ifdef OBSOLETE
|
||||
lpos_on_newline = this->lpos_;
|
||||
this->lpos_ = 0;
|
||||
#endif
|
||||
|
||||
++p;
|
||||
break;
|
||||
} else {
|
||||
/* increment .lpos on non-newline */
|
||||
++(this->lpos_);
|
||||
++p;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* p=e or *p=\n */
|
||||
|
||||
/* charseq [s,p) does not contain any newlines, print it */
|
||||
if (lpos_on_newline > 0) {
|
||||
/* charseq [s,p) does not contain any newlines, print it */
|
||||
sbuf2->sputn(s, p - s - 1);
|
||||
|
||||
if (this->location_flag_) {
|
||||
/* 'tab' to position lpos for [file:line] */
|
||||
sbuf2->sputc(' ');
|
||||
for (std::uint32_t i = lpos_on_newline + 1; i < log_config::location_tab; ++i)
|
||||
sbuf2->sputc(' ');
|
||||
|
||||
std::stringstream ss;
|
||||
ss << code_location(this->file_, this->line_,
|
||||
log_config::code_location_color);
|
||||
|
||||
std::string ss_str = ss.str(); /*hoping for copy elision here*/
|
||||
sbuf2->sputn(ss_str.c_str(), ss_str.size());
|
||||
|
||||
this->location_flag_ = false;
|
||||
this->file_ = "";
|
||||
this->line_ = 0;
|
||||
}
|
||||
|
||||
sbuf2->sputc('\n');
|
||||
} else {
|
||||
/* control here if .flush2sbuf() called without trailing newline in .p_sbuf_phase1 */
|
||||
sbuf2->sputn(s, p - s);
|
||||
}
|
||||
|
||||
if (p == e)
|
||||
break;
|
||||
|
||||
// {
|
||||
// char buf[80];
|
||||
// snprintf(buf, sizeof(buf), "*** indent=[%d] next=[%c]", this->nesting_level_, *(p+1));
|
||||
//
|
||||
// std::clog.rdbuf()->sputn(buf, strlen(buf));
|
||||
//}
|
||||
|
||||
/* control here only for continuation lines (application logging code embedding its own newlines)
|
||||
* - minimum indent = nesting level;
|
||||
* - however if space_after_nonspace defined, also indent for that
|
||||
*/
|
||||
std::uint32_t n_indent = 0;
|
||||
|
||||
n_indent += this->calc_time_indent();
|
||||
|
||||
n_indent += std::min(this->nesting_level_ * log_config::indent_width,
|
||||
log_config::max_indent_width);
|
||||
|
||||
#ifdef OBSOLETE // nice try, broken for multiline input + written before log_streambuf calculated lpos
|
||||
/* this is just to indent for per-line entry/exit label */
|
||||
if(space_after_nonspace)
|
||||
n_indent += (space_after_nonspace - s);
|
||||
#endif
|
||||
|
||||
for(std::uint32_t i = 0; i < n_indent; ++i)
|
||||
sbuf2->sputc(' ');
|
||||
|
||||
s = p;
|
||||
}
|
||||
|
||||
/* now write entire contents of *sbuf2 to clog */
|
||||
p_sbuf->sputn(sbuf2->lo(), sbuf2->pos());
|
||||
#endif
|
||||
p_sbuf->sputn(sbuf1->lo(), sbuf1->pos());
|
||||
|
||||
/* reset streams for next message */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue