Commit fbb5c574 authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter
Browse files

support declaration of local arrays test local array declaration

2007-04-03  Jürg Billeter  <j@bitron.ch>

	* vala/scanner.l, vala/parser.y, vala/valasemanticanalyzer.vala,
	  vala/valatypereference.vala: support declaration of local arrays
	* tests/test-022.vala: test local array declaration

svn path=/trunk/; revision=272
parent 813b94f9
2007-04-03 Jürg Billeter <j@bitron.ch>
* vala/scanner.l, vala/parser.y, vala/valasemanticanalyzer.vala,
vala/valatypereference.vala: support declaration of local arrays
* tests/test-022.vala: test local array declaration
2007-04-03 Jürg Billeter <j@bitron.ch>
* vala/valasymbolbuilder.vala, vala/valacodegenerator.vala: some fixes
......
......@@ -4,7 +4,7 @@ class Maman.Foo {
static int main (string[] args) {
stdout.printf ("One dimensional array creation and assignment: 1");
var a = new int[4] {1,2};
int[] a = new int[4] {1,2};
stdout.printf (" 2");
......
......@@ -101,6 +101,7 @@ static void yyerror (YYLTYPE *locp, ValaParser *parser, const char *msg);
%token OPEN_PARENS "("
%token OPEN_CAST_PARENS "cast ("
%token CLOSE_PARENS ")"
%token BRACKET_PAIR "[]"
%token OPEN_BRACKET "["
%token CLOSE_BRACKET "]"
%token ELLIPSIS "..."
......@@ -223,6 +224,8 @@ static void yyerror (YYLTYPE *locp, ValaParser *parser, const char *msg);
%type <expression> opt_initializer
%type <num> opt_rank_specifier
%type <num> rank_specifier
%type <num> opt_bracket_pair
%type <num> bracket_pair
%type <num> opt_comma_list
%type <num> comma_list
%type <expression> primary_no_array_creation_expression
......@@ -638,6 +641,22 @@ rank_specifier
{
$$ = $2;
}
| bracket_pair
;
opt_bracket_pair
: /* empty */
{
$$ = 0;
}
| bracket_pair
;
bracket_pair
: BRACKET_PAIR
{
$$ = 1;
}
;
opt_comma_list
......@@ -1432,15 +1451,17 @@ local_variable_declaration
GList *l;
ValaSourceReference *src = src(@2);
$$ = vala_local_variable_declaration_new ($1, src);
g_object_unref ($1);
g_object_unref (src);
for (l = $2; l != NULL; l = l->next) {
ValaVariableDeclarator *decl = l->data;
vala_variable_declarator_set_type_reference (decl, g_object_ref ($1));
ValaTypeReference *type = vala_type_reference_copy ($1);
vala_variable_declarator_set_type_reference (decl, type);
g_object_unref (type);
vala_local_variable_declaration_add_declarator ($$, decl);
g_object_unref (decl);
}
g_list_free ($2);
g_object_unref ($1);
}
| VAR variable_declarators
{
......@@ -1458,14 +1479,15 @@ local_variable_declaration
/* don't use type to prevent reduce/reduce conflict */
local_variable_type
: primary_expression opt_op_neg
: primary_expression opt_bracket_pair opt_op_neg
{
ValaSourceReference *src = src(@1);
$$ = vala_type_reference_new_from_expression ($1);
g_object_unref ($1);
g_object_unref (src);
vala_type_reference_set_takes_ownership ($$, TRUE);
if ($2) {
vala_type_reference_set_array_rank ($$, $2);
if ($3) {
vala_type_reference_set_non_null ($$, TRUE);
}
}
......@@ -1477,24 +1499,26 @@ local_variable_type
g_object_unref (src);
vala_type_reference_set_pointer_level ($$, $2);
}
| REF primary_expression opt_op_neg
| REF primary_expression opt_bracket_pair opt_op_neg
{
ValaSourceReference *src = src(@2);
$$ = vala_type_reference_new_from_expression ($2);
g_object_unref ($2);
g_object_unref (src);
vala_type_reference_set_takes_ownership ($$, TRUE);
if ($3) {
vala_type_reference_set_array_rank ($$, $3);
if ($4) {
vala_type_reference_set_non_null ($$, TRUE);
}
}
| WEAK primary_expression opt_op_neg
| WEAK primary_expression opt_bracket_pair opt_op_neg
{
ValaSourceReference *src = src(@2);
$$ = vala_type_reference_new_from_expression ($2);
g_object_unref ($2);
g_object_unref (src);
if ($3) {
vala_type_reference_set_array_rank ($$, $3);
if ($4) {
vala_type_reference_set_non_null ($$, TRUE);
}
}
......
......@@ -76,6 +76,7 @@ literal ({integer_literal}|{real_literal}|{character_literal}|{string_literal
"("{space}{ident}("."{ident})?("["{space}"]")*{space}")"{space}("("|{ident}|{literal}) { yyless (1); uploc; return OPEN_CAST_PARENS; }
"(" { uploc; return OPEN_PARENS; }
")" { uploc; return CLOSE_PARENS; }
"[]" { uploc; return BRACKET_PAIR; }
"[" { uploc; return OPEN_BRACKET; }
"]" { uploc; return CLOSE_BRACKET; }
"..." { uploc; return ELLIPSIS; }
......
......@@ -1363,7 +1363,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
if (args.length () != 1) {
expr.error = true;
Report.error (expr.source_reference, "internal error: array reference without type arguments");
Report.error (expr.source_reference, "internal error: array reference with %d type arguments, expected 1".printf (args.length ()));
return;
}
......
......@@ -264,13 +264,13 @@ public class Vala.TypeReference : CodeNode {
}
/**
* Creates a shallow copy of this type reference. May only be used with
* resolved type references.
* Creates a shallow copy of this type reference.
*
* @return copy of this type reference
*/
public ref TypeReference! copy () {
var result = new TypeReference ();
result.source_reference = source_reference;
result.reference_to_value_type = reference_to_value_type;
result.transfers_ownership = transfers_ownership;
result.takes_ownership = takes_ownership;
......@@ -278,6 +278,13 @@ public class Vala.TypeReference : CodeNode {
result.non_null = non_null;
result.data_type = data_type;
result.type_parameter = type_parameter;
result.floating_reference = floating_reference;
result.namespace_name = namespace_name;
result.type_name = type_name;
result.array_rank = array_rank;
result.pointer_level = pointer_level;
result.is_ref = is_ref;
result.is_weak = is_weak;
foreach (TypeReference arg in type_argument_list) {
result.type_argument_list.append (arg.copy ());
......
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