From: Andrei Zmievski Date: Fri, 27 Oct 2006 21:22:05 +0000 (+0000) Subject: Turn doc comments into zstr strings with corresponding adjustments. X-Git-Tag: RELEASE_1_0_0RC1~1189 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=75c272440eade8301a0811a70fc9f06e511f223e;p=php Turn doc comments into zstr strings with corresponding adjustments. --- diff --git a/Zend/zend.h b/Zend/zend.h index 4f21ecf6dd..c7434459fc 100644 --- a/Zend/zend.h +++ b/Zend/zend.h @@ -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; diff --git a/Zend/zend_API.c b/Zend/zend_API.c index 4657eabee9..8f8d0a99c8 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -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) diff --git a/Zend/zend_API.h b/Zend/zend_API.h index aae7d78b4b..2a23b47223 100644 --- a/Zend/zend_API.h +++ b/Zend/zend_API.h @@ -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); diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 227bfc746c..823acaa3c9 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -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); diff --git a/Zend/zend_compile.h b/Zend/zend_compile.h index fa26c1e2fe..f63e3174e3 100644 --- a/Zend/zend_compile.h +++ b/Zend/zend_compile.h @@ -42,11 +42,11 @@ #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]; diff --git a/Zend/zend_globals.h b/Zend/zend_globals.h index a9f14a93f3..d9718b80a7 100644 --- a/Zend/zend_globals.h +++ b/Zend/zend_globals.h @@ -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; diff --git a/Zend/zend_language_scanner.l b/Zend/zend_language_scanner.l index 02f99ed623..54328906c9 100644 --- a/Zend/zend_language_scanner.l +++ b/Zend/zend_language_scanner.l @@ -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") } "*/" { - 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; } diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 6ec1e70130..7fd68e2153 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -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; }