From: Jürg Billeter Date: Fri, 21 Nov 2008 21:16:02 +0000 (+0000) Subject: Small refactoring X-Git-Tag: VALA_0_5_2~56 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2dbbdb080e3cf5cc5591c605848ef1a3054bb96e;p=thirdparty%2Fvala.git Small refactoring 2008-11-21 Jürg Billeter * gobject/valaccodemethodmodule.vala: Small refactoring svn path=/trunk/; revision=2055 --- diff --git a/ChangeLog b/ChangeLog index 90325681e..41685bf6b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2008-11-21 Jürg Billeter + + * gobject/valaccodemethodmodule.vala: + + Small refactoring + 2008-11-21 Jürg Billeter * gobject/valadbusmodule.vala: diff --git a/gobject/valaccodemethodmodule.vala b/gobject/valaccodemethodmodule.vala index 123cd329a..8d7e4c69d 100644 --- a/gobject/valaccodemethodmodule.vala +++ b/gobject/valaccodemethodmodule.vala @@ -556,63 +556,6 @@ public class Vala.CCodeMethodModule : CCodeStructModule { source_type_member_definition.append (vfunc); } - if (m is CreationMethod) { - if (current_class != null && !current_class.is_compact) { - var vfunc = new CCodeFunction (m.get_cname (), creturn_type.get_cname ()); - vfunc.line = function.line; - - cparam_map = new HashMap (direct_hash, direct_equal); - var carg_map = new HashMap (direct_hash, direct_equal); - - var vblock = new CCodeBlock (); - - var vcall = new CCodeFunctionCall (new CCodeIdentifier (m.get_real_cname ())); - vcall.add_argument (new CCodeIdentifier (current_class.get_type_id ())); - - generate_cparameters (m, creturn_type, in_gtypeinstance_creation_method, cparam_map, vfunc, null, carg_map, vcall); - CCodeStatement cstmt = new CCodeReturnStatement (vcall); - cstmt.line = vfunc.line; - vblock.add_statement (cstmt); - - if (visible) { - header_type_member_declaration.append (vfunc.copy ()); - } else { - vfunc.modifiers |= CCodeModifiers.STATIC; - source_type_member_declaration.append (vfunc.copy ()); - } - - vfunc.block = vblock; - - source_type_member_definition.append (vfunc); - } - - if (current_class != null && current_class.is_subtype_of (gobject_type) - && (((CreationMethod) m).n_construction_params > 0 || 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")))); - var cunsetcall = new CCodeFunctionCall (new CCodeIdentifier ("g_value_unset")); - cunsetcall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeMemberAccess.pointer (new CCodeIdentifier ("__params_it"), "value"))); - cdofreeparam.add_statement (new CCodeExpressionStatement (cunsetcall)); - function.block.add_statement (new CCodeWhileStatement (ccond, cdofreeparam)); - - var cfreeparams = new CCodeFunctionCall (new CCodeIdentifier ("g_free")); - cfreeparams.add_argument (new CCodeIdentifier ("__params")); - function.block.add_statement (new CCodeExpressionStatement (cfreeparams)); - } - - if (current_type_symbol is Class) { - CCodeExpression cresult = new CCodeIdentifier ("self"); - if (get_custom_creturn_type (m) != null) { - cresult = new CCodeCastExpression (cresult, get_custom_creturn_type (m)); - } - - var creturn = new CCodeReturnStatement (); - creturn.return_expression = cresult; - function.block.add_statement (creturn); - } - } - if (m.entry_point) { // m is possible entry point, add appropriate startup code var cmain = new CCodeFunction ("main", "int"); @@ -880,6 +823,8 @@ public class Vala.CCodeMethodModule : CCodeStructModule { } public override void visit_creation_method (CreationMethod m) { + bool visible = !m.is_internal_symbol (); + if (m.body != null && current_type_symbol is Class && current_class.is_subtype_of (gobject_type)) { int n_params = 0; foreach (Statement stmt in m.body.get_statements ()) { @@ -895,5 +840,67 @@ public class Vala.CCodeMethodModule : CCodeStructModule { } head.visit_method (m); + + DataType creturn_type; + if (current_class != null) { + creturn_type = new ObjectType (current_class); + } else { + creturn_type = new VoidType (); + } + + if (current_class != null && !current_class.is_compact) { + var vfunc = new CCodeFunction (m.get_cname (), creturn_type.get_cname ()); + vfunc.line = function.line; + + var cparam_map = new HashMap (direct_hash, direct_equal); + var carg_map = new HashMap (direct_hash, direct_equal); + + var vblock = new CCodeBlock (); + + var vcall = new CCodeFunctionCall (new CCodeIdentifier (m.get_real_cname ())); + vcall.add_argument (new CCodeIdentifier (current_class.get_type_id ())); + + generate_cparameters (m, creturn_type, true, cparam_map, vfunc, null, carg_map, vcall); + CCodeStatement cstmt = new CCodeReturnStatement (vcall); + cstmt.line = vfunc.line; + vblock.add_statement (cstmt); + + if (visible) { + header_type_member_declaration.append (vfunc.copy ()); + } else { + vfunc.modifiers |= CCodeModifiers.STATIC; + source_type_member_declaration.append (vfunc.copy ()); + } + + vfunc.block = vblock; + + source_type_member_definition.append (vfunc); + } + + if (current_class != null && current_class.is_subtype_of (gobject_type) + && (((CreationMethod) m).n_construction_params > 0 || 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")))); + var cunsetcall = new CCodeFunctionCall (new CCodeIdentifier ("g_value_unset")); + cunsetcall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeMemberAccess.pointer (new CCodeIdentifier ("__params_it"), "value"))); + cdofreeparam.add_statement (new CCodeExpressionStatement (cunsetcall)); + function.block.add_statement (new CCodeWhileStatement (ccond, cdofreeparam)); + + var cfreeparams = new CCodeFunctionCall (new CCodeIdentifier ("g_free")); + cfreeparams.add_argument (new CCodeIdentifier ("__params")); + function.block.add_statement (new CCodeExpressionStatement (cfreeparams)); + } + + if (current_type_symbol is Class) { + CCodeExpression cresult = new CCodeIdentifier ("self"); + if (get_custom_creturn_type (m) != null) { + cresult = new CCodeCastExpression (cresult, get_custom_creturn_type (m)); + } + + var creturn = new CCodeReturnStatement (); + creturn.return_expression = cresult; + function.block.add_statement (creturn); + } } }