Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:17236 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 91023 invoked by uid 1010); 12 Jul 2005 04:20:20 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 91008 invoked from network); 12 Jul 2005 04:20:20 -0000 Received: from unknown (HELO gmail.com) (127.0.0.1) by localhost with SMTP; 12 Jul 2005 04:20:20 -0000 X-Host-Fingerprint: 70.149.23.220 adsl-149-23-220.mia.bellsouth.net Received: from ([70.149.23.220:14608] helo=localhost.localdomain) by pb1.pair.com (ecelerity 1.2 r(5656M)) with SMTP id DA/CD-23681-40543D24 for ; Tue, 12 Jul 2005 00:20:20 -0400 Message-ID: To: internals@lists.php.net Date: Tue, 12 Jul 2005 00:20:16 -0400 References: <84.75.05285.5EA7CC24@pb1.pair.com> <0MKwh2-1DqTBy43Wu-0004sH@mrelayeu.kundenserver.de> <3A.8A.05285.5EE3DC24@pb1.pair.com> Lines: 678 User-Agent: KNode/0.8.1 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="nextPart4508747.avlWegyz0H" Content-Transfer-Encoding: 7Bit X-Posted-By: 70.149.23.220 Subject: Re: [PHP-DEV] YANP (Yet Another Namespace Proposal) From: jrhernandez05@gmail.com (Jessie Hernandez) --nextPart4508747.avlWegyz0H Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8Bit The attached patch includes variable class name support (test file has also been updated). To clarify for the benefit of others, this means that the code below will work. Note that imports are still done on "file-level" scope, even at runtime, so you can only create objects using variable import class names for the imports that have been declared in that same file. -- Jessie Stanislav Malyshev wrote: > JH>>is a znode, and what is assigned to the opcode is "opline->op2 = > JH>>*class_name". This function is changed to check the import hashtable, > and if JH>>a match is found, then the znode string value is updated to > contain the full JH>>class name! Here's some pseudocode: > > This of course won't work with variable class names. --nextPart4508747.avlWegyz0H Content-Type: application/x-php; name="_class3.php" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="_class3.php" PD9waHAKbmFtZXNwYWNlIG15X25zCnsKCWNsYXNzIGNsYXNzMwoJewoJCXB1YmxpYyAkbWVtMyA9 IDc7Cgl9Cn0KPz4K --nextPart4508747.avlWegyz0H Content-Type: text/x-diff; name="ns_0711.patch" Content-Transfer-Encoding: 8Bit Content-Disposition: attachment; filename="ns_0711.patch" diff -Bbruw -X diff_exclude.txt php-5.1.0b2-bak/Zend/zend.c php-5.1.0b2/Zend/zend.c --- php-5.1.0b2-bak/Zend/zend.c 2005-06-15 15:05:55.000000000 -0400 +++ php-5.1.0b2/Zend/zend.c 2005-07-11 23:37:40.000000000 -0400 @@ -34,10 +34,12 @@ # define GLOBAL_CLASS_TABLE global_class_table # define GLOBAL_CONSTANTS_TABLE global_constants_table # define GLOBAL_AUTO_GLOBALS_TABLE global_auto_globals_table +# define GLOBAL_IMPORT_CLASS_TABLE global_import_class_table #else # define GLOBAL_FUNCTION_TABLE CG(function_table) # define GLOBAL_CLASS_TABLE CG(class_table) # define GLOBAL_AUTO_GLOBALS_TABLE CG(auto_globals) +# define GLOBAL_IMPORT_CLASS_TABLE CG(import_class_table) #endif #if defined(ZEND_WIN32) && ZEND_DEBUG @@ -88,6 +90,7 @@ HashTable *global_class_table; HashTable *global_constants_table; HashTable *global_auto_globals_table; +HashTable *global_import_class_table; #endif ZEND_API zend_utility_values zend_uv; @@ -430,6 +433,7 @@ { zend_function tmp_func; zend_class_entry *tmp_class; + HashTable tmp_hash; compiler_globals->compiled_filename = NULL; @@ -443,6 +447,17 @@ zend_set_default_compile_time_values(TSRMLS_C); + /* initialize namespace variables */ + compiler_globals->namespace_prefix = NULL; + compiler_globals->namespace_prefix_lc = NULL; + compiler_globals->namespace_prefix_len = 0; + + /* initialize the import table */ + compiler_globals->import_class_table = (HashTable *) malloc(sizeof(HashTable)); + compiler_globals->current_import_table = NULL; + zend_hash_init_ex(compiler_globals->import_class_table, 10, NULL, (dtor_func_t) zend_hash_destroy, 1, 0); + zend_hash_copy(compiler_globals->import_class_table, global_import_class_table, NULL, &tmp_hash, sizeof(tmp_hash)); + CG(interactive) = 0; compiler_globals->auto_globals = (HashTable *) malloc(sizeof(HashTable)); @@ -465,6 +480,10 @@ zend_hash_destroy(compiler_globals->auto_globals); free(compiler_globals->auto_globals); } + if (compiler_globals->import_class_table != GLOBAL_IMPORT_CLASS_TABLE) { + zend_hash_destroy(compiler_globals->import_class_table); + free(compiler_globals->import_class_table); + } } @@ -588,11 +607,13 @@ GLOBAL_FUNCTION_TABLE = (HashTable *) malloc(sizeof(HashTable)); GLOBAL_CLASS_TABLE = (HashTable *) malloc(sizeof(HashTable)); GLOBAL_AUTO_GLOBALS_TABLE = (HashTable *) malloc(sizeof(HashTable)); + GLOBAL_IMPORT_CLASS_TABLE = (HashTable *) malloc(sizeof(HashTable)); #ifdef ZTS GLOBAL_CONSTANTS_TABLE = (HashTable *) malloc(sizeof(HashTable)); #endif zend_hash_init_ex(GLOBAL_FUNCTION_TABLE, 100, NULL, ZEND_FUNCTION_DTOR, 1, 0); zend_hash_init_ex(GLOBAL_CLASS_TABLE, 10, NULL, ZEND_CLASS_DTOR, 1, 0); + zend_hash_init_ex(GLOBAL_IMPORT_CLASS_TABLE, 10, NULL, (dtor_func_t) zend_hash_destroy, 1, 0); zend_hash_init_ex(&module_registry, 50, NULL, ZEND_MODULE_DTOR, 1, 0); zend_init_rsrc_list_dtors(); @@ -618,10 +639,13 @@ compiler_globals->in_compilation = 0; compiler_globals->function_table = (HashTable *) malloc(sizeof(HashTable)); compiler_globals->class_table = (HashTable *) malloc(sizeof(HashTable)); + compiler_globals->import_class_table = (HashTable *) malloc(sizeof(HashTable)); + compiler_globals->current_import_table = NULL; *compiler_globals->function_table = *GLOBAL_FUNCTION_TABLE; *compiler_globals->class_table = *GLOBAL_CLASS_TABLE; compiler_globals->auto_globals = GLOBAL_AUTO_GLOBALS_TABLE; + *compiler_globals->import_class_table = *GLOBAL_IMPORT_CLASS_TABLE; zend_hash_destroy(executor_globals->zend_constants); *executor_globals->zend_constants = *GLOBAL_CONSTANTS_TABLE; @@ -676,9 +700,11 @@ *GLOBAL_FUNCTION_TABLE = *compiler_globals->function_table; *GLOBAL_CLASS_TABLE = *compiler_globals->class_table; *GLOBAL_CONSTANTS_TABLE = *executor_globals->zend_constants; + *GLOBAL_IMPORT_CLASS_TABLE = *compiler_globals->import_class_table; zend_destroy_rsrc_list(&EG(persistent_list) TSRMLS_CC); free(compiler_globals->function_table); free(compiler_globals->class_table); + free(compiler_globals->import_class_table); compiler_globals_ctor(compiler_globals, tsrm_ls); free(EG(zend_constants)); executor_globals_ctor(executor_globals, tsrm_ls); @@ -699,6 +725,7 @@ zend_hash_destroy(GLOBAL_FUNCTION_TABLE); zend_hash_destroy(GLOBAL_CLASS_TABLE); + zend_hash_destroy(GLOBAL_IMPORT_CLASS_TABLE); zend_hash_destroy(GLOBAL_AUTO_GLOBALS_TABLE); free(GLOBAL_AUTO_GLOBALS_TABLE); @@ -709,6 +736,7 @@ zend_shutdown_constants(TSRMLS_C); free(GLOBAL_FUNCTION_TABLE); free(GLOBAL_CLASS_TABLE); + free(GLOBAL_IMPORT_CLASS_TABLE); #ifdef ZTS zend_destroy_rsrc_list(&EG(persistent_list) TSRMLS_CC); zend_hash_destroy(GLOBAL_CONSTANTS_TABLE); @@ -716,6 +744,7 @@ GLOBAL_FUNCTION_TABLE = NULL; GLOBAL_CLASS_TABLE = NULL; GLOBAL_AUTO_GLOBALS_TABLE = NULL; + GLOBAL_IMPORT_CLASS_TABLE = NULL; #endif zend_destroy_rsrc_list_dtors(); } Only in php-5.1.0b2/Zend: zend.c~ diff -Bbruw -X diff_exclude.txt php-5.1.0b2-bak/Zend/zend_compile.c php-5.1.0b2/Zend/zend_compile.c --- php-5.1.0b2-bak/Zend/zend_compile.c 2005-06-22 04:32:57.000000000 -0400 +++ php-5.1.0b2/Zend/zend_compile.c 2005-07-10 16:11:32.000000000 -0400 @@ -185,8 +185,16 @@ ZEND_API char *zend_set_compiled_filename(char *new_compiled_filename TSRMLS_DC) { char **pp, *p; + HashTable file_imports; int length = strlen(new_compiled_filename); + /* make sure the import class hashtable for this file exists */ + if (!zend_hash_exists(CG(import_class_table), new_compiled_filename, length+1)) { + zend_hash_init(&file_imports, 10, NULL, ZVAL_DESTRUCTOR, 1); + zend_hash_add(CG(import_class_table), new_compiled_filename, length + 1, &file_imports, sizeof(file_imports), NULL); + zend_hash_find(CG(import_class_table), new_compiled_filename, length + 1, (void **)&CG(current_import_table)); + } + if (zend_hash_find(&CG(filenames_table), new_compiled_filename, length+1, (void **) &pp) == SUCCESS) { CG(compiled_filename) = *pp; return *pp; @@ -1385,6 +1392,7 @@ zval_dtor(&class_name->u.constant); break; default: + zend_resolve_class_name_node(class_name TSRMLS_CC); opline->op2 = *class_name; break; } @@ -2615,6 +2623,11 @@ zend_error(E_COMPILE_ERROR, "Cannot use '%s' as class name as it is reserved", class_name->u.constant.value.str.val); } + /* fully prefix the class name */ + efree(lcname); + zend_prefix_class_name_node(class_name TSRMLS_CC); + lcname = zend_str_tolower_dup(class_name->u.constant.value.str.val, class_name->u.constant.value.str.len); + new_class_entry->type = ZEND_USER_CLASS; new_class_entry->name = class_name->u.constant.value.str.val; new_class_entry->name_length = class_name->u.constant.value.str.len; @@ -2659,8 +2672,153 @@ CG(doc_comment) = NULL; CG(doc_comment_len) = 0; } + +} + +/***************************** + * BEGIN NAMESPACE FUNCTIONS * + *****************************/ + +void zend_do_begin_namespace(znode *ns_token, znode *ns_name TSRMLS_DC) +{ + /* allocate space for the namespace prefix */ + CG(namespace_prefix) = emalloc(ns_name->u.constant.value.str.len + 2); + *CG(namespace_prefix) = '\0'; + + /* get the namespace prefix */ + strcat(CG(namespace_prefix), ns_name->u.constant.value.str.val); + strcat(CG(namespace_prefix), ":"); + + /* get the lowercased namespace prefix */ + CG(namespace_prefix_lc) = zend_str_tolower_dup(CG(namespace_prefix), ns_name->u.constant.value.str.len + 1); + + /* save the prefix length */ + CG(namespace_prefix_len) = ns_name->u.constant.value.str.len + 1; +} + +void zend_do_end_namespace(znode *ns_token TSRMLS_DC) +{ + /* free the string memory */ + efree(CG(namespace_prefix)); + efree(CG(namespace_prefix_lc)); + CG(namespace_prefix_len) = 0; + + /* set the prefixes to null */ + CG(namespace_prefix) = NULL; + CG(namespace_prefix_lc) = NULL; +} + +void zend_do_import(znode *class_name, znode *alias_name TSRMLS_DC) +{ + char *alias_name_lc = NULL; + zend_uint alias_name_len = 0; + zval alias_val; + /* 'colon_pos' is the position of the last colon in the full class name */ + char *colon_pos = strrchr(class_name->u.constant.value.str.val, ':'); + /* 'last_pos' is the position of the null terminator in the full class name */ + char *last_pos = class_name->u.constant.value.str.val + class_name->u.constant.value.str.len; + + if (colon_pos == NULL) { + zend_error(E_COMPILE_ERROR, "Cannot import non-namespace class: %s!", class_name->u.constant.value.str.val); + return; + } + + if (alias_name == NULL) { + /* advance to the first character of the class name */ + ++colon_pos; + + /* get the lowercased class name as the alias */ + alias_name_len = last_pos - colon_pos; + alias_name_lc = zend_str_tolower_dup(colon_pos, alias_name_len); + } else /* alias_name != NULL */ { + alias_name_lc = zend_str_tolower_dup(alias_name->u.constant.value.str.val, alias_name->u.constant.value.str.len); + alias_name_len = alias_name->u.constant.value.str.len; + } + + /* make sure this import alias is not the same as a class name */ + if (zend_hash_exists(CG(class_table), alias_name_lc, alias_name_len + 1)) { + zend_error(E_COMPILE_ERROR, "Could not import %s as %s: a class exists with the name %s", class_name->u.constant.value.str.val, alias_name_lc, alias_name_lc); + return; + } + + /* make sure this import alias has not been used before */ + if (zend_hash_exists(CG(current_import_table), alias_name_lc, alias_name_len + 1)) { + zend_error(E_COMPILE_ERROR, "An import was already done with the %s alias", alias_name_lc); + return; + } + + /* initialize the full class name zval */ + INIT_ZVAL(alias_val); + alias_val.value.str.val = estrdup(class_name->u.constant.value.str.val); + alias_val.value.str.len = class_name->u.constant.value.str.len; + + /* add the alias */ + if (zend_hash_add(CG(current_import_table), alias_name_lc, alias_name_len + 1, &alias_val, sizeof(alias_val), NULL) == FAILURE) { + zend_error(E_COMPILE_ERROR, "Could not import %s as %s!", class_name->u.constant.value.str.val, alias_name_lc); + return; + } + + efree(alias_name_lc); +} + +void zend_do_namespace_import(znode *ns_name TSRMLS_DC) +{ +} + +#ifdef JESSIE_0 +void zend_do_unimport_all(TSRMLS_D) +{ + zend_hash_clean(CG(import_class_table)); +} +#endif + +void zend_prefix_class_name_node(znode *class_name TSRMLS_DC) +{ + zend_uint new_length = 0; + char *org_class_name = NULL; + + if (CG(namespace_prefix) != NULL) { + new_length = CG(namespace_prefix_len) + class_name->u.constant.value.str.len; + org_class_name = estrdup(class_name->u.constant.value.str.val); + + STR_REALLOC(class_name->u.constant.value.str.val, new_length + 1); + + /* prepare for strcat */ + *class_name->u.constant.value.str.val = '\0'; + + /* get the full class name */ + strcat(class_name->u.constant.value.str.val, CG(namespace_prefix)); + strcat(class_name->u.constant.value.str.val, org_class_name); + + /* get the new string length */ + class_name->u.constant.value.str.len = new_length; + + efree(org_class_name); + } +} + +void zend_resolve_class_name_node(znode *class_name TSRMLS_DC) +{ + zval* mapped_class_name = NULL; + char *org_class_name = zend_str_tolower_dup(class_name->u.constant.value.str.val, class_name->u.constant.value.str.len); + zend_uint org_class_name_len = class_name->u.constant.value.str.len; + + /* check to see if this class name is actually an import alias */ + if (zend_hash_find(CG(current_import_table), org_class_name, org_class_name_len + 1, (void **)&mapped_class_name) == SUCCESS) { + /* free the class name string */ + STR_FREE(class_name->u.constant.value.str.val); + + /* set the class node to contain the full class name */ + class_name->u.constant.value.str.val = estrdup(mapped_class_name->value.str.val); + class_name->u.constant.value.str.len = mapped_class_name->value.str.len; + } + + efree(org_class_name); } +/*************************** + * END NAMESPACE FUNCTIONS * + ***************************/ static void do_verify_abstract_class(TSRMLS_D) { Only in php-5.1.0b2/Zend: zend_compile.c~ diff -Bbruw -X diff_exclude.txt php-5.1.0b2-bak/Zend/zend_compile.h php-5.1.0b2/Zend/zend_compile.h --- php-5.1.0b2-bak/Zend/zend_compile.h 2005-06-22 04:32:57.000000000 -0400 +++ php-5.1.0b2/Zend/zend_compile.h 2005-07-09 00:44:41.000000000 -0400 @@ -438,6 +438,14 @@ void zend_do_declare_implicit_property(TSRMLS_D); void zend_do_declare_class_constant(znode *var_name, znode *value TSRMLS_DC); +void zend_do_begin_namespace(znode *ns_token, znode *ns_name TSRMLS_DC); +void zend_do_end_namespace(znode *ns_token TSRMLS_DC); +void zend_do_import(znode *class_name, znode *alias_name TSRMLS_DC); +void zend_do_namespace_import(znode *ns_name TSRMLS_DC); +void zend_do_unimport_all(TSRMLS_D); +void zend_prefix_class_name_node(znode *class_name TSRMLS_DC); +void zend_resolve_class_name_node(znode *class_name TSRMLS_DC); + void zend_do_fetch_property(znode *result, znode *object, znode *property TSRMLS_DC); diff -Bbruw -X diff_exclude.txt php-5.1.0b2-bak/Zend/zend_execute_API.c php-5.1.0b2/Zend/zend_execute_API.c --- php-5.1.0b2-bak/Zend/zend_execute_API.c 2005-06-22 11:26:05.000000000 -0400 +++ php-5.1.0b2/Zend/zend_execute_API.c 2005-07-12 00:01:04.000000000 -0400 @@ -135,6 +135,7 @@ EG(function_table) = CG(function_table); EG(class_table) = CG(class_table); + EG(import_class_table) = CG(import_class_table); EG(in_execution) = 0; EG(in_autoload) = NULL; @@ -890,6 +891,28 @@ } +void zend_resolve_class_name_string(char **lc_name, int *lc_name_len TSRMLS_DC) +{ + HashTable *current_import_table = NULL; + char *executed_filename = zend_get_executed_filename(TSRMLS_C); + int executed_filename_len = strlen(executed_filename); + zval* mapped_class_name = NULL; + + if (zend_hash_find(EG(import_class_table), executed_filename, executed_filename_len + 1, (void **)¤t_import_table) == SUCCESS) { + /* check to see if this class name is actually an import alias */ + if (zend_hash_find(current_import_table, *lc_name, *lc_name_len + 1, (void **)&mapped_class_name) == SUCCESS) { + /* free the class name string */ + free_alloca(*lc_name); + + /* set the class node to contain the full class name */ + *lc_name = do_alloca(mapped_class_name->value.str.len + 1); + zend_str_tolower_copy(*lc_name, mapped_class_name->value.str.val, mapped_class_name->value.str.len); + *lc_name_len = mapped_class_name->value.str.len; + } + } +} + + ZEND_API int zend_lookup_class(char *name, int name_length, zend_class_entry ***ce TSRMLS_DC) { zval **args[1]; @@ -898,6 +921,7 @@ zval *retval_ptr; int retval; char *lc_name; + int lc_name_length = name_length; zval *exception; char dummy = 1; zend_fcall_info fcall_info; @@ -910,7 +934,9 @@ lc_name = do_alloca(name_length + 1); zend_str_tolower_copy(lc_name, name, name_length); - if (zend_hash_find(EG(class_table), lc_name, name_length+1, (void **) ce) == SUCCESS) { + zend_resolve_class_name_string(&lc_name, &lc_name_length TSRMLS_CC); + + if (zend_hash_find(EG(class_table), lc_name, lc_name_length+1, (void **) ce) == SUCCESS) { free_alloca(lc_name); return SUCCESS; } @@ -928,7 +954,7 @@ zend_hash_init(EG(in_autoload), 0, NULL, NULL, 0); } - if (zend_hash_add(EG(in_autoload), lc_name, name_length+1, (void**)&dummy, sizeof(char), NULL) == FAILURE) { + if (zend_hash_add(EG(in_autoload), lc_name, lc_name_length+1, (void**)&dummy, sizeof(char), NULL) == FAILURE) { free_alloca(lc_name); return FAILURE; } @@ -963,7 +989,7 @@ zval_ptr_dtor(&class_name_ptr); - zend_hash_del(EG(in_autoload), lc_name, name_length+1); + zend_hash_del(EG(in_autoload), lc_name, lc_name_length+1); if (retval == FAILURE) { EG(exception) = exception; @@ -981,7 +1007,7 @@ zval_ptr_dtor(&retval_ptr); } - retval = zend_hash_find(EG(class_table), lc_name, name_length + 1, (void **) ce); + retval = zend_hash_find(EG(class_table), lc_name, lc_name_length + 1, (void **) ce); free_alloca(lc_name); return retval; } Only in php-5.1.0b2/Zend: zend_execute_API.c~ diff -Bbruw -X diff_exclude.txt php-5.1.0b2-bak/Zend/zend_globals.h php-5.1.0b2/Zend/zend_globals.h --- php-5.1.0b2-bak/Zend/zend_globals.h 2004-11-03 18:13:32.000000000 -0500 +++ php-5.1.0b2/Zend/zend_globals.h 2005-07-12 00:10:35.000000000 -0400 @@ -143,6 +143,14 @@ zend_encoding_converter encoding_converter; zend_encoding_oddlen encoding_oddlen; #endif /* ZEND_MULTIBYTE */ + + /* namespace variables */ + char *namespace_prefix; + char *namespace_prefix_lc; + zend_uint namespace_prefix_len; + + HashTable *import_class_table; + HashTable *current_import_table; }; @@ -232,6 +240,8 @@ zend_property_info std_property_info; + HashTable *import_class_table; /* import class table */ + void *reserved[ZEND_MAX_RESERVED_RESOURCES]; }; Only in php-5.1.0b2/Zend: zend_globals.h~ diff -Bbruw -X diff_exclude.txt php-5.1.0b2-bak/Zend/zend_language_parser.y php-5.1.0b2/Zend/zend_language_parser.y --- php-5.1.0b2-bak/Zend/zend_language_parser.y 2005-06-08 02:49:00.000000000 -0400 +++ php-5.1.0b2/Zend/zend_language_parser.y 2005-07-10 15:57:02.000000000 -0400 @@ -145,7 +145,9 @@ %token T_DOLLAR_OPEN_CURLY_BRACES %token T_CURLY_OPEN %token T_PAAMAYIM_NEKUDOTAYIM - +%token T_IMPORT +%token T_NAMESPACE_NAME +%token T_NAMESPACE %% /* Rules */ start: @@ -162,6 +164,7 @@ statement | function_declaration_statement { zend_do_early_binding(TSRMLS_C); } | class_declaration_statement { zend_do_early_binding(TSRMLS_C); } + | namespace_declaration_statement | T_HALT_COMPILER '(' ')' ';' { REGISTER_MAIN_LONG_CONSTANT("__COMPILER_HALT_OFFSET__", zend_get_scanned_file_offset(TSRMLS_C), CONST_CS); YYACCEPT; } ; @@ -231,6 +234,10 @@ '{' inner_statement_list '}' { zend_do_end_catch(&$1 TSRMLS_CC); } additional_catches { zend_do_mark_last_catch(&$7, &$18 TSRMLS_CC); } | T_THROW expr ';' { zend_do_throw(&$2 TSRMLS_CC); } + | T_IMPORT T_NAMESPACE_NAME ';' { zend_do_import(&$2, NULL TSRMLS_CC); } + | T_IMPORT T_NAMESPACE_NAME T_AS T_STRING ';' { zend_do_import(&$2, &$4 TSRMLS_CC); } + | T_IMPORT T_NAMESPACE T_NAMESPACE_NAME ';' { zend_do_namespace_import(&$3 TSRMLS_CC); } + | T_IMPORT T_NAMESPACE T_STRING ';' { zend_do_namespace_import(&$3 TSRMLS_CC); } ; @@ -307,6 +314,19 @@ | T_FINAL T_CLASS { $$.u.opline_num = CG(zend_lineno); $$.u.EA.type = ZEND_ACC_FINAL_CLASS; } ; +namespace_declaration_statement: + T_NAMESPACE namespace_name '{' { zend_do_begin_namespace(&$1, &$2 TSRMLS_CC); } namespace_statement_list '}' { zend_do_end_namespace(&$1 TSRMLS_CC); } +; + +namespace_statement_list: + namespace_statement_list namespace_statement + | /* empty */ +; + +namespace_statement: + class_declaration_statement { zend_do_early_binding(TSRMLS_C); } +; + extends_from: /* empty */ { $$.op_type = IS_UNUSED; } | T_EXTENDS fully_qualified_class_name { $$ = $2; } @@ -439,6 +459,7 @@ optional_class_type: /* empty */ { $$.op_type = IS_UNUSED; } | T_STRING { $$ = $1; } + | T_NAMESPACE_NAME { $$ = $1; } | T_ARRAY { $$.op_type = IS_CONST; $$.u.constant.type=IS_NULL;} ; @@ -639,10 +660,12 @@ fully_qualified_class_name: T_STRING { zend_do_fetch_class(&$$, &$1 TSRMLS_CC); } + | T_NAMESPACE_NAME { zend_do_fetch_class(&$$, &$1 TSRMLS_CC); } ; class_name_reference: T_STRING { zend_do_fetch_class(&$$, &$1 TSRMLS_CC); } + | T_NAMESPACE_NAME { zend_do_fetch_class(&$$, &$1 TSRMLS_CC); } | dynamic_class_name_reference { zend_do_end_variable_parse(BP_VAR_R, 0 TSRMLS_CC); zend_do_fetch_class(&$$, &$1 TSRMLS_CC); } ; @@ -654,6 +677,10 @@ | base_variable { $$ = $1; } ; +namespace_name: + T_NAMESPACE_NAME { $$ = $1; } + | T_STRING { $$ = $1; } +; dynamic_class_name_variable_properties: dynamic_class_name_variable_properties dynamic_class_name_variable_property Only in php-5.1.0b2/Zend: zend_language_parser.y~ diff -Bbruw -X diff_exclude.txt php-5.1.0b2-bak/Zend/zend_language_scanner.l php-5.1.0b2/Zend/zend_language_scanner.l --- php-5.1.0b2-bak/Zend/zend_language_scanner.l 2005-06-16 09:31:21.000000000 -0400 +++ php-5.1.0b2/Zend/zend_language_scanner.l 2005-07-09 00:44:41.000000000 -0400 @@ -790,6 +790,7 @@ ESCAPED_AND_WHITESPACE [\n\t\r #'.:;,()|^&+-/*=%!~<>?@]+ ANY_CHAR (.|[\n]) NEWLINE ("\r"|"\n"|"\r\n") +NAMESPACE_NAME ({LABEL}":")*{LABEL} %option noyylineno %option noyywrap @@ -923,6 +924,14 @@ return T_CLASS; } +"namespace" { + return T_NAMESPACE; +} + +"import" { + return T_IMPORT; +} + "interface" { return T_INTERFACE; } @@ -1433,6 +1442,13 @@ return T_STRING; } +{NAMESPACE_NAME} { + zendlval->value.str.val = (char *)estrndup(yytext, yyleng); + zendlval->value.str.len = yyleng; + zendlval->type = IS_STRING; + return T_NAMESPACE_NAME; +} + {LABEL} { zend_copy_value(zendlval, yytext, yyleng); zendlval->type = IS_STRING; Only in php-5.1.0b2/Zend: zend_vm_def.h~ diff -Bbruw -X diff_exclude.txt php-5.1.0b2-bak/Zend/zend_vm_execute.h php-5.1.0b2/Zend/zend_vm_execute.h --- php-5.1.0b2-bak/Zend/zend_vm_execute.h 2005-06-22 08:24:25.000000000 -0400 +++ php-5.1.0b2/Zend/zend_vm_execute.h 2005-07-10 11:52:40.000000000 -0400 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_vm_execute.h,v 1.46 2005/06/22 12:24:25 stas Exp $ */ +/* $Id: zend_vm_gen.php,v 1.10 2005/06/22 12:24:25 stas Exp $ */ ULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL}; @@ -117,7 +117,7 @@ ZEND_VM_NEXT_OPCODE(); } - int zend_do_fcall_common_helper_SPEC(ZEND_OPCODE_HANDLER_ARGS) +static int zend_do_fcall_common_helper_SPEC(ZEND_OPCODE_HANDLER_ARGS) { zend_op *opline = EX(opline); zval **original_return_value; @@ -369,6 +369,7 @@ zval *object_zval; zend_function *constructor; +//printf("new %s: class file is %s, scope is %s\n", EX_T(opline->op1.u.var).class_entry->name, EX_T(opline->op1.u.var).class_entry->filename, zend_get_executed_filename()); if (EX_T(opline->op1.u.var).class_entry->ce_flags & (ZEND_ACC_INTERFACE|ZEND_ACC_IMPLICIT_ABSTRACT_CLASS|ZEND_ACC_EXPLICIT_ABSTRACT_CLASS)) { char *class_type; diff -Bbruw -X diff_exclude.txt php-5.1.0b2-bak/Zend/zend_vm_opcodes.h php-5.1.0b2/Zend/zend_vm_opcodes.h --- php-5.1.0b2-bak/Zend/zend_vm_opcodes.h 2005-06-22 04:33:00.000000000 -0400 +++ php-5.1.0b2/Zend/zend_vm_opcodes.h 2005-07-10 11:52:39.000000000 -0400 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_vm_opcodes.h,v 1.32 2005/06/22 08:33:00 dmitry Exp $ */ +/* $Id: zend_vm_gen.php,v 1.10 2005/06/22 12:24:25 stas Exp $ */ #define ZEND_NOP 0 #define ZEND_ADD 1 --nextPart4508747.avlWegyz0H Content-Type: application/x-php; name="_testns.php" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="_testns.php" PD9waHAKcmVxdWlyZV9vbmNlKCBkaXJuYW1lKCBfX0ZJTEVfXyApIC4gJy9fY2xhc3MzLnBocCcg KTsKCmNsYXNzIHJlZ3VsYXJfY2xhc3MKewoJcHVibGljICRtZW0gPSAxOwp9CgpuYW1lc3BhY2Ug bXlfbnMKewoJY2xhc3MgY2xhc3MxCgl7CgkJcHVibGljICRtZW0xID0gMzsKCX0KCgljbGFzcyBj bGFzczIKCXsKCQlwdWJsaWMgJG1lbTIgPSA1OwoJCXB1YmxpYyBzdGF0aWMgJG15X3N0YXRpYyA9 ICd0aGlzIGlzIHN0YXRpYyc7Cgl9Cn0KCmltcG9ydCBteV9uczpjbGFzczE7CmltcG9ydCBteV9u czpjbGFzczIgYXMgbXlfbnNfY2xhc3MyOwppbXBvcnQgbXlfbnM6Y2xhc3MzOwoKJHJjID0gbmV3 IHJlZ3VsYXJfY2xhc3MoKTsKdmFyX2R1bXAoICRyYyApOwoKJGMwID0gbmV3IG15X25zOmNsYXNz MSgpOwp2YXJfZHVtcCggJGMwICk7CgokYzEgPSBuZXcgY2xhc3MxKCk7CnZhcl9kdW1wKCAkYzEg KTsKCiRjMiA9IG5ldyBteV9uc19jbGFzczIoKTsKdmFyX2R1bXAoICRjMiApOwoKJGMzID0gbmV3 IGNsYXNzMygpOwp2YXJfZHVtcCggJGMzICk7CgplY2hvICItLS0gU1RBVElDIFZBUklBQkxFIFBS SU5USU5HIC0tLVxuIjsKZWNobyBteV9uczpjbGFzczI6OiRteV9zdGF0aWMsICJcblxuIjsKCmVj aG8gIi0tLSBWQVJJQUJMRSBDTEFTUyBDUkVBVElPTiAtLS1cbiI7CiRjbGFzczNfc3RyID0gJ2Ns YXNzMyc7CiRjNCA9IG5ldyAkY2xhc3MzX3N0cigpOwp2YXJfZHVtcCggJGM0ICk7Cgo/PgoK --nextPart4508747.avlWegyz0H--