Browse Source

- Initial work on changing namespace scope. Only methods & variables

- right now.
<?
	$hey = "Global hey\n";

	class foo {
		static $hey = "Namespace hey\n";
		function bar()
		{
			print "in foo::bar()\n";
		}
	}
	function bar()
	{
		print "in bar()\n";
	}

	bar();
	namespace foo;
	bar();
	namespace;
	bar();
	namespace foo;
	$bar_indirect = "bar";
	$bar_indirect();

	namespace;
	print $hey;
	namespace foo;
	print $hey;
	$hey = "Namespace hey #2\n";
	namespace;
	print $hey;
	$hey = "Global hey #2\n";
	namespace foo;
	print $hey;
?>
experimental/ZendEngine2
Andi Gutmans 25 years ago
parent
commit
42486196ad
  1. 6
      Zend/zend_compile.c
  2. 12
      Zend/zend_execute.c
  3. 2
      Zend/zend_execute_API.c
  4. 2
      Zend/zend_globals.h
  5. 1
      Zend/zend_language_parser.y

6
Zend/zend_compile.c

@ -2448,7 +2448,11 @@ void do_namespace(znode *namespace TSRMLS_DC)
zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
opline->opcode = ZEND_NAMESPACE;
opline->op1 = *namespace;
if (namespace) {
opline->op1 = *namespace;
} else {
SET_UNUSED(opline->op1);
}
SET_UNUSED(opline->op2);
}

12
Zend/zend_execute.c

@ -532,7 +532,8 @@ static void zend_fetch_var_address(zend_op *opline, temp_variable *Ts, int type
switch (opline->extended_value) {
case ZEND_FETCH_LOCAL:
target_symbol_table = EG(active_symbol_table);
//target_symbol_table = EG(active_symbol_table);
target_symbol_table = EG(namespace)?&EG(namespace)->static_members:EG(active_symbol_table);
break;
case ZEND_FETCH_GLOBAL:
if (opline->op1.op_type == IS_VAR) {
@ -1608,7 +1609,7 @@ binary_assign_op_addr: {
}
} else { /* function pointer */
EX(object).ptr = NULL;
active_function_table = EG(function_table);
active_function_table = EG(namespace)?&EG(namespace)->function_table:EG(function_table);
}
if (zend_hash_find(active_function_table, function_name->value.str.val, function_name->value.str.len+1, (void **) &function)==FAILURE) {
zend_error(E_ERROR, "Call to undefined function: %s()", function_name->value.str.val);
@ -1625,7 +1626,7 @@ overloaded_function_call_cont:
case ZEND_DO_FCALL: {
zval *fname = get_zval_ptr(&EX(opline)->op1, EX(Ts), &EG(free_op1), BP_VAR_R);
if (zend_hash_find(EG(function_table), fname->value.str.val, fname->value.str.len+1, (void **) &EX(function_state).function)==FAILURE) {
if (zend_hash_find(EG(namespace)?&EG(namespace)->function_table:EG(function_table), fname->value.str.val, fname->value.str.len+1, (void **) &EX(function_state).function)==FAILURE) {
zend_error(E_ERROR, "Unknown function: %s()\n", fname->value.str.val);
}
FREE_OP(EX(Ts), &EX(opline)->op1, EG(free_op1));
@ -1806,6 +1807,11 @@ do_fcall_common:
NEXT_OPCODE();
case ZEND_NAMESPACE:
{
if (EX(opline)->op1.op_type == IS_UNUSED) {
EG(namespace) = NULL;
} else {
EG(namespace) = EX(Ts)[EX(opline)->op1.u.var].EA.class_entry;
}
NEXT_OPCODE();
}
case ZEND_SEND_VAL:

2
Zend/zend_execute_API.c

@ -158,6 +158,8 @@ void init_executor(TSRMLS_D)
#endif
EG(exception) = NULL;
EG(namespace) = NULL;
}

2
Zend/zend_globals.h

@ -158,6 +158,8 @@ struct _zend_executor_globals {
HashTable *class_table; /* class table */
HashTable *zend_constants; /* constants table */
zend_class_entry *namespace;
long precision;
int ticks_count;

1
Zend/zend_language_parser.y

@ -210,6 +210,7 @@ unticked_statement:
| T_THROW expr ';' { zend_do_throw(&$2 TSRMLS_CC); }
| T_DELETE cvar ';' { zend_do_end_variable_parse(BP_VAR_UNSET, 0 TSRMLS_CC); zend_do_unset(&$1, ZEND_UNSET_OBJ TSRMLS_CC); }
| T_NAMESPACE namespace_class_entry { do_namespace(&$2 TSRMLS_CC); }
| T_NAMESPACE ';' { do_namespace(NULL TSRMLS_CC); }
;
unset_variables:

Loading…
Cancel
Save