/[jscoverage]/trunk/instrument-js.cpp
ViewVC logotype

Diff of /trunk/instrument-js.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 339 by siliconforks, Fri Oct 24 16:13:57 2008 UTC revision 340 by siliconforks, Fri Oct 24 16:14:20 2008 UTC
# Line 324  Line 324 
324    Stream_write_char(f, ')');    Stream_write_char(f, ')');
325  }  }
326    
327    static void instrument_declarations(JSParseNode * list, Stream * f) {
328      assert(list->pn_arity == PN_LIST);
329      for (JSParseNode * p = list->pn_head; p != NULL; p = p->pn_next) {
330        assert(p->pn_type == TOK_NAME);
331        assert(p->pn_arity == PN_NAME);
332        if (p != list->pn_head) {
333          Stream_write_string(f, ", ");
334        }
335        print_string_atom(p->pn_atom, f);
336        if (p->pn_expr != NULL) {
337          Stream_write_string(f, " = ");
338          instrument_expression(p->pn_expr, f);
339        }
340      }
341    }
342    
343  /*  /*
344  See <Expressions> in jsparse.h.  See <Expressions> in jsparse.h.
345  TOK_FUNCTION is handled as a statement and as an expression.  TOK_FUNCTION is handled as a statement and as an expression.
# Line 628  Line 644 
644      Stream_write_string(f, " in ");      Stream_write_string(f, " in ");
645      instrument_expression(node->pn_right, f);      instrument_expression(node->pn_right, f);
646      break;      break;
647      case TOK_LEXICALSCOPE:
648        assert(node->pn_arity == PN_NAME);
649        assert(node->pn_expr->pn_type == TOK_LET);
650        assert(node->pn_expr->pn_arity == PN_BINARY);
651        Stream_write_string(f, "let(");
652        assert(node->pn_expr->pn_left->pn_type == TOK_LP);
653        assert(node->pn_expr->pn_left->pn_arity == PN_LIST);
654        instrument_declarations(node->pn_expr->pn_left, f);
655        Stream_write_string(f, ") ");
656        instrument_expression(node->pn_expr->pn_right, f);
657        break;
658    default:    default:
659      fatal("unsupported node type in file %s: %d", file_id, node->pn_type);      fatal("unsupported node type in file %s: %d", file_id, node->pn_type);
660    }    }
# Line 637  Line 664 
664    assert(node->pn_arity == PN_LIST);    assert(node->pn_arity == PN_LIST);
665    Stream_printf(f, "%*s", indent, "");    Stream_printf(f, "%*s", indent, "");
666    Stream_write_string(f, "var ");    Stream_write_string(f, "var ");
667    for (struct JSParseNode * p = node->pn_u.list.head; p != NULL; p = p->pn_next) {    instrument_declarations(node, f);
668      assert(p->pn_type == TOK_NAME);  }
669      assert(p->pn_arity == PN_NAME);  
670      if (p != node->pn_head) {  static void instrument_let_definition(JSParseNode * node, Stream * f, int indent) {
671        Stream_write_string(f, ", ");    assert(node->pn_arity == PN_LIST);
672      }    Stream_printf(f, "%*s", indent, "");
673      print_string_atom(p->pn_atom, f);    Stream_write_string(f, "let ");
674      if (p->pn_expr != NULL) {    instrument_declarations(node, f);
       Stream_write_string(f, " = ");  
       instrument_expression(p->pn_expr, f);  
     }  
   }  
675  }  }
676    
677  static void output_statement(JSParseNode * node, Stream * f, int indent, bool is_jscoverage_if) {  static void output_statement(JSParseNode * node, Stream * f, int indent, bool is_jscoverage_if) {
# Line 784  Line 807 
807        case TOK_VAR:        case TOK_VAR:
808          instrument_var_statement(node->pn_left->pn_left, f, 0);          instrument_var_statement(node->pn_left->pn_left, f, 0);
809          break;          break;
810          case TOK_LET:
811            instrument_let_definition(node->pn_left->pn_left, f, 0);
812            break;
813        case TOK_NAME:        case TOK_NAME:
814          instrument_expression(node->pn_left->pn_left, f);          instrument_expression(node->pn_left->pn_left, f);
815          break;          break;
# Line 805  Line 831 
831        /* for (;;) */        /* for (;;) */
832        assert(node->pn_left->pn_arity == PN_TERNARY);        assert(node->pn_left->pn_arity == PN_TERNARY);
833        if (node->pn_left->pn_kid1) {        if (node->pn_left->pn_kid1) {
834          if (node->pn_left->pn_kid1->pn_type == TOK_VAR) {          switch (node->pn_left->pn_kid1->pn_type) {
835            case TOK_VAR:
836            instrument_var_statement(node->pn_left->pn_kid1, f, 0);            instrument_var_statement(node->pn_left->pn_kid1, f, 0);
837          }            break;
838          else {          case TOK_LET:
839              instrument_let_definition(node->pn_left->pn_kid1, f, 0);
840              break;
841            default:
842            instrument_expression(node->pn_left->pn_kid1, f);            instrument_expression(node->pn_left->pn_kid1, f);
843              break;
844          }          }
845        }        }
846        Stream_write_string(f, ";");        Stream_write_string(f, ";");
# Line 933  Line 964 
964      */      */
965      output_statement(node->pn_expr, f, indent, false);      output_statement(node->pn_expr, f, indent, false);
966      break;      break;
967      case TOK_LEXICALSCOPE:
968        /* let statement */
969        assert(node->pn_arity == PN_NAME);
970        switch (node->pn_expr->pn_type) {
971        case TOK_LET:
972          /* let statement */
973          assert(node->pn_expr->pn_arity == PN_BINARY);
974          instrument_statement(node->pn_expr, f, indent, false);
975          break;
976        case TOK_LC:
977          /* block */
978          Stream_printf(f, "%*s", indent, "");
979          Stream_write_string(f, "{\n");
980          instrument_statement(node->pn_expr, f, indent + 2, false);
981          Stream_printf(f, "%*s", indent, "");
982          Stream_write_string(f, "}\n");
983          break;
984        case TOK_FOR:
985          instrument_statement(node->pn_expr, f, indent, false);
986          break;
987        default:
988          abort();
989          break;
990        }
991        break;
992      case TOK_LET:
993        switch (node->pn_arity) {
994        case PN_BINARY:
995          /* let statement */
996          Stream_printf(f, "%*s", indent, "");
997          Stream_write_string(f, "let (");
998          assert(node->pn_left->pn_type == TOK_LP);
999          assert(node->pn_left->pn_arity == PN_LIST);
1000          instrument_declarations(node->pn_left, f);
1001          Stream_write_string(f, ") {\n");
1002          instrument_statement(node->pn_right, f, indent + 2, false);
1003          Stream_printf(f, "%*s", indent, "");
1004          Stream_write_string(f, "}\n");
1005          break;
1006        case PN_LIST:
1007          /* let definition */
1008          instrument_let_definition(node, f, indent);
1009          Stream_write_string(f, ";\n");
1010          break;
1011        default:
1012          abort();
1013          break;
1014        }
1015        break;
1016    default:    default:
1017      fatal("unsupported node type in file %s: %d", file_id, node->pn_type);      fatal("unsupported node type in file %s: %d", file_id, node->pn_type);
1018    }    }
# Line 944  Line 1024 
1024  TOK_EXPORT, TOK_IMPORT are not handled.  TOK_EXPORT, TOK_IMPORT are not handled.
1025  */  */
1026  static void instrument_statement(JSParseNode * node, Stream * f, int indent, bool is_jscoverage_if) {  static void instrument_statement(JSParseNode * node, Stream * f, int indent, bool is_jscoverage_if) {
1027    if (node->pn_type != TOK_LC) {    if (node->pn_type != TOK_LC && node->pn_type != TOK_LEXICALSCOPE) {
1028      uint16_t line = node->pn_pos.begin.lineno;      uint16_t line = node->pn_pos.begin.lineno;
1029      if (line > num_lines) {      if (line > num_lines) {
1030        fatal("%s: script contains more than 65,535 lines", file_id);        fatal("%s: script contains more than 65,535 lines", file_id);

Legend:
Removed from v.339  
changed lines
  Added in v.340

  ViewVC Help
Powered by ViewVC 1.1.24