cvs: ZendEngine2 / zend_compile.c zend_constants.c zend_language_parser.y /tests ns_034.phpt ns_035.phpt ns_036.phpt
| From: | Dmitry Stogov | Date: | Fri, 27 Jul 2007 09:04:13 +0000 |
| Subject: | cvs: ZendEngine2 / zend_compile.c zend_constants.c zend_language_parser.y /tests ns_034.phpt ns_035.phpt ns_036.phpt | ||
| Groups: | php.zend-engine.cvs | ||
| Request: | Send a blank email to php-zend-engine-cvs+get-5930@lists.php.net to get a copy of this message | ||
dmitry Fri Jul 27 09:04:13 2007 UTC
Added files:
/ZendEngine2/tests ns_034.phpt ns_035.phpt ns_036.phpt
Modified files:
/ZendEngine2 zend_compile.c zend_constants.c zend_language_parser.y
Log:
Support for namespaces in compile-time constant reference
http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_compile.c?r1=1.758&r2=1.759&diff_format=u
Index: ZendEngine2/zend_compile.c
diff -u ZendEngine2/zend_compile.c:1.758 ZendEngine2/zend_compile.c:1.759
--- ZendEngine2/zend_compile.c:1.758 Thu Jul 26 08:57:52 2007
+++ ZendEngine2/zend_compile.c Fri Jul 27 09:04:12 2007
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: zend_compile.c,v 1.758 2007/07/26 08:57:52 dmitry Exp $ */
+/* $Id: zend_compile.c,v 1.759 2007/07/27 09:04:12 dmitry Exp $ */
#include <zend_language_parser.h>
#include "zend.h"
@@ -3649,6 +3649,11 @@
switch (mode) {
case ZEND_CT:
if (constant_container) {
+ ulong fetch_type;
+
+ if (ZEND_FETCH_CLASS_DEFAULT ==
zend_get_class_fetch_type(Z_TYPE(constant_container->u.constant),
Z_UNIVAL(constant_container->u.constant), Z_UNILEN(constant_container->u.constant))) {
+ zend_resolve_class_name(constant_container, &fetch_type TSRMLS_CC);
+ }
zend_do_fetch_class_name(NULL, constant_container, constant_name TSRMLS_CC);
*result = *constant_container;
result->u.constant.type = IS_CONSTANT;
http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_constants.c?r1=1.95&r2=1.96&diff_format=u
Index: ZendEngine2/zend_constants.c
diff -u ZendEngine2/zend_constants.c:1.95 ZendEngine2/zend_constants.c:1.96
--- ZendEngine2/zend_constants.c:1.95 Wed Jul 11 11:19:58 2007
+++ ZendEngine2/zend_constants.c Fri Jul 27 09:04:12 2007
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: zend_constants.c,v 1.95 2007/07/11 11:19:58 tony2001 Exp $ */
+/* $Id: zend_constants.c,v 1.96 2007/07/27 09:04:12 dmitry Exp $ */
#include "zend.h"
#include "zend_constants.h"
@@ -265,19 +265,19 @@
zstr lookup_name;
zstr colon;
- if ((UG(unicode) && (colon.u = u_memchr(name.u, ':', name_len)) &&
colon.u[1] == ':') ||
- (!UG(unicode) && (colon.s = memchr(name.s, ':', name_len)) &&
colon.s[1] == ':')) {
+ if ((UG(unicode) && (colon.u = u_memrchr(name.u, ':', name_len)) &&
colon.u > name.u && *(colon.u-1) == ':') ||
+ (!UG(unicode) && (colon.s = zend_memrchr(name.s, ':', name_len))&&
colon.s > name.s && *(colon.s-1) == ':')) {
/* class constant */
zend_class_entry **ce = NULL;
- int class_name_len = UG(unicode)?colon.u-name.u:colon.s-name.s;
+ int class_name_len = UG(unicode)?colon.u-name.u-1:colon.s-name.s-1;
int const_name_len = name_len - class_name_len - 2;
zstr constant_name, class_name;
zval **ret_constant;
if (UG(unicode)) {
- constant_name.u = colon.u + 2;
+ constant_name.u = colon.u + 1;
} else {
- constant_name.s = colon.s + 2;
+ constant_name.s = colon.s + 1;
}
if (!scope) {
@@ -314,6 +314,26 @@
} else {
if (zend_u_lookup_class(type, class_name, class_name_len, &ce TSRMLS_CC) != SUCCESS) {
retval = 0;
+ if ((UG(unicode) && (colon.u = u_memrchr(class_name.u, ':', class_name_len))
&& colon.u > class_name.u && *(colon.u-1) == ':') ||
+ (!UG(unicode) && (colon.s = zend_memrchr(class_name.s, ':',
class_name_len))&& colon.s > class_name.s && *(colon.s-1) == ':')) {
+ zend_class_entry **pce;
+ zstr lcname;
+ unsigned int lcname_len;
+
+ if (UG(unicode)) {
+ colon.u++;
+ lcname_len = class_name_len - (colon.u - class_name.u);
+ } else {
+ colon.s++;
+ lcname_len = class_name_len - (colon.s - class_name.s);
+ }
+ lcname = zend_u_str_case_fold(type, colon, lcname_len, 0, &lcname_len);
+ if (zend_u_hash_find(CG(class_table), type, lcname, lcname_len+1, (void**)&ce) == SUCCESS
&&
+ (*ce)->type == ZEND_INTERNAL_CLASS) {
+ retval = 1;
+ }
+ efree(lcname.v);
+ }
}
}
http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_language_parser.y?r1=1.185&r2=1.186&diff_format=u
Index: ZendEngine2/zend_language_parser.y
diff -u ZendEngine2/zend_language_parser.y:1.185 ZendEngine2/zend_language_parser.y:1.186
--- ZendEngine2/zend_language_parser.y:1.185 Thu Jul 12 09:23:48 2007
+++ ZendEngine2/zend_language_parser.y Fri Jul 27 09:04:12 2007
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: zend_language_parser.y,v 1.185 2007/07/12 09:23:48 dmitry Exp $ */
+/* $Id: zend_language_parser.y,v 1.186 2007/07/27 09:04:12 dmitry Exp $ */
/*
* LALR shift/reduce conflicts and how they are resolved:
@@ -724,7 +724,7 @@
;
static_class_constant:
- T_STRING T_PAAMAYIM_NEKUDOTAYIM T_STRING { zend_do_fetch_constant(&$$, &$1, &$3,
ZEND_CT TSRMLS_CC); }
+ fully_qualified_class_name T_PAAMAYIM_NEKUDOTAYIM T_STRING { zend_do_fetch_constant(&$$,
&$1, &$3, ZEND_CT TSRMLS_CC); }
;
scalar:
http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/ns_034.phpt?view=markup&rev=1.1
Index: ZendEngine2/tests/ns_034.phpt
+++ ZendEngine2/tests/ns_034.phpt
--TEST--
034: Support for namespaces in compile-time constant reference
--FILE--
<?php
namespace A;
import A as B;
class Foo {
const C = "ok\n";
}
function f1($x=Foo::C) {
echo $x;
}
function f2($x=A::Foo::C) {
echo $x;
}
function f3($x=B::Foo::C) {
echo $x;
}
function f4($x=::A::Foo::C) {
echo $x;
}
echo Foo::C;
echo A::Foo::C;
echo B::Foo::C;
echo ::A::Foo::C;
f1();
f2();
f3();
f4();
--EXPECT--
ok
ok
ok
ok
ok
ok
ok
ok
http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/ns_035.phpt?view=markup&rev=1.1
Index: ZendEngine2/tests/ns_035.phpt
+++ ZendEngine2/tests/ns_035.phpt
--TEST--
035: Name ambiguity in compile-time constant reference (php name)
--FILE--
<?php
namespace A;
function f1($x = ArrayObject::STD_PROP_LIST) {
var_dump($x);
}
function f2($x = ::ArrayObject::STD_PROP_LIST) {
var_dump($x);
}
var_dump(ArrayObject::STD_PROP_LIST);
var_dump(::ArrayObject::STD_PROP_LIST);
f1();
f2();
--EXPECT--
int(1)
int(1)
int(1)
int(1)
http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/ns_036.phpt?view=markup&rev=1.1
Index: ZendEngine2/tests/ns_036.phpt
+++ ZendEngine2/tests/ns_036.phpt
--TEST--
036: Name ambiguity in compile-time constant reference (ns name)
--FILE--
<?php
namespace A;
import A as B;
class ArrayObject {
const STD_PROP_LIST = 2;
}
function f1($x = ArrayObject::STD_PROP_LIST) {
var_dump($x);
}
function f2($x = ::ArrayObject::STD_PROP_LIST) {
var_dump($x);
}
function f3($x = A::ArrayObject::STD_PROP_LIST) {
var_dump($x);
}
function f4($x = B::ArrayObject::STD_PROP_LIST) {
var_dump($x);
}
function f5($x = ::A::ArrayObject::STD_PROP_LIST) {
var_dump($x);
}
var_dump(ArrayObject::STD_PROP_LIST);
var_dump(::ArrayObject::STD_PROP_LIST);
var_dump(A::ArrayObject::STD_PROP_LIST);
var_dump(B::ArrayObject::STD_PROP_LIST);
var_dump(::A::ArrayObject::STD_PROP_LIST);
f1();
f2();
f3();
f4();
f5();
--EXPECT--
int(2)
int(1)
int(2)
int(2)
int(2)
int(2)
int(1)
int(2)
int(2)
int(2)