cvs: ZendEngine2 / zend_compile.c
| From: | Zeev Suraski | Date: | Wed, 04 Feb 2004 14:25:25 +0000 |
| Subject: | cvs: ZendEngine2 / zend_compile.c | ||
| Groups: | php.zend-engine.cvs | ||
| Request: | Send a blank email to php-zend-engine-cvs+get-2318@lists.php.net to get a copy of this message | ||
zeev Wed Feb 4 09:25:25 2004 EDT
Modified files:
/ZendEngine2 zend_compile.c
Log:
- Improve $this assignment detection and generalize some code in zend_compile.c
http://cvs.php.net/diff.php/ZendEngine2/zend_compile.c?r1=1.531&r2=1.532&ty=u
Index: ZendEngine2/zend_compile.c
diff -u ZendEngine2/zend_compile.c:1.531 ZendEngine2/zend_compile.c:1.532
--- ZendEngine2/zend_compile.c:1.531 Wed Feb 4 08:56:41 2004
+++ ZendEngine2/zend_compile.c Wed Feb 4 09:25:25 2004
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: zend_compile.c,v 1.531 2004/02/04 13:56:41 zeev Exp $ */
+/* $Id: zend_compile.c,v 1.532 2004/02/04 14:25:25 zeev Exp $ */
#include "zend_language_parser.h"
#include "zend.h"
@@ -464,6 +464,17 @@
}
}
+static zend_bool opline_is_fetch_this(zend_op *opline TSRMLS_DC)
+{
+ if (CG(active_class_entry) && (opline->opcode == ZEND_FETCH_W) &&
(opline->op1.op_type == IS_CONST)
+ && (opline->op1.u.constant.type == IS_STRING)
+ && (opline->op1.u.constant.value.str.len == (sizeof("this")-1))
+ && !memcmp(opline->op1.u.constant.value.str.val, "this",
sizeof("this"))) {
+ return 1;
+ } else {
+ return 0;
+ }
+}
void zend_do_assign(znode *result, znode *variable, znode *value TSRMLS_DC)
{
@@ -487,10 +498,7 @@
SET_UNUSED(opline->result);
*result = last_op->result;
} else {
- if (CG(active_class_entry) && (last_op->opcode == ZEND_FETCH_W) &&
(last_op->op1.op_type == IS_CONST)
- && (last_op->op1.u.constant.type == IS_STRING)
- && (last_op->op1.u.constant.value.str.len == (sizeof("this")-1))
- && !memcmp(last_op->op1.u.constant.value.str.val, "this",
sizeof("this"))) {
+ if (opline_is_fetch_this(last_op TSRMLS_CC)) {
zend_error(E_COMPILE_ERROR, "Cannot re-assign $this");
}
@@ -507,9 +515,14 @@
void zend_do_assign_ref(znode *result, znode *lvar, znode *rvar TSRMLS_DC)
{
+ int last_op_number = get_next_op_number(CG(active_op_array))-1;
zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
+ zend_op *last_op = &CG(active_op_array)->opcodes[last_op_number];
opline->opcode = ZEND_ASSIGN_REF;
+ if (opline_is_fetch_this(last_op TSRMLS_CC)) {
+ zend_error(E_COMPILE_ERROR, "Cannot re-assign $this");
+ }
if (result) {
opline->result.op_type = IS_VAR;
opline->result.u.EA.type = 0;
@@ -804,12 +817,8 @@
num_of_created_opcodes++;
}
- if (num_of_created_opcodes == 1) {
- if ((opline_ptr->op1.op_type == IS_CONST) && (opline_ptr->op1.u.constant.type ==
IS_STRING) &&
- (opline_ptr->op1.u.constant.value.str.len == (sizeof("this")-1)) &&
- !memcmp(opline_ptr->op1.u.constant.value.str.val, "this", sizeof("this")))
{
- CG(active_op_array)->uses_this = 1;
- }
+ if (num_of_created_opcodes == 1 && opline_is_fetch_this(opline_ptr TSRMLS_CC)) {
+ CG(active_op_array)->uses_this = 1;
}
zend_llist_destroy(fetch_list_ptr);
@@ -2582,9 +2591,7 @@
le = fetch_list_ptr->head;
opline_ptr = (zend_op *) le->data;
- if ((opline_ptr->op1.op_type == IS_CONST) && (opline_ptr->op1.u.constant.type ==
IS_STRING) &&
- (opline_ptr->op1.u.constant.value.str.len == (sizeof("this")-1)) &&
- !memcmp(opline_ptr->op1.u.constant.value.str.val, "this",
sizeof("this"))) {
+ if (opline_is_fetch_this(opline_ptr TSRMLS_CC)) {
efree(opline_ptr->op1.u.constant.value.str.val);
SET_UNUSED(opline_ptr->op1); /* this means $this for objects */
opline_ptr->op2 = *property;