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

Mark generic type parameter properties as construct-only, fixes bug 528567

2008-04-19  Juerg Billeter  <j@bitron.ch>

	* gobject/valaccodeassignmentbinding.vala,
	  gobject/valaccodebinding.vala, gobject/valaccodeclassbinding.vala,
	  gobject/valaccodemethodbinding.vala:

	  Mark generic type parameter properties as construct-only,
	  fixes bug 528567

svn path=/trunk/; revision=1265
parent 70bbd52f
2008-04-19 Jürg Billeter <j@bitron.ch>
* gobject/valaccodeassignmentbinding.vala,
gobject/valaccodebinding.vala, gobject/valaccodeclassbinding.vala,
gobject/valaccodemethodbinding.vala:
Mark generic type parameter properties as construct-only,
fixes bug 528567
2008-04-19 Jürg Billeter <j@bitron.ch>
* vala/valasemanticanalyzer.vala: disable null warnings with
......
......@@ -41,33 +41,7 @@ public class Vala.CCodeAssignmentBinding : CCodeExpressionBinding {
var prop = (Property) assignment.left.symbol_reference;
if (prop.set_accessor.construction && codegen.current_type_symbol is Class && codegen.current_class.is_subtype_of (codegen.gobject_type) && codegen.in_creation_method) {
// this property is used as a construction parameter
var cpointer = new CCodeIdentifier ("__params_it");
var ccomma = new CCodeCommaExpression ();
// set name in array for current parameter
var cnamemember = new CCodeMemberAccess.pointer (cpointer, "name");
var cnameassign = new CCodeAssignment (cnamemember, prop.get_canonical_cconstant ());
ccomma.append_expression (cnameassign);
var gvaluearg = new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeMemberAccess.pointer (cpointer, "value"));
// initialize GValue in array for current parameter
var cvalueinit = new CCodeFunctionCall (new CCodeIdentifier ("g_value_init"));
cvalueinit.add_argument (gvaluearg);
cvalueinit.add_argument (new CCodeIdentifier (prop.type_reference.get_type_id ()));
ccomma.append_expression (cvalueinit);
// set GValue for current parameter
var cvalueset = new CCodeFunctionCall (get_value_setter_function (prop.type_reference));
cvalueset.add_argument (gvaluearg);
cvalueset.add_argument ((CCodeExpression) assignment.right.ccodenode);
ccomma.append_expression (cvalueset);
// move pointer to next parameter in array
ccomma.append_expression (new CCodeUnaryExpression (CCodeUnaryOperator.POSTFIX_INCREMENT, cpointer));
codenode = ccomma;
codenode = get_construct_property_assignment (prop.get_canonical_cconstant (), prop.type_reference, (CCodeExpression) assignment.right.ccodenode);
} else {
CCodeExpression cexpr = (CCodeExpression) assignment.right.ccodenode;
......
......@@ -44,6 +44,36 @@ public abstract class Vala.CCodeBinding : CodeBinding {
}
}
public CCodeExpression get_construct_property_assignment (CCodeConstant canonical_cconstant, DataType property_type, CCodeExpression value) {
// this property is used as a construction parameter
var cpointer = new CCodeIdentifier ("__params_it");
var ccomma = new CCodeCommaExpression ();
// set name in array for current parameter
var cnamemember = new CCodeMemberAccess.pointer (cpointer, "name");
var cnameassign = new CCodeAssignment (cnamemember, canonical_cconstant);
ccomma.append_expression (cnameassign);
var gvaluearg = new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeMemberAccess.pointer (cpointer, "value"));
// initialize GValue in array for current parameter
var cvalueinit = new CCodeFunctionCall (new CCodeIdentifier ("g_value_init"));
cvalueinit.add_argument (gvaluearg);
cvalueinit.add_argument (new CCodeIdentifier (property_type.get_type_id ()));
ccomma.append_expression (cvalueinit);
// set GValue for current parameter
var cvalueset = new CCodeFunctionCall (get_value_setter_function (property_type));
cvalueset.add_argument (gvaluearg);
cvalueset.add_argument (value);
ccomma.append_expression (cvalueset);
// move pointer to next parameter in array
ccomma.append_expression (new CCodeUnaryExpression (CCodeUnaryOperator.POSTFIX_INCREMENT, cpointer));
return ccomma;
}
public CCodeBinding? code_binding (CodeNode node) {
return (CCodeBinding) node.get_code_binding (codegen);
}
......
......@@ -371,7 +371,7 @@ public class Vala.CCodeClassBinding : CCodeTypesymbolBinding {
cspec.add_argument (new CCodeConstant ("\"type\""));
cspec.add_argument (new CCodeConstant ("\"type\""));
cspec.add_argument (new CCodeIdentifier ("G_TYPE_NONE"));
cspec.add_argument (new CCodeConstant ("G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_WRITABLE"));
cspec.add_argument (new CCodeConstant ("G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY"));
cinst.add_argument (cspec);
init_block.add_statement (new CCodeExpressionStatement (cinst));
codegen.prop_enum.add_value (new CCodeEnumValue (enum_value));
......@@ -389,7 +389,7 @@ public class Vala.CCodeClassBinding : CCodeTypesymbolBinding {
cspec.add_argument (func_name_constant);
cspec.add_argument (new CCodeConstant ("\"dup func\""));
cspec.add_argument (new CCodeConstant ("\"dup func\""));
cspec.add_argument (new CCodeConstant ("G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_WRITABLE"));
cspec.add_argument (new CCodeConstant ("G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY"));
cinst.add_argument (cspec);
init_block.add_statement (new CCodeExpressionStatement (cinst));
codegen.prop_enum.add_value (new CCodeEnumValue (enum_value));
......@@ -407,7 +407,7 @@ public class Vala.CCodeClassBinding : CCodeTypesymbolBinding {
cspec.add_argument (func_name_constant);
cspec.add_argument (new CCodeConstant ("\"destroy func\""));
cspec.add_argument (new CCodeConstant ("\"destroy func\""));
cspec.add_argument (new CCodeConstant ("G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_WRITABLE"));
cspec.add_argument (new CCodeConstant ("G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY"));
cinst.add_argument (cspec);
init_block.add_statement (new CCodeExpressionStatement (cinst));
codegen.prop_enum.add_value (new CCodeEnumValue (enum_value));
......
......@@ -92,7 +92,7 @@ public class Vala.CCodeMethodBinding : CCodeBinding {
}
}
add_object_creation (cblock, ((CreationMethod) m).n_construction_params > 0);
add_object_creation (cblock, ((CreationMethod) m).n_construction_params > 0 || codegen.current_class.get_type_parameters ().size > 0);
foreach (CodeNode stmt in m.body.get_statements ()) {
if (!((ExpressionStatement) stmt).assigned_property ().set_accessor.construction) {
......@@ -348,11 +348,11 @@ public class Vala.CCodeMethodBinding : CCodeBinding {
if (in_gobject_creation_method) {
int n_params = ((CreationMethod) m).n_construction_params;
if (n_params > 0) {
if (n_params > 0 || codegen.current_class.get_type_parameters ().size > 0) {
// declare construction parameter array
var cparamsinit = new CCodeFunctionCall (new CCodeIdentifier ("g_new0"));
cparamsinit.add_argument (new CCodeIdentifier ("GParameter"));
cparamsinit.add_argument (new CCodeConstant (n_params.to_string ()));
cparamsinit.add_argument (new CCodeConstant ((n_params + 3 * codegen.current_class.get_type_parameters ().size).to_string ()));
var cdecl = new CCodeDeclaration ("GParameter *");
cdecl.add_declarator (new CCodeVariableDeclarator.with_initializer ("__params", cparamsinit));
......@@ -365,24 +365,20 @@ public class Vala.CCodeMethodBinding : CCodeBinding {
/* type, dup func, and destroy func properties for generic types */
foreach (TypeParameter type_param in codegen.current_class.get_type_parameters ()) {
string func_name;
CCodeMemberAccess cmember;
CCodeAssignment cassign;
func_name = "%s_type".printf (type_param.name.down ());
cmember = new CCodeMemberAccess.pointer (new CCodeMemberAccess.pointer (new CCodeIdentifier ("self"), "priv"), func_name);
cassign = new CCodeAssignment (cmember, new CCodeIdentifier (func_name));
codegen.function.block.add_statement (new CCodeExpressionStatement (cassign));
func_name = "%s_dup_func".printf (type_param.name.down ());
cmember = new CCodeMemberAccess.pointer (new CCodeMemberAccess.pointer (new CCodeIdentifier ("self"), "priv"), func_name);
cassign = new CCodeAssignment (cmember, new CCodeIdentifier (func_name));
codegen.function.block.add_statement (new CCodeExpressionStatement (cassign));
func_name = "%s_destroy_func".printf (type_param.name.down ());
cmember = new CCodeMemberAccess.pointer (new CCodeMemberAccess.pointer (new CCodeIdentifier ("self"), "priv"), func_name);
cassign = new CCodeAssignment (cmember, new CCodeIdentifier (func_name));
codegen.function.block.add_statement (new CCodeExpressionStatement (cassign));
CCodeConstant prop_name;
CCodeIdentifier param_name;
prop_name = new CCodeConstant ("\"%s-type\"".printf (type_param.name.down ()));
param_name = new CCodeIdentifier ("%s_type".printf (type_param.name.down ()));
cinit.append (new CCodeExpressionStatement (get_construct_property_assignment (prop_name, new ValueType (codegen.gtype_type), param_name)));
prop_name = new CCodeConstant ("\"%s-dup-func\"".printf (type_param.name.down ()));
param_name = new CCodeIdentifier ("%s_dup_func".printf (type_param.name.down ()));
cinit.append (new CCodeExpressionStatement (get_construct_property_assignment (prop_name, new PointerType (new VoidType ()), param_name)));
prop_name = new CCodeConstant ("\"%s-destroy-func\"".printf (type_param.name.down ()));
param_name = new CCodeIdentifier ("%s_destroy_func".printf (type_param.name.down ()));
cinit.append (new CCodeExpressionStatement (get_construct_property_assignment (prop_name, new PointerType (new VoidType ()), param_name)));
}
} else if (in_fundamental_creation_method) {
var cl = (Class) m.parent_symbol;
......@@ -587,7 +583,8 @@ public class Vala.CCodeMethodBinding : CCodeBinding {
}
if (m is CreationMethod) {
if (((CreationMethod) m).n_construction_params > 0) {
if (codegen.current_class != null && codegen.current_class.is_subtype_of (codegen.gobject_type)
&& (((CreationMethod) m).n_construction_params > 0 || codegen.current_class.get_type_parameters ().size > 0)) {
var ccond = new CCodeBinaryExpression (CCodeBinaryOperator.GREATER_THAN, new CCodeIdentifier ("__params_it"), new CCodeIdentifier ("__params"));
var cdofreeparam = new CCodeBlock ();
cdofreeparam.add_statement (new CCodeExpressionStatement (new CCodeUnaryExpression (CCodeUnaryOperator.PREFIX_DECREMENT, new CCodeIdentifier ("__params_it"))));
......
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