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

Diff of /trunk/instrument-js.c

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

revision 349 by siliconforks, Fri Oct 24 16:17:19 2008 UTC revision 355 by siliconforks, Fri Oct 24 16:19:11 2008 UTC
# Line 28  Line 28 
28  #include <jsapi.h>  #include <jsapi.h>
29  #include <jsarena.h>  #include <jsarena.h>
30  #include <jsatom.h>  #include <jsatom.h>
31    #include <jsemit.h>
32  #include <jsexn.h>  #include <jsexn.h>
33  #include <jsfun.h>  #include <jsfun.h>
34  #include <jsinterp.h>  #include <jsinterp.h>
# Line 314  Line 315 
315        Stream_write_string(f, ", ");        Stream_write_string(f, ", ");
316      }      }
317      JSAtom * param = JS_LOCAL_NAME_TO_ATOM(local_names[i]);      JSAtom * param = JS_LOCAL_NAME_TO_ATOM(local_names[i]);
318        if (param == NULL) {
319          fatal("unsupported parameter type for function: %s", file_id);
320        }
321      print_string_atom(param, f);      print_string_atom(param, f);
322    }    }
323    JS_FinishArenaPool(&pool);    JS_FinishArenaPool(&pool);
# Line 332  Line 336 
336  }  }
337    
338  static void instrument_function_call(JSParseNode * node, Stream * f) {  static void instrument_function_call(JSParseNode * node, Stream * f) {
339    if (node->pn_head->pn_type == TOK_FUNCTION) {    JSParseNode * function_node = node->pn_head;
340      /* it's a generator expression */    if (function_node->pn_type == TOK_FUNCTION) {
341      JSParseNode * function_node = node->pn_head;      JSObject * object = function_node->pn_funpob->object;
342      JSParseNode * lexical_scope_node = function_node->pn_body;      assert(JS_ObjectIsFunction(context, object));
343      assert(lexical_scope_node->pn_type == TOK_LEXICALSCOPE);      JSFunction * function = (JSFunction *) JS_GetPrivate(context, object);
344      assert(lexical_scope_node->pn_arity == PN_NAME);      assert(function);
345      JSParseNode * for_node = lexical_scope_node->pn_body;      assert(object == &function->object);
346      assert(for_node->pn_type == TOK_FOR);  
347      assert(for_node->pn_arity == PN_BINARY);      if (function_node->pn_flags & TCF_GENEXP_LAMBDA) {
348      JSParseNode * if_node = NULL;        /* it's a generator expression */
349      JSParseNode * semi_node;        JSParseNode * lexical_scope_node = function_node->pn_body;
350      switch (for_node->pn_right->pn_type) {        assert(lexical_scope_node->pn_type == TOK_LEXICALSCOPE);
351      case TOK_SEMI:        assert(lexical_scope_node->pn_arity == PN_NAME);
352        semi_node = for_node->pn_right;        JSParseNode * for_node = lexical_scope_node->pn_body;
353        break;        assert(for_node->pn_type == TOK_FOR);
354      case TOK_IF:        assert(for_node->pn_arity == PN_BINARY);
355        if_node = for_node->pn_right;        JSParseNode * if_node = NULL;
356        assert(if_node->pn_arity == PN_TERNARY);        JSParseNode * semi_node;
357        semi_node = if_node->pn_kid2;        switch (for_node->pn_right->pn_type) {
358        assert(semi_node->pn_type == TOK_SEMI);        case TOK_SEMI:
359        break;          semi_node = for_node->pn_right;
360      default:          break;
361        abort();        case TOK_IF:
362        break;          if_node = for_node->pn_right;
363            assert(if_node->pn_arity == PN_TERNARY);
364            semi_node = if_node->pn_kid2;
365            assert(semi_node->pn_type == TOK_SEMI);
366            break;
367          default:
368            abort();
369            break;
370          }
371          assert(semi_node->pn_arity == PN_UNARY);
372          JSParseNode * yield_node = semi_node->pn_kid;
373          assert(yield_node->pn_type == TOK_YIELD);
374          Stream_write_char(f, '(');
375          instrument_expression(yield_node->pn_kid, f);
376          Stream_write_char(f, ' ');
377          output_for_in(for_node, f);
378          if (if_node) {
379            Stream_write_string(f, " if (");
380            instrument_expression(if_node->pn_kid1, f);
381            Stream_write_char(f, ')');
382          }
383          Stream_write_char(f, ')');
384          return;
385      }      }
386      assert(semi_node->pn_arity == PN_UNARY);      else {
387      JSParseNode * yield_node = semi_node->pn_kid;        Stream_write_char(f, '(');
388      assert(yield_node->pn_type == TOK_YIELD);        instrument_expression(function_node, f);
     Stream_write_char(f, '(');  
     instrument_expression(yield_node->pn_kid, 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);  
389        Stream_write_char(f, ')');        Stream_write_char(f, ')');
390      }      }
     Stream_write_char(f, ')');  
391    }    }
392    else {    else {
393      instrument_expression(node->pn_head, f);      instrument_expression(function_node, f);
394      Stream_write_char(f, '(');    }
395      for (struct JSParseNode * p = node->pn_head->pn_next; p != NULL; p = p->pn_next) {    Stream_write_char(f, '(');
396        if (p != node->pn_head->pn_next) {    for (struct JSParseNode * p = function_node->pn_next; p != NULL; p = p->pn_next) {
397          Stream_write_string(f, ", ");      if (p != node->pn_head->pn_next) {
398        }        Stream_write_string(f, ", ");
       instrument_expression(p, f);  
399      }      }
400      Stream_write_char(f, ')');      instrument_expression(p, f);
401    }    }
402      Stream_write_char(f, ')');
403  }  }
404    
405  static void instrument_declarations(JSParseNode * list, Stream * f) {  static void instrument_declarations(JSParseNode * list, Stream * f) {
# Line 526  Line 544 
544        instrument_expression(node->pn_kid, f);        instrument_expression(node->pn_kid, f);
545        break;        break;
546      default:      default:
547        abort();        fatal("%s: unknown operator (%d) in file", file_id, node->pn_op);
548        break;        break;
549      }      }
550      break;      break;
# Line 635  Line 653 
653    case TOK_RC:    case TOK_RC:
654      Stream_write_char(f, '{');      Stream_write_char(f, '{');
655      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) {
656        assert(p->pn_type == TOK_COLON);        if (p->pn_type != TOK_COLON) {
657            fatal("unsupported node type in file %s: %d", file_id, p->pn_type);
658          }
659        if (p != node->pn_head) {        if (p != node->pn_head) {
660          Stream_write_string(f, ", ");          Stream_write_string(f, ", ");
661        }        }
# Line 741  Line 761 
761      break;      break;
762    case TOK_YIELD:    case TOK_YIELD:
763      assert(node->pn_arity == PN_UNARY);      assert(node->pn_arity == PN_UNARY);
764      Stream_write_string(f, "yield ");      Stream_write_string(f, "yield");
765      instrument_expression(node->pn_kid, f);      if (node->pn_kid != NULL) {
766          Stream_write_char(f, ' ');
767          instrument_expression(node->pn_kid, f);
768        }
769      break;      break;
770    case TOK_ARRAYCOMP:    case TOK_ARRAYCOMP:
771      assert(node->pn_arity == PN_LIST);      assert(node->pn_arity == PN_LIST);
# Line 880  Line 903 
903      Stream_write_string(f, "switch (");      Stream_write_string(f, "switch (");
904      instrument_expression(node->pn_left, f);      instrument_expression(node->pn_left, f);
905      Stream_write_string(f, ") {\n");      Stream_write_string(f, ") {\n");
906      for (struct JSParseNode * p = node->pn_right->pn_head; p != NULL; p = p->pn_next) {      {
907        Stream_printf(f, "%*s", indent, "");        JSParseNode * list = node->pn_right;
908        switch (p->pn_type) {        if (list->pn_type == TOK_LEXICALSCOPE) {
909        case TOK_CASE:          list = list->pn_expr;
910          Stream_write_string(f, "case ");        }
911          instrument_expression(p->pn_left, f);        for (struct JSParseNode * p = list->pn_head; p != NULL; p = p->pn_next) {
912          Stream_write_string(f, ":\n");          Stream_printf(f, "%*s", indent, "");
913          break;          switch (p->pn_type) {
914        case TOK_DEFAULT:          case TOK_CASE:
915          Stream_write_string(f, "default:\n");            Stream_write_string(f, "case ");
916          break;            instrument_expression(p->pn_left, f);
917        default:            Stream_write_string(f, ":\n");
918          abort();            break;
919          break;          case TOK_DEFAULT:
920              Stream_write_string(f, "default:\n");
921              break;
922            default:
923              abort();
924              break;
925            }
926            instrument_statement(p->pn_right, f, indent + 2, false);
927        }        }
       instrument_statement(p->pn_right, f, indent + 2, false);  
928      }      }
929      Stream_printf(f, "%*s", indent, "");      Stream_printf(f, "%*s", indent, "");
930      Stream_write_string(f, "}\n");      Stream_write_string(f, "}\n");

Legend:
Removed from v.349  
changed lines
  Added in v.355

  ViewVC Help
Powered by ViewVC 1.1.24