2002-12-01
2002-12-01 18:39:07 by Martin Stjernholm <mast@lysator.liu.se>
-
7c7a3f7c4ed46da89e355413fb675bd81c72aade
(237 lines)
(+143/-94)
[
Show
| Annotate
]
Branch: 7.9
Separated the line retrieval functions into two variants so that it's
possible to avoid the dwim:ey fallback strings when a line isn't found.
Added a function to be able to store a line number in the placeholder
program returned by __empty_program.
Rev: src/program.c:1.465
Rev: src/program.h:1.170
2:
|| This file is part of Pike. For copyright information see COPYRIGHT.
|| Pike is distributed under GPL, LGPL and MPL. See the file COPYING
|| for more information.
- || $Id: program.c,v 1.464 2002/12/01 00:16:55 mast Exp $
+ || $Id: program.c,v 1.465 2002/12/01 18:39:07 mast Exp $
*/
#include "global.h"
- RCSID("$Id: program.c,v 1.464 2002/12/01 00:16:55 mast Exp $");
+ RCSID("$Id: program.c,v 1.465 2002/12/01 18:39:07 mast Exp $");
#include "program.h"
#include "object.h"
#include "dynamic_buffer.h"
1781:
#define START_SIZE 64
#define FOO(NUMTYPE,TYPE,NAME) \
+ if (Pike_compiler->new_program->NAME) { \
+ 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=(TYPE *)xalloc(sizeof(TYPE) * START_SIZE);
#include "program_areas.h"
4748:
#endif /* PIKE_DEBUG */
}
+ static void ext_insert_small_number (char **ptr, INT32 a)
+ {
+ if(a>-127 && a<127)
+ {
+ *(*ptr)++ = a;
+ }else if(a>=-32768 && a<32768){
+ *(*ptr)++ = -127;
+ *(*ptr)++ = a>>8;
+ *(*ptr)++ = a;
+ }else{
+ *(*ptr)++ = -128;
+ *(*ptr)++ = a>>24;
+ *(*ptr)++ = a>>16;
+ *(*ptr)++ = a>>8;
+ *(*ptr)++ = a;
+ }
+ }
+
+ void ext_store_program_line (struct program *prog, INT32 line, struct pike_string *file)
+ {
+ char *ptr;
+
+ #ifdef PIKE_DEBUG
+ if (prog->linenumbers)
+ 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) + 5 + 5);
+ *ptr++ = 127;
+ ext_insert_small_number (&ptr, file->len);
+ *ptr++ = file->size_shift;
+ MEMCPY (ptr, file->str, file->len << file->size_shift);
+ ptr += file->len << file->size_shift;
+ *ptr++ = 0; /* PC */
+ ext_insert_small_number (&ptr, line);
+ prog->num_linenumbers = ptr - prog->linenumbers;
+ }
+
void store_linenumber(INT32 current_line, struct pike_string *current_file)
{
/* if(!store_linenumbers) Pike_fatal("Fnord.\n"); */
4844:
}
}
- /* 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,
+ PMOD_EXPORT struct pike_string *low_get_program_line (struct program *prog,
INT32 *linep)
{
-
+ if (prog->linenumbers) {
char *cnt;
size_t len = 0;
INT32 shift = 0;
char *file = NULL;
- if(prog == Pike_compiler->new_program)
- {
- struct pike_string *optimizer;
- linep[0]=0;
- MAKE_CONSTANT_SHARED_STRING(optimizer, "Optimizer");
- return optimizer;
- }
-
+
cnt = prog->linenumbers;
if (cnt < prog->linenumbers + prog->num_linenumbers) {
if (*cnt == 127) {
4876:
*linep = get_small_number(&cnt);
}
else *linep = 0;
+
if (file) {
struct pike_string *str = begin_wide_shared_string(len, shift);
memcpy(str->str, file, len<<shift);
return end_shared_string(str);
- } else {
+ }
+ }
+
+ 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,
+ INT32 *linep)
+ {
+ struct pike_string *res = low_get_program_line(prog, linep);
+ if (!res) {
struct pike_string *dash;
MAKE_CONSTANT_SHARED_STRING(dash, "-");
return dash;
}
-
+ return res;
}
#ifdef PIKE_DEBUG
4902: Inside #if defined(PIKE_DEBUG)
char *file = NULL;
static char buffer[1025];
- if(prog == Pike_compiler->new_program)
- {
- linep[0]=0;
- return "optimizer";
- }
+ if (!prog->linenumbers)
+ return "stub";
cnt = prog->linenumbers;
if (cnt < prog->linenumbers + prog->num_linenumbers) {
4957:
}
#endif
- /*
- * return the file in which we were executing. pc should be the
- * program counter (i.e. the address in prog->program), prog the
- * current program, and line will be initialized to the line in that
- * file.
- */
- PMOD_EXPORT struct pike_string *get_line(PIKE_OPCODE_T *pc,
+ PMOD_EXPORT struct pike_string *low_get_line (PIKE_OPCODE_T *pc,
struct program *prog, INT32 *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 char *cnt;
static INT32 off,line,pid;
static size_t len;
static INT32 shift;
- ptrdiff_t offset;
+
- linep[0] = 0;
-
- if (prog == 0) {
- struct pike_string *unknown_program;
- MAKE_CONSTANT_SHARED_STRING(unknown_program, "Unknown program");
- return unknown_program;
- }
-
- if(prog == Pike_compiler->new_program)
- {
- struct pike_string *optimizer;
- MAKE_CONSTANT_SHARED_STRING(optimizer, "Optimizer");
- return optimizer;
- }
-
- offset = pc - prog->program;
-
- if ((offset > (ptrdiff_t)prog->num_program) || (offset < 0)) {
- struct pike_string *not_found;
- MAKE_CONSTANT_SHARED_STRING(not_found, "Line not found");
- return not_found;
- }
-
+
if(prog->id != pid || offset < off)
{
cnt=prog->linenumbers;
5023:
line+=get_small_number(&cnt);
}
linep[0]=line;
- if (!file) {
- struct pike_string *not_found;
- MAKE_CONSTANT_SHARED_STRING(not_found, "Line not found");
- return not_found;
- } else {
+ if (file) {
struct pike_string *res = begin_wide_shared_string(len, shift);
memcpy(res->str, file, len<<shift);
return end_shared_string(res);
}
}
-
+ }
-
+ return NULL;
+ }
+
+ /*
+ * return the file in which we were executing. pc should be the
+ * program counter (i.e. the address in prog->program), prog the
+ * current program, and line will be initialized to the line in that
+ * file.
+ */
+ PMOD_EXPORT struct pike_string *get_line(PIKE_OPCODE_T *pc,
+ struct program *prog, INT32 *linep)
+ {
+ struct pike_string *res;
+
+ if (prog == 0) {
+ struct pike_string *unknown_program;
+ MAKE_CONSTANT_SHARED_STRING(unknown_program, "Unknown program");
+ linep[0] = 0;
+ return unknown_program;
+ }
+
+ res = low_get_line(pc, prog, linep);
+ if (!res) {
+ struct pike_string *not_found;
+ MAKE_CONSTANT_SHARED_STRING(not_found, "Line not found");
+ return not_found;
+ }
+ return res;
+ }
+
void my_yyerror(char *fmt,...) ATTRIBUTE((format(printf,1,2)))
{
va_list args;