From 4649b39e4ae6460506f435875a5ff1de9332a7d2 Mon Sep 17 00:00:00 2001 From: Juerg Billeter Date: Mon, 9 Jul 2007 05:08:30 +0000 Subject: [PATCH] support delegate keyword and optional modifiers to declare callbacks 2007-07-09 Juerg Billeter * vala/scanner.l, vala/parser.y: support delegate keyword and optional modifiers to declare callbacks svn path=/trunk/; revision=332 --- ChangeLog | 5 +++++ vala/parser.y | 45 +++++++++++++++++++++++++++++++++++++++++++++ vala/scanner.l | 1 + 3 files changed, 51 insertions(+) diff --git a/ChangeLog b/ChangeLog index f6ca8f9..16dcb07 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2007-07-09 Jürg Billeter + * vala/scanner.l, vala/parser.y: support delegate keyword and optional + modifiers to declare callbacks + +2007-07-09 Jürg Billeter + * vala/parser.y: support # modifier to transfer ownership in method parameters diff --git a/vala/parser.y b/vala/parser.y index 56016fe..dd3f6c2 100644 --- a/vala/parser.y +++ b/vala/parser.y @@ -162,6 +162,7 @@ static void yyerror (YYLTYPE *locp, ValaParser *parser, const char *msg); %token CONSTRUCT "construct" %token CONTINUE "continue" %token DEFAULT "default" +%token DELEGATE "delegate" %token DO "do" %token ELSE "else" %token ENUM "enum" @@ -3328,6 +3329,50 @@ callback_declaration g_list_free ($10); } } + | comment opt_attributes opt_access_modifier opt_modifiers DELEGATE type identifier opt_name_specifier opt_type_parameter_list OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS SEMICOLON + { + ValaSourceReference *src; + GList *l; + char *name = $7; + + if ($8 != NULL) { + ValaSourceReference *ns_src = src(@7); + current_namespace = vala_namespace_new ($7, ns_src); + g_free ($7); + g_object_unref (ns_src); + current_namespace_implicit = TRUE; + + vala_source_file_add_namespace (current_source_file, current_namespace); + g_object_unref (current_namespace); + + name = $8; + } + + src = src_com(@7, $1); + $$ = vala_callback_new (name, $6, src); + g_free (name); + g_object_unref ($6); + g_object_unref (src); + if ($3 != 0) { + VALA_DATA_TYPE($$)->access = $3; + } + VALA_CODE_NODE($$)->attributes = $2; + + if ($9 != NULL) { + for (l = $9; l != NULL; l = l->next) { + vala_callback_add_type_parameter ($$, l->data); + g_object_unref (l->data); + } + g_list_free ($9); + } + if ($11 != NULL) { + for (l = $11; l != NULL; l = l->next) { + vala_callback_add_parameter ($$, l->data); + g_object_unref (l->data); + } + g_list_free ($11); + } + } ; opt_attributes diff --git a/vala/scanner.l b/vala/scanner.l index 90754b2..b1b81a7 100644 --- a/vala/scanner.l +++ b/vala/scanner.l @@ -138,6 +138,7 @@ literal ({integer_literal}|{real_literal}|{character_literal}|{string_literal "construct" { uploc; return CONSTRUCT; } "continue" { uploc; return CONTINUE; } "default" { uploc; return DEFAULT; } +"delegate" { uploc; return DELEGATE; } "do" { uploc; return DO; } "else" { uploc; return ELSE; } "enum" { uploc; return ENUM; } -- 2.7.4