pike.git / src / program.c

version» Context lines:

pike.git/src/program.c:1337:      static struct program *reporter_program = NULL;   struct program *compilation_program = 0;   struct program *compilation_env_program = 0;   struct object *compilation_environment = NULL;      struct program *gc_internal_program = 0;   static struct program *gc_mark_program_pos = 0;      #ifdef PIKE_DEBUG - #define CHECK_FILE_ENTRY(PROG, POS, LEN, SHIFT) \ + #define CHECK_FILE_ENTRY(PROG, STRNO) \    do { \ -  if (SHIFT < 0 || SHIFT > 2 || \ -  POS + (LEN << SHIFT) > PROG->linenumbers + PROG->num_linenumbers) \ +  if ((STRNO < 0) || (STRNO >= PROG->num_strings)) \    Pike_fatal ("Invalid file entry in linenumber info.\n"); \    } while (0)   #else - #define CHECK_FILE_ENTRY(PROG, POS, LEN, SHIFT) do {} while (0) + #define CHECK_FILE_ENTRY(PROG, STRNO) do {} while (0)   #endif      INT_TYPE get_small_number(char **q);      PMOD_EXPORT void do_free_program (struct program *p)   {    if (p)    free_program(p);   }   
pike.git/src/program.c:2931:   #define FOO(NUMTYPE,TYPE,ARGTYPE,NAME) \    Pike_compiler->malloc_size_program->PIKE_CONCAT(num_,NAME) = \    Pike_compiler->new_program->PIKE_CONCAT(num_,NAME);   #include "program_areas.h"       {    INT_TYPE line = 0;    INT32 off = 0;    size_t len = 0;    INT32 shift = 0; -  char *file=0; +  struct pike_string *file=0;    char *cnt=Pike_compiler->new_program->linenumbers;       while(cnt < Pike_compiler->new_program->linenumbers +    Pike_compiler->new_program->num_linenumbers)    {    if(*cnt == 127)    { -  +  int strno;    cnt++; -  len = get_small_number(&cnt); -  shift = *cnt; -  file = ++cnt; -  CHECK_FILE_ENTRY (Pike_compiler->new_program, cnt, len, shift); -  cnt += len<<shift; +  strno = get_small_number(&cnt); +  CHECK_FILE_ENTRY (Pike_compiler->new_program, strno); +  file = Pike_compiler->new_program->strings[strno];    }    off+=get_small_number(&cnt);    line+=get_small_number(&cnt);    }    Pike_compiler->last_line=line;    Pike_compiler->last_pc=off;    if(file)    { -  struct pike_string *str = begin_wide_shared_string(len, shift); +     if(Pike_compiler->last_file) free_string(Pike_compiler->last_file); -  memcpy(str->str, file, len<<shift); -  Pike_compiler->last_file = end_shared_string(str); +  copy_shared_string(Pike_compiler->last_file, file);    }    }       }else{    static struct pike_string *s;    struct inherit i;    -  +  if (Pike_compiler->new_program->strings) { +  struct pike_string **str = Pike_compiler->new_program->strings; +  int j = Pike_compiler->new_program->num_strings; +  while(j--) { +  free_string(*str); +  str++; +  } +  } +    #define START_SIZE 64   #ifdef PIKE_USE_MACHINE_CODE   #define BAR(NUMTYPE,TYPE,ARGTYPE,NAME) \    if (Pike_compiler->new_program->NAME) { \    mexec_free(Pike_compiler->new_program->NAME); \    Pike_compiler->new_program->PIKE_CONCAT(num_,NAME) = 0; \    } \    Pike_compiler->malloc_size_program->PIKE_CONCAT(num_,NAME) = \    START_SIZE; \    Pike_compiler->new_program->NAME = \
pike.git/src/program.c:3493:    fprintf(stderr, "\n"    "%*sLinenumber table:\n",    indent, "");    {    INT32 off = 0;    INT_TYPE line = 0;    char *cnt = p->linenumbers;       while (cnt < p->linenumbers + p->num_linenumbers) {    if (*cnt == 127) { -  int len, shift; -  char *file; +  int strno;    cnt++; -  len = get_small_number(&cnt); -  shift = *cnt; -  file = ++cnt; -  CHECK_FILE_ENTRY (p, cnt, len, shift); -  cnt += len << shift; -  if (!shift) { -  fprintf(stderr, "%*s Filename: \"%s\"\n", indent, "", file); -  } else { -  fprintf(stderr, "%*s Filename: len:%d, shift:%d\n", indent, "", len, shift); +  strno = get_small_number(&cnt); +  fprintf(stderr, "%*s Filename: String #%d\n", indent, "", strno);    } -  } +     off += get_small_number(&cnt);    line += get_small_number(&cnt);    fprintf(stderr, "%*s %8d:%8ld\n", indent, "", off, (long)line);    }    }       fprintf(stderr, "\n");   }      void check_program(struct program *p)
pike.git/src/program.c:7072:    if (low_program_index_no_free(to, p, e, parent, parent_identifier))    return 1;    }       SET_SVAL(*to, T_INT, NUMBER_UNDEFINED, integer, 0);    return 1;   }      /*    * Line number support routines, now also tells what file we are in. -  * -  * FIXME: Consider storing the filenames in strings (like what is now done -  * for identifiers). +     */      /* program.linenumbers format:    *    * Filename entry:    * 1. char 127 (marker). -  * 2. small number Filename string length. -  * 3. char Filename string size shift. -  * 4. string data (Possibly wide) filename string without null -  * termination. -  * Each character is stored in native byte order. +  * 2. small number Filename entry number in string table.    *    * Line number entry:    * 1. small number Index in program.program (pc).    * Stored as the difference from the pc in the    * closest previous line number entry. The first    * stored entry is absolute.    * 2. small number Line number. Stored in the same way as the pc.    *    * Small number:    * If -127 < n < 127:
pike.git/src/program.c:7261:    *(*ptr)++ = a>>8;    *(*ptr)++ = a;    }   }      void ext_store_program_line (struct program *prog, INT_TYPE line, struct pike_string *file)   {    char *ptr;      #ifdef PIKE_DEBUG -  if (prog->linenumbers) +  if (prog->linenumbers || prog->strings)    Pike_fatal ("Program already got linenumber info.\n");    if (Pike_compiler->new_program == prog)    Pike_fatal ("Use store_linenumber instead when the program is compiled.\n");   #endif    -  ptr = prog->linenumbers = xalloc (1 + 5 + 1 + (file->len << file->size_shift) + 1 + 11); +  add_ref((prog->strings = xalloc(sizeof(struct pike_string *)))[0] = file); +  +  ptr = prog->linenumbers = xalloc (1 + 1 + 1 + 11);    *ptr++ = 127; /* 1 */ -  ext_insert_small_number (&ptr, file->len); /* 5 */ -  *ptr++ = (char) file->size_shift; /* 1 */ -  MEMCPY (ptr, file->str, file->len << file->size_shift); /* - */ -  ptr += file->len << file->size_shift; +  *ptr++ = 0; /* String #0 */ /* 1 */    *ptr++ = 0; /* PC */ /* 1 */    ext_insert_small_number (&ptr, line); /* 11 */    prog->num_linenumbers = ptr - prog->linenumbers;   }      void store_linenumber(INT_TYPE current_line, struct pike_string *current_file)   {   /* if(!store_linenumbers) Pike_fatal("Fnord.\n"); */   #ifdef PIKE_DEBUG    if(a_flag)    {    INT_TYPE line=0;    INT32 off=0; -  size_t len = 0; -  INT32 shift = 0; -  char *file=0; +     char *cnt=Pike_compiler->new_program->linenumbers; -  +  struct pike_string *file = NULL;       if (a_flag > 50) {    fprintf(stderr, "store_linenumber(%ld, \"%s\") at pc %d\n",    (long)current_line, current_file->str,    (INT32) PIKE_PC);    fprintf(stderr, " last_line:%ld last_file:\"%s\"\n",    (long)Pike_compiler->last_line,    Pike_compiler->last_file?Pike_compiler->last_file->str:"");    }       while(cnt < Pike_compiler->new_program->linenumbers +    Pike_compiler->new_program->num_linenumbers)    {    char *start = cnt;    if(*cnt == 127)    { -  +  int strno;    cnt++; -  len = get_small_number(&cnt); -  shift = *cnt; -  file = ++cnt; -  CHECK_FILE_ENTRY (Pike_compiler->new_program, cnt, len, shift); -  cnt += len<<shift; +  strno = get_small_number(&cnt); +  CHECK_FILE_ENTRY (Pike_compiler->new_program, strno);    if (a_flag > 100) { -  +  file = Pike_compiler->new_program->strings[strno];    fprintf(stderr, "Filename entry:\n"    " len: %"PRINTSIZET"d, shift: %d\n", -  len, shift); +  file->len, file->size_shift);    }    }    off+=get_small_number(&cnt);    line+=get_small_number(&cnt);    if (a_flag > 100) {    fprintf(stderr, " off: %d, line: %ld\n"    " raw: ",    off, (long)line);    for (;start < cnt; start++) {    fprintf(stderr, "%02x ", *((unsigned char *)start));    }    fprintf(stderr, "\n");    }    }       if(Pike_compiler->last_line != line ||    Pike_compiler->last_pc != off || -  (Pike_compiler->last_file && file && -  MEMCMP(Pike_compiler->last_file->str, file, len<<shift))) +  (file && (Pike_compiler->last_file != file)))    {    Pike_fatal("Line numbering out of whack\n"    " (line : %ld ?= %ld)!\n"    " ( pc : %d ?= %d)!\n"    " (shift: %d ?= %d)!\n"    " (len : %"PRINTSIZET"d ?= %"PRINTSIZET"d)!\n"    " (file : %s ?= %s)!\n",    (long)Pike_compiler->last_line, (long)line,    Pike_compiler->last_pc, off,    Pike_compiler->last_file?Pike_compiler->last_file->size_shift:0, -  shift, -  Pike_compiler->last_file?Pike_compiler->last_file->len:0, len, +  file?file->size_shift:0, +  Pike_compiler->last_file?Pike_compiler->last_file->len:0, +  file?file->len:0,    Pike_compiler->last_file?Pike_compiler->last_file->str:"N/A", -  file?file:"N/A"); +  file?file->str:"N/A");    }    }   #endif    if(Pike_compiler->last_line != current_line ||    Pike_compiler->last_file != current_file)    {    if(Pike_compiler->last_file != current_file)    { -  char *tmp; -  INT32 remain = DO_NOT_WARN((INT32)current_file->len)<< -  current_file->size_shift; -  +     if(Pike_compiler->last_file) free_string(Pike_compiler->last_file);    add_to_linenumbers(127); -  insert_small_number(DO_NOT_WARN((INT32)current_file->len)); -  add_to_linenumbers(current_file->size_shift); -  for(tmp=current_file->str; remain-- > 0; tmp++) -  add_to_linenumbers(*tmp); +  insert_small_number(store_prog_string(current_file));    copy_shared_string(Pike_compiler->last_file, current_file);    }    insert_small_number(DO_NOT_WARN((INT32)(PIKE_PC-Pike_compiler->last_pc)));    insert_small_number(current_line-Pike_compiler->last_line);    Pike_compiler->last_line = current_line;    Pike_compiler->last_pc = DO_NOT_WARN((INT32)PIKE_PC);    }   }    - #define FIND_PROGRAM_LINE(prog, file, len, shift, line) do { \ + #define FIND_PROGRAM_LINE(prog, file, line) do { \    char *pos = prog->linenumbers; \ -  len = 0; \ -  shift = 0; \ +     file = NULL; \    \    if (pos < prog->linenumbers + prog->num_linenumbers) { \    if (*pos == 127) { \ -  +  int strno; \    pos++; \ -  len = get_small_number(&pos); \ -  shift = *pos; \ -  file = ++pos; \ -  CHECK_FILE_ENTRY (prog, pos, len, shift); \ -  pos += len<<shift; \ +  strno = get_small_number(&pos); \ +  CHECK_FILE_ENTRY (Pike_compiler->new_program, strno); \ +  file = prog->strings[strno]; \    } \    get_small_number(&pos); /* Ignore the offset */ \    line = get_small_number(&pos); \    } \    } while (0)      PMOD_EXPORT struct pike_string *low_get_program_line (struct program *prog,    INT_TYPE *linep)   {    *linep = 0;       if (prog->linenumbers) { -  size_t len; -  INT32 shift; -  char *file; +  struct pike_string *file;    -  FIND_PROGRAM_LINE (prog, file, len, shift, (*linep)); +  FIND_PROGRAM_LINE (prog, file, (*linep));       if (file) { -  struct pike_string *str = begin_wide_shared_string(len, shift); -  memcpy(str->str, file, len<<shift); -  return end_shared_string(str); +  add_ref(file); +  return file;    }    }       return NULL;   }      static char *make_plain_file (char *file, size_t len, INT32 shift, int malloced)   {    static char buf[1000];    if(shift)
pike.git/src/program.c:7496:    * can't be touched. It also converts wide strings to ordinary ones    * with escaping.    */   PMOD_EXPORT char *low_get_program_line_plain(struct program *prog,    INT_TYPE *linep,    int malloced)   {    *linep = 0;       if (prog->linenumbers) { -  char *file; -  size_t len; -  INT32 shift; -  FIND_PROGRAM_LINE (prog, file, len, shift, (*linep)); -  if (file) return make_plain_file (file, len, shift, malloced); +  struct pike_string *file; +  FIND_PROGRAM_LINE (prog, file, (*linep)); +  if (file) +  return make_plain_file(file->str, file->len, file->size_shift, malloced);    }       return NULL;   }      /* Returns the file where the program is defined. The line of the    * class start is written to linep, or 0 if the program is the top    * level of the file. */   PMOD_EXPORT struct pike_string *get_program_line(struct program *prog,    INT_TYPE *linep)
pike.git/src/program.c:7530:      PMOD_EXPORT struct pike_string *low_get_line (PIKE_OPCODE_T *pc,    struct program *prog,    INT_TYPE *linep)   {    linep[0] = 0;       if (prog->program && prog->linenumbers) {    ptrdiff_t offset = pc - prog->program;    if ((offset < (ptrdiff_t)prog->num_program) && (offset >= 0)) { -  static char *file = NULL; +  static struct pike_string *file = NULL;    static char *base, *cnt;    static ptrdiff_t off;    static INT32 pid;    static INT_TYPE line; -  static size_t len; -  static INT32 shift; +        if(prog->linenumbers == base && prog->id == pid && offset > off &&    cnt < prog->linenumbers + prog->num_linenumbers)    goto fromold;       base = cnt = prog->linenumbers;    off=line=0;    pid=prog->id;    file = 0;       while(cnt < prog->linenumbers + prog->num_linenumbers)    {    if(*cnt == 127)    { -  +  int strno;    cnt++; -  len = get_small_number(&cnt); -  shift = *cnt; -  file = ++cnt; -  CHECK_FILE_ENTRY (prog, cnt, len, shift); -  cnt += len<<shift; +  strno = get_small_number(&cnt); +  CHECK_FILE_ENTRY (prog, strno); +  file = prog->strings[strno];    continue;    }    off+=get_small_number(&cnt);    fromold:    if(off > offset) break;    line+=get_small_number(&cnt);    }    if (cnt >= prog->linenumbers + prog->num_linenumbers) {    /* We reached the end of the table. Make sure    * we get in sync again next time we're called.    */    base = NULL;    }    linep[0]=line;    if (file) { -  struct pike_string *res = begin_wide_shared_string(len, shift); -  memcpy(res->str, file, len<<shift); -  return end_shared_string(res); +  add_ref(file); +  return file;    }    } else {    fprintf(stderr, "Bad offset: pc:%p program:%p (%p)\n",    pc, prog->program, (void *)prog->num_program);    }    } else {    fprintf(stderr, "No program of linenumbers program:%p linenumbers:%p\n",    prog->program, prog->linenumbers);    }   
pike.git/src/program.c:7602:   {    linep[0] = 0;       if (prog->program && prog->linenumbers) {    ptrdiff_t offset = pc - prog->program;       if ((offset < (ptrdiff_t)prog->num_program) && (offset >= 0)) {    char *cnt = prog->linenumbers;    INT32 off = 0;    INT_TYPE line = 0; -  char *file = NULL; -  size_t len = 0; -  INT32 shift = 0; +  struct pike_string *file = NULL;       while(cnt < prog->linenumbers + prog->num_linenumbers)    {    if(*cnt == 127)    { -  +  int strno;    cnt++; -  len = get_small_number(&cnt); -  shift = *cnt; -  file = ++cnt; -  CHECK_FILE_ENTRY (prog, cnt, len, shift); -  cnt += len<<shift; +  strno = get_small_number(&cnt); +  CHECK_FILE_ENTRY (Pike_compiler->new_program, strno); +  file = prog->strings[strno];    }    off+=get_small_number(&cnt);    if(off > offset) break;    line+=get_small_number(&cnt);    }    linep[0]=line;    -  if (file) return make_plain_file (file, len, shift, malloced); +  if (file) +  return make_plain_file(file->str, file->len, file->size_shift, malloced);    }    }       return NULL;   }      #ifdef PIKE_DEBUG   /* Variants for convenient use from a debugger. */      void gdb_program_line (struct program *prog)