From: Jürg Billeter Date: Sat, 3 Mar 2007 16:08:05 +0000 (+0000) Subject: support new construction syntax write interface with new construction X-Git-Tag: VALA_0_0_7~12 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ce5a414071d81e78e9993f0c7ace5268bc6f5179;p=platform%2Fupstream%2Fvala.git support new construction syntax write interface with new construction 2007-03-03 Jürg Billeter * vala/parser.y: support new construction syntax * vala/valainterfacewriter.vala: write interface with new construction syntax svn path=/trunk/; revision=210 --- diff --git a/vala/ChangeLog b/vala/ChangeLog index 54efc93..63e96d7 100644 --- a/vala/ChangeLog +++ b/vala/ChangeLog @@ -1,3 +1,9 @@ +2007-03-03 Jürg Billeter + + * vala/parser.y: support new construction syntax + * vala/valainterfacewriter.vala: write interface with new construction + syntax + 2007-03-01 Jürg Billeter * vala/valatypereference.vala: improve equality check diff --git a/vala/vala/parser.y b/vala/vala/parser.y index 3e7bed7..00eb30b 100644 --- a/vala/vala/parser.y +++ b/vala/vala/parser.y @@ -79,7 +79,8 @@ static void yyerror (YYLTYPE *locp, ValaParser *parser, const char *msg); ValaCallback *callback; ValaConstant *constant; ValaField *field; - ValaMethod *method; + // TODO change back to ValaMethod after construction syntax transition + ValaCodeNode *method; ValaFormalParameter *formal_parameter; ValaProperty *property; ValaPropertyAccessor *property_accessor; @@ -328,7 +329,6 @@ static void yyerror (YYLTYPE *locp, ValaParser *parser, const char *msg); %type fixed_parameters %type fixed_parameter %type signal_declaration -%type constructor_declaration %type destructor_declaration %type opt_attributes %type attributes @@ -2099,7 +2099,12 @@ class_member_declaration { /* skip declarations with errors */ if ($1 != NULL) { - vala_class_add_method (current_class, $1); + // TODO remove after construction syntax transition + if (VALA_IS_CONSTRUCTOR($1)) { + vala_class_set_constructor (current_class, $1); + } else { + vala_class_add_method (current_class, $1); + } g_object_unref ($1); } } @@ -2119,14 +2124,6 @@ class_member_declaration g_object_unref ($1); } } - | constructor_declaration - { - /* skip declarations with errors */ - if ($1 != NULL) { - vala_class_set_constructor (current_class, $1); - g_object_unref ($1); - } - } | destructor_declaration { /* skip declarations with errors */ @@ -2255,7 +2252,12 @@ method_declaration : method_header method_body { $$ = $1; - vala_method_set_body ($$, VALA_BLOCK($2)); + // TODO remove after construction syntax transition + if (VALA_IS_CONSTRUCTOR($$)) { + vala_constructor_set_body ($$, $2); + } else { + vala_method_set_body ($$, VALA_BLOCK($2)); + } if ($2 != NULL) { g_object_unref ($2); } @@ -2279,7 +2281,7 @@ method_header $$ = vala_method_new ($6, $5, src); g_object_unref (src); if ($3 != 0) { - $$->access = $3; + VALA_METHOD($$)->access = $3; } if (($4 & VALA_MODIFIER_STATIC) == VALA_MODIFIER_STATIC) { vala_method_set_instance ($$, FALSE); @@ -2306,6 +2308,46 @@ method_header g_object_unref ($5); g_free ($6); } + | comment opt_attributes opt_access_modifier opt_modifiers IDENTIFIER opt_name_specifier OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS + { + if ($3 != 0) { + GList *l; + + ValaSourceReference *src = src_com(@5, $1); + $$ = vala_method_new ($6, NULL, src); + g_free ($5); + g_free ($6); + g_object_unref (src); + vala_method_set_construction ($$, TRUE); + vala_method_set_instance ($$, FALSE); + if ($3 != 0) { + VALA_METHOD($$)->access = $3; + } + VALA_CODE_NODE($$)->attributes = $2; + + if ($8 != NULL) { + for (l = $8; l != NULL; l = l->next) { + vala_method_add_parameter ($$, l->data); + g_object_unref (l->data); + } + g_list_free ($8); + } + } else { + // TODO remove after construction syntax transition + ValaSourceReference *src = src_com(@5, $1); + $$ = vala_constructor_new (src); + g_object_unref (src); + g_free ($5); + g_free ($6); + } + } + | comment opt_attributes opt_access_modifier CONSTRUCT + { + ValaSourceReference *src = src_com(@4, $1); + $$ = vala_constructor_new (src); + g_object_unref (src); + } + // TODO remove after construction syntax transition | comment opt_attributes opt_access_modifier CONSTRUCT opt_identifier OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS { GList *l; @@ -2317,7 +2359,7 @@ method_header vala_method_set_construction ($$, TRUE); vala_method_set_instance ($$, FALSE); if ($3 != 0) { - $$->access = $3; + VALA_METHOD($$)->access = $3; } VALA_CODE_NODE($$)->attributes = $2; @@ -2520,19 +2562,6 @@ signal_declaration } ; -constructor_declaration - : comment opt_attributes opt_access_modifier opt_modifiers IDENTIFIER OPEN_PARENS CLOSE_PARENS block - { - ValaSourceReference *src = src_com(@5, $1); - $$ = vala_constructor_new (src); - g_object_unref (src); - vala_constructor_set_body ($$, $8); - - g_free ($5); - g_object_unref ($8); - } - ; - destructor_declaration : comment opt_attributes opt_access_modifier opt_modifiers TILDE IDENTIFIER OPEN_PARENS CLOSE_PARENS block { diff --git a/vala/vala/valainterfacewriter.vala b/vala/vala/valainterfacewriter.vala index b2d02c8..ce1af29 100644 --- a/vala/vala/valainterfacewriter.vala +++ b/vala/vala/valainterfacewriter.vala @@ -391,7 +391,14 @@ public class Vala.InterfaceWriter : CodeVisitor { write_string ("public"); if (m.construction) { - write_string (" construct"); + write_string (" "); + var datatype = (DataType) m.symbol.parent_symbol.node; + write_identifier (datatype.name); + + if (m.name != null) { + write_string ("."); + write_identifier (m.name); + } } else if (!m.instance) { write_string (" static"); } else if (m.is_abstract) { @@ -415,9 +422,7 @@ public class Vala.InterfaceWriter : CodeVisitor { write_string ("!"); } } - } - - if (m.name != null) { + write_string (" "); if (m.name == "class" || m.name == "construct" || m.name == "foreach" || m.name == "get" ||