diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2016-08-28 15:21:12 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2016-08-28 15:21:12 -0700 |
commit | 1ba81b0f57f965f390e09f40c5f70eb9931c7498 (patch) | |
tree | 1d9a10935897804d4c96a6de10baa1a475fb7463 /003trace.cc | |
parent | fd6d8612edf07ea4a4612fd5263ad4250e06c77f (diff) | |
download | mu-1ba81b0f57f965f390e09f40c5f70eb9931c7498.tar.gz |
3270
Clean up the Globals section so that we can generate extern declarations for all globals out using this command after we carve it out into globals.cc: grep ';' globals.cc |perl -pwe 's/[=(].*/;/' |perl -pwe 's/^[^\/# ]/extern $&/' > globals.h The first perl command strips out initializers. The second prepends 'extern'. This simplistic approach requires each global definition to lie all on one line.
Diffstat (limited to '003trace.cc')
-rw-r--r-- | 003trace.cc | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/003trace.cc b/003trace.cc index bbe5fb80..d8b92ba1 100644 --- a/003trace.cc +++ b/003trace.cc @@ -155,11 +155,19 @@ string trace_stream::readable_contents(string label) { trace_stream* Trace_stream = NULL; int Trace_errors = 0; // used only when Trace_stream is NULL +:(before "End Includes") +#define CLEAR_TRACE delete Trace_stream, Trace_stream = new trace_stream; + // Top-level helper. IMPORTANT: can't nest #define trace(...) !Trace_stream ? cerr /*print nothing*/ : Trace_stream->stream(__VA_ARGS__) +// Just for debugging; 'git log' should never show any calls to 'dbg'. +#define dbg trace(0, "a") +#define DUMP(label) if (Trace_stream) cerr << Trace_stream->readable_contents(label); + // Errors are a special layer. #define raise (!Trace_stream ? (tb_shutdown(),++Trace_errors,cerr) /*do print*/ : Trace_stream->stream(Error_depth, "error")) + // Inside tests, fail any tests that displayed (unexpected) errors. // Expected errors in tests should always be hidden and silently checked for. :(before "End Test Teardown") @@ -168,9 +176,6 @@ if (Passed && !Hide_errors && trace_count("error") > 0) { ++Num_failures; } -// Just for debugging. -#define dbg trace(0, "a") - :(before "End Types") struct end {}; :(code) @@ -180,26 +185,26 @@ ostream& operator<<(ostream& os, unused end) { } :(before "End Globals") -#define CLEAR_TRACE delete Trace_stream, Trace_stream = new trace_stream; - -#define DUMP(label) if (Trace_stream) cerr << Trace_stream->readable_contents(label); - bool Save_trace = false; // Trace_stream is a resource, lease_tracer uses RAII to manage it. +:(before "End Types") struct lease_tracer { - lease_tracer() { Trace_stream = new trace_stream; } - ~lease_tracer() { - if (!Trace_stream) return; // in case tests close Trace_stream - if (Save_trace) { - ofstream fout("last_trace"); - fout << Trace_stream->readable_contents(""); - fout.close(); - } - delete Trace_stream, Trace_stream = NULL; - } + lease_tracer(); + ~lease_tracer(); }; - +:(code) +lease_tracer::lease_tracer() { Trace_stream = new trace_stream; } +lease_tracer::~lease_tracer() { + if (!Trace_stream) return; // in case tests close Trace_stream + if (Save_trace) { + ofstream fout("last_trace"); + fout << Trace_stream->readable_contents(""); + fout.close(); + } + delete Trace_stream, Trace_stream = NULL; +} +:(before "End Includes") #define START_TRACING_UNTIL_END_OF_SCOPE lease_tracer leased_tracer; :(before "End Test Setup") START_TRACING_UNTIL_END_OF_SCOPE |