Commit 87d0f44c authored by Sergio Costas's avatar Sergio Costas

Add support for array parameters

This patch adds support for parameters in the form:

    function(type name[]);

and

    function(type name[number]);
parent 91e8d25e
......@@ -95,6 +95,7 @@ class tokens(object):
348:'CRUST_SET_NULL',
349:'CRUST_SET_NOT_NULL',
350:'CRUST_OVERRIDE',
351:'OWN_POINTER',
'IDENTIFIER':258,
'CONSTANT':259,
'STRING_LITERAL':260,
......@@ -188,6 +189,7 @@ class tokens(object):
'CRUST_SET_NULL':348,
'CRUST_SET_NOT_NULL':349,
'CRUST_OVERRIDE':350,
'OWN_POINTER':351,
}
@staticmethod
......
......@@ -80,6 +80,7 @@ void add_type_element(char *);
%token CRUST_SET_NULL
%token CRUST_SET_NOT_NULL
%token CRUST_OVERRIDE
%token OWN_POINTER
//%start translation_unit
%start start_unit
......@@ -728,7 +729,12 @@ parameter_declaration
mix_ast_leaves($$, $2);
free_tree($2);
} else {
show_error(__LINE__, $$);
if ($2->type == OWN_POINTER) {
$$->pointer+=$2->pointer;
free_tree($2);
} else {
show_error(__LINE__, $$);
}
}
}
| declaration_specifiers { $$ = $1; show_debug(__LINE__, $$, "parameter_declaration"); }
......@@ -756,8 +762,17 @@ direct_abstract_declarator
: '(' abstract_declarator ')' { $$ = $2; show_debug(__LINE__, $$, "direct_abstract_declarator");
free_tree($1);
free_tree($3); }
| '[' ']' { $$ = $1; show_error(__LINE__, $$); }
| '[' assignment_expression ']' { $$ = $1; show_error(__LINE__, $$); }
| '[' ']' { $$ = new_leaf(OWN_POINTER, NULL);
show_debug(__LINE__, $$, "direct_abstract_declarator");
$$->pointer = 1;
free_tree($1);
free_tree($2); }
| '[' assignment_expression ']' { $$ = new_leaf(OWN_POINTER, NULL);
show_debug(__LINE__, $$, "direct_abstract_declarator");
$$->pointer = 1;
free_tree($1);
free_tree($2);
free_tree($3); }
| direct_abstract_declarator '[' ']' { $$ = $1; show_error(__LINE__, $$); }
| direct_abstract_declarator '[' assignment_expression ']' { $$ = $1; show_error(__LINE__, $$); }
| '[' '*' ']' { $$ = $1; show_error(__LINE__, $$); }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment