Turn doc comments into zstr strings with corresponding adjustments.

This commit is contained in:
Andrei Zmievski 2006-10-27 21:22:05 +00:00
parent 60de9952d7
commit 75c272440e
8 changed files with 50 additions and 56 deletions

View File

@ -399,7 +399,7 @@ struct _zend_class_entry {
char *filename; char *filename;
zend_uint line_start; zend_uint line_start;
zend_uint line_end; zend_uint line_end;
char *doc_comment; zstr doc_comment;
zend_uint doc_comment_len; zend_uint doc_comment_len;
struct _zend_module_entry *module; struct _zend_module_entry *module;

View File

@ -2902,7 +2902,7 @@ ZEND_API char *zend_get_module_version(char *module_name)
return module->version; 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; zend_property_info property_info;
HashTable *target_symbol_table; 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; 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) 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) 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) ZEND_API int zend_declare_property_null(zend_class_entry *ce, char *name, int name_length, int access_type TSRMLS_DC)

View 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 char *zend_get_module_version(char *module_name);
ZEND_API int zend_get_module_started(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(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_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_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); 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_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(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(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); ZEND_API int zend_declare_class_constant_null(zend_class_entry *ce, char *name, size_t name_length TSRMLS_DC);

View File

@ -41,11 +41,14 @@ static void zend_duplicate_property_info(zend_property_info *property_info)
if (UG(unicode)) { if (UG(unicode)) {
property_info->name.u = eustrndup(property_info->name.u, property_info->name_length); 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 { } else {
property_info->name.s = estrndup(property_info->name.s, property_info->name_length); property_info->name.s = estrndup(property_info->name.s, property_info->name_length);
if (property_info->doc_comment.s) {
property_info->doc_comment.s = estrndup(property_info->doc_comment.s, property_info->doc_comment_len);
} }
if (property_info->doc_comment) {
property_info->doc_comment = estrndup(property_info->doc_comment, 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) static void zend_destroy_property_info(zend_property_info *property_info)
{ {
efree(property_info->name.v); efree(property_info->name.v);
if (property_info->doc_comment) { if (property_info->doc_comment.v) {
efree(property_info->doc_comment); 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 = CG(doc_comment);
CG(active_op_array)->doc_comment_len = CG(doc_comment_len); 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; 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; opline->result.op_type = IS_CONST;
CG(implementing_class) = opline->result; 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 = CG(doc_comment);
CG(active_class_entry)->doc_comment_len = CG(doc_comment_len); 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; 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; zval *property;
zend_property_info *existing_property_info; zend_property_info *existing_property_info;
char *comment = NULL; zstr comment = NULL_ZSTR;
int comment_len = 0; int comment_len = 0;
if (CG(active_class_entry)->ce_flags & ZEND_ACC_INTERFACE) { 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; Z_TYPE_P(property) = IS_NULL;
} }
if (CG(doc_comment)) { if (CG(doc_comment).v) {
comment = CG(doc_comment); comment = CG(doc_comment);
comment_len = CG(doc_comment_len); comment_len = CG(doc_comment_len);
CG(doc_comment) = NULL; CG(doc_comment) = NULL_ZSTR;
CG(doc_comment_len) = 0; 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->constants_updated = 0;
ce->ce_flags = 0; ce->ce_flags = 0;
ce->doc_comment = NULL; ce->doc_comment = NULL_ZSTR;
ce->doc_comment_len = 0; ce->doc_comment_len = 0;
zend_u_hash_init_ex(&ce->default_properties, 0, NULL, zval_ptr_dtor_func, persistent_hashes, UG(unicode), 0); zend_u_hash_init_ex(&ce->default_properties, 0, NULL, zval_ptr_dtor_func, persistent_hashes, UG(unicode), 0);

View File

@ -42,9 +42,9 @@
#define RESET_DOC_COMMENT() \ #define RESET_DOC_COMMENT() \
{ \ { \
if (CG(doc_comment)) { \ if (CG(doc_comment.v)) { \
efree(CG(doc_comment)); \ efree(CG(doc_comment.v)); \
CG(doc_comment) = NULL; \ CG(doc_comment) = NULL_ZSTR; \
} \ } \
CG(doc_comment_len) = 0; \ CG(doc_comment_len) = 0; \
} }
@ -152,7 +152,7 @@ typedef struct _zend_property_info {
zstr name; zstr name;
int name_length; int name_length;
ulong h; ulong h;
char *doc_comment; zstr doc_comment;
int doc_comment_len; int doc_comment_len;
zend_class_entry *ce; zend_class_entry *ce;
} zend_property_info; } zend_property_info;
@ -220,7 +220,7 @@ struct _zend_op_array {
char *script_encoding; char *script_encoding;
zend_uint line_start; zend_uint line_start;
zend_uint line_end; zend_uint line_end;
char *doc_comment; zstr doc_comment;
zend_uint doc_comment_len; zend_uint doc_comment_len;
void *reserved[ZEND_MAX_RESERVED_RESOURCES]; void *reserved[ZEND_MAX_RESERVED_RESOURCES];

View File

@ -126,7 +126,7 @@ struct _zend_compiler_globals {
zend_uint access_type; zend_uint access_type;
char *doc_comment; zstr doc_comment;
zend_uint doc_comment_len; zend_uint doc_comment_len;
zend_uchar literal_type; zend_uchar literal_type;

View File

@ -130,7 +130,7 @@ void startup_scanner(TSRMLS_D)
{ {
CG(heredoc) = NULL; CG(heredoc) = NULL;
CG(heredoc_len) = 0; CG(heredoc_len) = 0;
CG(doc_comment) = NULL; CG(doc_comment) = NULL_ZSTR;
CG(doc_comment_len) = 0; CG(doc_comment_len) = 0;
SCNG(yy_start_stack_ptr) = 0; SCNG(yy_start_stack_ptr) = 0;
SCNG(yy_start_stack_depth) = 0; SCNG(yy_start_stack_depth) = 0;
@ -2167,9 +2167,14 @@ NEWLINE ("\r"|"\n"|"\r\n")
} }
<ST_DOC_COMMENT>"*/" { <ST_DOC_COMMENT>"*/" {
CG(doc_comment) = estrndup(yytext, yyleng); zval temp;
CG(doc_comment_len) = yyleng;
HANDLE_NEWLINES(yytext, yyleng); 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); BEGIN(ST_IN_SCRIPTING);
return T_DOC_COMMENT; return T_DOC_COMMENT;
} }

View 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); string_printf(&sub_indent, "%s ", indent);
/* TBD: Repair indenting of doc comment (or is this to be done in the parser?) */ /* TBD: Repair indenting of doc comment (or is this to be done in the parser?) */
if (ce->type == ZEND_USER_CLASS && ce->doc_comment) { if (ce->type == ZEND_USER_CLASS && ce->doc_comment.v) {
string_printf(str, "%s%s", indent, ce->doc_comment); string_printf(str, "%s%v", indent, ce->doc_comment.v);
string_write(str, "\n", 1); 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 * What's "wrong" is that any whitespace before the doc comment start is
* swallowed, leading to an unaligned comment. * swallowed, leading to an unaligned comment.
*/ */
if (fptr->type == ZEND_USER_FUNCTION && fptr->op_array.doc_comment) { if (fptr->type == ZEND_USER_FUNCTION && fptr->op_array.doc_comment.v) {
string_printf(str, "%s%s\n", indent, fptr->op_array.doc_comment); string_printf(str, "%s%v\n", indent, fptr->op_array.doc_comment.v);
} }
string_printf(str, fptr->common.scope ? "%sMethod [ " : "%sFunction [ ", indent); 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); METHOD_NOTSTATIC_NUMPARAMS(reflection_function_abstract_ptr, 0);
GET_REFLECTION_OBJECT_PTR(fptr); GET_REFLECTION_OBJECT_PTR(fptr);
if (fptr->type == ZEND_USER_FUNCTION && fptr->op_array.doc_comment) { if (fptr->type == ZEND_USER_FUNCTION && fptr->op_array.doc_comment.v) {
/* FIXME RETURN_ZSTRL(fptr->op_array.doc_comment, fptr->op_array.doc_comment_len, ZEND_STR_TYPE, 1);
* 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);
} }
RETURN_FALSE; RETURN_FALSE;
} }
@ -2957,13 +2953,8 @@ ZEND_METHOD(reflection_class, getDocComment)
METHOD_NOTSTATIC_NUMPARAMS(reflection_class_ptr, 0); METHOD_NOTSTATIC_NUMPARAMS(reflection_class_ptr, 0);
GET_REFLECTION_OBJECT_PTR(ce); GET_REFLECTION_OBJECT_PTR(ce);
if (ce->type == ZEND_USER_CLASS && ce->doc_comment) { if (ce->type == ZEND_USER_CLASS && ce->doc_comment.v) {
/* FIXME RETURN_ZSTRL(ce->doc_comment, ce->doc_comment_len, ZEND_STR_TYPE, 1);
* 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);
} }
RETURN_FALSE; RETURN_FALSE;
} }
@ -4162,13 +4153,8 @@ ZEND_METHOD(reflection_property, getDocComment)
METHOD_NOTSTATIC_NUMPARAMS(reflection_property_ptr, 0); METHOD_NOTSTATIC_NUMPARAMS(reflection_property_ptr, 0);
GET_REFLECTION_OBJECT_PTR(ref); GET_REFLECTION_OBJECT_PTR(ref);
if (ref->prop->doc_comment) { if (ref->prop->doc_comment.v) {
/* FIXME RETURN_ZSTRL(ref->prop->doc_comment, ref->prop->doc_comment_len, ZEND_STR_TYPE, 1);
* 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);
} }
RETURN_FALSE; RETURN_FALSE;
} }