cvs: ZendEngine2(PHP_5_3) / zend_compile.c zend_compile.h zend_globals.h zend_language_parser.y /tests ns_079.phpt ns_080.phpt ns_081.phpt ns_082.phpt ns_083.phpt ns_084.phpt ns_085.phpt ns_086.phpt ns_087.phpt php-src NEWS
[email protected] ("Dmitry Stogov")
| Newsgroups | php.zend-engine.cvs |
|---|---|
| Message-ID | <cvsdmitry1227606992@cvsserver> |
dmitry Tue Nov 25 09:56:32 2008 UTC
Added files: (Branch: PHP_5_3)
/ZendEngine2/tests ns_079.phpt ns_080.phpt ns_081.phpt ns_082.phpt
ns_083.phpt ns_084.phpt ns_085.phpt ns_086.phpt
ns_087.phpt
Modified files:
/php-src NEWS
/ZendEngine2 zend_compile.c zend_compile.h zend_globals.h
zend_language_parser.y
Log:
Added support for namespaces with brackets. (Greg)
dmitry-20081125095632.txt
(text/plain, 11.2 KB)
http://cvs.php.net/viewvc.cgi/php-src/NEWS?r1=1.2027.2.547.2.965.2.388&r2=1.2027.2.547.2.965.2.389&diff_format=u
Index: php-src/NEWS
diff -u php-src/NEWS:1.2027.2.547.2.965.2.388 php-src/NEWS:1.2027.2.547.2.965.2.389
--- php-src/NEWS:1.2027.2.547.2.965.2.388 Sat Nov 22 22:54:17 2008
+++ php-src/NEWS Tue Nov 25 09:56:31 2008
@@ -10,6 +10,7 @@
parameter validation. (Felipe)
- Changed openssl info to show the shared library version number. (Scott)
+- Added support for namespaces with brackets. (Greg)
- Added stream_cast() and stream_set_options() to user-space stream wrappers,
allowing stream_select(), stream_set_blocking(), stream_set_timeout() and
stream_set_write_buffer() to work with user-space stream wrappers. (Arnaud)
http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_compile.c?r1=1.647.2.27.2.41.2.93&r2=1.647.2.27.2.41.2.94&diff_format=u
Index: ZendEngine2/zend_compile.c
diff -u ZendEngine2/zend_compile.c:1.647.2.27.2.41.2.93 ZendEngine2/zend_compile.c:1.647.2.27.2.41.2.94
--- ZendEngine2/zend_compile.c:1.647.2.27.2.41.2.93 Sun Nov 23 20:35:16 2008
+++ ZendEngine2/zend_compile.c Tue Nov 25 09:56:32 2008
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: zend_compile.c,v 1.647.2.27.2.41.2.93 2008/11/23 20:35:16 lbarnaud Exp $ */
+/* $Id: zend_compile.c,v 1.647.2.27.2.41.2.94 2008/11/25 09:56:32 dmitry Exp $ */
#include <zend_language_parser.h>
#include "zend.h"
@@ -138,6 +138,8 @@
CG(in_compilation) = 0;
CG(start_lineno) = 0;
CG(current_namespace) = NULL;
+ CG(in_namespace) = 0;
+ CG(has_bracketed_namespaces) = 0;
CG(current_import) = NULL;
init_compiler_declarables(TSRMLS_C);
zend_hash_apply(CG(auto_globals), (apply_func_t) zend_auto_global_arm TSRMLS_CC);
@@ -4948,6 +4950,9 @@
if (LANG_SCNG(yy_text)[LANG_SCNG(yy_leng)-1] != '>') {
CG(increment_lineno) = 1;
}
+ if (CG(has_bracketed_namespaces) && !CG(in_namespace)) {
+ goto again;
+ }
retval = ';'; /* implicit ; */
break;
case T_OPEN_TAG_WITH_ECHO:
@@ -5081,11 +5086,28 @@
}
/* }}} */
-void zend_do_namespace(const znode *name TSRMLS_DC) /* {{{ */
+void zend_do_begin_namespace(const znode *name, zend_bool with_bracket TSRMLS_DC) /* {{{ */
{
char *lcname;
- if (CG(active_op_array)->last > 0) {
+ /* handle mixed syntax declaration or nested namespaces */
+ if (!CG(has_bracketed_namespaces)) {
+ if (CG(current_namespace)) {
+ /* previous namespace declarations were unbracketed */
+ if (with_bracket) {
+ zend_error(E_COMPILE_ERROR, "Cannot mix bracketed namespace declarations with unbracketed namespace declarations");
+ }
+ }
+ } else {
+ /* previous namespace declarations were bracketed */
+ if (!with_bracket) {
+ zend_error(E_COMPILE_ERROR, "Cannot mix bracketed namespace declarations with unbracketed namespace declarations");
+ } else if (CG(current_namespace) || CG(in_namespace)) {
+ zend_error(E_COMPILE_ERROR, "Namespace declarations cannot be nested");
+ }
+ }
+
+ if (((!with_bracket && !CG(current_namespace)) || (with_bracket && !CG(has_bracketed_namespaces))) && CG(active_op_array)->last > 0) {
/* ignore ZEND_EXT_STMT and ZEND_TICKS */
int num = CG(active_op_array)->last;
while (num > 0 &&
@@ -5093,31 +5115,45 @@
CG(active_op_array)->opcodes[num-1].opcode == ZEND_TICKS)) {
--num;
}
- if (!CG(current_namespace) && num > 0) {
+ if (num > 0) {
zend_error(E_COMPILE_ERROR, "Namespace declaration statement has to be the very first statement in the script");
}
}
- lcname = zend_str_tolower_dup(Z_STRVAL(name->u.constant), Z_STRLEN(name->u.constant));
- if (((Z_STRLEN(name->u.constant) == sizeof("self")-1) &&
- !memcmp(lcname, "self", sizeof("self")-1)) ||
- ((Z_STRLEN(name->u.constant) == sizeof("parent")-1) &&
- !memcmp(lcname, "parent", sizeof("parent")-1))) {
- zend_error(E_COMPILE_ERROR, "Cannot use '%s' as namespace name", Z_STRVAL(name->u.constant));
+
+ CG(in_namespace) = 1;
+ if (with_bracket) {
+ CG(has_bracketed_namespaces) = 1;
}
- efree(lcname);
- if (CG(current_namespace)) {
- zval_dtor(CG(current_namespace));
+ if (name) {
+ lcname = zend_str_tolower_dup(Z_STRVAL(name->u.constant), Z_STRLEN(name->u.constant));
+ if (((Z_STRLEN(name->u.constant) == sizeof("self")-1) &&
+ !memcmp(lcname, "self", sizeof("self")-1)) ||
+ ((Z_STRLEN(name->u.constant) == sizeof("parent")-1) &&
+ !memcmp(lcname, "parent", sizeof("parent")-1))) {
+ zend_error(E_COMPILE_ERROR, "Cannot use '%s' as namespace name", Z_STRVAL(name->u.constant));
+ }
+ efree(lcname);
+
+ if (CG(current_namespace)) {
+ zval_dtor(CG(current_namespace));
+ } else {
+ ALLOC_ZVAL(CG(current_namespace));
+ }
+ *CG(current_namespace) = name->u.constant;
} else {
- ALLOC_ZVAL(CG(current_namespace));
+ if (CG(current_namespace)) {
+ zval_dtor(CG(current_namespace));
+ FREE_ZVAL(CG(current_namespace));
+ CG(current_namespace) = NULL;
+ }
}
+
if (CG(current_import)) {
zend_hash_destroy(CG(current_import));
efree(CG(current_import));
CG(current_import) = NULL;
}
-
- *CG(current_namespace) = name->u.constant;
}
/* }}} */
@@ -5233,8 +5269,17 @@
}
/* }}} */
-void zend_do_end_compilation(TSRMLS_D) /* {{{ */
+void zend_verify_namespace(TSRMLS_D) /* {{{ */
{
+ if (CG(has_bracketed_namespaces) && !CG(in_namespace)) {
+ zend_error(E_COMPILE_ERROR, "No code may exist outside of namespace {}");
+ }
+}
+/* }}} */
+
+void zend_do_end_namespace(TSRMLS_D) /* {{{ */
+{
+ CG(in_namespace) = 0;
if (CG(current_namespace)) {
zval_dtor(CG(current_namespace));
FREE_ZVAL(CG(current_namespace));
@@ -5248,6 +5293,13 @@
}
/* }}} */
+void zend_do_end_compilation(TSRMLS_D) /* {{{ */
+{
+ CG(has_bracketed_namespaces) = 0;
+ zend_do_end_namespace(TSRMLS_C);
+}
+/* }}} */
+
/* {{{ zend_dirname
Returns directory name component of path */
ZEND_API size_t zend_dirname(char *path, size_t len)
http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_compile.h?r1=1.316.2.8.2.12.2.35&r2=1.316.2.8.2.12.2.36&diff_format=u
Index: ZendEngine2/zend_compile.h
diff -u ZendEngine2/zend_compile.h:1.316.2.8.2.12.2.35 ZendEngine2/zend_compile.h:1.316.2.8.2.12.2.36
--- ZendEngine2/zend_compile.h:1.316.2.8.2.12.2.35 Tue Nov 11 19:45:26 2008
+++ ZendEngine2/zend_compile.h Tue Nov 25 09:56:32 2008
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: zend_compile.h,v 1.316.2.8.2.12.2.35 2008/11/11 19:45:26 stas Exp $ */
+/* $Id: zend_compile.h,v 1.316.2.8.2.12.2.36 2008/11/25 09:56:32 dmitry Exp $ */
#ifndef ZEND_COMPILE_H
#define ZEND_COMPILE_H
@@ -537,7 +537,9 @@
void zend_do_declare_constant(znode *name, znode *value TSRMLS_DC);
void zend_do_build_namespace_name(znode *result, znode *prefix, znode *name TSRMLS_DC);
-void zend_do_namespace(const znode *name TSRMLS_DC);
+void zend_do_begin_namespace(const znode *name, zend_bool with_brackets TSRMLS_DC);
+void zend_do_end_namespace(TSRMLS_D);
+void zend_verify_namespace(TSRMLS_D);
void zend_do_use(znode *name, znode *new_name, int is_global TSRMLS_DC);
void zend_do_end_compilation(TSRMLS_D);
http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_globals.h?r1=1.141.2.3.2.7.2.19&r2=1.141.2.3.2.7.2.20&diff_format=u
Index: ZendEngine2/zend_globals.h
diff -u ZendEngine2/zend_globals.h:1.141.2.3.2.7.2.19 ZendEngine2/zend_globals.h:1.141.2.3.2.7.2.20
--- ZendEngine2/zend_globals.h:1.141.2.3.2.7.2.19 Thu Aug 14 10:24:51 2008
+++ ZendEngine2/zend_globals.h Tue Nov 25 09:56:32 2008
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: zend_globals.h,v 1.141.2.3.2.7.2.19 2008/08/14 10:24:51 helly Exp $ */
+/* $Id: zend_globals.h,v 1.141.2.3.2.7.2.20 2008/11/25 09:56:32 dmitry Exp $ */
#ifndef ZEND_GLOBALS_H
#define ZEND_GLOBALS_H
@@ -134,6 +134,8 @@
zval *current_namespace;
HashTable *current_import;
+ zend_bool in_namespace;
+ zend_bool has_bracketed_namespaces;
HashTable *labels;
zend_stack labels_stack;
http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_language_parser.y?r1=1.160.2.4.2.8.2.31&r2=1.160.2.4.2.8.2.32&diff_format=u
Index: ZendEngine2/zend_language_parser.y
diff -u ZendEngine2/zend_language_parser.y:1.160.2.4.2.8.2.31 ZendEngine2/zend_language_parser.y:1.160.2.4.2.8.2.32
--- ZendEngine2/zend_language_parser.y:1.160.2.4.2.8.2.31 Mon Nov 17 18:00:43 2008
+++ ZendEngine2/zend_language_parser.y Tue Nov 25 09:56:32 2008
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: zend_language_parser.y,v 1.160.2.4.2.8.2.31 2008/11/17 18:00:43 stas Exp $ */
+/* $Id: zend_language_parser.y,v 1.160.2.4.2.8.2.32 2008/11/25 09:56:32 dmitry Exp $ */
/*
* LALR shift/reduce conflicts and how they are resolved:
@@ -166,13 +166,17 @@
;
top_statement:
- statement
- | function_declaration_statement { zend_do_early_binding(TSRMLS_C); }
- | class_declaration_statement { zend_do_early_binding(TSRMLS_C); }
+ statement { zend_verify_namespace(TSRMLS_C); }
+ | function_declaration_statement { zend_verify_namespace(TSRMLS_C); zend_do_early_binding(TSRMLS_C); }
+ | class_declaration_statement { zend_verify_namespace(TSRMLS_C); zend_do_early_binding(TSRMLS_C); }
| T_HALT_COMPILER '(' ')' ';' { zend_do_halt_compiler_register(TSRMLS_C); YYACCEPT; }
- | T_NAMESPACE namespace_name ';' { zend_do_namespace(&$2 TSRMLS_CC); }
- | T_USE use_declarations ';'
- | constant_declaration ';'
+ | T_NAMESPACE namespace_name ';' { zend_do_begin_namespace(&$2, 0 TSRMLS_CC); }
+ | T_NAMESPACE namespace_name '{' { zend_do_begin_namespace(&$2, 1 TSRMLS_CC); }
+ top_statement_list '}' { zend_do_end_namespace(TSRMLS_C); }
+ | T_NAMESPACE '{' { zend_do_begin_namespace(NULL, 1 TSRMLS_CC); }
+ top_statement_list '}' { zend_do_end_namespace(TSRMLS_C); }
+ | T_USE use_declarations ';' { zend_verify_namespace(TSRMLS_C); }
+ | constant_declaration ';' { zend_verify_namespace(TSRMLS_C); }
;
use_declarations:
http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/ns_079.phpt?view=markup&rev=1.1
Index: ZendEngine2/tests/ns_079.phpt
+++ ZendEngine2/tests/ns_079.phpt
http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/ns_080.phpt?view=markup&rev=1.1
Index: ZendEngine2/tests/ns_080.phpt
+++ ZendEngine2/tests/ns_080.phpt
http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/ns_081.phpt?view=markup&rev=1.1
Index: ZendEngine2/tests/ns_081.phpt
+++ ZendEngine2/tests/ns_081.phpt
http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/ns_082.phpt?view=markup&rev=1.1
Index: ZendEngine2/tests/ns_082.phpt
+++ ZendEngine2/tests/ns_082.phpt
http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/ns_083.phpt?view=markup&rev=1.1
Index: ZendEngine2/tests/ns_083.phpt
+++ ZendEngine2/tests/ns_083.phpt
http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/ns_084.phpt?view=markup&rev=1.1
Index: ZendEngine2/tests/ns_084.phpt
+++ ZendEngine2/tests/ns_084.phpt
http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/ns_085.phpt?view=markup&rev=1.1
Index: ZendEngine2/tests/ns_085.phpt
+++ ZendEngine2/tests/ns_085.phpt
http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/ns_086.phpt?view=markup&rev=1.1
Index: ZendEngine2/tests/ns_086.phpt
+++ ZendEngine2/tests/ns_086.phpt
http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/ns_087.phpt?view=markup&rev=1.1
Index: ZendEngine2/tests/ns_087.phpt
+++ ZendEngine2/tests/ns_087.phpt