From e4ac3c9e6e5464a0fc0f8fd3763a572e0e180c04 Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Sat, 1 Dec 2018 14:13:33 -0800 Subject: 4814 --- html/003trace.cc.html | 136 ++++++++++++++++++++++++++------------------------ 1 file changed, 70 insertions(+), 66 deletions(-) (limited to 'html/003trace.cc.html') diff --git a/html/003trace.cc.html b/html/003trace.cc.html index c7c1a4e0..cbda9303 100644 --- a/html/003trace.cc.html +++ b/html/003trace.cc.html @@ -11,17 +11,20 @@ @@ -56,6 +59,7 @@ if ('onhashchange' in window) { +https://github.com/akkartik/mu/blob/master/003trace.cc
   1 //: The goal of layers is to make programs more easy to understand and more
   2 //: malleable, easy to rewrite in radical ways without accidentally breaking
@@ -139,20 +143,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 +165,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 App_depth = 2;  // temporarily where all Mu code will trace to
+105 const int Max_depth = 9999;
+106 const int Error_depth = 0;  // definitely always print errors
+107 const int App_depth = 2;  // temporarily where all Mu code will trace to
 108 
 109 struct trace_stream {
 110   vector<trace_line> past_lines;
@@ -174,11 +178,11 @@ if ('onhashchange' in window) {
 115   int callstack_depth;
 116   int collect_depth;
 117   ofstream null_stream;  // never opens a file, so writes silently fail
-118   trace_stream() :curr_stream(NULL), curr_depth(Max_depth), callstack_depth(0), collect_depth(Max_depth) {}
+118   trace_stream() :curr_stream(NULL), curr_depth(Max_depth), callstack_depth(0), collect_depth(Max_depth) {}
 119   ~trace_stream() { if (curr_stream) delete curr_stream; }
 120 
 121   ostream& stream(string label) {
-122     return stream(Max_depth, label);
+122     return stream(Max_depth, label);
 123   }
 124 
 125   ostream& stream(int depth, string label) {
@@ -190,7 +194,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,15 +212,15 @@ 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_label == "error")
-153         || Dump_trace
-154         || (!Dump_label.empty() && curr_label == Dump_label))
+152     if ((!Hide_errors && curr_label == "error")
+153         || Dump_trace
+154         || (!Dump_label.empty() && curr_label == Dump_label))
 155       cerr << curr_label << ": " << curr_contents << '\n';
 156   }
 157   delete curr_stream;
 158   curr_stream = NULL;
 159   curr_label.clear();
-160   curr_depth = Max_depth;
+160   curr_depth = Max_depth;
 161 }
 162 
 163 string trace_stream::readable_contents(string label) {
@@ -229,17 +233,17 @@ if ('onhashchange' in window) {
 170 }
 171 
 172 :(before "End Globals")
-173 trace_stream* Trace_stream = NULL;
-174 int Trace_errors = 0;  // used only when Trace_stream is NULL
+173 trace_stream* Trace_stream = NULL;
+174 int Trace_errors = 0;  // used only when Trace_stream is NULL
 175 
 176 :(before "End Globals")
-177 bool Hide_errors = false;  // if set, don't print even error trace lines to screen
-178 bool Dump_trace = false;  // if set, print trace lines to screen
-179 string Dump_label = "";  // if set, print trace lines matching a single label to screen
+177 bool Hide_errors = false;  // if set, don't print even error trace lines to screen
+178 bool Dump_trace = false;  // if set, print trace lines to screen
+179 string Dump_label = "";  // if set, print trace lines matching a single label to screen
 180 :(before "End Reset")
-181 Hide_errors = false;
-182 Dump_trace = false;  // toggle this to print traces to screen as they are emitted
-183 Dump_label = "";
+181 Hide_errors = false;
+182 Dump_trace = false;  // toggle this to print traces to screen as they are emitted
+183 Dump_label = "";
 184 
 185 :(before "End Includes")
 186 #define CLEAR_TRACE  delete Trace_stream, Trace_stream = new trace_stream;
@@ -265,31 +269,31 @@ if ('onhashchange' in window) {
 206   if (!tb_is_active()) return;
 207   // leave the screen in a relatively clean state
 208   tb_set_cursor(tb_width()-1, tb_height()-1);
-209   cout << "\r\n";
+209   cout << "\r\n";
 210   tb_shutdown();
 211 }
 212 
 213 // Inside tests, fail any tests that displayed (unexpected) errors.
 214 // Expected errors in tests should always be hidden and silently checked for.
 215 :(before "End Test Teardown")
-216 if (Passed && !Hide_errors && trace_contains_errors()) {
-217   Passed = false;
+216 if (Passed && !Hide_errors && trace_contains_errors()) {
+217   Passed = false;
 218 }
 219 :(code)
 220 bool trace_contains_errors() {
-221   return Trace_errors > 0 || trace_count("error") > 0;
+221   return Trace_errors > 0 || trace_count("error") > 0;
 222 }
 223 
 224 :(before "End Types")
 225 struct end {};
 226 :(code)
 227 ostream& operator<<(ostream& os, end /*unused*/) {
-228   if (Trace_stream) Trace_stream->newline();
+228   if (Trace_stream) Trace_stream->newline();
 229   return os;
 230 }
 231 
 232 :(before "End Globals")
-233 bool Save_trace = false;  // if set, write out trace to disk
+233 bool Save_trace = false;  // if set, write out trace to disk
 234 
 235 // Trace_stream is a resource, lease_tracer uses RAII to manage it.
 236 :(before "End Types")
@@ -298,10 +302,10 @@ if ('onhashchange' in window) {
 239   ~lease_tracer();
 240 };
 241 :(code)
-242 lease_tracer::lease_tracer() { Trace_stream = new trace_stream; }
+242 lease_tracer::lease_tracer() { Trace_stream = new trace_stream; }
 243 lease_tracer::~lease_tracer() {
-244   if (Save_trace) Trace_stream->save();
-245   delete Trace_stream, Trace_stream = NULL;
+244   if (Save_trace) Trace_stream->save();
+245   delete Trace_stream, Trace_stream = NULL;
 246 }
 247 :(before "End Includes")
 248 #define START_TRACING_UNTIL_END_OF_SCOPE  lease_tracer leased_tracer;
@@ -313,19 +317,19 @@ if ('onhashchange' in window) {
 254 
 255 #define CHECK_TRACE_CONTAINS_ERRORS()  CHECK(trace_contains_errors())
 256 #define CHECK_TRACE_DOESNT_CONTAIN_ERRORS() \
-257   if (Passed && trace_contains_errors()) { \
-258     cerr << "\nF - " << __FUNCTION__ << "(" << __FILE__ << ":" << __LINE__ << "): unexpected errors\n"; \
+257   if (Passed && trace_contains_errors()) { \
+258     cerr << "\nF - " << __FUNCTION__ << "(" << __FILE__ << ":" << __LINE__ << "): unexpected errors\n"; \
 259     DUMP("error"); \
-260     Passed = false; \
+260     Passed = false; \
 261     return; \
 262   }
 263 
 264 #define CHECK_TRACE_COUNT(label, count) \
-265   if (Passed && trace_count(label) != (count)) { \
-266     cerr << "\nF - " << __FUNCTION__ << "(" << __FILE__ << ":" << __LINE__ << "): trace_count of " << label << " should be " << count << '\n'; \
+265   if (Passed && trace_count(label) != (count)) { \
+266     cerr << "\nF - " << __FUNCTION__ << "(" << __FILE__ << ":" << __LINE__ << "): trace_count of " << label << " should be " << count << '\n'; \
 267     cerr << "  got " << trace_count(label) << '\n';  /* multiple eval */ \
 268     DUMP(label); \
-269     Passed = false; \
+269     Passed = false; \
 270     return;  /* Currently we stop at the very first failure. */ \
 271   }
 272 
@@ -333,8 +337,8 @@ if ('onhashchange' in window) {
 274 
 275 :(code)
 276 bool check_trace_contents(string FUNCTION, string FILE, int LINE, string expected) {
-277   if (!Passed) return false;
-278   if (!Trace_stream) return false;
+277   if (!Passed) return false;
+278   if (!Trace_stream) return false;
 279   vector<string> expected_lines = split(expected, "^D");
 280   int curr_expected_line = 0;
 281   while (curr_expected_line < SIZE(expected_lines) && expected_lines.at(curr_expected_line).empty())
@@ -342,7 +346,7 @@ if ('onhashchange' in window) {
 283   if (curr_expected_line == SIZE(expected_lines)) return true;
 284   string label, contents;
 285   split_label_contents(expected_lines.at(curr_expected_line), &label, &contents);
-286   for (vector<trace_line>::iterator p = Trace_stream->past_lines.begin();  p != Trace_stream->past_lines.end();  ++p) {
+286   for (vector<trace_line>::iterator p = Trace_stream->past_lines.begin();  p != Trace_stream->past_lines.end();  ++p) {
 287     if (label != p->label) continue;
 288     if (contents != trim(p->contents)) continue;
 289     ++curr_expected_line;
@@ -353,14 +357,14 @@ if ('onhashchange' in window) {
 294   }
 295 
 296   if (line_exists_anywhere(label, contents)) {
-297     cerr << "\nF - " << FUNCTION << "(" << FILE << ":" << LINE << "): line [" << label << ": " << contents << "] out of order in trace:\n";
+297     cerr << "\nF - " << FUNCTION << "(" << FILE << ":" << LINE << "): line [" << label << ": " << contents << "] out of order in trace:\n";
 298     DUMP("");
 299   }
 300   else {
-301     cerr << "\nF - " << FUNCTION << "(" << FILE << ":" << LINE << "): missing [" << contents << "] in trace:\n";
+301     cerr << "\nF - " << FUNCTION << "(" << FILE << ":" << LINE << "): missing [" << contents << "] in trace:\n";
 302     DUMP(label);
 303   }
-304   Passed = false;
+304   Passed = false;
 305   return false;
 306 }
 307 
@@ -378,7 +382,7 @@ if ('onhashchange' in window) {
 319 }
 320 
 321 bool line_exists_anywhere(const string& label, const string& contents) {
-322   for (vector<trace_line>::iterator p = Trace_stream->past_lines.begin();  p != Trace_stream->past_lines.end();  ++p) {
+322   for (vector<trace_line>::iterator p = Trace_stream->past_lines.begin();  p != Trace_stream->past_lines.end();  ++p) {
 323     if (label != p->label) continue;
 324     if (contents == trim(p->contents)) return true;
 325   }
@@ -390,9 +394,9 @@ if ('onhashchange' in window) {
 331 }
 332 
 333 int trace_count(string label, string line) {
-334   if (!Trace_stream) return 0;
+334   if (!Trace_stream) return 0;
 335   long result = 0;
-336   for (vector<trace_line>::iterator p = Trace_stream->past_lines.begin();  p != Trace_stream->past_lines.end();  ++p) {
+336   for (vector<trace_line>::iterator p = Trace_stream->past_lines.begin();  p != Trace_stream->past_lines.end();  ++p) {
 337     if (label == p->label) {
 338       if (line == "" || trim(line) == trim(p->contents))
 339         ++result;
@@ -402,9 +406,9 @@ if ('onhashchange' in window) {
 343 }
 344 
 345 int trace_count_prefix(string label, string prefix) {
-346   if (!Trace_stream) return 0;
+346   if (!Trace_stream) return 0;
 347   long result = 0;
-348   for (vector<trace_line>::iterator p = Trace_stream->past_lines.begin();  p != Trace_stream->past_lines.end();  ++p) {
+348   for (vector<trace_line>::iterator p = Trace_stream->past_lines.begin();  p != Trace_stream->past_lines.end();  ++p) {
 349     if (label == p->label) {
 350       if (starts_with(trim(p->contents), trim(prefix)))
 351         ++result;
@@ -420,7 +424,7 @@ if ('onhashchange' in window) {
 361 bool trace_doesnt_contain(string expected) {
 362   vector<string> tmp = split_first(expected, ": ");
 363   if (SIZE(tmp) == 1) {
-364     raise << expected << ": missing label or contents in trace line\n" << end();
+364     raise << expected << ": missing label or contents in trace line\n" << end();
 365     assert(false);
 366   }
 367   return trace_doesnt_contain(tmp.at(0), tmp.at(1));
@@ -487,8 +491,8 @@ if ('onhashchange' in window) {
 428 //: Errors will be depth 0.
 429 //: Mu 'applications' will be able to use depths 1-100 as they like.
 430 //: Primitive statements will occupy 101-9989
-431 extern const int Initial_callstack_depth = 101;
-432 extern const int Max_callstack_depth = 9989;
+431 extern const int Initial_callstack_depth = 101;
+432 extern const int Max_callstack_depth = 9989;
 433 //: Finally, details of primitive Mu statements will occupy depth 9990-9999
 434 //: (more on that later as well)
 435 //:
-- 
cgit 1.4.1-2-gfad0