/[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 2 by siliconforks, Wed Aug 1 13:51:53 2007 UTC revision 90 by siliconforks, Tue May 6 14:05:12 2008 UTC
# Line 1  Line 1 
1  /*  /*
2      instrument-js.c - JavaScript instrumentation routines      instrument-js.c - JavaScript instrumentation routines
3      Copyright (C) 2007 siliconforks.com      Copyright (C) 2007, 2008 siliconforks.com
4    
5      This program is free software; you can redistribute it and/or modify      This program is free software; you can redistribute it and/or modify
6      it under the terms of the GNU General Public License as published by      it under the terms of the GNU General Public License as published by
# Line 385  Line 385 
385      the dot syntax.      the dot syntax.
386      */      */
387      instrument_expression(node->pn_expr, f);      instrument_expression(node->pn_expr, f);
388      /*      assert(ATOM_IS_STRING(node->pn_atom));
389      fputc('.', f);      {
390      print_string_atom(node->pn_atom, f);        JSString * s = ATOM_TO_STRING(node->pn_atom);
391      */        /* XXX - semantics changed in 1.7 */
392      fputc('[', f);        if (! ATOM_KEYWORD(node->pn_atom) && js_IsIdentifier(s)) {
393      print_quoted_string_atom(node->pn_atom, f);          fputc('.', f);
394      fputc(']', f);          print_string_atom(node->pn_atom, f);
395          }
396          else {
397            fputc('[', f);
398            print_quoted_string_atom(node->pn_atom, f);
399            fputc(']', f);
400          }
401        }
402      break;      break;
403    case TOK_LB:    case TOK_LB:
404      instrument_expression(node->pn_left, f);      instrument_expression(node->pn_left, f);
# Line 794  Line 801 
801    output_statement(node, f, indent);    output_statement(node, f, indent);
802  }  }
803    
804  static void instrument_js_stream(const char * id, int line, FILE * input, FILE * output) {  static void instrument_js_stream(const char * id, int line, FILE * input, FILE * output, const char * temporary_file_name) {
805    file_id = id;    file_id = id;
806    
807    /* scan the javascript */    /* scan the javascript */
# Line 818  Line 825 
825    Create a temporary file - we can't write directly to the output because we    Create a temporary file - we can't write directly to the output because we
826    need to know the line number info first.    need to know the line number info first.
827    */    */
828    FILE * temporary = tmpfile();    FILE * temporary = fopen(temporary_file_name, "w+");
829    if (temporary == NULL) {    if (temporary == NULL) {
830      fatal("cannot create temporary file for script: %s", file_id);      fatal("cannot create temporary file for script: %s", file_id);
831    }    }
# Line 838  Line 845 
845      }      }
846    }    }
847    fprintf(output, "}\n");    fprintf(output, "}\n");
848      free(lines);
849    lines = NULL;    lines = NULL;
850    
851    /* copy the temporary to the output */    /* copy the temporary to the output */
# Line 849  Line 857 
857    file_id = NULL;    file_id = NULL;
858  }  }
859    
860  void jscoverage_instrument_js(const char * id, FILE * input, FILE * output) {  void jscoverage_instrument_js(const char * id, FILE * input, FILE * output, const char * temporary_file_name) {
861    instrument_js_stream(id, 0, input, output);    instrument_js_stream(id, 0, input, output, temporary_file_name);
862  }  }

Legend:
Removed from v.2  
changed lines
  Added in v.90

  ViewVC Help
Powered by ViewVC 1.1.24