"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "profile.c" between
gawk-5.0.1.tar.xz and gawk-5.1.0.tar.xz

About: GNU awk - pattern scanning and processing language.

profile.c  (gawk-5.0.1.tar.xz):profile.c  (gawk-5.1.0.tar.xz)
/* /*
* profile.c - gawk bytecode pretty-printer with counts * profile.c - gawk bytecode pretty-printer with counts
*/ */
/* /*
* Copyright (C) 1999-2019 the Free Software Foundation, Inc. * Copyright (C) 1999-2020 the Free Software Foundation, Inc.
* *
* This file is part of GAWK, the GNU implementation of the * This file is part of GAWK, the GNU implementation of the
* AWK Programming Language. * AWK Programming Language.
* *
* GAWK is free software; you can redistribute it and/or modify * GAWK is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or * the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* GAWK is distributed in the hope that it will be useful, * GAWK is distributed in the hope that it will be useful,
skipping to change at line 198 skipping to change at line 198
static NODE * static NODE *
pp_pop() pp_pop()
{ {
NODE *n; NODE *n;
n = pp_stack; n = pp_stack;
pp_stack = n->pp_next; pp_stack = n->pp_next;
return n; return n;
} }
/* pp_top --- look at what's on the top of the stack */
#define pp_top() pp_stack
/* pp_free --- release a pretty printed node */ /* pp_free --- release a pretty printed node */
static void static void
pp_free(NODE *n) pp_free(NODE *n)
{ {
if ((n->flags & CAN_FREE) != 0) if ((n->flags & CAN_FREE) != 0)
efree(n->pp_str); efree(n->pp_str);
freenode(n); freenode(n);
} }
skipping to change at line 667 skipping to change at line 671
fatal(_("internal error: builtin with null fname" )); fatal(_("internal error: builtin with null fname" ));
} }
break; break;
case Op_K_print: case Op_K_print:
case Op_K_printf: case Op_K_printf:
case Op_K_print_rec: case Op_K_print_rec:
if (pc->opcode == Op_K_print_rec) if (pc->opcode == Op_K_print_rec)
// instead of `print $0', just `print' // instead of `print $0', just `print'
tmp = strdup(""); tmp = strdup("");
else if (pc->redir_type != 0) else if (pc->redir_type != 0) {
tmp = pp_list(pc->expr_count, "()", ", "); // Avoid turning printf("hello\n") into printf(("
else { hello\n"))
NODE *n = pp_top();
if (pc->expr_count == 1
&& n->pp_str[0] == '('
&& n->pp_str[n->pp_len - 1] == ')') {
n = pp_pop();
tmp = strdup(n->pp_str);
pp_free(n);
} else
tmp = pp_list(pc->expr_count, "()", ", ")
;
} else {
tmp = pp_list(pc->expr_count, " ", ", "); tmp = pp_list(pc->expr_count, " ", ", ");
tmp[strlen(tmp) - 1] = '\0'; /* remove trailin g space */ tmp[strlen(tmp) - 1] = '\0'; /* remove trailin g space */
} }
if (pc->redir_type != 0) { if (pc->redir_type != 0) {
t1 = pp_pop(); t1 = pp_pop();
if (is_binary(t1->type)) if (is_binary(t1->type))
pp_parenthesize(t1); pp_parenthesize(t1);
fprintf(prof_fp, "%s%s%s%s", op2str(pc->opcode), fprintf(prof_fp, "%s%s%s%s", op2str(pc->opcode),
tmp, redir2str(pc->redir_ type), t1->pp_str); tmp, redir2str(pc->redir_ type), t1->pp_str);
skipping to change at line 1787 skipping to change at line 1802
assert(strlen(paren) == 2); assert(strlen(paren) == 2);
len += 2; len += 2;
} }
} }
comment = NULL; comment = NULL;
emalloc(str, char *, len + 1, "pp_list"); emalloc(str, char *, len + 1, "pp_list");
s = str; s = str;
if (paren != NULL) if (paren != NULL)
*s++ = paren[0]; *s++ = paren[0];
if (nargs > 0) {
r = pp_args[nargs]; for (i = nargs; i > 0; i--) {
// argument
r = pp_args[i];
memcpy(s, r->pp_str, r->pp_len); memcpy(s, r->pp_str, r->pp_len);
s += r->pp_len; s += r->pp_len;
pp_free(r);
for (i = nargs - 1; i > 0; i--) { // delimiter
if (delimlen > 0) { if (i > 1 && delimlen > 0) {
memcpy(s, delim, delimlen); memcpy(s, delim, delimlen);
s += delimlen; s += delimlen;
} }
if (r->pp_comment != NULL) {
check_indent_level(); // comment if any
comment = (INSTRUCTION *) r->pp_comment; if (r->pp_comment != NULL) {
memcpy(s, comment->memory->stptr, comment->memory check_indent_level();
->stlen); comment = (INSTRUCTION *) r->pp_comment;
s += comment->memory->stlen; memcpy(s, comment->memory->stptr, comment->memory->stlen)
memcpy(s, tabs, indent_level + 1); ;
s += indent_level + 1; s += comment->memory->stlen;
} memcpy(s, tabs, indent_level + 1);
r = pp_args[i]; s += indent_level + 1;
memcpy(s, r->pp_str, r->pp_len);
s += r->pp_len;
pp_free(r);
} }
pp_free(r);
} }
if (paren != NULL) if (paren != NULL)
*s++ = paren[1]; *s++ = paren[1];
*s = '\0'; *s = '\0';
return str; return str;
} }
/* is_unary_minus --- return true if string starts with unary minus */ /* is_unary_minus --- return true if string starts with unary minus */
static bool static bool
is_unary_minus(const char *str) is_unary_minus(const char *str)
skipping to change at line 1847 skipping to change at line 1863
if (pp_args == NULL) { if (pp_args == NULL) {
npp_args = nargs; npp_args = nargs;
emalloc(pp_args, NODE **, (nargs + 2) * sizeof(NODE *), "pp_conca t"); emalloc(pp_args, NODE **, (nargs + 2) * sizeof(NODE *), "pp_conca t");
} else if (nargs > npp_args) { } else if (nargs > npp_args) {
npp_args = nargs; npp_args = nargs;
erealloc(pp_args, NODE **, (nargs + 2) * sizeof(NODE *), "pp_conc at"); erealloc(pp_args, NODE **, (nargs + 2) * sizeof(NODE *), "pp_conc at");
} }
/* /*
* items are on the stack in reverse order that they * items are on the stack in reverse order that they
* will be printed to pop them off backwards. * will be printed so pop them off backwards.
*/ */
len = -delimlen; len = -delimlen;
for (i = nargs; i >= 1; i--) { for (i = nargs; i >= 1; i--) {
r = pp_args[i] = pp_pop(); r = pp_args[i] = pp_pop();
len += r->pp_len + delimlen + 2; len += r->pp_len + delimlen + 2;
} }
emalloc(str, char *, len + 1, "pp_concat"); emalloc(str, char *, len + 1, "pp_concat");
s = str; s = str;
skipping to change at line 1888 skipping to change at line 1904
s += r->pp_len; s += r->pp_len;
*s++ = ')'; *s++ = ')';
} else { } else {
memcpy(s, r->pp_str, r->pp_len); memcpy(s, r->pp_str, r->pp_len);
s += r->pp_len; s += r->pp_len;
} }
} else { } else {
memcpy(s, r->pp_str, r->pp_len); memcpy(s, r->pp_str, r->pp_len);
s += r->pp_len; s += r->pp_len;
} }
pp_free(r);
if (i < nargs) { if (i < nargs) {
*s++ = ' '; *s++ = ' ';
} }
} }
pl_l = prec_level(pp_args[nargs-1]->type); pl_l = prec_level(pp_args[nargs-1]->type);
pl_r = prec_level(pp_args[nargs]->type); pl_r = prec_level(pp_args[nargs]->type);
r = pp_args[nargs]; r = pp_args[nargs];
if (r->pp_str[0] == '(') { if (r->pp_str[0] == '(') {
skipping to change at line 1910 skipping to change at line 1925
s += r->pp_len; s += r->pp_len;
} else if (is_unary_minus(r->pp_str) || ((pl_l >= pl_r && ! is_scalar(pp_ args[nargs]->type)))) { } else if (is_unary_minus(r->pp_str) || ((pl_l >= pl_r && ! is_scalar(pp_ args[nargs]->type)))) {
*s++ = '('; *s++ = '(';
memcpy(s, r->pp_str, r->pp_len); memcpy(s, r->pp_str, r->pp_len);
s += r->pp_len; s += r->pp_len;
*s++ = ')'; *s++ = ')';
} else { } else {
memcpy(s, r->pp_str, r->pp_len); memcpy(s, r->pp_str, r->pp_len);
s += r->pp_len; s += r->pp_len;
} }
pp_free(r);
for (i = nargs; i >= 1; i--) {
pp_free(pp_args[i]);
}
*s = '\0'; *s = '\0';
return str; return str;
} }
/* pp_group3 --- string together up to 3 strings */ /* pp_group3 --- string together up to 3 strings */
static char * static char *
pp_group3(const char *s1, const char *s2, const char *s3) pp_group3(const char *s1, const char *s2, const char *s3)
{ {
 End of changes. 10 change blocks. 
28 lines changed or deleted 48 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)