vala r980 - in trunk: . gobject vala
- From: juergbi svn gnome org
- To: svn-commits-list gnome org
- Subject: vala r980 - in trunk: . gobject vala
- Date: Tue, 5 Feb 2008 21:24:48 +0000 (GMT)
Author: juergbi
Date: Tue Feb 5 21:24:48 2008
New Revision: 980
URL: http://svn.gnome.org/viewvc/vala?rev=980&view=rev
Log:
2008-02-05 Juerg Billeter <j bitron ch>
* vala/parser.y, vala/valaclass.vala, vala/valaproperty.vala,
gobject/valaccodegeneratorinterface.vala: support default values
for properties, fixes bug 437434
Modified:
trunk/ChangeLog
trunk/gobject/valaccodegeneratorinterface.vala
trunk/vala/parser.y
trunk/vala/valaclass.vala
trunk/vala/valaproperty.vala
Modified: trunk/gobject/valaccodegeneratorinterface.vala
==============================================================================
--- trunk/gobject/valaccodegeneratorinterface.vala (original)
+++ trunk/gobject/valaccodegeneratorinterface.vala Tue Feb 5 21:24:48 2008
@@ -109,35 +109,63 @@
cspec.call = new CCodeIdentifier ("g_param_spec_int");
cspec.add_argument (new CCodeConstant ("G_MININT"));
cspec.add_argument (new CCodeConstant ("G_MAXINT"));
- cspec.add_argument (new CCodeConstant ("0"));
+ if (prop.default_expression != null) {
+ cspec.add_argument ((CCodeExpression) prop.default_expression.ccodenode);
+ } else {
+ cspec.add_argument (new CCodeConstant ("0"));
+ }
} else if (prop.type_reference.data_type == uint_type.data_type) {
cspec.call = new CCodeIdentifier ("g_param_spec_uint");
cspec.add_argument (new CCodeConstant ("0"));
cspec.add_argument (new CCodeConstant ("G_MAXUINT"));
- cspec.add_argument (new CCodeConstant ("0U"));
+ if (prop.default_expression != null) {
+ cspec.add_argument ((CCodeExpression) prop.default_expression.ccodenode);
+ } else {
+ cspec.add_argument (new CCodeConstant ("0U"));
+ }
} else if (prop.type_reference.data_type == long_type.data_type) {
cspec.call = new CCodeIdentifier ("g_param_spec_long");
cspec.add_argument (new CCodeConstant ("G_MINLONG"));
cspec.add_argument (new CCodeConstant ("G_MAXLONG"));
- cspec.add_argument (new CCodeConstant ("0L"));
+ if (prop.default_expression != null) {
+ cspec.add_argument ((CCodeExpression) prop.default_expression.ccodenode);
+ } else {
+ cspec.add_argument (new CCodeConstant ("0L"));
+ }
} else if (prop.type_reference.data_type == ulong_type.data_type) {
cspec.call = new CCodeIdentifier ("g_param_spec_ulong");
cspec.add_argument (new CCodeConstant ("0"));
cspec.add_argument (new CCodeConstant ("G_MAXULONG"));
- cspec.add_argument (new CCodeConstant ("0UL"));
+ if (prop.default_expression != null) {
+ cspec.add_argument ((CCodeExpression) prop.default_expression.ccodenode);
+ } else {
+ cspec.add_argument (new CCodeConstant ("0UL"));
+ }
} else if (prop.type_reference.data_type == bool_type.data_type) {
cspec.call = new CCodeIdentifier ("g_param_spec_boolean");
- cspec.add_argument (new CCodeConstant ("FALSE"));
+ if (prop.default_expression != null) {
+ cspec.add_argument ((CCodeExpression) prop.default_expression.ccodenode);
+ } else {
+ cspec.add_argument (new CCodeConstant ("FALSE"));
+ }
} else if (prop.type_reference.data_type == float_type.data_type) {
cspec.call = new CCodeIdentifier ("g_param_spec_float");
cspec.add_argument (new CCodeConstant ("-G_MAXFLOAT"));
cspec.add_argument (new CCodeConstant ("G_MAXFLOAT"));
- cspec.add_argument (new CCodeConstant ("0.0F"));
+ if (prop.default_expression != null) {
+ cspec.add_argument ((CCodeExpression) prop.default_expression.ccodenode);
+ } else {
+ cspec.add_argument (new CCodeConstant ("0.0F"));
+ }
} else if (prop.type_reference.data_type == double_type.data_type) {
cspec.call = new CCodeIdentifier ("g_param_spec_double");
cspec.add_argument (new CCodeConstant ("-G_MAXDOUBLE"));
cspec.add_argument (new CCodeConstant ("G_MAXDOUBLE"));
- cspec.add_argument (new CCodeConstant ("0.0"));
+ if (prop.default_expression != null) {
+ cspec.add_argument ((CCodeExpression) prop.default_expression.ccodenode);
+ } else {
+ cspec.add_argument (new CCodeConstant ("0.0"));
+ }
} else {
cspec.call = new CCodeIdentifier ("g_param_spec_pointer");
}
Modified: trunk/vala/parser.y
==============================================================================
--- trunk/vala/parser.y (original)
+++ trunk/vala/parser.y Tue Feb 5 21:24:48 2008
@@ -342,6 +342,8 @@
%type <property_accessor> get_accessor_declaration
%type <property_accessor> opt_set_accessor_declaration
%type <property_accessor> set_accessor_declaration
+%type <expression> opt_default_value
+%type <expression> default_value
%type <constant> constant_declaration
%type <field> field_declaration
%type <list> variable_declarators
@@ -3331,7 +3333,7 @@
;
property_declaration
- : comment opt_attributes opt_access_modifier opt_modifiers type identifier OPEN_BRACE get_accessor_declaration opt_set_accessor_declaration CLOSE_BRACE
+ : comment opt_attributes opt_access_modifier opt_modifiers type identifier OPEN_BRACE get_accessor_declaration opt_set_accessor_declaration opt_default_value CLOSE_BRACE
{
ValaSourceReference *src;
@@ -3356,6 +3358,11 @@
g_object_unref ($9);
}
+ if ($10 != NULL) {
+ vala_property_set_default_expression ($$, $10);
+ g_object_unref ($10);
+ }
+
if (($4 & VALA_MODIFIER_ABSTRACT) == VALA_MODIFIER_ABSTRACT) {
vala_property_set_is_abstract ($$, TRUE);
}
@@ -3369,7 +3376,7 @@
vala_property_set_instance ($$, FALSE);
}
}
- | comment opt_attributes opt_access_modifier opt_modifiers type identifier OPEN_BRACE set_accessor_declaration opt_get_accessor_declaration CLOSE_BRACE
+ | comment opt_attributes opt_access_modifier opt_modifiers type identifier OPEN_BRACE set_accessor_declaration opt_get_accessor_declaration opt_default_value CLOSE_BRACE
{
ValaSourceReference *src;
@@ -3394,6 +3401,11 @@
g_object_unref ($9);
}
+ if ($10 != NULL) {
+ vala_property_set_default_expression ($$, $10);
+ g_object_unref ($10);
+ }
+
if (($4 & VALA_MODIFIER_ABSTRACT) == VALA_MODIFIER_ABSTRACT) {
vala_property_set_is_abstract ($$, TRUE);
}
@@ -3506,6 +3518,21 @@
}
;
+opt_default_value
+ : /* empty */
+ {
+ $$ = NULL;
+ }
+ | default_value
+ ;
+
+default_value
+ : DEFAULT OPEN_PARENS expression CLOSE_PARENS SEMICOLON
+ {
+ $$ = $3;
+ }
+ ;
+
signal_declaration
: comment opt_attributes opt_access_modifier SIGNAL type identifier OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS SEMICOLON
{
Modified: trunk/vala/valaclass.vala
==============================================================================
--- trunk/vala/valaclass.vala (original)
+++ trunk/vala/valaclass.vala Tue Feb 5 21:24:48 2008
@@ -254,7 +254,7 @@
if (empty_get && empty_set) {
/* automatic property accessor body generation */
var field_type = prop.type_reference.copy ();
- var f = new Field ("_%s".printf (prop.name), field_type, null, prop.source_reference);
+ var f = new Field ("_%s".printf (prop.name), field_type, prop.default_expression, prop.source_reference);
f.access = SymbolAccessibility.PRIVATE;
add_field (f);
}
Modified: trunk/vala/valaproperty.vala
==============================================================================
--- trunk/vala/valaproperty.vala (original)
+++ trunk/vala/valaproperty.vala Tue Feb 5 21:24:48 2008
@@ -111,6 +111,11 @@
public Property base_interface_property { get; set; }
/**
+ * Specifies the default value of this property.
+ */
+ public Expression default_expression { get; set; }
+
+ /**
* Nickname of this property.
*/
public string nick {
@@ -177,6 +182,10 @@
if (set_accessor != null) {
set_accessor.accept (visitor);
}
+
+ if (default_expression != null) {
+ default_expression.accept (visitor);
+ }
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]