/[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 116 by siliconforks, Sat May 31 21:42:36 2008 UTC revision 155 by siliconforks, Mon Sep 1 20:30:28 2008 UTC
# Line 148  Line 148 
148  static void instrument_expression(JSParseNode * node, Stream * f);  static void instrument_expression(JSParseNode * node, Stream * f);
149  static void instrument_statement(JSParseNode * node, Stream * f, int indent);  static void instrument_statement(JSParseNode * node, Stream * f, int indent);
150    
151  static void instrument_function(JSParseNode * node, Stream * f, int indent) {  enum FunctionType {
152      FUNCTION_NORMAL,
153      FUNCTION_GETTER_OR_SETTER
154    };
155    
156    static void instrument_function(JSParseNode * node, Stream * f, int indent, enum FunctionType type) {
157      assert(node->pn_arity == PN_FUNC);      assert(node->pn_arity == PN_FUNC);
158      assert(ATOM_IS_OBJECT(node->pn_funAtom));      assert(ATOM_IS_OBJECT(node->pn_funAtom));
159      JSObject * object = ATOM_TO_OBJECT(node->pn_funAtom);      JSObject * object = ATOM_TO_OBJECT(node->pn_funAtom);
# Line 157  Line 162 
162      assert(function);      assert(function);
163      assert(object == function->object);      assert(object == function->object);
164      Stream_printf(f, "%*s", indent, "");      Stream_printf(f, "%*s", indent, "");
165      Stream_write_string(f, "function");      if (type == FUNCTION_NORMAL) {
166          Stream_write_string(f, "function");
167        }
168    
169      /* function name */      /* function name */
170      if (function->atom) {      if (function->atom) {
# Line 228  Line 235 
235  static void instrument_expression(JSParseNode * node, Stream * f) {  static void instrument_expression(JSParseNode * node, Stream * f) {
236    switch (node->pn_type) {    switch (node->pn_type) {
237    case TOK_FUNCTION:    case TOK_FUNCTION:
238      instrument_function(node, f, 0);      instrument_function(node, f, 0, FUNCTION_NORMAL);
239      break;      break;
240    case TOK_COMMA:    case TOK_COMMA:
241      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) {
# Line 435  Line 442 
442        if (p != node->pn_head) {        if (p != node->pn_head) {
443          Stream_write_string(f, ", ");          Stream_write_string(f, ", ");
444        }        }
445        instrument_expression(p->pn_left, f);  
446        Stream_write_string(f, ": ");        /* check whether this is a getter or setter */
447        instrument_expression(p->pn_right, f);        switch (p->pn_op) {
448          case JSOP_GETTER:
449            Stream_write_string(f, "get ");
450            instrument_expression(p->pn_left, f);
451            instrument_function(p->pn_right, f, 0, FUNCTION_GETTER_OR_SETTER);
452            break;
453          case JSOP_SETTER:
454            Stream_write_string(f, "set ");
455            instrument_expression(p->pn_left, f);
456            instrument_function(p->pn_right, f, 0, FUNCTION_GETTER_OR_SETTER);
457            break;
458          default:
459            instrument_expression(p->pn_left, f);
460            Stream_write_string(f, ": ");
461            instrument_expression(p->pn_right, f);
462            break;
463          }
464      }      }
465      Stream_write_char(f, '}');      Stream_write_char(f, '}');
466      break;      break;
# Line 541  Line 564 
564  static void output_statement(JSParseNode * node, Stream * f, int indent) {  static void output_statement(JSParseNode * node, Stream * f, int indent) {
565    switch (node->pn_type) {    switch (node->pn_type) {
566    case TOK_FUNCTION:    case TOK_FUNCTION:
567      instrument_function(node, f, indent);      instrument_function(node, f, indent, FUNCTION_NORMAL);
568      break;      break;
569    case TOK_LC:    case TOK_LC:
570      assert(node->pn_arity == PN_LIST);      assert(node->pn_arity == PN_LIST);

Legend:
Removed from v.116  
changed lines
  Added in v.155

  ViewVC Help
Powered by ViewVC 1.1.24