aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2014-09-04 08:52:50 +0300
committerArnold D. Robbins <arnold@skeeve.com>2014-09-04 08:52:50 +0300
commitcb92ab7aa657c57446cc9e0087f1364adaac8fee (patch)
treea3bb5c0d5bd18a2164e8e568596049d2107fb460
parenta0d7edfff1b489e50ae8751429ebf925948b746f (diff)
downloadegawk-cb92ab7aa657c57446cc9e0087f1364adaac8fee.tar.gz
egawk-cb92ab7aa657c57446cc9e0087f1364adaac8fee.tar.bz2
egawk-cb92ab7aa657c57446cc9e0087f1364adaac8fee.zip
Improve printing empty for loop header in profiler.
-rw-r--r--ChangeLog5
-rw-r--r--profile.c30
-rw-r--r--test/ChangeLog4
-rw-r--r--test/profile2.ok4
4 files changed, 30 insertions, 13 deletions
diff --git a/ChangeLog b/ChangeLog
index a892931e..81631787 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2014-09-04 Arnold D. Robbins <arnold@skeeve.com>
+
+ * profile.c (pprint): Case Op_K_for: Improve printing of
+ empty for loop header.
+
2014-09-01 Arnold D. Robbins <arnold@skeeve.com>
* builtin.c (do_substr): Return "" instead of null string in case
diff --git a/profile.c b/profile.c
index eae24b1c..d07bea4a 100644
--- a/profile.c
+++ b/profile.c
@@ -731,20 +731,28 @@ cleanup:
ip = pc + 1;
indent(ip->forloop_body->exec_count);
fprintf(prof_fp, "%s (", op2str(pc->opcode));
- pprint(pc->nexti, ip->forloop_cond, true);
- fprintf(prof_fp, "; ");
- if (ip->forloop_cond->opcode == Op_no_op &&
- ip->forloop_cond->nexti == ip->forloop_body)
+ /* If empty for looop header, print it a little more nicely. */
+ if ( pc->nexti->opcode == Op_no_op
+ && ip->forloop_cond == pc->nexti
+ && pc->target_continue->opcode == Op_jmp) {
+ fprintf(prof_fp, ";;");
+ } else {
+ pprint(pc->nexti, ip->forloop_cond, true);
fprintf(prof_fp, "; ");
- else {
- pprint(ip->forloop_cond, ip->forloop_body, true);
- t1 = pp_pop();
- fprintf(prof_fp, "%s; ", t1->pp_str);
- pp_free(t1);
- }
- pprint(pc->target_continue, pc->target_break, true);
+ if (ip->forloop_cond->opcode == Op_no_op &&
+ ip->forloop_cond->nexti == ip->forloop_body)
+ fprintf(prof_fp, "; ");
+ else {
+ pprint(ip->forloop_cond, ip->forloop_body, true);
+ t1 = pp_pop();
+ fprintf(prof_fp, "%s; ", t1->pp_str);
+ pp_free(t1);
+ }
+
+ pprint(pc->target_continue, pc->target_break, true);
+ }
fprintf(prof_fp, ") {\n");
indent_in();
pprint(ip->forloop_body->nexti, pc->target_continue, false);
diff --git a/test/ChangeLog b/test/ChangeLog
index ba9bef3b..c6a102b4 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,7 @@
+2014-09-04 Arnold D. Robbins <arnold@skeeve.com>
+
+ * profile2.ok: Update after code improvement in profiler.
+
2014-08-15 Arnold D. Robbins <arnold@skeeve.com>
* badargs.ok: Adjust after revising text for -L option.
diff --git a/test/profile2.ok b/test/profile2.ok
index fe76a2c9..50c7e190 100644
--- a/test/profile2.ok
+++ b/test/profile2.ok
@@ -7,7 +7,7 @@
1 asplit("BEGIN:END:atan2:break:close:continue:cos:delete:" "do:else:exit:exp:for:getline:gsub:if:in:index:int:" "length:log:match:next:print:printf:rand:return:sin:" "split:sprintf:sqrt:srand:sub:substr:system:while", keywords, ":")
1 split("00:00:00:00:00:00:00:00:00:00:" "20:10:10:12:12:11:07:00:00:00:" "08:08:08:08:08:33:08:00:00:00:" "08:44:08:36:08:08:08:00:00:00:" "08:44:45:42:42:41:08", machine, ":")
1 state = 1
- 571 for (; ; ) {
+ 571 for (;;) {
571 symb = lex()
571 nextstate = substr(machine[state symb], 1, 1)
571 act = substr(machine[state symb], 2, 1)
@@ -109,7 +109,7 @@
571 function lex()
{
- 1702 for (; ; ) {
+ 1702 for (;;) {
1702 if (tok == "(eof)") {
return 7
}