- Merge the NAMESPACES_BRANCH. It wasn't a good idea to have a branch when

- the whole CVS tree is work in progress
This commit is contained in:
Andi Gutmans 2001-09-30 17:29:55 +00:00
parent 516b8bc723
commit 2eabb14dc7
9 changed files with 527 additions and 416 deletions

View File

@ -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
@ -65,6 +67,7 @@ HashTable *global_function_table;
HashTable *global_class_table;
HashTable *global_constants_table;
HashTable *global_auto_globals_table;
HashTable *global_namespaces_table;
#endif
zend_utility_values zend_uv;
@ -427,9 +430,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);
{
zend_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(zend_namespace), NULL);
}
register_standard_class();
zend_hash_init_ex(&module_registry, 50, NULL, ZEND_MODULE_DTOR, 1, 0);
zend_init_rsrc_list_dtors();
@ -452,6 +468,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
@ -498,6 +515,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

View File

@ -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 _zend_namespace_struct {
namespace_type type;
HashTable *class_table;
HashTable *function_table;
} zend_namespace;
/*
* zval
*/

View File

@ -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,46 @@ void zend_do_end_heredoc(TSRMLS_D)
}
void do_namespace(znode *namespace TSRMLS_DC)
{
zend_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) {
zend_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(zend_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);

View File

@ -32,7 +32,7 @@
#define DEBUG_ZEND 0
#define FREE_PNODE(znode) zval_dtor(&znode->u.constant);
#define FREE_OP(op, should_free) if (should_free) zval_dtor(&Ts[(op)->u.var].tmp_var);
#define FREE_OP(Ts, op, should_free) if (should_free) zval_dtor(&Ts[(op)->u.var].tmp_var);
#define SET_UNUSED(op) (op).op_type = IS_UNUSED
@ -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 */

File diff suppressed because it is too large Load Diff

View File

@ -129,6 +129,7 @@ void init_executor(TSRMLS_D)
EG(function_table) = CG(function_table);
EG(class_table) = CG(class_table);
EG(namespaces) = CG(namespaces);
EG(in_execution) = 0;

View File

@ -87,6 +87,7 @@ struct _zend_compiler_globals {
HashTable *function_table; /* function symbol table */
HashTable *class_table; /* class table */
HashTable *namespaces;
HashTable filenames_table;
@ -116,6 +117,9 @@ struct _zend_compiler_globals {
int interactive;
zend_bool increment_lineno;
char *namespace;
int namespace_len;
};
@ -154,6 +158,7 @@ struct _zend_executor_globals {
HashTable *function_table; /* function symbol table */
HashTable *class_table; /* class table */
HashTable *zend_constants; /* constants table */
HashTable *namespaces;
long precision;

View File

@ -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:

View File

@ -591,6 +591,10 @@ NEWLINE ("\r"|"\n"|"\r\n")
return T_PRINT;
}
<ST_IN_SCRIPTING>"namespace" {
return T_NAMESPACE;
}
<ST_IN_SCRIPTING>"class" {
return T_CLASS;
}