gawk-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gawk-diffs] [SCM] gawk branch, comment, updated. gawk-4.1.0-731-gae131a


From: Stephen Davies
Subject: [gawk-diffs] [SCM] gawk branch, comment, updated. gawk-4.1.0-731-gae131ae
Date: Wed, 03 Sep 2014 03:01:19 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "gawk".

The branch, comment has been updated
       via  ae131ae925aa5ba54fb7f8ae105e5cbbf3655f06 (commit)
      from  8006ef4ca16fa8264dcc1e849783e1f4ce4978a1 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.sv.gnu.org/cgit/gawk.git/commit/?id=ae131ae925aa5ba54fb7f8ae105e5cbbf3655f06

commit ae131ae925aa5ba54fb7f8ae105e5cbbf3655f06
Author: Stephen Davies <address@hidden>
Date:   Wed Sep 3 12:23:22 2014 +0930

    ll except functions looking OK

diff --git a/awkgram.y b/awkgram.y
index 664b0c8..1cf2298 100644
--- a/awkgram.y
+++ b/awkgram.y
@@ -209,7 +209,6 @@ program
        | program nls
        | program LEX_EOF
          {
-/* add any outstanding comments to end. But how?  */
                next_sourcefile();
                if (sourcefile == srcfiles)
                        process_deferred();
@@ -291,9 +290,22 @@ library
 
 pattern
        : /* empty */
-         {     $$ = NULL; rule = Rule; }
+         {     rule = Rule;
+               if (comment != NULL){
+                       $$ = list_create(comment);
+                       comment = NULL;
+               } else
+                       $$ = NULL;
+         }
        | exp
-         {     $$ = $1; rule = Rule; }
+         {     rule = Rule;
+               if (comment != NULL){
+                       $$ = list_prepend($1, comment);
+                       comment = NULL;
+               } else
+                       $$ = $1;
+         }
+               
        | exp ',' opt_nls exp
          {
                INSTRUCTION *tp;
@@ -323,6 +335,7 @@ pattern
        | LEX_BEGIN
          {
                static int begin_seen = 0;
+               INSTRUCTION *ip;
                if (do_lint_old && ++begin_seen == 2)
                        warning_ln($1->source_line,
                                _("old awk does not support multiple `BEGIN' or 
`END' rules"));
@@ -359,10 +372,12 @@ pattern
 action
        : l_brace statements r_brace opt_semi opt_nls
          {
+               INSTRUCTION *ip;
                if ($2 == NULL)
-                       $$ = list_create(instruction(Op_no_op));
+                       ip = list_create(instruction(Op_no_op));
                else
-                       $$ = $2;
+                       ip = $2;
+               $$ = ip;
          }
        ;
 
@@ -467,7 +482,7 @@ statements
                                }
                        } else {
                                if (comment != NULL){
-                                       list_append($2, comment);
+                                       list_prepend($2, comment);
                                        comment = NULL;
                                }
                                $$ = list_merge($1, $2);
@@ -488,7 +503,7 @@ statement
        : semi opt_nls
          { $$ = NULL; }
        | l_brace statements r_brace
-         { $$ = $2; }
+         { $$ = $2; } 
        | if_statement
          {
                if (do_pretty_print)
@@ -2240,6 +2255,8 @@ mk_program()
                                cp = end_block;
                        else
                                cp = list_merge(begin_block, end_block);
+                       if (comment != NULL)
+                               (void) list_append(cp, comment);
                        (void) list_append(cp, ip_atexit);
                        (void) list_append(cp, instruction(Op_stop));
 
@@ -2272,6 +2289,8 @@ mk_program()
        if (begin_block != NULL)
                cp = list_merge(begin_block, cp);
 
+       if (comment != NULL)
+               (void) list_append(cp, comment);
        (void) list_append(cp, ip_atexit);
        (void) list_append(cp, instruction(Op_stop));
 
@@ -2969,7 +2988,7 @@ int get_comment(void)
                        } while (isspace(c) && c != END_FILE) ;
                        if ( c == END_FILE)
                                break;
-                       else if (c != '\#'){
+                       else if (c != '#'){
                                pushback();
                                break;
                        } else
@@ -2977,17 +2996,9 @@ int get_comment(void)
                } else
                        break;
        }
-       if (comment != NULL) {
-               size_t new = comment->memory->stlen + (tok - tokstart) + 2;
-               erealloc(comment->memory->stptr, char *, new, "yylex");
-               memcpy(comment->memory->stptr + comment->memory->stlen, 
tokstart, (tok - tokstart));
-               comment->memory->stlen += (tok - tokstart);
-               comment->memory->stptr[comment->memory->stlen] = '\0';
-       } else {
-               comment = bcalloc(Op_comment, 1, sourceline);
-               comment->source_file = source;
-               comment->memory = make_str_node(tokstart, tok - tokstart, 0);
-       }
+       comment = bcalloc(Op_comment, 1, sourceline);
+       comment->source_file = source;
+       comment->memory = make_str_node(tokstart, tok - tokstart, 0);
 
        return c;
 }
@@ -3228,7 +3239,6 @@ retry:
                                        return lasttok = NEWLINE_EOF;
                        }
                }
-//             sourceline++;
                return lasttok = NEWLINE;
 
        case '@':
diff --git a/profile.c b/profile.c
index 51ef971..4db29c9 100644
--- a/profile.c
+++ b/profile.c
@@ -36,7 +36,8 @@ static bool is_scalar(int type);
 static int prec_level(int type);
 static void pp_push(int type, char *s, int flag);
 static NODE *pp_pop(void);
-static void pp_free(NODE *n);
+static void pprint(INSTRUCTION *startp, INSTRUCTION *endp, bool in_for_header);
+static void print_comment(INSTRUCTION *pc, long in);
 const char *redir2str(int redirtype);
 
 #define pp_str vname
@@ -174,9 +175,12 @@ pprint(INSTRUCTION *startp, INSTRUCTION *endp, bool 
in_for_header)
        char *str;
        NODE *t2;
        INSTRUCTION *ip;
+       INSTRUCTION *ic;
+       INSTRUCTION *i2;
        NODE *m;
        char *tmp;
        int rule;
+       long lind;
        static int rule_count[MAXRULE];
 
        for (pc = startp; pc != endp; pc = pc->nexti) {
@@ -189,16 +193,30 @@ pprint(INSTRUCTION *startp, INSTRUCTION *endp, bool 
in_for_header)
                        rule = pc->in_rule;
 
                        if (rule != Rule) {
+                               ip = (pc + 1)->firsti;
+                               if (ip->opcode == Op_comment){
+       /* print pre-begin/end comments */
+                                       print_comment(ip, 0);
+                                       ip = pc->nexti->nexti;
+                               }
                                if (! rule_count[rule]++)
                                        fprintf(prof_fp, _("\t# %s 
block(s)\n\n"), ruletab[rule]);
                                fprintf(prof_fp, "\t%s {\n", ruletab[rule]);
-                               ip = (pc + 1)->firsti;
                        } else {
                                if (! rule_count[rule]++)
                                        fprintf(prof_fp, _("\t# Rule(s)\n\n"));
-                               ip = pc->nexti;
-                               indent(ip->exec_count);
+                               ic = ip = pc->nexti;
+                               i2 = (pc + 1)->firsti;
+                               lind = ip->exec_count;
+       /*print pre-block comments */
+                               if(ip->opcode == Op_exec_count && 
ip->nexti->opcode == Op_comment)ip = ip->nexti;
+                               if(ip->opcode == Op_comment){
+                                       print_comment(ip, lind);
+                                       if (ip->nexti->nexti == (pc + 
1)->firsti)
+                                               ip = ip->nexti->nexti;
+                               }
                                if (ip != (pc + 1)->firsti) {           /* 
non-empty pattern */
+                                       indent(lind);
                                        pprint(ip->nexti, (pc + 1)->firsti, 
false);
                                        t1 = pp_pop();
                                        fprintf(prof_fp, "%s {", t1->pp_str);
@@ -210,7 +228,7 @@ pprint(INSTRUCTION *startp, INSTRUCTION *endp, bool 
in_for_header)
 
                                        fprintf(prof_fp, "\n");
                                } else {
-                                       fprintf(prof_fp, "{\n");
+                                       fprintf(prof_fp, "\t{\n");
                                        ip = (pc + 1)->firsti;
                                }
                                ip = ip->nexti;
@@ -874,27 +892,11 @@ cleanup:
                        break;
 
                case Op_comment:
-               {
-                       char *text;
-                       size_t count;
-                       bool after_newline = false;
-
-                       count = pc->memory->stlen;
-                       text = pc->memory->stptr;
-
-                       indent(SPACEOVER);   /* is this correct? Where should 
comments go?  */
-                       for (; count > 0; count--, text++) {
-                               if (after_newline) {
-                                       indent(SPACEOVER);
-                                       after_newline = false;
-                               }
-                               putc(*text, prof_fp);
-                               if (*text == '\n')
-                                       after_newline = true;
-                       }
-               }
+                       print_comment(pc, 0);
                        break;
 
+               case Op_list:
+                       break;
                default:
                        cant_happen();
                }
@@ -977,6 +979,28 @@ print_lib_list(FILE *prof_fp)
                fprintf(prof_fp, "\n");
 }
 
+/* print comment text with proper indentation */
+static void
+print_comment(INSTRUCTION* pc, long in){
+                       char *text;
+                       size_t count;
+                       bool after_newline = false;
+
+                       count = pc->memory->stlen;
+                       text = pc->memory->stptr;
+
+                       indent(in);   /* is this correct? Where should comments 
go?  */
+                       for (; count > 0; count--, text++) {
+                               if (after_newline) {
+                                       indent(in);
+                                       after_newline = false;
+                               }
+                               putc(*text, prof_fp);
+                               if (*text == '\n')
+                                       after_newline = true;
+                       }
+}
+
 /* dump_prog --- dump the program */
 
 /*

-----------------------------------------------------------------------

Summary of changes:
 awkgram.y |   50 +++++++++++++++++++++++++-----------------
 profile.c |   72 ++++++++++++++++++++++++++++++++++++++++--------------------
 2 files changed, 78 insertions(+), 44 deletions(-)


hooks/post-receive
-- 
gawk



reply via email to

[Prev in Thread] Current Thread [Next in Thread]