[prev in list] [next in list] [prev in thread] [next in thread]
List: php-cvs
Subject: [PHP-CVS] com php-src: Support doc comments for propreties: =?UTF-8?Q?Zend/zend=5Fc?= =?UTF-8?Q?ompi
From: Nikita Popov <nikic () php ! net>
Date: 2014-07-30 17:12:48
Message-ID: php-mail-adf3be794c52ed0bfb7d796598381f581250502686 () git ! php ! net
[Download RAW message or body]
Commit: 6cf89612dbe3b44d756c805edd3ce7067a99c3ea
Author: Nikita Popov <nikic@php.net> Wed, 30 Jul 2014 19:12:48 +0200
Parents: 8e9a840a53ba7fa2f969f64bcfb73c2e251b4c7b
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=6cf89612dbe3b44d756c805edd3ce7067a99c3ea
Log:
Support doc comments for propreties
Changed paths:
M Zend/zend_compile.c
M Zend/zend_compile.h
M Zend/zend_language_parser.y
Diff:
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index 0435988..5bcfe93 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -3098,6 +3098,16 @@ zend_ast *zend_ast_append_str(zend_ast *left_ast, zend_ast *right_ast) {
return left_ast;
}
+/* A hacky way that is used to store the doc comment for properties */
+zend_ast_list *zend_ast_append_doc_comment(zend_ast_list *list TSRMLS_DC) {
+ if (CG(doc_comment)) {
+ list = zend_ast_list_add(list, zend_ast_create_zval_from_str(CG(doc_comment)));
+ CG(doc_comment) = NULL;
+ }
+
+ return list;
+}
+
void zend_verify_namespace(TSRMLS_D) /* {{{ */
{
if (CG(has_bracketed_namespaces) && !CG(in_namespace)) {
@@ -3693,7 +3703,7 @@ void zend_compile_static_prop(znode *result, zend_ast *ast, zend_uint type TSRML
zend_adjust_for_fetch_type(opline, type);
}
-static zend_uchar get_list_fetch_opcode(zend_uchar op_type) {
+static inline zend_uchar get_list_fetch_opcode(zend_uchar op_type) {
switch (op_type) {
case IS_VAR:
case IS_CV:
@@ -5632,7 +5642,8 @@ void zend_compile_prop_decl(zend_ast *ast TSRMLS_DC) {
zend_ast_list *list = zend_ast_get_list(ast);
zend_uint flags = list->attr;
zend_class_entry *ce = CG(active_class_entry);
- zend_uint i;
+ zend_uint i, children = list->children;
+ zend_string *doc_comment = NULL;
if (ce->ce_flags & ZEND_ACC_INTERFACE) {
zend_error_noreturn(E_COMPILE_ERROR, "Interfaces may not include member variables");
@@ -5642,7 +5653,13 @@ void zend_compile_prop_decl(zend_ast *ast TSRMLS_DC) {
zend_error_noreturn(E_COMPILE_ERROR, "Properties cannot be declared abstract");
}
- for (i = 0; i < list->children; ++i) {
+ /* Doc comment has been appended as last element in property list */
+ if (list->child[children - 1]->kind == ZEND_AST_ZVAL) {
+ doc_comment = STR_COPY(zend_ast_get_str(list->child[children - 1]));
+ children -= 1;
+ }
+
+ for (i = 0; i < children; ++i) {
zend_ast *prop_ast = list->child[i];
zend_ast *name_ast = prop_ast->child[0];
zend_ast *value_ast = prop_ast->child[1];
@@ -5667,8 +5684,10 @@ void zend_compile_prop_decl(zend_ast *ast TSRMLS_DC) {
}
name = zend_new_interned_string_safe(name TSRMLS_CC);
- zend_declare_property_ex(ce, name, &value_zv, flags,
- NULL /* TODO.AST doc comment */ TSRMLS_CC);
+ zend_declare_property_ex(ce, name, &value_zv, flags, doc_comment TSRMLS_CC);
+
+ /* Doc comment is only assigned to first property */
+ doc_comment = NULL;
}
}
diff --git a/Zend/zend_compile.h b/Zend/zend_compile.h
index 9286756..d3d81d0 100644
--- a/Zend/zend_compile.h
+++ b/Zend/zend_compile.h
@@ -452,11 +452,11 @@ ZEND_API unary_op_type get_unary_op(int opcode);
ZEND_API binary_op_type get_binary_op(int opcode);
ZEND_API void zend_make_immutable_array(zval *zv TSRMLS_DC);
-void zend_discard_doc_comment(TSRMLS_D);
void zend_stop_lexing(TSRMLS_D);
void zend_emit_final_return(zval *zv TSRMLS_DC);
zend_ast *zend_ast_append_str(zend_ast *left, zend_ast *right);
zend_uint zend_add_member_modifier(zend_uint flags, zend_uint new_flag);
+zend_ast_list *zend_ast_append_doc_comment(zend_ast_list *list TSRMLS_DC);
/* parser-driven code generators */
void zend_do_free(znode *op1 TSRMLS_DC);
diff --git a/Zend/zend_language_parser.y b/Zend/zend_language_parser.y
index e3d1660..cc5f7f2 100644
--- a/Zend/zend_language_parser.y
+++ b/Zend/zend_language_parser.y
@@ -605,7 +605,7 @@ class_statement_list:
class_statement:
variable_modifiers property_list ';'
- { $$.ast = $2.ast; $$.ast->attr = $1.num; }
+ { $$.list = zend_ast_append_doc_comment($2.list TSRMLS_CC); $$.ast->attr = $1.num; }
| T_CONST class_const_list ';'
{ $$.ast = $2.ast; RESET_DOC_COMMENT(); }
| T_USE name_list trait_adaptations
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic