Browse files

- 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;
?>
  • Loading branch information...
1 parent fe94f59 commit 42486196ad5e92d248b62b9c0691969ab81ef453 @andigutmans andigutmans committed Dec 6, 2001
Showing with 19 additions and 4 deletions.
  1. +5 −1 Zend/zend_compile.c
  2. +9 −3 Zend/zend_execute.c
  3. +2 −0 Zend/zend_execute_API.c
  4. +2 −0 Zend/zend_globals.h
  5. +1 −0 Zend/zend_language_parser.y
View
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);
}
View
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 @@ binary_assign_op_addr: {
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 @@ binary_assign_op_addr: {
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:
View
2 Zend/zend_execute_API.c
@@ -158,6 +158,8 @@ void init_executor(TSRMLS_D)
#endif
EG(exception) = NULL;
+
+ EG(namespace) = NULL;
}
View
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;
View
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:

0 comments on commit 4248619

Please sign in to comment.