Commit 92279289 authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter

generate get_property and set_property methods only when necessary, fixes

2007-05-09  Jürg Billeter  <j@bitron.ch>

	* gobject/valacodegeneratorclass.vala: generate get_property and
	  set_property methods only when necessary, fixes bug 435848

svn path=/trunk/; revision=313
parent 00722508
2007-05-09 Jürg Billeter <j@bitron.ch>
* gobject/valacodegeneratorclass.vala: generate get_property and
set_property methods only when necessary, fixes bug 435848
2007-05-09 Jürg Billeter <j@bitron.ch>
* vala/parser.y: add basic checks for method modifiers, fixes bug 435853
......
......@@ -89,8 +89,12 @@ public class Vala.CodeGenerator {
public override void visit_end_class (Class! cl) {
if (!cl.is_static) {
add_get_property_function (cl);
add_set_property_function (cl);
if (class_has_readable_properties (cl)) {
add_get_property_function (cl);
}
if (class_has_writable_properties (cl)) {
add_set_property_function (cl);
}
add_class_init_function (cl);
foreach (TypeReference base_type in cl.get_base_types ()) {
......@@ -155,8 +159,12 @@ public class Vala.CodeGenerator {
/* set property handlers */
ccall = new CCodeFunctionCall (new CCodeIdentifier ("G_OBJECT_CLASS"));
ccall.add_argument (new CCodeIdentifier ("klass"));
init_block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeMemberAccess.pointer (ccall, "get_property"), new CCodeIdentifier ("%s_get_property".printf (cl.get_lower_case_cname (null))))));
init_block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeMemberAccess.pointer (ccall, "set_property"), new CCodeIdentifier ("%s_set_property".printf (cl.get_lower_case_cname (null))))));
if (class_has_readable_properties (cl)) {
init_block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeMemberAccess.pointer (ccall, "get_property"), new CCodeIdentifier ("%s_get_property".printf (cl.get_lower_case_cname (null))))));
}
if (class_has_writable_properties (cl)) {
init_block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeMemberAccess.pointer (ccall, "set_property"), new CCodeIdentifier ("%s_set_property".printf (cl.get_lower_case_cname (null))))));
}
/* set constructor */
if (cl.constructor != null) {
......@@ -376,7 +384,25 @@ public class Vala.CodeGenerator {
return new CCodeIdentifier ("g_value_set_pointer");
}
}
private bool class_has_readable_properties (Class! cl) {
foreach (Property prop in cl.get_properties ()) {
if (prop.get_accessor != null && !prop.is_abstract) {
return true;
}
}
return false;
}
private bool class_has_writable_properties (Class! cl) {
foreach (Property prop in cl.get_properties ()) {
if (prop.set_accessor != null && !prop.is_abstract) {
return true;
}
}
return false;
}
private void add_get_property_function (Class! cl) {
var get_prop = new CCodeFunction ("%s_get_property".printf (cl.get_lower_case_cname (null)), "void");
get_prop.modifiers = CCodeModifiers.STATIC;
......
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