Andi and Stas, Here is reworked version of doc comment patch. It doesn't store last doc comment in the compiler globals anymore, instead it's returned inside the T_DOC_COMMENT token. I've also modified a couple of rules in the parser to store the doc comment in zend_class_entry and zend_op_array for classes and functions respectively. There is one problem, however, that I need your help with. I tried adding optional_doc_comment to class method declaration but it resulted in a bunch of shift/reduce conflicts. I am not a parser expert, so might you tell me to fix it? The patch is attached.
-Andrei http://www.gravitonic.com/ "Beware of bugs in the above code; I have only proved it correct, not tried it." -- Donald Knuth
Index: zend.h =================================================================== RCS file: /repository/ZendEngine2/zend.h,v retrieving revision 1.204 diff -u -2 -b -w -B -r1.204 zend.h --- zend.h 5 Mar 2003 11:14:41 -0000 1.204 +++ zend.h 21 Mar 2003 15:57:13 -0000 @@ -336,4 +336,7 @@ zend_uint num_interfaces; + char *doc_comment; + zend_uint doc_comment_len; + /* old handlers */ #if 0 Index: zend_compile.c =================================================================== RCS file: /repository/ZendEngine2/zend_compile.c,v retrieving revision 1.397 diff -u -2 -b -w -B -r1.397 zend_compile.c --- zend_compile.c 19 Mar 2003 21:17:47 -0000 1.397 +++ zend_compile.c 21 Mar 2003 15:57:13 -0000 @@ -1071,5 +1071,5 @@ -void zend_do_end_function_declaration(znode *function_token TSRMLS_DC) +void zend_do_end_function_declaration(znode *function_token, znode *doc_comment TSRMLS_DC) { zend_do_extended_info(TSRMLS_C); @@ -1077,4 +1077,8 @@ pass_two(CG(active_op_array) TSRMLS_CC); CG(active_op_array)->line_end = CG(zend_lineno); + if (doc_comment->op_type != IS_UNUSED) { + CG(active_op_array)->doc_comment = doc_comment->u.constant.value.str.val; + CG(active_op_array)->doc_comment_len = doc_comment->u.constant.value.str.len; + } CG(active_op_array) = function_token->u.op_array; @@ -2180,8 +2184,13 @@ -void zend_do_end_class_declaration(znode *class_token, znode *parent_token TSRMLS_DC) +void zend_do_end_class_declaration(znode *class_token, znode *parent_token, znode *doc_comment TSRMLS_DC) { do_inherit_parent_constructor(CG(active_class_entry)); + if (doc_comment->op_type != IS_UNUSED) { + CG(active_class_entry)->doc_comment = doc_comment->u.constant.value.str.val; + CG(active_class_entry)->doc_comment_len = doc_comment->u.constant.value.str.len; + } + if (CG(active_class_entry)->num_interfaces > 0) { CG(active_class_entry)->interfaces = (zend_class_entry **) emalloc(sizeof(zend_class_entry *)*CG(active_class_entry)->num_interfaces); @@ -3214,5 +3223,4 @@ switch (retval) { case T_COMMENT: - case T_DOC_COMMENT: case T_OPEN_TAG: case T_WHITESPACE: @@ -3369,4 +3377,7 @@ ce->constants_updated = 0; ce->ce_flags = 0; + + ce->doc_comment = NULL; + ce->doc_comment_len = 0; zend_hash_init_ex(&ce->default_properties, 0, NULL, ZVAL_PTR_DTOR, persistent_hashes, 0); Index: zend_compile.h =================================================================== RCS file: /repository/ZendEngine2/zend_compile.h,v retrieving revision 1.225 diff -u -2 -b -w -B -r1.225 zend_compile.h --- zend_compile.h 19 Mar 2003 21:17:47 -0000 1.225 +++ zend_compile.h 21 Mar 2003 15:57:13 -0000 @@ -149,4 +149,6 @@ int line_start; int line_end; + char *doc_comment; + zend_uint doc_comment_len; void *reserved[ZEND_MAX_RESERVED_RESOURCES]; @@ -314,5 +316,5 @@ int zend_do_verify_access_types(znode *current_access_type, znode *new_modifier); void zend_do_begin_function_declaration(znode *function_token, znode *function_name, int is_method, int return_reference, znode *fn_flags_znode TSRMLS_DC); -void zend_do_end_function_declaration(znode *function_token TSRMLS_DC); +void zend_do_end_function_declaration(znode *function_token, znode *doc_comment TSRMLS_DC); void zend_do_receive_arg(zend_uchar op, znode *var, znode *offset, znode *initialization, znode *class_type, zend_uchar pass_type TSRMLS_DC); int zend_do_begin_function_call(znode *function_name TSRMLS_DC); @@ -356,5 +358,5 @@ void zend_do_begin_class_declaration(znode *class_token, znode *class_name, znode *parent_class_name TSRMLS_DC); -void zend_do_end_class_declaration(znode *class_token, znode *parent_token TSRMLS_DC); +void zend_do_end_class_declaration(znode *class_token, znode *parent_token, znode *doc_comment TSRMLS_DC); void zend_do_declare_property(znode *var_name, znode *value, zend_uint access_type TSRMLS_DC); void zend_do_declare_class_constant(znode *var_name, znode *value TSRMLS_DC); Index: zend_globals.h =================================================================== RCS file: /repository/ZendEngine2/zend_globals.h,v retrieving revision 1.121 diff -u -2 -b -w -B -r1.121 zend_globals.h --- zend_globals.h 19 Mar 2003 21:17:47 -0000 1.121 +++ zend_globals.h 21 Mar 2003 15:57:13 -0000 @@ -86,6 +86,4 @@ char *heredoc; int heredoc_len; - char *doc_comment; - int doc_comment_len; zend_op_array *active_op_array; Index: zend_language_parser.y =================================================================== RCS file: /repository/ZendEngine2/zend_language_parser.y,v retrieving revision 1.104 diff -u -2 -b -w -B -r1.104 zend_language_parser.y --- zend_language_parser.y 19 Mar 2003 21:17:47 -0000 1.104 +++ zend_language_parser.y 21 Mar 2003 15:57:13 -0000 @@ -285,17 +285,21 @@ unticked_function_declaration_statement: - T_FUNCTION { $1.u.opline_num = CG(zend_lineno); } is_reference T_STRING { zend_do_begin_function_declaration(&$1, &$4, 0, $3.op_type, NULL TSRMLS_CC); } - '(' parameter_list ')' '{' inner_statement_list '}' { zend_do_end_function_declaration(&$1 TSRMLS_CC); } + optional_doc_comment T_FUNCTION { $2.u.opline_num = CG(zend_lineno); } is_reference T_STRING { zend_do_begin_function_declaration(&$2, &$5, 0, $4.op_type, NULL TSRMLS_CC); } + '(' parameter_list ')' '{' inner_statement_list '}' { zend_do_end_function_declaration(&$2, &$1 TSRMLS_CC); } ; unticked_class_declaration_statement: - class_entry_type T_STRING extends_from - { zend_do_begin_class_declaration(&$1, &$2, &$3 TSRMLS_CC); } + optional_doc_comment class_entry_type T_STRING extends_from + { zend_do_begin_class_declaration(&$2, &$3, &$4 TSRMLS_CC); } implements_list '{' class_statement_list - '}' { zend_do_end_class_declaration(&$1, &$2 TSRMLS_CC); } + '}' { zend_do_end_class_declaration(&$2, &$4, &$1 TSRMLS_CC); } ; +optional_doc_comment: + T_DOC_COMMENT { $$ = $1; } + | /* empty */ { $$.op_type = IS_UNUSED; } +; class_entry_type: @@ -505,5 +509,5 @@ | class_constant_declaration ';' | method_modifiers T_FUNCTION { $2.u.opline_num = CG(zend_lineno); } is_reference T_STRING { zend_do_begin_function_declaration(&$2, &$5, 1, $4.op_type, &$1 TSRMLS_CC); } '(' - parameter_list ')' method_body { zend_do_abstract_method(&$5, &$1, &$10 TSRMLS_CC); zend_do_end_function_declaration(&$2 TSRMLS_CC); } + parameter_list ')' method_body { zend_do_abstract_method(&$5, &$1, &$10 TSRMLS_CC); zend_do_end_function_declaration(&$2, NULL TSRMLS_CC); } ; Index: zend_language_scanner.l =================================================================== RCS file: /repository/ZendEngine2/zend_language_scanner.l,v retrieving revision 1.81 diff -u -2 -b -w -B -r1.81 zend_language_scanner.l --- zend_language_scanner.l 19 Mar 2003 21:17:47 -0000 1.81 +++ zend_language_scanner.l 21 Mar 2003 15:57:13 -0000 @@ -136,8 +136,4 @@ CG(heredoc_len)=0; } - if (CG(doc_comment)) { - efree(CG(doc_comment)); - CG(doc_comment_len) = 0; - } } END_EXTERN_C() @@ -1193,9 +1189,7 @@ <ST_DOC_COMMENT>"*/" { - if (CG(doc_comment)) { - efree(CG(doc_comment)); - } - CG(doc_comment) = estrndup(yytext, yyleng); - CG(doc_comment_len) = yyleng; + zendlval->value.str.val = (char *)estrndup(yytext, yyleng); + zendlval->value.str.len = yyleng; + zendlval->type = IS_STRING; HANDLE_NEWLINES(yytext, yyleng); BEGIN(ST_IN_SCRIPTING); Index: zend_opcode.c =================================================================== RCS file: /repository/ZendEngine2/zend_opcode.c,v retrieving revision 1.85 diff -u -2 -b -w -B -r1.85 zend_opcode.c --- zend_opcode.c 5 Mar 2003 11:14:43 -0000 1.85 +++ zend_opcode.c 21 Mar 2003 15:57:13 -0000 @@ -75,4 +75,6 @@ op_array->function_name = NULL; op_array->filename = zend_get_compiled_filename(TSRMLS_C); + op_array->doc_comment = NULL; + op_array->doc_comment_len = 0; op_array->arg_types = NULL; @@ -158,4 +160,7 @@ efree(ce->interfaces); } + if (ce->doc_comment) { + efree(ce->doc_comment); + } efree(ce); break; @@ -231,4 +236,7 @@ efree(op_array->function_name); } + if (op_array->doc_comment) { + efree(op_array->doc_comment); + } if (op_array->arg_types) { efree(op_array->arg_types);
-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php