Permalink
Browse files

scalar types cleanup

  • Loading branch information...
1 parent 0c107d3 commit e18618905c51ee5396da33067a6bc02ebea0312c @smalyshev smalyshev committed Jun 3, 2011
View
@@ -573,10 +573,6 @@ typedef int (*zend_write_func_t)(const char *str, uint str_length);
#define IS_RESOURCE 7
#define IS_CONSTANT 8
#define IS_CONSTANT_ARRAY 9
-/* used for type-hinting only */
-#define IS_CLASS 10
-#define IS_SCALAR 11
-#define IS_NUMERIC 12
/* Ugly hack to support constants as static array indices */
#define IS_CONSTANT_TYPE_MASK 0x00f
View
@@ -205,18 +205,13 @@ ZEND_API char *zend_get_type_by_const(int type) /* {{{ */
switch(type) {
case IS_BOOL:
return "boolean";
- case IS_SCALAR:
- return "scalar";
- case IS_NUMERIC:
- return "numeric";
case IS_LONG:
return "integer";
case IS_DOUBLE:
return "double";
case IS_STRING:
return "string";
case IS_OBJECT:
- case IS_CLASS:
return "object";
case IS_RESOURCE:
return "resource";
View
@@ -98,7 +98,7 @@ typedef struct _zend_fcall_info_cache {
#define ZEND_ARG_INFO(pass_by_ref, name) { #name, sizeof(#name)-1, NULL, 0, 0, 0, pass_by_ref},
#define ZEND_ARG_PASS_INFO(pass_by_ref) { NULL, 0, NULL, 0, 0, 0, pass_by_ref},
-#define ZEND_ARG_OBJ_INFO(pass_by_ref, name, classname, allow_null) { #name, sizeof(#name)-1, #classname, sizeof(#classname)-1, IS_CLASS, allow_null, pass_by_ref},
+#define ZEND_ARG_OBJ_INFO(pass_by_ref, name, classname, allow_null) { #name, sizeof(#name)-1, #classname, sizeof(#classname)-1, IS_OBJECT, allow_null, pass_by_ref},
#define ZEND_ARG_ARRAY_INFO(pass_by_ref, name, allow_null) { #name, sizeof(#name)-1, NULL, 0, IS_ARRAY, allow_null, pass_by_ref},
#define ZEND_ARG_TYPE_INFO(pass_by_ref, name, type_hint, allow_null) { #name, sizeof(#name)-1, NULL, 0, type_hint, allow_null, pass_by_ref},
#define ZEND_BEGIN_ARG_INFO_EX(name, pass_rest_by_reference, return_reference, required_num_args) \
View
@@ -1847,10 +1847,9 @@ void zend_do_receive_arg(zend_uchar op, znode *varname, const znode *offset, con
if (class_type->op_type != IS_UNUSED) {
cur_arg_info->allow_null = 0;
- cur_arg_info->type_hint = class_type->u.constant.type;
- switch (class_type->u.constant.type) {
- case IS_CLASS:
+ if (class_type->u.constant.type != IS_NULL) {
+ cur_arg_info->type_hint = IS_OBJECT;
if (ZEND_FETCH_CLASS_DEFAULT == zend_get_class_fetch_type(Z_STRVAL(class_type->u.constant), Z_STRLEN(class_type->u.constant))) {
zend_resolve_class_name(class_type, &opline->extended_value, 1 TSRMLS_CC);
}
@@ -1864,49 +1863,15 @@ void zend_do_receive_arg(zend_uchar op, znode *varname, const znode *offset, con
zend_error(E_COMPILE_ERROR, "Default value for parameters with a class type hint can only be NULL");
}
}
- break;
-
- case IS_ARRAY:
+ } else {
+ cur_arg_info->type_hint = IS_ARRAY;
if (op == ZEND_RECV_INIT) {
if (Z_TYPE(initialization->u.constant) == IS_NULL || (Z_TYPE(initialization->u.constant) == IS_CONSTANT && !strcasecmp(Z_STRVAL(initialization->u.constant), "NULL"))) {
cur_arg_info->allow_null = 1;
} else if (Z_TYPE(initialization->u.constant) != IS_ARRAY && Z_TYPE(initialization->u.constant) != IS_CONSTANT_ARRAY) {
zend_error(E_COMPILE_ERROR, "Default value for parameters with array type hint can only be an array or NULL");
}
}
- break;
-
- /* scalar type hinting */
- case IS_SCALAR:
- if (op == ZEND_RECV_INIT && Z_TYPE(initialization->u.constant) != IS_ARRAY && Z_TYPE(initialization->u.constant) != IS_CONSTANT_ARRAY) {
- break;
- }
- /* fall through */
-
- /* scalar type hinting */
- case IS_NUMERIC:
- if (op == ZEND_RECV_INIT && (Z_TYPE(initialization->u.constant) == IS_LONG || Z_TYPE(initialization->u.constant) == IS_DOUBLE)) {
- break;
- }
- /* fall through */
-
- case IS_BOOL:
- case IS_STRING:
- case IS_LONG:
- case IS_DOUBLE:
- case IS_RESOURCE:
- case IS_OBJECT:
- if (op == ZEND_RECV_INIT) {
- if (Z_TYPE(initialization->u.constant) != class_type->u.constant.type && Z_TYPE(initialization->u.constant) != IS_NULL && (Z_TYPE(initialization->u.constant) & IS_CONSTANT_TYPE_MASK) != IS_CONSTANT) {
- zend_error(E_COMPILE_ERROR, "Default value for parameters with %s type hint can only be %s or NULL", zend_get_type_by_const(class_type->u.constant.type), zend_get_type_by_const(class_type->u.constant.type));
- } else if (Z_TYPE(initialization->u.constant) == IS_NULL) {
- cur_arg_info->allow_null = 1;
- }
- }
- break;
-
- default:
- zend_error(E_COMPILE_ERROR, "Unknown type hint");
}
}
}
@@ -69,7 +69,7 @@
%left '*' '/' '%'
%right '!'
%nonassoc T_INSTANCEOF
-%right '~' T_INC T_DEC T_INT_CAST T_NUMERIC_CAST T_SCALAR_CAST T_DOUBLE_CAST T_STRING_CAST T_ARRAY_CAST T_OBJECT_CAST T_BOOL_CAST T_UNSET_CAST '@'
+%right '~' T_INC T_DEC T_INT_CAST T_DOUBLE_CAST T_STRING_CAST T_ARRAY_CAST T_OBJECT_CAST T_BOOL_CAST T_UNSET_CAST '@'
%right '['
%nonassoc T_NEW T_CLONE
%token T_EXIT
@@ -466,8 +466,8 @@ non_empty_parameter_list:
optional_class_type:
/* empty */ { $$.op_type = IS_UNUSED; }
- | T_ARRAY { $$ = $1; $$.op_type = IS_CONST; Z_TYPE($$.u.constant)=IS_ARRAY; }
- | fully_qualified_class_name { $$ = $1; $$.op_type = IS_CONST; Z_TYPE($$.u.constant)=IS_CLASS; }
+ | T_ARRAY { $$.op_type = IS_CONST; Z_TYPE($$.u.constant)=IS_NULL; }
+ | fully_qualified_class_name { $$ = $1; }
;
@@ -700,8 +700,6 @@ expr_without_variable:
| T_ARRAY_CAST expr { zend_do_cast(&$$, &$2, IS_ARRAY TSRMLS_CC); }
| T_OBJECT_CAST expr { zend_do_cast(&$$, &$2, IS_OBJECT TSRMLS_CC); }
| T_BOOL_CAST expr { zend_do_cast(&$$, &$2, IS_BOOL TSRMLS_CC); }
- | T_SCALAR_CAST expr { zend_do_cast(&$$, &$2, IS_SCALAR TSRMLS_CC); }
- | T_NUMERIC_CAST expr { zend_do_cast(&$$, &$2, IS_NUMERIC TSRMLS_CC); }
| T_UNSET_CAST expr { zend_do_cast(&$$, &$2, IS_NULL TSRMLS_CC); }
| T_EXIT exit_expr { zend_do_exit(&$$, &$2 TSRMLS_CC); }
| '@' { zend_do_begin_silence(&$1 TSRMLS_CC); } expr { zend_do_end_silence(&$1 TSRMLS_CC); $$ = $3; }
Oops, something went wrong.

0 comments on commit e186189

Please sign in to comment.