/[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 352 by siliconforks, Fri Oct 24 16:18:18 2008 UTC revision 357 by siliconforks, Fri Oct 24 21:48:21 2008 UTC
# Line 277  Line 277 
277    Stream_write_char(f, ')');    Stream_write_char(f, ')');
278  }  }
279    
280    static void output_array_comprehension_or_generator_expression(JSParseNode * node, Stream * f) {
281      assert(node->pn_type == TOK_LEXICALSCOPE);
282      assert(node->pn_arity == PN_NAME);
283      JSParseNode * for_node = node->pn_expr;
284      assert(for_node->pn_type == TOK_FOR);
285      assert(for_node->pn_arity == PN_BINARY);
286      JSParseNode * p = for_node;
287      while (p->pn_type == TOK_FOR) {
288        p = p->pn_right;
289      }
290      JSParseNode * if_node = NULL;
291      if (p->pn_type == TOK_IF) {
292        if_node = p;
293        assert(if_node->pn_arity == PN_TERNARY);
294        p = if_node->pn_kid2;
295      }
296      assert(p->pn_arity == PN_UNARY);
297      p = p->pn_kid;
298      if (p->pn_type == TOK_YIELD) {
299        /* for generator expressions */
300        p = p->pn_kid;
301      }
302    
303      instrument_expression(p, f);
304      p = for_node;
305      while (p->pn_type == TOK_FOR) {
306        Stream_write_char(f, ' ');
307        output_for_in(p, f);
308        p = p->pn_right;
309      }
310      if (if_node) {
311        Stream_write_string(f, " if (");
312        instrument_expression(if_node->pn_kid1, f);
313        Stream_write_char(f, ')');
314      }
315    }
316    
317  static void instrument_function(JSParseNode * node, Stream * f, int indent, enum FunctionType type) {  static void instrument_function(JSParseNode * node, Stream * f, int indent, enum FunctionType type) {
318    assert(node->pn_type == TOK_FUNCTION);    assert(node->pn_type == TOK_FUNCTION);
319    assert(node->pn_arity == PN_FUNC);    assert(node->pn_arity == PN_FUNC);
# Line 346  Line 383 
383    
384      if (function_node->pn_flags & TCF_GENEXP_LAMBDA) {      if (function_node->pn_flags & TCF_GENEXP_LAMBDA) {
385        /* it's a generator expression */        /* it's a generator expression */
       JSParseNode * lexical_scope_node = function_node->pn_body;  
       assert(lexical_scope_node->pn_type == TOK_LEXICALSCOPE);  
       assert(lexical_scope_node->pn_arity == PN_NAME);  
       JSParseNode * for_node = lexical_scope_node->pn_body;  
       assert(for_node->pn_type == TOK_FOR);  
       assert(for_node->pn_arity == PN_BINARY);  
       JSParseNode * if_node = NULL;  
       JSParseNode * semi_node;  
       switch (for_node->pn_right->pn_type) {  
       case TOK_SEMI:  
         semi_node = for_node->pn_right;  
         break;  
       case TOK_IF:  
         if_node = for_node->pn_right;  
         assert(if_node->pn_arity == PN_TERNARY);  
         semi_node = if_node->pn_kid2;  
         assert(semi_node->pn_type == TOK_SEMI);  
         break;  
       default:  
         abort();  
         break;  
       }  
       assert(semi_node->pn_arity == PN_UNARY);  
       JSParseNode * yield_node = semi_node->pn_kid;  
       assert(yield_node->pn_type == TOK_YIELD);  
386        Stream_write_char(f, '(');        Stream_write_char(f, '(');
387        instrument_expression(yield_node->pn_kid, f);        output_array_comprehension_or_generator_expression(function_node->pn_body, f);
       Stream_write_char(f, ' ');  
       output_for_in(for_node, f);  
       if (if_node) {  
         Stream_write_string(f, " if (");  
         instrument_expression(if_node->pn_kid1, f);  
         Stream_write_char(f, ')');  
       }  
388        Stream_write_char(f, ')');        Stream_write_char(f, ')');
389        return;        return;
390      }      }
# Line 544  Line 549 
549        instrument_expression(node->pn_kid, f);        instrument_expression(node->pn_kid, f);
550        break;        break;
551      default:      default:
552        abort();        fatal("%s: unknown operator (%d) in file", file_id, node->pn_op);
553        break;        break;
554      }      }
555      break;      break;
# Line 653  Line 658 
658    case TOK_RC:    case TOK_RC:
659      Stream_write_char(f, '{');      Stream_write_char(f, '{');
660      for (struct JSParseNode * p = node->pn_head; p != NULL; p = p->pn_next) {      for (struct JSParseNode * p = node->pn_head; p != NULL; p = p->pn_next) {
661        assert(p->pn_type == TOK_COLON);        if (p->pn_type != TOK_COLON) {
662            fatal("unsupported node type in file %s: %d", file_id, p->pn_type);
663          }
664        if (p != node->pn_head) {        if (p != node->pn_head) {
665          Stream_write_string(f, ", ");          Stream_write_string(f, ", ");
666        }        }
# Line 759  Line 766 
766      break;      break;
767    case TOK_YIELD:    case TOK_YIELD:
768      assert(node->pn_arity == PN_UNARY);      assert(node->pn_arity == PN_UNARY);
769      Stream_write_string(f, "yield ");      Stream_write_string(f, "yield");
770      instrument_expression(node->pn_kid, f);      if (node->pn_kid != NULL) {
771          Stream_write_char(f, ' ');
772          instrument_expression(node->pn_kid, f);
773        }
774      break;      break;
775    case TOK_ARRAYCOMP:    case TOK_ARRAYCOMP:
776      assert(node->pn_arity == PN_LIST);      assert(node->pn_arity == PN_LIST);
# Line 777  Line 787 
787          abort();          abort();
788          break;          break;
789        }        }
       assert(block_node->pn_type == TOK_LEXICALSCOPE);  
       assert(block_node->pn_arity == PN_NAME);  
       JSParseNode * for_node = block_node->pn_expr;  
       assert(for_node->pn_type == TOK_FOR);  
       assert(for_node->pn_arity == PN_BINARY);  
       JSParseNode * if_node = NULL;  
       JSParseNode * push_node;  
       switch (for_node->pn_right->pn_type) {  
       case TOK_ARRAYPUSH:  
         push_node = for_node->pn_right;  
         assert(push_node->pn_arity == PN_UNARY);  
         break;  
       case TOK_IF:  
         if_node = for_node->pn_right;  
         assert(if_node->pn_arity == PN_TERNARY);  
         push_node = if_node->pn_kid2;  
         break;  
       default:  
         abort();  
         break;  
       }  
790        Stream_write_char(f, '[');        Stream_write_char(f, '[');
791        instrument_expression(push_node->pn_kid, f);        output_array_comprehension_or_generator_expression(block_node, f);
       Stream_write_char(f, ' ');  
       output_for_in(for_node, f);  
       if (if_node) {  
         Stream_write_string(f, " if (");  
         instrument_expression(if_node->pn_kid1, f);  
         Stream_write_char(f, ')');  
       }  
792        Stream_write_char(f, ']');        Stream_write_char(f, ']');
793      }      }
794      break;      break;

Legend:
Removed from v.352  
changed lines
  Added in v.357

  ViewVC Help
Powered by ViewVC 1.1.24