Skip to content

Commit

Permalink
#120 - Add support for mixed type in parameters and return type
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeckerson committed Sep 15, 2021
1 parent 3fee124 commit bd500e6
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 1 deletion.
3 changes: 3 additions & 0 deletions parser/base.c
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,9 @@ void xx_parse_program(zval *return_value, char *program, size_t program_length,
case XX_T_TYPE_RESOURCE:
xx_(xx_parser, XX_TYPE_RESOURCE, NULL, parser_status);
break;
case XX_T_TYPE_MIXED:
xx_(xx_parser, XX_TYPE_MIXED, NULL, parser_status);
break;
case XX_T_TYPE_CALLABLE:
xx_(xx_parser, XX_TYPE_CALLABLE, NULL, parser_status);
break;
Expand Down
9 changes: 8 additions & 1 deletion parser/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,6 @@ static void xx_ret_return_type_item(zval *ret, zval *type, zval *cast, int manda
static void xx_ret_type(zval *ret, int type)
{
switch (type) {

case XX_TYPE_INTEGER:
parser_get_string(ret, "int");
return;
Expand Down Expand Up @@ -587,6 +586,10 @@ static void xx_ret_type(zval *ret, int type)
parser_get_string(ret, "object");
return;

case XX_TYPE_MIXED:
parser_get_string(ret, "mixed");
return;

case XX_T_TYPE_NULL:
parser_get_string(ret, "null");
return;
Expand Down Expand Up @@ -1040,6 +1043,10 @@ static void xx_ret_declare_statement(zval *ret, int type, zval *variables, xx_sc
parser_add_str(ret, "data-type", "resource");
break;

case XX_T_TYPE_MIXED:
parser_add_str(ret, "data-type", "mixed");
break;

case XX_T_TYPE_OBJECT:
parser_add_str(ret, "data-type", "object");
break;
Expand Down
1 change: 1 addition & 0 deletions parser/scanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#define XX_T_TYPE_RESOURCE 333
#define XX_T_TYPE_NULL 334
#define XX_T_TYPE_THIS 335
#define XX_T_TYPE_MIXED 336

#define XX_T_NAMESPACE 350
#define XX_T_CLASS 351
Expand Down
6 changes: 6 additions & 0 deletions parser/scanner.re
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,12 @@ int xx_get_token(xx_scanner_state *s, xx_scanner_token *token) {
return 0;
}
'mixed' {
s->active_char += sizeof("mixed")-1;
token->opcode = XX_T_TYPE_MIXED;
return 0;
}
'if' {
s->active_char += sizeof("if")-1;
token->opcode = XX_T_IF;
Expand Down
8 changes: 8 additions & 0 deletions parser/zephir.lemon
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,10 @@ xx_parameter_type(R) ::= TYPE_RESOURCE . {
xx_ret_type(&R, XX_TYPE_RESOURCE);
}

xx_parameter_type(R) ::= TYPE_MIXED . {
xx_ret_type(&R, XX_TYPE_MIXED);
}

xx_parameter_type(R) ::= TYPE_OBJECT . {
xx_ret_type(&R, XX_TYPE_OBJECT);
}
Expand Down Expand Up @@ -1596,6 +1600,10 @@ xx_declare_statement(R) ::= TYPE_ARRAY xx_declare_variable_list(L) DOTCOMMA . {
xx_ret_declare_statement(&R, XX_T_TYPE_ARRAY, &L, status->scanner_state);
}

xx_declare_statement(R) ::= TYPE_MIXED xx_declare_variable_list(L) DOTCOMMA . {
xx_ret_declare_statement(&R, XX_T_TYPE_MIXED, &L, status->scanner_state);
}

xx_declare_variable_list(R) ::= xx_declare_variable_list(L) COMMA xx_declare_variable(V) . {
xx_ret_list(&R, &L, &V, status->scanner_state);
}
Expand Down

0 comments on commit bd500e6

Please sign in to comment.