]> granicus.if.org Git - php/commitdiff
Make compile_string() accept a description of the code
authorZeev Suraski <zeev@php.net>
Tue, 12 Sep 2000 19:47:25 +0000 (19:47 +0000)
committerZeev Suraski <zeev@php.net>
Tue, 12 Sep 2000 19:47:25 +0000 (19:47 +0000)
Zend/zend-scanner.l
Zend/zend.c
Zend/zend_builtin_functions.c
Zend/zend_compile.h
Zend/zend_execute.c
Zend/zend_execute.h
Zend/zend_execute_API.c
Zend/zend_highlight.h

index 99feccfceb8e61cb962c286ad34dc1fa03e31bb4..0e0a670fd5c50dbc95040eea5a852bbe632d4740 100644 (file)
@@ -410,9 +410,9 @@ zend_op_array *compile_filename(int type, zval *filename CLS_DC ELS_DC)
 }
 
 #ifndef ZTS
-static inline int prepare_string_for_scanning(zval *str)
+static inline int prepare_string_for_scanning(zval *str, char *filename)
 #else
-static inline int prepare_string_for_scanning(zval *str, istrstream **input_stream CLS_DC)
+static inline int prepare_string_for_scanning(zval *str, istrstream **input_stream, char *filename CLS_DC)
 #endif
 {
 #ifndef ZTS
@@ -429,13 +429,13 @@ static inline int prepare_string_for_scanning(zval *str, istrstream **input_stre
 
        CG(ZFL)->switch_streams(*input_stream, &cout);
 #endif
-       zend_set_compiled_filename("Eval code");
+       zend_set_compiled_filename(filename);
        CG(zend_lineno) = 1;
        return SUCCESS;
 }
 
 
-zend_op_array *compile_string(zval *source_string CLS_DC)
+zend_op_array *compile_string(zval *source_string, char *filename CLS_DC)
 {
        zend_lex_state original_lex_state;
        zend_op_array *op_array = (zend_op_array *) emalloc(sizeof(zend_op_array));
@@ -462,9 +462,9 @@ zend_op_array *compile_string(zval *source_string CLS_DC)
 
        save_lexical_state(&original_lex_state CLS_CC);
 #ifndef ZTS
-       if (prepare_string_for_scanning(source_string)==FAILURE) {
+       if (prepare_string_for_scanning(source_string, filename)==FAILURE) {
 #else
-       if (prepare_string_for_scanning(source_string, &input_stream CLS_CC)==FAILURE) {
+       if (prepare_string_for_scanning(source_string, &input_stream, filename CLS_CC)==FAILURE) {
 #endif
                efree(op_array);
                retval = NULL;
@@ -521,8 +521,7 @@ int highlight_file(char *filename, zend_syntax_highlighter_ini *syntax_highlight
        return SUCCESS;
 }
 
-
-int highlight_string(zval *str, zend_syntax_highlighter_ini *syntax_highlighter_ini)
+int highlight_string(zval *str, zend_syntax_highlighter_ini *syntax_highlighter_ini, char *str_name)
 {
        zend_lex_state original_lex_state;
        zval tmp = *str;
@@ -535,9 +534,9 @@ int highlight_string(zval *str, zend_syntax_highlighter_ini *syntax_highlighter_
        zval_copy_ctor(str);
        save_lexical_state(&original_lex_state CLS_CC);
 #ifndef ZTS
-       if (prepare_string_for_scanning(str)==FAILURE) {
+       if (prepare_string_for_scanning(str, str_name)==FAILURE) {
 #else
-       if (prepare_string_for_scanning(str, &input_stream CLS_CC)==FAILURE) {
+       if (prepare_string_for_scanning(str, &input_stream, str_name CLS_CC)==FAILURE) {
 #endif
                return FAILURE;
        }
index 2c2fa082ae3565ce4f986654ee8bffcd0b68f28a..01737f89463b9dfedf8801924971dceed4c9216a 100644 (file)
@@ -730,3 +730,29 @@ ZEND_API int zend_execute_scripts(int type CLS_DC ELS_DC, int file_count, ...)
        return SUCCESS;
 }
 
+#define COMPILED_STRING_DESCRIPTION_FORMAT "%s(%d) : %s"
+
+ZEND_API char *zend_make_compiled_string_description(char *name)
+{
+       char *cur_filename;
+       int cur_lineno;
+       char *compiled_string_description;
+       CLS_FETCH();
+       ELS_FETCH();
+
+       if (zend_is_compiling()) {
+               cur_filename = zend_get_compiled_filename(CLS_C);
+               cur_lineno = zend_get_compiled_lineno(CLS_C);
+       } else if (zend_is_executing()) {
+               cur_filename = zend_get_executed_filename(ELS_C);
+               cur_lineno = zend_get_executed_lineno(ELS_C);
+       } else {
+               cur_filename = "Unknown";
+               cur_lineno = 0;
+       }
+
+       compiled_string_description = emalloc(sizeof(COMPILED_STRING_DESCRIPTION_FORMAT)+strlen(name)+strlen(cur_filename)+MAX_LENGTH_OF_LONG);
+       sprintf(compiled_string_description, COMPILED_STRING_DESCRIPTION_FORMAT, cur_filename, cur_lineno, name);
+       return compiled_string_description;
+}
+
index f4e25a6f2a0a0a281dea5830b5e09c014820dd44..7c0941186aacab28226e1aad8c9eed67dfa89d83 100644 (file)
@@ -855,6 +855,7 @@ ZEND_FUNCTION(create_function)
        int eval_code_length, function_name_length;
        zval **z_function_args, **z_function_code;
        int retval;
+       char *eval_name;
        CLS_FETCH();
 
        if (ZEND_NUM_ARGS()!=2 || zend_get_parameters_ex(2, &z_function_args, &z_function_code)==FAILURE) {
@@ -873,8 +874,11 @@ ZEND_FUNCTION(create_function)
        eval_code = (char *) emalloc(eval_code_length);
        sprintf(eval_code, "function " LAMBDA_TEMP_FUNCNAME "(%s){%s}", Z_STRVAL_PP(z_function_args), Z_STRVAL_PP(z_function_code));
 
-       retval = zend_eval_string(eval_code, NULL CLS_CC ELS_CC);
+       eval_name = zend_make_compiled_string_description("runtime-created function");
+       retval = zend_eval_string(eval_code, NULL, eval_name CLS_CC ELS_CC);
        efree(eval_code);
+       efree(eval_name);
+
        if (retval==SUCCESS) {
                zend_function *func;
 
index 64b54ff0bca93af774a974ee1e44af930d4b2448..57d90be57efae04e02191c80ee0af593825c7239 100644 (file)
@@ -376,7 +376,7 @@ ZEND_API void function_add_ref(zend_function *function);
 
 /* helper functions in zend-scanner.l */
 ZEND_API zend_op_array *compile_file(zend_file_handle *file_handle, int type CLS_DC);
-ZEND_API zend_op_array *compile_string(zval *source_string CLS_DC);    
+ZEND_API zend_op_array *compile_string(zval *source_string, char *filename CLS_DC);    
 ZEND_API zend_op_array *compile_filename(int type, zval *filename CLS_DC ELS_DC);
 ZEND_API int zend_execute_scripts(int type CLS_DC ELS_DC, int file_count, ...);
 ZEND_API int open_file_for_scanning(zend_file_handle *file_handle CLS_DC);
@@ -400,6 +400,7 @@ void print_op_array(zend_op_array *op_array, int optimizations);
 int pass_two(zend_op_array *op_array);
 zend_brk_cont_element *get_next_brk_cont_element(zend_op_array *op_array);
 ZEND_API zend_bool zend_is_compiling(void);
+ZEND_API char *zend_make_compiled_string_description(char *name);
 
 int zendlex(znode *zendlval CLS_DC);
 
index 6232490bf371ad28713a13c0cb6df3ba5124d956..4faf7f0c2b10322ca2c28677187341c04895b435 100644 (file)
@@ -2007,12 +2007,14 @@ send_by_ref:
                                                        break;
                                                case ZEND_INCLUDE:
                                                case ZEND_REQUIRE:
-                                               {
                                                        new_op_array = compile_filename(opline->op2.u.constant.value.lval, inc_filename CLS_CC ELS_CC);
                                                        break;
-                                               }
-                                               case ZEND_EVAL:
-                                                       new_op_array = compile_string(inc_filename CLS_CC);
+                                               case ZEND_EVAL: {
+                                                               char *eval_desc = zend_make_compiled_string_description("eval()'d code");
+
+                                                               new_op_array = compile_string(inc_filename, eval_desc CLS_CC);
+                                                               efree(eval_desc);
+                                                       }
                                                        break;
                                                EMPTY_SWITCH_DEFAULT_CASE()
                                        }
index 8fcd5c0ea997b5eef4d9258402df5582e7ee16ac..5e733de7989d5c057d03684b24d79021174ca524 100644 (file)
@@ -67,7 +67,7 @@ ZEND_API inline void safe_free_zval_ptr(zval *p)
 ;
 #endif
 
-ZEND_API int zend_eval_string(char *str, zval *retval_ptr CLS_DC ELS_DC);
+ZEND_API int zend_eval_string(char *str, zval *retval_ptr, char *string_name CLS_DC ELS_DC);
 ZEND_API inline int i_zend_is_true(zval *op)
 #if defined(C9X_INLINE_SEMANTICS)
 {
index d67c98395aff2b4435970becafaad0ee001ff667..fc17c591bd4c5a39305bc011bf8a669764592c99 100644 (file)
@@ -457,7 +457,7 @@ int call_user_function_ex(HashTable *function_table, zval *object, zval *functio
 }
 
 
-ZEND_API int zend_eval_string(char *str, zval *retval_ptr CLS_DC ELS_DC)
+ZEND_API int zend_eval_string(char *str, zval *retval_ptr, char *string_name CLS_DC ELS_DC)
 {
        zval pv;
        zend_op_array *new_op_array;
@@ -482,7 +482,7 @@ ZEND_API int zend_eval_string(char *str, zval *retval_ptr CLS_DC ELS_DC)
 
        original_handle_op_arrays = CG(handle_op_arrays);
        CG(handle_op_arrays) = 0;
-       new_op_array = compile_string(&pv CLS_CC);
+       new_op_array = compile_string(&pv, string_name CLS_CC);
        CG(handle_op_arrays) = original_handle_op_arrays;
 
        if (new_op_array) {
index e9dff976f06bb8baece188451b8ae2ad44765293..e2b5553bd3701fa98bad821e571d750877958ead 100644 (file)
@@ -41,7 +41,7 @@ typedef struct _zend_syntax_highlighter_ini {
 BEGIN_EXTERN_C()
 ZEND_API void zend_highlight(zend_syntax_highlighter_ini *syntax_highlighter_ini);
 int highlight_file(char *filename, zend_syntax_highlighter_ini *syntax_highlighter_ini);
-int highlight_string(zval *str, zend_syntax_highlighter_ini *syntax_highlighter_ini);
+int highlight_string(zval *str, zend_syntax_highlighter_ini *syntax_highlighter_ini, char *str_name);
 ZEND_API void zend_html_putc(char c);
 ZEND_API void zend_html_puts(char *s, uint len);
 END_EXTERN_C()