Skip to content

Commit

Permalink
- Create a branch for namespaces. This isn't even remotely close to
Browse files Browse the repository at this point in the history
- working.
  • Loading branch information
Andi Gutmans committed Sep 20, 2001
1 parent 6b900b3 commit 7fc45bf
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Zend/zend.c
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions Zend/zend.h
Expand Up @@ -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
*/
Expand Down
48 changes: 48 additions & 0 deletions Zend/zend_compile.c
Expand Up @@ -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;
}


Expand All @@ -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));
}
}


Expand Down Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions Zend/zend_compile.h
Expand Up @@ -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);
Expand Down Expand Up @@ -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 */


Expand Down
3 changes: 3 additions & 0 deletions Zend/zend_execute.c
Expand Up @@ -1757,6 +1757,9 @@ binary_assign_op_addr: {
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)) {
Expand Down
5 changes: 5 additions & 0 deletions Zend/zend_globals.h
Expand Up @@ -116,6 +116,11 @@ struct _zend_compiler_globals {
int interactive;

zend_bool increment_lineno;

char *namespace;
int namespace_len;

HashTable *namespaces;
};


Expand Down
2 changes: 2 additions & 0 deletions Zend/zend_language_parser.y
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions Zend/zend_language_scanner.l
Expand Up @@ -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;
}
Expand Down

0 comments on commit 7fc45bf

Please sign in to comment.