1 /* valaccodebinding.vala
3 * Copyright (C) 2007-2008 Jürg Billeter
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 * Jürg Billeter <j@bitron.ch>
26 * The link between a source code node and generated code.
28 public abstract class Vala
.CCodeBinding
: CodeBinding
{
30 * The C Code generator.
32 public CCodeGenerator codegen
{ get; set; }
35 * Generate code for this source code node.
37 public virtual void emit () {
40 public CCodeIdentifier
get_value_setter_function (DataType type_reference
) {
41 if (type_reference
.data_type
!= null) {
42 return new
CCodeIdentifier (type_reference
.data_type
.get_set_value_function ());
44 return new
CCodeIdentifier ("g_value_set_pointer");
48 public CCodeExpression
get_construct_property_assignment (CCodeConstant canonical_cconstant
, DataType property_type
, CCodeExpression value
) {
49 // this property is used as a construction parameter
50 var cpointer
= new
CCodeIdentifier ("__params_it");
52 var ccomma
= new
CCodeCommaExpression ();
53 // set name in array for current parameter
54 var cnamemember
= new CCodeMemberAccess
.pointer (cpointer
, "name");
55 var cnameassign
= new
CCodeAssignment (cnamemember
, canonical_cconstant
);
56 ccomma
.append_expression (cnameassign
);
58 var gvaluearg
= new
CCodeUnaryExpression (CCodeUnaryOperator
.ADDRESS_OF
, new CCodeMemberAccess
.pointer (cpointer
, "value"));
60 // initialize GValue in array for current parameter
61 var cvalueinit
= new
CCodeFunctionCall (new
CCodeIdentifier ("g_value_init"));
62 cvalueinit
.add_argument (gvaluearg
);
63 cvalueinit
.add_argument (new
CCodeIdentifier (property_type
.get_type_id ()));
64 ccomma
.append_expression (cvalueinit
);
66 // set GValue for current parameter
67 var cvalueset
= new
CCodeFunctionCall (get_value_setter_function (property_type
));
68 cvalueset
.add_argument (gvaluearg
);
69 cvalueset
.add_argument (value
);
70 ccomma
.append_expression (cvalueset
);
72 // move pointer to next parameter in array
73 ccomma
.append_expression (new
CCodeUnaryExpression (CCodeUnaryOperator
.POSTFIX_INCREMENT
, cpointer
));
78 public CCodeBinding?
code_binding (CodeNode node
) {
79 return (CCodeBinding
) node
.get_code_binding (codegen
);
82 public CCodeMethodBinding
method_binding (Method node
) {
83 return (CCodeMethodBinding
) node
.get_code_binding (codegen
);
86 public CCodeArrayCreationExpressionBinding
array_creation_expression_binding (ArrayCreationExpression node
) {
87 return (CCodeArrayCreationExpressionBinding
) node
.get_code_binding (codegen
);
90 public CCodeElementAccessBinding
element_access_binding (ElementAccess node
) {
91 return (CCodeElementAccessBinding
) node
.get_code_binding (codegen
);
94 public CCodeAssignmentBinding
assignment_binding (Assignment node
) {
95 return (CCodeAssignmentBinding
) node
.get_code_binding (codegen
);