aboutsummaryrefslogtreecommitdiffstats
path: root/profile.c
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2016-03-03 22:05:24 +0200
committerArnold D. Robbins <arnold@skeeve.com>2016-03-17 22:02:20 +0200
commit4b33ad392a8ddf1cc480d29498af80f7da1db269 (patch)
tree4fec86680f2e9eabaa4c1db9e5ec3faecdc07004 /profile.c
parentcd6b37514fd3eea9cc26a76514d487328a11a8ba (diff)
downloadegawk-4b33ad392a8ddf1cc480d29498af80f7da1db269.tar.gz
egawk-4b33ad392a8ddf1cc480d29498af80f7da1db269.tar.bz2
egawk-4b33ad392a8ddf1cc480d29498af80f7da1db269.zip
Initial changes to improve end of line comments.
Diffstat (limited to 'profile.c')
-rw-r--r--profile.c55
1 files changed, 39 insertions, 16 deletions
diff --git a/profile.c b/profile.c
index 43875600..f55ad287 100644
--- a/profile.c
+++ b/profile.c
@@ -26,7 +26,7 @@
#include "awk.h"
static void pprint(INSTRUCTION *startp, INSTRUCTION *endp, int flags);
-static void end_line(INSTRUCTION *ip);
+static INSTRUCTION *end_line(INSTRUCTION *ip);
static void pp_parenthesize(NODE *n);
static void parenthesize(int type, NODE *left, NODE *right);
static char *pp_list(int nargs, const char *paren, const char *delim);
@@ -207,6 +207,7 @@ pprint(INSTRUCTION *startp, INSTRUCTION *endp, int flags)
char *tmp;
int rule;
static int rule_count[MAXRULE];
+ static bool skip_comment = false;
for (pc = startp; pc != endp; pc = pc->nexti) {
if (pc->source_line > 0)
@@ -214,8 +215,13 @@ pprint(INSTRUCTION *startp, INSTRUCTION *endp, int flags)
/* skip leading EOL comment as it has already been printed */
if (pc->opcode == Op_comment
- && pc->memory->comment_type == EOL_COMMENT)
+ && pc->memory->comment_type == EOL_COMMENT
+ && skip_comment) {
+ skip_comment = false;
continue;
+ }
+ skip_comment = false;
+
switch (pc->opcode) {
case Op_rule:
/*
@@ -246,6 +252,7 @@ pprint(INSTRUCTION *startp, INSTRUCTION *endp, int flags)
}
fprintf(prof_fp, "%s {", ruletab[rule]);
end_line(pc);
+ skip_comment = true;
} else {
if (do_profile && ! rule_count[rule]++)
fprintf(prof_fp, _("\t# Rule(s)\n\n"));
@@ -268,6 +275,7 @@ pprint(INSTRUCTION *startp, INSTRUCTION *endp, int flags)
fprintf(prof_fp, " # %ld", ip1->exec_count);
end_line(ip1);
+ skip_comment = true;
} else {
fprintf(prof_fp, "{\n");
ip1 = (pc + 1)->firsti;
@@ -366,7 +374,7 @@ cleanup:
pp_free(t2);
pp_free(t1);
if ((flags & IN_FOR_HEADER) == 0)
- end_line(pc);
+ pc = end_line(pc);
break;
default:
@@ -492,7 +500,7 @@ cleanup:
pp_free(t2);
pp_free(t1);
if ((flags & IN_FOR_HEADER) == 0)
- end_line(pc);
+ pc = end_line(pc);
break;
case Op_concat:
@@ -513,7 +521,7 @@ cleanup:
} else
fprintf(prof_fp, "%s %s", op2str(Op_K_delete), array);
if ((flags & IN_FOR_HEADER) == 0)
- end_line(pc);
+ pc = end_line(pc);
pp_free(t1);
}
break;
@@ -625,7 +633,7 @@ cleanup:
fprintf(prof_fp, "%s%s", op2str(pc->opcode), tmp);
efree(tmp);
if ((flags & IN_FOR_HEADER) == 0)
- end_line(pc);
+ pc = end_line(pc);
break;
case Op_push_re:
@@ -734,7 +742,8 @@ cleanup:
case Op_K_break:
case Op_K_nextfile:
case Op_K_next:
- fprintf(prof_fp, "%s\n", op2str(pc->opcode));
+ fprintf(prof_fp, "%s", op2str(pc->opcode));
+ pc = end_line(pc);
break;
case Op_K_return:
@@ -742,8 +751,10 @@ cleanup:
t1 = pp_pop();
if (is_binary(t1->type))
pp_parenthesize(t1);
- if (pc->source_line > 0) /* don't print implicit 'return' at end of function */
- fprintf(prof_fp, "%s %s\n", op2str(pc->opcode), t1->pp_str);
+ if (pc->source_line > 0) { /* don't print implicit 'return' at end of function */
+ fprintf(prof_fp, "%s %s", op2str(pc->opcode), t1->pp_str);
+ pc = end_line(pc);
+ }
pp_free(t1);
break;
@@ -751,7 +762,7 @@ cleanup:
t1 = pp_pop();
fprintf(prof_fp, "%s", t1->pp_str);
if ((flags & IN_FOR_HEADER) == 0)
- end_line(pc);
+ pc = end_line(pc);
pp_free(t1);
break;
@@ -878,10 +889,13 @@ cleanup:
indent(pc->stmt_start->exec_count);
if (pc->opcode == Op_K_case) {
t1 = pp_pop();
- fprintf(prof_fp, "%s %s:\n", op2str(pc->opcode), t1->pp_str);
+ fprintf(prof_fp, "%s %s:", op2str(pc->opcode), t1->pp_str);
+ pc = end_line(pc);
pp_free(t1);
- } else
- fprintf(prof_fp, "%s:\n", op2str(pc->opcode));
+ } else {
+ fprintf(prof_fp, "%s:", op2str(pc->opcode));
+ pc = end_line(pc);
+ }
indent_in();
pprint(pc->stmt_start->nexti, pc->stmt_end->nexti, NO_PPRINT_FLAGS);
indent_out();
@@ -996,17 +1010,21 @@ cleanup:
/* end_line --- end pretty print line with new line or on-line comment */
-void
+INSTRUCTION *
end_line(INSTRUCTION *ip)
{
+ INSTRUCTION *ret = ip;
+
if (ip->nexti->opcode == Op_comment
&& ip->nexti->memory->comment_type == EOL_COMMENT) {
fprintf(prof_fp, "\t");
print_comment(ip->nexti, -1);
- ip = ip->nexti->nexti;
+ ret = ip->nexti;
}
else
fprintf(prof_fp, "\n");
+
+ return ret;
}
/* pp_string_fp --- printy print a string to the fp */
@@ -1736,7 +1754,12 @@ pp_func(INSTRUCTION *pc, void *data ATTRIBUTE_UNUSED)
if (j < pcount - 1)
fprintf(prof_fp, ", ");
}
- fprintf(prof_fp, ")\n");
+ if (fp->opcode == Op_comment
+ && fp->memory->comment_type == EOL_COMMENT) {
+ fprintf(prof_fp, ")");
+ fp = end_line(fp);
+ } else
+ fprintf(prof_fp, ")\n");
if (do_profile)
indent(0);
fprintf(prof_fp, "{\n");