diff options
author | Andi Gutmans <andi@php.net> | 2001-09-20 15:53:14 +0000 |
---|---|---|
committer | Andi Gutmans <andi@php.net> | 2001-09-20 15:53:14 +0000 |
commit | 7fc45bf8536d24652dbfa728c8c25bb866a5bdf2 (patch) | |
tree | 097c5d9df75fc1b12d43e85d1c73d105ace2eef0 | |
parent | 6b900b344974360925bf80f70c48d04034e552b6 (diff) | |
download | php-git-7fc45bf8536d24652dbfa728c8c25bb866a5bdf2.tar.gz |
- Create a branch for namespaces. This isn't even remotely close to
- working.
-rw-r--r-- | Zend/zend.c | 18 | ||||
-rw-r--r-- | Zend/zend.h | 11 | ||||
-rw-r--r-- | Zend/zend_compile.c | 48 | ||||
-rw-r--r-- | Zend/zend_compile.h | 4 | ||||
-rw-r--r-- | Zend/zend_execute.c | 3 | ||||
-rw-r--r-- | Zend/zend_globals.h | 5 | ||||
-rw-r--r-- | Zend/zend_language_parser.y | 2 | ||||
-rw-r--r-- | Zend/zend_language_scanner.l | 4 |
8 files changed, 95 insertions, 0 deletions
diff --git a/Zend/zend.c b/Zend/zend.c index aed08ed5fd..f68e1efeb0 100644 --- a/Zend/zend.c +++ b/Zend/zend.c @@ -32,11 +32,13 @@ # 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_NAMESPACES_TABLE global_namespaces_table #else # define GLOBAL_FUNCTION_TABLE CG(function_table) # define GLOBAL_CLASS_TABLE CG(class_table) # define GLOBAL_CONSTANTS_TABLE CG(zend_constants) # define GLOBAL_AUTO_GLOBALS_TABLE CG(auto_globals) +# define GLOBAL_NAMESPACES_TABLE CG(namespaces) #endif #if defined(ZEND_WIN32) && ZEND_DEBUG @@ -424,9 +426,22 @@ int zend_startup(zend_utility_functions *utility_functions, char **extensions, i GLOBAL_FUNCTION_TABLE = (HashTable *) malloc(sizeof(HashTable)); GLOBAL_CLASS_TABLE = (HashTable *) malloc(sizeof(HashTable)); GLOBAL_AUTO_GLOBALS_TABLE = (HashTable *) malloc(sizeof(HashTable)); + GLOBAL_NAMESPACES_TABLE = (HashTable *) malloc(sizeof(HashTable)); 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_AUTO_GLOBALS_TABLE, 8, NULL, NULL, 1, 0); + zend_hash_init_ex(GLOBAL_NAMESPACES_TABLE, 8, NULL, NULL, 1, 0); + + { + Namespace main_namespace; + + main_namespace.type = INTERNAL_NAMESPACE; + main_namespace.class_table = GLOBAL_CLASS_TABLE; + main_namespace.function_table = GLOBAL_FUNCTION_TABLE; + + zend_hash_update(GLOBAL_NAMESPACES_TABLE, "", sizeof(""), &main_namespace, sizeof(Namespace), NULL); + } + register_standard_class(); zend_hash_init_ex(&module_registry, 50, NULL, ZEND_MODULE_DTOR, 1, 0); zend_init_rsrc_list_dtors(); @@ -449,6 +464,7 @@ int zend_startup(zend_utility_functions *utility_functions, char **extensions, i compiler_globals->function_table = GLOBAL_FUNCTION_TABLE; compiler_globals->class_table = GLOBAL_CLASS_TABLE; compiler_globals->auto_globals = GLOBAL_AUTO_GLOBALS_TABLE; + compiler_globals->namespaces = GLOBAL_NAMESPACES_TABLE; zend_startup_constants(tsrm_ls); GLOBAL_CONSTANTS_TABLE = EG(zend_constants); #else @@ -495,6 +511,8 @@ void zend_shutdown(TSRMLS_D) free(GLOBAL_CLASS_TABLE); zend_hash_destroy(GLOBAL_AUTO_GLOBALS_TABLE); free(GLOBAL_AUTO_GLOBALS_TABLE); + zend_hash_destroy(GLOBAL_NAMESPACES_TABLE); + free(GLOBAL_NAMESPACES_TABLE); zend_shutdown_extensions(TSRMLS_C); free(zend_version_info); #ifndef ZTS diff --git a/Zend/zend.h b/Zend/zend.h index 580286846f..6b54bfabea 100644 --- a/Zend/zend.h +++ b/Zend/zend.h @@ -168,6 +168,17 @@ typedef unsigned short zend_ushort; #define INTERNAL_FUNCTION_PARAMETERS int ht, zval *return_value, zval *this_ptr, int return_value_used TSRMLS_DC #define INTERNAL_FUNCTION_PARAM_PASSTHRU ht, return_value, this_ptr, return_value_used TSRMLS_CC +typedef enum { + INTERNAL_NAMESPACE = 0, + USER_NAMESPACE = 1 +} namespace_type; + +typedef struct _Namespace_struct { + namespace_type type; + HashTable *class_table; + HashTable *function_table; +} Namespace; + /* * zval */ diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 97761ee984..befca7a360 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -82,6 +82,8 @@ void zend_init_compiler_data_structures(TSRMLS_D) CG(in_compilation) = 0; init_compiler_declarables(TSRMLS_C); CG(throw_list) = NULL; + CG(namespace) = NULL; + CG(namespace_len) = 0; } @@ -106,6 +108,10 @@ void shutdown_compiler(TSRMLS_D) zend_stack_destroy(&CG(list_stack)); zend_hash_destroy(&CG(filenames_table)); zend_llist_destroy(&CG(open_files)); + + if (CG(namespace)) { + efree(CG(namespace)); + } } @@ -2341,6 +2347,48 @@ void zend_do_end_heredoc(TSRMLS_D) } +void do_namespace(znode *namespace TSRMLS_DC) +{ + HashTable *new_function_table; + HashTable *new_class_table; + Namespace *namespace_ptr; + + zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC); + + if (CG(namespace)) { + efree(CG(namespace)); + } + CG(namespace) = namespace->u.constant.value.str.val; + CG(namespace_len) = namespace->u.constant.value.str.len; + + opline->opcode = ZEND_NAMESPACE; + zval_copy_ctor(&namespace->u.constant); + opline->op1 = *namespace; + SET_UNUSED(opline->op2); + + if (zend_hash_find(CG(namespaces), CG(namespace), CG(namespace_len)+1, (void **) &namespace_ptr) == FAILURE) { + Namespace new_namespace; + HashTable *new_function_table; + HashTable *new_class_table; + + new_function_table = (HashTable *) malloc(sizeof(HashTable)); + new_class_table = (HashTable *) malloc(sizeof(HashTable)); + zend_hash_init_ex(new_function_table, 100, NULL, ZEND_FUNCTION_DTOR, 1, 0); + zend_hash_init_ex(new_class_table, 10, NULL, ZEND_CLASS_DTOR, 1, 0); + new_namespace.type = USER_NAMESPACE; + new_namespace.function_table = new_function_table; + new_namespace.class_table = new_class_table; + + zend_hash_update(CG(namespaces), CG(namespace), CG(namespace_len)+1, &new_namespace, sizeof(Namespace), NULL); + CG(function_table) = new_function_table; + CG(class_table) = new_class_table; + } else { + CG(function_table) = namespace_ptr->function_table; + CG(class_table) = namespace_ptr->class_table; + } +} + + void zend_do_exit(znode *result, znode *message TSRMLS_DC) { zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC); diff --git a/Zend/zend_compile.h b/Zend/zend_compile.h index 29f624dc58..755d4ea739 100644 --- a/Zend/zend_compile.h +++ b/Zend/zend_compile.h @@ -343,6 +343,8 @@ void zend_do_declare_end(TSRMLS_D); void zend_do_end_heredoc(TSRMLS_D); +void do_namespace(znode *namespace TSRMLS_DC); + void zend_do_exit(znode *result, znode *message TSRMLS_DC); void zend_do_begin_silence(znode *strudel_token TSRMLS_DC); @@ -533,6 +535,8 @@ int zendlex(znode *zendlval TSRMLS_DC); #define ZEND_CATCH 107 #define ZEND_THROW 108 +#define ZEND_NAMESPACE 109 + /* end of block */ diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index 828b697c0a..010d181ca4 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -1757,6 +1757,9 @@ do_fcall_common: opline->op1.u.constant.value.str.len+1, &EG(exception), sizeof(zval *), (void **) NULL); EG(exception) = NULL; NEXT_OPCODE(); + case ZEND_NAMESPACE: + fprintf(stderr, "Namespace '%s'\n", opline->op1.u.constant.value.str.val); + NEXT_OPCODE(); case ZEND_SEND_VAL: if (opline->extended_value==ZEND_DO_FCALL_BY_NAME && ARG_SHOULD_BE_SENT_BY_REF(opline->op2.u.opline_num, fbc, fbc->common.arg_types)) { diff --git a/Zend/zend_globals.h b/Zend/zend_globals.h index a6151b866b..e5148b7a8f 100644 --- a/Zend/zend_globals.h +++ b/Zend/zend_globals.h @@ -116,6 +116,11 @@ struct _zend_compiler_globals { int interactive; zend_bool increment_lineno; + + char *namespace; + int namespace_len; + + HashTable *namespaces; }; diff --git a/Zend/zend_language_parser.y b/Zend/zend_language_parser.y index 5eeacb0ae6..aa2e5f2687 100644 --- a/Zend/zend_language_parser.y +++ b/Zend/zend_language_parser.y @@ -115,6 +115,7 @@ %token T_UNSET %token T_ISSET %token T_EMPTY +%token T_NAMESPACE %token T_CLASS %token T_EXTENDS %token T_OBJECT_OPERATOR @@ -208,6 +209,7 @@ unticked_statement: T_CATCH '(' T_VARIABLE ')' { zend_do_begin_catch(&$1, &$8 TSRMLS_CC); } '{' inner_statement_list '}' { zend_do_end_catch(&$1 TSRMLS_CC); } | 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 T_STRING { do_namespace(&$2 TSRMLS_CC); } ; unset_variables: diff --git a/Zend/zend_language_scanner.l b/Zend/zend_language_scanner.l index 7b24957478..77bc423a7f 100644 --- a/Zend/zend_language_scanner.l +++ b/Zend/zend_language_scanner.l @@ -587,6 +587,10 @@ NEWLINE ("\r"|"\n"|"\r\n") return T_PRINT; } +<ST_IN_SCRIPTING>"namespace" { + return T_NAMESPACE; +} + <ST_IN_SCRIPTING>"class" { return T_CLASS; } |