]> granicus.if.org Git - php/commitdiff
Turn doc comments into zstr strings with corresponding adjustments.
authorAndrei Zmievski <andrei@php.net>
Fri, 27 Oct 2006 21:22:05 +0000 (21:22 +0000)
committerAndrei Zmievski <andrei@php.net>
Fri, 27 Oct 2006 21:22:05 +0000 (21:22 +0000)
Zend/zend.h
Zend/zend_API.c
Zend/zend_API.h
Zend/zend_compile.c
Zend/zend_compile.h
Zend/zend_globals.h
Zend/zend_language_scanner.l
ext/reflection/php_reflection.c

index 4f21ecf6dd73bb2e69aecfcf4d7d053418165fce..c7434459fcdb757568fcc6ab49e8c099e12656df 100644 (file)
@@ -399,7 +399,7 @@ struct _zend_class_entry {
        char *filename;
        zend_uint line_start;
        zend_uint line_end;
-       char *doc_comment;
+       zstr doc_comment;
        zend_uint doc_comment_len;
 
        struct _zend_module_entry *module;
index 4657eabee9a3f5179df11346b5d971a68c87e5e8..8f8d0a99c89820476a6519ee9ce5e2094cb53a40 100644 (file)
@@ -2902,7 +2902,7 @@ ZEND_API char *zend_get_module_version(char *module_name)
        return module->version;
 }
 
-ZEND_API int zend_u_declare_property_ex(zend_class_entry *ce, zend_uchar type, zstr name, int name_length, zval *property, int access_type, char *doc_comment, int doc_comment_len TSRMLS_DC)
+ZEND_API int zend_u_declare_property_ex(zend_class_entry *ce, zend_uchar type, zstr name, int name_length, zval *property, int access_type, zstr doc_comment, int doc_comment_len TSRMLS_DC)
 {
        zend_property_info property_info;
        HashTable *target_symbol_table;
@@ -2977,19 +2977,19 @@ ZEND_API int zend_u_declare_property_ex(zend_class_entry *ce, zend_uchar type, z
        return SUCCESS;
 }
 
-ZEND_API int zend_declare_property_ex(zend_class_entry *ce, char *name, int name_length, zval *property, int access_type, char *doc_comment, int doc_comment_len TSRMLS_DC)
+ZEND_API int zend_declare_property_ex(zend_class_entry *ce, char *name, int name_length, zval *property, int access_type, zstr doc_comment, int doc_comment_len TSRMLS_DC)
 {
-       return zend_u_declare_property_ex(ce, IS_STRING, ZSTR(name), name_length, property, access_type, NULL, 0 TSRMLS_CC);
+       return zend_u_declare_property_ex(ce, IS_STRING, ZSTR(name), name_length, property, access_type, doc_comment, doc_comment_len TSRMLS_CC);
 }
 
 ZEND_API int zend_u_declare_property(zend_class_entry *ce, zend_uchar type, zstr name, int name_length, zval *property, int access_type TSRMLS_DC)
 {
-       return zend_u_declare_property_ex(ce, type, name, name_length, property, access_type, NULL, 0 TSRMLS_CC);
+       return zend_u_declare_property_ex(ce, type, name, name_length, property, access_type, NULL_ZSTR, 0 TSRMLS_CC);
 }
 
 ZEND_API int zend_declare_property(zend_class_entry *ce, char *name, int name_length, zval *property, int access_type TSRMLS_DC)
 {
-       return zend_u_declare_property_ex(ce, IS_STRING, ZSTR(name), name_length, property, access_type, NULL, 0 TSRMLS_CC);
+       return zend_u_declare_property_ex(ce, IS_STRING, ZSTR(name), name_length, property, access_type, NULL_ZSTR, 0 TSRMLS_CC);
 }
 
 ZEND_API int zend_declare_property_null(zend_class_entry *ce, char *name, int name_length, int access_type TSRMLS_DC)
index aae7d78b4b0834b49640853d2504dd0533e3f373..2a23b47223a0eb4a77dcdc76911803d4d705f392 100644 (file)
@@ -224,7 +224,7 @@ ZEND_API zend_bool zend_make_callable(zval *callable, zval *callable_name TSRMLS
 ZEND_API char *zend_get_module_version(char *module_name);
 ZEND_API int zend_get_module_started(char *module_name);
 ZEND_API int zend_declare_property(zend_class_entry *ce, char *name, int name_length, zval *property, int access_type TSRMLS_DC);
-ZEND_API int zend_declare_property_ex(zend_class_entry *ce, char *name, int name_length, zval *property, int access_type, char *doc_comment, int doc_comment_len TSRMLS_DC);
+ZEND_API int zend_declare_property_ex(zend_class_entry *ce, char *name, int name_length, zval *property, int access_type, zstr doc_comment, int doc_comment_len TSRMLS_DC);
 ZEND_API int zend_declare_property_null(zend_class_entry *ce, char *name, int name_length, int access_type TSRMLS_DC);
 ZEND_API int zend_declare_property_bool(zend_class_entry *ce, char *name, int name_length, long value, int access_type TSRMLS_DC);
 ZEND_API int zend_declare_property_long(zend_class_entry *ce, char *name, int name_length, long value, int access_type TSRMLS_DC);
@@ -233,7 +233,7 @@ ZEND_API int zend_declare_property_string(zend_class_entry *ce, char *name, int
 ZEND_API int zend_declare_property_stringl(zend_class_entry *ce, char *name, int name_length, char *value, int value_len, int access_type TSRMLS_DC);
 
 ZEND_API int zend_u_declare_property(zend_class_entry *ce, zend_uchar type, zstr name, int name_length, zval *property, int access_type TSRMLS_DC);
-ZEND_API int zend_u_declare_property_ex(zend_class_entry *ce, zend_uchar type, zstr name, int name_length, zval *property, int access_type, char *doc_comment, int doc_comment_len TSRMLS_DC);
+ZEND_API int zend_u_declare_property_ex(zend_class_entry *ce, zend_uchar type, zstr name, int name_length, zval *property, int access_type, zstr doc_comment, int doc_comment_len TSRMLS_DC);
 
 ZEND_API int zend_declare_class_constant(zend_class_entry *ce, char *name, size_t name_length, zval *value TSRMLS_DC);
 ZEND_API int zend_declare_class_constant_null(zend_class_entry *ce, char *name, size_t name_length TSRMLS_DC);
index 227bfc746c53e5747bc3629594b60182f62e7a36..823acaa3c94446c09bb64722ec71f2e6d85eea78 100644 (file)
@@ -41,11 +41,14 @@ static void zend_duplicate_property_info(zend_property_info *property_info)
 
        if (UG(unicode)) {
                property_info->name.u = eustrndup(property_info->name.u, property_info->name_length);
+               if (property_info->doc_comment.u) {
+                       property_info->doc_comment.u = eustrndup(property_info->doc_comment.u, property_info->doc_comment_len);
+               }
        } else {
                property_info->name.s = estrndup(property_info->name.s, property_info->name_length);
-       }
-       if (property_info->doc_comment) {
-               property_info->doc_comment = estrndup(property_info->doc_comment, property_info->doc_comment_len);
+               if (property_info->doc_comment.s) {
+                       property_info->doc_comment.s = estrndup(property_info->doc_comment.s, property_info->doc_comment_len);
+               }
        }
 }
 
@@ -65,8 +68,8 @@ static void zend_duplicate_property_info_internal(zend_property_info *property_i
 static void zend_destroy_property_info(zend_property_info *property_info)
 {
        efree(property_info->name.v);
-       if (property_info->doc_comment) {
-               efree(property_info->doc_comment);
+       if (property_info->doc_comment.v) {
+               efree(property_info->doc_comment.v);
        }
 }
 
@@ -1250,10 +1253,10 @@ void zend_do_begin_function_declaration(znode *function_token, znode *function_n
                }
        }
 
-       if (CG(doc_comment)) {
+       if (CG(doc_comment).v) {
                CG(active_op_array)->doc_comment = CG(doc_comment);
                CG(active_op_array)->doc_comment_len = CG(doc_comment_len);
-               CG(doc_comment) = NULL;
+               CG(doc_comment) = NULL_ZSTR;
                CG(doc_comment_len) = 0;
        }
 
@@ -2936,10 +2939,10 @@ void zend_do_begin_class_declaration(znode *class_token, znode *class_name, znod
        opline->result.op_type = IS_CONST;
        CG(implementing_class) = opline->result;
 
-       if (CG(doc_comment)) {
+       if (CG(doc_comment).v) {
                CG(active_class_entry)->doc_comment = CG(doc_comment);
                CG(active_class_entry)->doc_comment_len = CG(doc_comment_len);
-               CG(doc_comment) = NULL;
+               CG(doc_comment) = NULL_ZSTR;
                CG(doc_comment_len) = 0;
        }
 }
@@ -3147,7 +3150,7 @@ void zend_do_declare_property(znode *var_name, znode *value, zend_uint access_ty
 {
        zval *property;
        zend_property_info *existing_property_info;
-       char *comment = NULL;
+       zstr comment = NULL_ZSTR;
        int comment_len = 0;
 
        if (CG(active_class_entry)->ce_flags & ZEND_ACC_INTERFACE) {
@@ -3177,10 +3180,10 @@ void zend_do_declare_property(znode *var_name, znode *value, zend_uint access_ty
                Z_TYPE_P(property) = IS_NULL;
        }
 
-       if (CG(doc_comment)) {
+       if (CG(doc_comment).v) {
                comment = CG(doc_comment);
                comment_len = CG(doc_comment_len);
-               CG(doc_comment) = NULL;
+               CG(doc_comment) = NULL_ZSTR;
                CG(doc_comment_len) = 0;
        }
 
@@ -4337,7 +4340,7 @@ ZEND_API void zend_initialize_class_data(zend_class_entry *ce, zend_bool nullify
        ce->constants_updated = 0;
        ce->ce_flags = 0;
 
-       ce->doc_comment = NULL;
+       ce->doc_comment = NULL_ZSTR;
        ce->doc_comment_len = 0;
 
        zend_u_hash_init_ex(&ce->default_properties, 0, NULL, zval_ptr_dtor_func, persistent_hashes, UG(unicode), 0);
index fa26c1e2fe9daea4423ef90f5e51fad50e0462f4..f63e3174e3a29846d0e385e47ab31bf0ef0d4cfc 100644 (file)
 
 #define RESET_DOC_COMMENT()        \
     {                              \
-        if (CG(doc_comment)) {     \
-          efree(CG(doc_comment));  \
-          CG(doc_comment) = NULL;  \
-        }                          \
-        CG(doc_comment_len) = 0;   \
+               if (CG(doc_comment.v)) {     \
+                       efree(CG(doc_comment.v));  \
+                       CG(doc_comment) = NULL_ZSTR;  \
+               }                          \
+               CG(doc_comment_len) = 0;   \
     }
 
 typedef struct _zend_op_array zend_op_array;
@@ -152,7 +152,7 @@ typedef struct _zend_property_info {
        zstr name;
        int name_length;
        ulong h;
-       char *doc_comment;
+       zstr doc_comment;
        int doc_comment_len;
        zend_class_entry *ce;
 } zend_property_info;
@@ -220,7 +220,7 @@ struct _zend_op_array {
        char *script_encoding;
        zend_uint line_start;
        zend_uint line_end;
-       char *doc_comment;
+       zstr doc_comment;
        zend_uint doc_comment_len;
 
        void *reserved[ZEND_MAX_RESERVED_RESOURCES];
index a9f14a93f31f639a958890e722b037732be971f9..d9718b80a766185624c9a670a57849ffb9c089b6 100644 (file)
@@ -126,7 +126,7 @@ struct _zend_compiler_globals {
 
        zend_uint access_type;
 
-       char *doc_comment;
+       zstr doc_comment;
        zend_uint doc_comment_len;
 
        zend_uchar literal_type;
index 02f99ed623f09e230aa7ed54e4224aa0698b4bb9..54328906c9f1de5536697e18b01ba92f02b5d9e3 100644 (file)
@@ -130,7 +130,7 @@ void startup_scanner(TSRMLS_D)
 {
        CG(heredoc) = NULL;
        CG(heredoc_len) = 0;
-       CG(doc_comment) = NULL;
+       CG(doc_comment) = NULL_ZSTR;
        CG(doc_comment_len) = 0;
        SCNG(yy_start_stack_ptr) = 0;
        SCNG(yy_start_stack_depth) = 0;
@@ -2167,9 +2167,14 @@ NEWLINE ("\r"|"\n"|"\r\n")
 }
 
 <ST_DOC_COMMENT>"*/" {
-       CG(doc_comment) = estrndup(yytext, yyleng);
-       CG(doc_comment_len) = yyleng;
+       zval temp;
+
        HANDLE_NEWLINES(yytext, yyleng);
+       if (!zend_copy_scanner_string(&temp, yytext, yyleng, UG(unicode)?IS_UNICODE:IS_STRING, SCNG(output_conv) TSRMLS_CC)) {
+               return 0;
+       }
+       CG(doc_comment) = temp.value.uni.val;
+       CG(doc_comment_len) = temp.value.uni.len;
        BEGIN(ST_IN_SCRIPTING);
        return T_DOC_COMMENT;
 }
index 6ec1e7013067ef3bbfbef94bf7357bcb8eefc0fb..7fd68e2153a49c27f297f53b55b75fdd85fd1d17 100644 (file)
@@ -292,8 +292,8 @@ static void _class_string(string *str, zend_class_entry *ce, zval *obj, char *in
        string_printf(&sub_indent, "%s    ", indent);
 
        /* TBD: Repair indenting of doc comment (or is this to be done in the parser?) */
-       if (ce->type == ZEND_USER_CLASS && ce->doc_comment) {
-               string_printf(str, "%s%s", indent, ce->doc_comment);
+       if (ce->type == ZEND_USER_CLASS && ce->doc_comment.v) {
+               string_printf(str, "%s%v", indent, ce->doc_comment.v);
                string_write(str, "\n", 1);
        }
 
@@ -708,8 +708,8 @@ static void _function_string(string *str, zend_function *fptr, zend_class_entry
         * What's "wrong" is that any whitespace before the doc comment start is 
         * swallowed, leading to an unaligned comment.
         */
-       if (fptr->type == ZEND_USER_FUNCTION && fptr->op_array.doc_comment) {
-               string_printf(str, "%s%s\n", indent, fptr->op_array.doc_comment);
+       if (fptr->type == ZEND_USER_FUNCTION && fptr->op_array.doc_comment.v) {
+               string_printf(str, "%s%v\n", indent, fptr->op_array.doc_comment.v);
        }
 
        string_printf(str, fptr->common.scope ? "%sMethod [ " : "%sFunction [ ", indent);
@@ -1537,12 +1537,8 @@ ZEND_METHOD(reflection_function, getDocComment)
 
        METHOD_NOTSTATIC_NUMPARAMS(reflection_function_abstract_ptr, 0);
        GET_REFLECTION_OBJECT_PTR(fptr);
-       if (fptr->type == ZEND_USER_FUNCTION && fptr->op_array.doc_comment) {
-               /* FIXME
-                * It should use the encoding in which the doc comment was written, aka
-                * the script encoding for the file that the class was defined in.
-                */
-               RETURN_RT_STRINGL(fptr->op_array.doc_comment, fptr->op_array.doc_comment_len, 1);
+       if (fptr->type == ZEND_USER_FUNCTION && fptr->op_array.doc_comment.v) {
+               RETURN_ZSTRL(fptr->op_array.doc_comment, fptr->op_array.doc_comment_len, ZEND_STR_TYPE, 1);
        }
        RETURN_FALSE;
 }
@@ -2957,13 +2953,8 @@ ZEND_METHOD(reflection_class, getDocComment)
 
        METHOD_NOTSTATIC_NUMPARAMS(reflection_class_ptr, 0);
        GET_REFLECTION_OBJECT_PTR(ce);
-       if (ce->type == ZEND_USER_CLASS && ce->doc_comment) {
-               /* FIXME
-                * It should use the encoding in which the doc comment was written, aka
-                * the script encoding for the file that the class was defined in. We
-                * don't have access to that yet.
-                */
-               RETURN_RT_STRINGL(ce->doc_comment, ce->doc_comment_len, 1);
+       if (ce->type == ZEND_USER_CLASS && ce->doc_comment.v) {
+               RETURN_ZSTRL(ce->doc_comment, ce->doc_comment_len, ZEND_STR_TYPE, 1);
        }
        RETURN_FALSE;
 }
@@ -4162,13 +4153,8 @@ ZEND_METHOD(reflection_property, getDocComment)
 
        METHOD_NOTSTATIC_NUMPARAMS(reflection_property_ptr, 0);
        GET_REFLECTION_OBJECT_PTR(ref);
-       if (ref->prop->doc_comment) {
-               /* FIXME
-                * It should use the encoding in which the doc comment was written, aka
-                * the script encoding for the file that the class was defined in. We
-                * don't have access to that yet.
-                */
-               RETURN_RT_STRINGL(ref->prop->doc_comment, ref->prop->doc_comment_len, 1);
+       if (ref->prop->doc_comment.v) {
+               RETURN_ZSTRL(ref->prop->doc_comment, ref->prop->doc_comment_len, ZEND_STR_TYPE, 1);
        }
        RETURN_FALSE;
 }