1 /* valaccodemodule.vala
3 * Copyright (C) 2008-2009 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 * Code visitor generating C Code.
28 public abstract class Vala
.CCodeModule
{
29 public weak CCodeGenerator codegen
{ get; private set; }
31 public CCodeModule head
{
35 // propagate head property to all modules
42 weak CCodeModule _head
;
45 public CCodeModule (CCodeGenerator codegen
, CCodeModule? next
) {
46 this
.codegen
= codegen
;
51 public virtual void emit (CodeContext context
) {
55 public virtual void visit_source_file (SourceFile source_file
) {
56 next
.visit_source_file (source_file
);
59 public virtual void visit_class (Class cl
) {
60 next
.visit_class (cl
);
63 public virtual void visit_interface (Interface iface
) {
64 next
.visit_interface (iface
);
67 public virtual void visit_struct (Struct st
) {
68 next
.visit_struct (st
);
71 public virtual void visit_enum (Enum en
) {
75 public virtual void visit_enum_value (EnumValue ev
) {
76 next
.visit_enum_value (ev
);
79 public virtual void visit_error_domain (ErrorDomain edomain
) {
80 next
.visit_error_domain (edomain
);
83 public virtual void visit_error_code (ErrorCode ecode
) {
84 next
.visit_error_code (ecode
);
87 public virtual void visit_delegate (Delegate d
) {
88 next
.visit_delegate (d
);
91 public virtual void visit_member (Member m
) {
92 next
.visit_member (m
);
95 public virtual void visit_constant (Constant c
) {
96 next
.visit_constant (c
);
99 public virtual void visit_field (Field f
) {
100 next
.visit_field (f
);
103 public virtual void visit_method (Method m
) {
104 next
.visit_method (m
);
107 public virtual void visit_creation_method (CreationMethod m
) {
108 next
.visit_creation_method (m
);
111 public virtual void visit_formal_parameter (FormalParameter p
) {
112 next
.visit_formal_parameter (p
);
115 public virtual void visit_property (Property prop
) {
116 next
.visit_property (prop
);
119 public virtual void visit_property_accessor (PropertyAccessor acc
) {
120 next
.visit_property_accessor (acc
);
123 public virtual void visit_signal (Signal sig
) {
124 next
.visit_signal (sig
);
127 public virtual void visit_constructor (Constructor c
) {
128 next
.visit_constructor (c
);
131 public virtual void visit_destructor (Destructor d
) {
132 next
.visit_destructor (d
);
135 public virtual void visit_block (Block b
) {
136 next
.visit_block (b
);
139 public virtual void visit_empty_statement (EmptyStatement stmt
) {
140 next
.visit_empty_statement (stmt
);
143 public virtual void visit_declaration_statement (DeclarationStatement stmt
) {
144 next
.visit_declaration_statement (stmt
);
147 public virtual void visit_local_variable (LocalVariable local
) {
148 next
.visit_local_variable (local
);
151 public virtual void visit_initializer_list (InitializerList list
) {
152 next
.visit_initializer_list (list
);
155 public virtual void visit_end_full_expression (Expression expr
) {
156 next
.visit_end_full_expression (expr
);
159 public virtual void visit_expression_statement (ExpressionStatement stmt
) {
160 next
.visit_expression_statement (stmt
);
163 public virtual void visit_if_statement (IfStatement stmt
) {
164 next
.visit_if_statement (stmt
);
167 public virtual void visit_switch_statement (SwitchStatement stmt
) {
168 next
.visit_switch_statement (stmt
);
171 public virtual void visit_switch_section (SwitchSection section
) {
172 next
.visit_switch_section (section
);
175 public virtual void visit_switch_label (SwitchLabel label
) {
176 next
.visit_switch_label (label
);
179 public virtual void visit_while_statement (WhileStatement stmt
) {
180 next
.visit_while_statement (stmt
);
183 public virtual void visit_do_statement (DoStatement stmt
) {
184 next
.visit_do_statement (stmt
);
187 public virtual void visit_for_statement (ForStatement stmt
) {
188 next
.visit_for_statement (stmt
);
191 public virtual void visit_foreach_statement (ForeachStatement stmt
) {
192 next
.visit_foreach_statement (stmt
);
195 public virtual void visit_break_statement (BreakStatement stmt
) {
196 next
.visit_break_statement (stmt
);
199 public virtual void visit_continue_statement (ContinueStatement stmt
) {
200 next
.visit_continue_statement (stmt
);
203 public virtual void visit_return_statement (ReturnStatement stmt
) {
204 next
.visit_return_statement (stmt
);
207 public virtual void visit_yield_statement (YieldStatement stmt
) {
208 next
.visit_yield_statement (stmt
);
211 public virtual void visit_throw_statement (ThrowStatement stmt
) {
212 next
.visit_throw_statement (stmt
);
215 public virtual void visit_try_statement (TryStatement stmt
) {
216 next
.visit_try_statement (stmt
);
219 public virtual void visit_catch_clause (CatchClause clause
) {
220 next
.visit_catch_clause (clause
);
223 public virtual void visit_lock_statement (LockStatement stmt
) {
224 next
.visit_lock_statement (stmt
);
227 public virtual void visit_delete_statement (DeleteStatement stmt
) {
228 next
.visit_delete_statement (stmt
);
231 public virtual void visit_expression (Expression expr
) {
232 next
.visit_expression (expr
);
235 public virtual void visit_array_creation_expression (ArrayCreationExpression expr
) {
236 next
.visit_array_creation_expression (expr
);
239 public virtual void visit_boolean_literal (BooleanLiteral expr
) {
240 next
.visit_boolean_literal (expr
);
243 public virtual void visit_character_literal (CharacterLiteral expr
) {
244 next
.visit_character_literal (expr
);
247 public virtual void visit_integer_literal (IntegerLiteral expr
) {
248 next
.visit_integer_literal (expr
);
251 public virtual void visit_real_literal (RealLiteral expr
) {
252 next
.visit_real_literal (expr
);
255 public virtual void visit_string_literal (StringLiteral expr
) {
256 next
.visit_string_literal (expr
);
259 public virtual void visit_null_literal (NullLiteral expr
) {
260 next
.visit_null_literal (expr
);
263 public virtual void visit_parenthesized_expression (ParenthesizedExpression expr
) {
264 next
.visit_parenthesized_expression (expr
);
267 public virtual void visit_member_access (MemberAccess expr
) {
268 next
.visit_member_access (expr
);
271 public virtual void visit_method_call (MethodCall expr
) {
272 next
.visit_method_call (expr
);
275 public virtual void visit_element_access (ElementAccess expr
) {
276 next
.visit_element_access (expr
);
279 public virtual void visit_base_access (BaseAccess expr
) {
280 next
.visit_base_access (expr
);
283 public virtual void visit_postfix_expression (PostfixExpression expr
) {
284 next
.visit_postfix_expression (expr
);
287 public virtual void visit_object_creation_expression (ObjectCreationExpression expr
) {
288 next
.visit_object_creation_expression (expr
);
291 public virtual void visit_sizeof_expression (SizeofExpression expr
) {
292 next
.visit_sizeof_expression (expr
);
295 public virtual void visit_typeof_expression (TypeofExpression expr
) {
296 next
.visit_typeof_expression (expr
);
299 public virtual void visit_unary_expression (UnaryExpression expr
) {
300 next
.visit_unary_expression (expr
);
303 public virtual void visit_cast_expression (CastExpression expr
) {
304 next
.visit_cast_expression (expr
);
307 public virtual void visit_pointer_indirection (PointerIndirection expr
) {
308 next
.visit_pointer_indirection (expr
);
311 public virtual void visit_addressof_expression (AddressofExpression expr
) {
312 next
.visit_addressof_expression (expr
);
315 public virtual void visit_reference_transfer_expression (ReferenceTransferExpression expr
) {
316 next
.visit_reference_transfer_expression (expr
);
319 public virtual void visit_binary_expression (BinaryExpression expr
) {
320 next
.visit_binary_expression (expr
);
323 public virtual void visit_type_check (TypeCheck expr
) {
324 next
.visit_type_check (expr
);
327 public virtual void visit_lambda_expression (LambdaExpression l
) {
328 next
.visit_lambda_expression (l
);
331 public virtual void visit_assignment (Assignment a
) {
332 next
.visit_assignment (a
);
335 public virtual void generate_cparameters (Method m
, DataType creturn_type
, bool in_gtypeinstance_creation_method
, Map
<int,CCodeFormalParameter
> cparam_map
, CCodeFunction func
, CCodeFunctionDeclarator? vdeclarator
= null, Map
<int,CCodeExpression
>? carg_map
= null, CCodeFunctionCall? vcall
= null, int direction
= 3) {
336 next
.generate_cparameters (m
, creturn_type
, in_gtypeinstance_creation_method
, cparam_map
, func
, vdeclarator
, carg_map
, vcall
, direction
);
339 public virtual string?
get_custom_creturn_type (Method m
) {
340 return next
.get_custom_creturn_type (m
);
343 public virtual void generate_dynamic_method_wrapper (DynamicMethod method
) {
344 next
.generate_dynamic_method_wrapper (method
);
347 public virtual bool method_has_wrapper (Method method
) {
348 return next
.method_has_wrapper (method
);
351 public virtual CCodeIdentifier
get_value_setter_function (DataType type_reference
) {
352 return next
.get_value_setter_function (type_reference
);
355 public virtual CCodeExpression
get_construct_property_assignment (CCodeConstant canonical_cconstant
, DataType property_type
, CCodeExpression value
) {
356 return next
.get_construct_property_assignment (canonical_cconstant
, property_type
, value
);
359 public virtual CCodeFunctionCall
get_param_spec (Property prop
) {
360 return next
.get_param_spec (prop
);
363 public virtual CCodeFunctionCall
get_signal_creation (Signal sig
, TypeSymbol type
) {
364 return next
.get_signal_creation (sig
, type
);
367 public virtual CCodeFragment
register_dbus_info (ObjectTypeSymbol bindable
) {
368 return next
.register_dbus_info (bindable
);
371 public virtual string get_dynamic_property_getter_cname (DynamicProperty node
) {
372 return next
.get_dynamic_property_getter_cname (node
);
375 public virtual string get_dynamic_property_setter_cname (DynamicProperty node
) {
376 return next
.get_dynamic_property_setter_cname (node
);
379 public virtual string get_dynamic_signal_cname (DynamicSignal node
) {
380 return next
.get_dynamic_signal_cname (node
);
383 public virtual string get_dynamic_signal_connect_wrapper_name (DynamicSignal node
) {
384 return next
.get_dynamic_signal_connect_wrapper_name (node
);
387 public virtual string get_dynamic_signal_disconnect_wrapper_name (DynamicSignal node
) {
388 return next
.get_dynamic_signal_disconnect_wrapper_name (node
);
391 public virtual void generate_marshaller (Gee
.List
<FormalParameter
> params
, DataType return_type
, bool dbus
= false) {
392 next
.generate_marshaller (params
, return_type
, dbus
);
395 public virtual string get_marshaller_function (Gee
.List
<FormalParameter
> params
, DataType return_type
, string? prefix
= null, bool dbus
= false) {
396 return next
.get_marshaller_function (params
, return_type
, prefix
, dbus
);
399 public virtual string get_array_length_cname (string array_cname
, int dim
) {
400 return next
.get_array_length_cname (array_cname
, dim
);
403 public virtual CCodeExpression
get_array_length_cexpression (Expression array_expr
, int dim
= -1) {
404 return next
.get_array_length_cexpression (array_expr
, dim
);
407 public virtual string get_array_size_cname (string array_cname
) {
408 return next
.get_array_size_cname (array_cname
);
411 public virtual CCodeExpression
get_array_size_cexpression (Expression array_expr
) {
412 return next
.get_array_size_cexpression (array_expr
);
415 public virtual void add_simple_check (CodeNode node
, CCodeFragment cfrag
) {
416 next
.add_simple_check (node
, cfrag
);