From d1c9392a5461e0d33e226375a8f7986a97d2d66b Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Mon, 26 Nov 2018 01:19:47 -0800 Subject: 4782 --- html/subx/003trace.cc.html | 119 +++++++++++++++++++++++---------------------- 1 file changed, 60 insertions(+), 59 deletions(-) (limited to 'html/subx/003trace.cc.html') diff --git a/html/subx/003trace.cc.html b/html/subx/003trace.cc.html index 8f4b68e1..1abc6fe9 100644 --- a/html/subx/003trace.cc.html +++ b/html/subx/003trace.cc.html @@ -18,6 +18,7 @@ a:hover { text-decoration: underline; } .LineNr { color: #444444; } .Constant { color: #00a0a0; } .Delimiter { color: #800080; } +.Special { color: #c00000; } .Identifier { color: #c0a020; } .Normal { color: #aaaaaa; background-color: #080808; padding-bottom: 1px; } .Comment { color: #9090ff; } @@ -139,20 +140,20 @@ if ('onhashchange' in window) { 80 //: Traces can have a lot of overhead, so only turn them on when asked. 81 :(before "End Commandline Options(*arg)") 82 else if (is_equal(*arg, "--trace")) { - 83 Save_trace = true; + 83 Save_trace = true; 84 } 85 :(before "End Commandline Parsing") - 86 if (Save_trace) { - 87 cerr << "initializing trace\n"; - 88 Trace_stream = new trace_stream; + 86 if (Save_trace) { + 87 cerr << "initializing trace\n"; + 88 Trace_stream = new trace_stream; 89 } 90 :(code) 91 void cleanup_main() { - 92 if (!Trace_stream) return; - 93 if (Save_trace) - 94 Trace_stream->save(); - 95 delete Trace_stream; - 96 Trace_stream = NULL; + 92 if (!Trace_stream) return; + 93 if (Save_trace) + 94 Trace_stream->save(); + 95 delete Trace_stream; + 96 Trace_stream = NULL; 97 } 98 :(before "End One-time Setup") 99 atexit(cleanup_main); @@ -161,9 +162,9 @@ if ('onhashchange' in window) { 102 // Pre-define some global constants that trace_stream needs to know about. 103 // Since they're in the Types section, they'll be included in any cleaved 104 // compilation units. So no extern linkage. -105 const int Max_depth = 9999; -106 const int Error_depth = 0; // definitely always print errors -107 const int Warn_depth = 1; +105 const int Max_depth = 9999; +106 const int Error_depth = 0; // definitely always print errors +107 const int Warn_depth = 1; 108 109 struct trace_stream { 110 vector<trace_line> past_lines; @@ -173,11 +174,11 @@ if ('onhashchange' in window) { 114 int curr_depth; 115 int collect_depth; 116 ofstream null_stream; // never opens a file, so writes silently fail -117 trace_stream() :curr_stream(NULL), curr_depth(Max_depth), collect_depth(Max_depth) {} +117 trace_stream() :curr_stream(NULL), curr_depth(Max_depth), collect_depth(Max_depth) {} 118 ~trace_stream() { if (curr_stream) delete curr_stream; } 119 120 ostream& stream(string label) { -121 return stream(Max_depth, label); +121 return stream(Max_depth, label); 122 } 123 124 ostream& stream(int depth, string label) { @@ -190,7 +191,7 @@ if ('onhashchange' in window) { 131 } 132 133 void save() { -134 cerr << "saving trace to 'last_run'\n"; +134 cerr << "saving trace to 'last_run'\n"; 135 ofstream fout("last_run"); 136 fout << readable_contents(""); 137 fout.close(); @@ -208,16 +209,16 @@ if ('onhashchange' in window) { 149 string curr_contents = curr_stream->str(); 150 if (!curr_contents.empty()) { 151 past_lines.push_back(trace_line(curr_depth, trim(curr_label), curr_contents)); // preserve indent in contents -152 if ((!Hide_errors && curr_depth == Error_depth) -153 || (!Hide_warnings && !Hide_errors && curr_depth == Warn_depth) -154 || Dump_trace -155 || (!Dump_label.empty() && curr_label == Dump_label)) +152 if ((!Hide_errors && curr_depth == Error_depth) +153 || (!Hide_warnings && !Hide_errors && curr_depth == Warn_depth) +154 || Dump_trace +155 || (!Dump_label.empty() && curr_label == Dump_label)) 156 cerr << curr_label << ": " << curr_contents << '\n'; 157 } 158 delete curr_stream; 159 curr_stream = NULL; 160 curr_label.clear(); -161 curr_depth = Max_depth; +161 curr_depth = Max_depth; 162 } 163 164 string trace_stream::readable_contents(string label) { @@ -230,30 +231,30 @@ if ('onhashchange' in window) { 171 } 172 173 :(before "End Globals") -174 trace_stream* Trace_stream = NULL; -175 int Trace_errors = 0; // used only when Trace_stream is NULL +174 trace_stream* Trace_stream = NULL; +175 int Trace_errors = 0; // used only when Trace_stream is NULL 176 177 //: option to print trace to the screen 178 :(before "End Globals") -179 bool Flag_dump_trace = false; +179 bool Flag_dump_trace = false; 180 :(before "End Commandline Options(*arg)") 181 else if (is_equal(*arg, "--dump")) { -182 Flag_dump_trace = true; +182 Flag_dump_trace = true; 183 } 184 185 :(before "End Globals") -186 bool Hide_errors = false; // if set, don't print even error trace lines to screen -187 bool Hide_warnings = false; // if set, don't print warnings to screen -188 bool Dump_trace = false; // if set, print trace lines to screen -189 string Dump_label = ""; // if set, print trace lines matching a single label to screen +186 bool Hide_errors = false; // if set, don't print even error trace lines to screen +187 bool Hide_warnings = false; // if set, don't print warnings to screen +188 bool Dump_trace = false; // if set, print trace lines to screen +189 string Dump_label = ""; // if set, print trace lines matching a single label to screen 190 :(before "End Reset") -191 Hide_errors = false; -192 Hide_warnings = false; -193 Dump_trace = Flag_dump_trace; -194 Dump_label = ""; +191 Hide_errors = false; +192 Hide_warnings = false; +193 Dump_trace = Flag_dump_trace; +194 Dump_label = ""; 195 //: Never dump warnings in scenarios 196 :(before "End Test Setup") -197 Hide_warnings = true; +197 Hide_warnings = true; 198 199 :(before "End Includes") 200 #define CLEAR_TRACE delete Trace_stream, Trace_stream = new trace_stream; @@ -276,24 +277,24 @@ if ('onhashchange' in window) { 217 // Inside tests, fail any tests that displayed (unexpected) errors. 218 // Expected errors in tests should always be hidden and silently checked for. 219 :(before "End Test Teardown") -220 if (Passed && !Hide_errors && trace_contains_errors()) { -221 Passed = false; +220 if (Passed && !Hide_errors && trace_contains_errors()) { +221 Passed = false; 222 } 223 :(code) 224 bool trace_contains_errors() { -225 return Trace_errors > 0 || trace_count("error") > 0; +225 return Trace_errors > 0 || trace_count("error") > 0; 226 } 227 228 :(before "End Types") 229 struct end {}; 230 :(code) 231 ostream& operator<<(ostream& os, end /*unused*/) { -232 if (Trace_stream) Trace_stream->newline(); +232 if (Trace_stream) Trace_stream->newline(); 233 return os; 234 } 235 236 :(before "End Globals") -237 bool Save_trace = false; // if set, write out trace to disk +237 bool Save_trace = false; // if set, write out trace to disk 238 239 // Trace_stream is a resource, lease_tracer uses RAII to manage it. 240 :(before "End Types") @@ -302,10 +303,10 @@ if ('onhashchange' in window) { 243 ~lease_tracer(); 244 }; 245 :(code) -246 lease_tracer::lease_tracer() { Trace_stream = new trace_stream; } +246 lease_tracer::lease_tracer() { Trace_stream = new trace_stream; } 247 lease_tracer::~lease_tracer() { -248 if (Save_trace) Trace_stream->save(); -249 delete Trace_stream, Trace_stream = NULL; +248 if (Save_trace) Trace_stream->save(); +249 delete Trace_stream, Trace_stream = NULL; 250 } 251 :(before "End Includes") 252 #define START_TRACING_UNTIL_END_OF_SCOPE lease_tracer leased_tracer; @@ -317,19 +318,19 @@ if ('onhashchange' in window) { 258 259 #define CHECK_TRACE_CONTAINS_ERRORS() CHECK(trace_contains_errors()) 260 #define CHECK_TRACE_DOESNT_CONTAIN_ERRORS() \ -261 if (Passed && trace_contains_errors()) { \ -262 cerr << "\nF - " << __FUNCTION__ << "(" << __FILE__ << ":" << __LINE__ << "): unexpected errors\n"; \ +261 if (Passed && trace_contains_errors()) { \ +262 cerr << "\nF - " << __FUNCTION__ << "(" << __FILE__ << ":" << __LINE__ << "): unexpected errors\n"; \ 263 DUMP("error"); \ -264 Passed = false; \ +264 Passed = false; \ 265 return; \ 266 } 267 268 #define CHECK_TRACE_COUNT(label, count) \ -269 if (Passed && trace_count(label) != (count)) { \ -270 cerr << "\nF - " << __FUNCTION__ << "(" << __FILE__ << ":" << __LINE__ << "): trace_count of " << label << " should be " << count << '\n'; \ +269 if (Passed && trace_count(label) != (count)) { \ +270 cerr << "\nF - " << __FUNCTION__ << "(" << __FILE__ << ":" << __LINE__ << "): trace_count of " << label << " should be " << count << '\n'; \ 271 cerr << " got " << trace_count(label) << '\n'; /* multiple eval */ \ 272 DUMP(label); \ -273 Passed = false; \ +273 Passed = false; \ 274 return; /* Currently we stop at the very first failure. */ \ 275 } 276 @@ -337,8 +338,8 @@ if ('onhashchange' in window) { 278 279 :(code) 280 bool check_trace_contents(string FUNCTION, string FILE, int LINE, string expected) { -281 if (!Passed) return false; -282 if (!Trace_stream) return false; +281 if (!Passed) return false; +282 if (!Trace_stream) return false; 283 vector<string> expected_lines = split(expected, "^D"); 284 int curr_expected_line = 0; 285 while (curr_expected_line < SIZE(expected_lines) && expected_lines.at(curr_expected_line).empty()) @@ -346,7 +347,7 @@ if ('onhashchange' in window) { 287 if (curr_expected_line == SIZE(expected_lines)) return true; 288 string label, contents; 289 split_label_contents(expected_lines.at(curr_expected_line), &label, &contents); -290 for (vector<trace_line>::iterator p = Trace_stream->past_lines.begin(); p != Trace_stream->past_lines.end(); ++p) { +290 for (vector<trace_line>::iterator p = Trace_stream->past_lines.begin(); p != Trace_stream->past_lines.end(); ++p) { 291 if (label != p->label) continue; 292 if (contents != trim(p->contents)) continue; 293 ++curr_expected_line; @@ -357,14 +358,14 @@ if ('onhashchange' in window) { 298 } 299 300 if (line_exists_anywhere(label, contents)) { -301 cerr << "\nF - " << FUNCTION << "(" << FILE << ":" << LINE << "): line [" << label << ": " << contents << "] out of order in trace:\n"; +301 cerr << "\nF - " << FUNCTION << "(" << FILE << ":" << LINE << "): line [" << label << ": " << contents << "] out of order in trace:\n"; 302 DUMP(""); 303 } 304 else { -305 cerr << "\nF - " << FUNCTION << "(" << FILE << ":" << LINE << "): missing [" << contents << "] in trace:\n"; +305 cerr << "\nF - " << FUNCTION << "(" << FILE << ":" << LINE << "): missing [" << contents << "] in trace:\n"; 306 DUMP(label); 307 } -308 Passed = false; +308 Passed = false; 309 return false; 310 } 311 @@ -382,7 +383,7 @@ if ('onhashchange' in window) { 323 } 324 325 bool line_exists_anywhere(const string& label, const string& contents) { -326 for (vector<trace_line>::iterator p = Trace_stream->past_lines.begin(); p != Trace_stream->past_lines.end(); ++p) { +326 for (vector<trace_line>::iterator p = Trace_stream->past_lines.begin(); p != Trace_stream->past_lines.end(); ++p) { 327 if (label != p->label) continue; 328 if (contents == trim(p->contents)) return true; 329 } @@ -394,9 +395,9 @@ if ('onhashchange' in window) { 335 } 336 337 int trace_count(string label, string line) { -338 if (!Trace_stream) return 0; +338 if (!Trace_stream) return 0; 339 long result = 0; -340 for (vector<trace_line>::iterator p = Trace_stream->past_lines.begin(); p != Trace_stream->past_lines.end(); ++p) { +340 for (vector<trace_line>::iterator p = Trace_stream->past_lines.begin(); p != Trace_stream->past_lines.end(); ++p) { 341 if (label == p->label) { 342 if (line == "" || trim(line) == trim(p->contents)) 343 ++result; @@ -406,9 +407,9 @@ if ('onhashchange' in window) { 347 } 348 349 int trace_count_prefix(string label, string prefix) { -350 if (!Trace_stream) return 0; +350 if (!Trace_stream) return 0; 351 long result = 0; -352 for (vector<trace_line>::iterator p = Trace_stream->past_lines.begin(); p != Trace_stream->past_lines.end(); ++p) { +352 for (vector<trace_line>::iterator p = Trace_stream->past_lines.begin(); p != Trace_stream->past_lines.end(); ++p) { 353 if (label == p->label) { 354 if (starts_with(trim(p->contents), trim(prefix))) 355 ++result; @@ -424,7 +425,7 @@ if ('onhashchange' in window) { 365 bool trace_doesnt_contain(string expected) { 366 vector<string> tmp = split_first(expected, ": "); 367 if (SIZE(tmp) == 1) { -368 raise << expected << ": missing label or contents in trace line\n" << end(); +368 raise << expected << ": missing label or contents in trace line\n" << end(); 369 assert(false); 370 } 371 return trace_doesnt_contain(tmp.at(0), tmp.at(1)); -- cgit 1.4.1-2-gfad0