valaccodemodule.vala 11.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
/* valaccodemodule.vala
 *
 * Copyright (C) 2008  Jürg Billeter
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.

 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.

 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
 *
 * Author:
 * 	Jürg Billeter <j@bitron.ch>
 */

using Gee;

/**
 * Code visitor generating C Code.
 */
public abstract class Vala.CCodeModule {
29
	public weak CCodeGenerator codegen { get; private set; }
30
	
31 32 33 34 35 36 37 38 39 40 41 42 43
	public CCodeModule head {
		get { return _head; }
		private set {
			_head = value;
			// propagate head property to all modules
			if (next != null) {
				next.head = value;
			}
		}
	}

	weak CCodeModule _head;
	CCodeModule? next;
44

45 46
	public CCodeModule (CCodeGenerator codegen, CCodeModule? next) {
		this.codegen = codegen;
47
		this.next = next;
48
		this.head = this;
49 50 51
	}

	public virtual void emit (CodeContext context) {
52 53 54
		next.emit (context);
	}

55 56 57 58
	public virtual void visit_source_file (SourceFile source_file) {
		next.visit_source_file (source_file);
	}

59 60 61 62 63 64 65 66
	public virtual void visit_class (Class cl) {
		next.visit_class (cl);
	}

	public virtual void visit_interface (Interface iface) {
		next.visit_interface (iface);
	}

Jürg Billeter's avatar
Jürg Billeter committed
67 68 69 70
	public virtual void visit_struct (Struct st) {
		next.visit_struct (st);
	}

71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
	public virtual void visit_enum (Enum en) {
		next.visit_enum (en);
	}

	public virtual void visit_enum_value (EnumValue ev) {
		next.visit_enum_value (ev);
	}

	public virtual void visit_error_domain (ErrorDomain edomain) {
		next.visit_error_domain (edomain);
	}

	public virtual void visit_error_code (ErrorCode ecode) {
		next.visit_error_code (ecode);
	}

	public virtual void visit_delegate (Delegate d) {
		next.visit_delegate (d);
	}
	
	public virtual void visit_member (Member m) {
		next.visit_member (m);
	}

	public virtual void visit_constant (Constant c) {
		next.visit_constant (c);
	}

	public virtual void visit_field (Field f) {
		next.visit_field (f);
	}

103 104 105 106
	public virtual void visit_method (Method m) {
		next.visit_method (m);
	}

107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
	public virtual void visit_creation_method (CreationMethod m) {
		next.visit_creation_method (m);
	}

	public virtual void visit_formal_parameter (FormalParameter p) {
		next.visit_formal_parameter (p);
	}

	public virtual void visit_property (Property prop) {
		next.visit_property (prop);
	}

	public virtual void visit_property_accessor (PropertyAccessor acc) {
		next.visit_property_accessor (acc);
	}

Jürg Billeter's avatar
Jürg Billeter committed
123 124 125 126
	public virtual void visit_signal (Signal sig) {
		next.visit_signal (sig);
	}

127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
	public virtual void visit_constructor (Constructor c) {
		next.visit_constructor (c);
	}

	public virtual void visit_destructor (Destructor d) {
		next.visit_destructor (d);
	}

	public virtual void visit_block (Block b) {
		next.visit_block (b);
	}

	public virtual void visit_empty_statement (EmptyStatement stmt) {
		next.visit_empty_statement (stmt);
	}

	public virtual void visit_declaration_statement (DeclarationStatement stmt) {
		next.visit_declaration_statement (stmt);
	}

	public virtual void visit_local_variable (LocalVariable local) {
		next.visit_local_variable (local);
	}

	public virtual void visit_initializer_list (InitializerList list) {
		next.visit_initializer_list (list);
	}

	public virtual void visit_end_full_expression (Expression expr) {
		next.visit_end_full_expression (expr);
	}
	
	public virtual void visit_expression_statement (ExpressionStatement stmt) {
		next.visit_expression_statement (stmt);
	}

	public virtual void visit_if_statement (IfStatement stmt) {
		next.visit_if_statement (stmt);
	}

	public virtual void visit_switch_statement (SwitchStatement stmt) {
		next.visit_switch_statement (stmt);
	}

	public virtual void visit_switch_section (SwitchSection section) {
		next.visit_switch_section (section);
	}

175 176 177 178
	public virtual void visit_switch_label (SwitchLabel label) {
		next.visit_switch_label (label);
	}

179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
	public virtual void visit_while_statement (WhileStatement stmt) {
		next.visit_while_statement (stmt);
	}

	public virtual void visit_do_statement (DoStatement stmt) {
		next.visit_do_statement (stmt);
	}

	public virtual void visit_for_statement (ForStatement stmt) {
		next.visit_for_statement (stmt);
	}

	public virtual void visit_foreach_statement (ForeachStatement stmt) {
		next.visit_foreach_statement (stmt);
	}

	public virtual void visit_break_statement (BreakStatement stmt) {
		next.visit_break_statement (stmt);
	}

	public virtual void visit_continue_statement (ContinueStatement stmt) {
		next.visit_continue_statement (stmt);
	}

	public virtual void visit_return_statement (ReturnStatement stmt) {
		next.visit_return_statement (stmt);
	}

	public virtual void visit_yield_statement (YieldStatement stmt) {
		next.visit_yield_statement (stmt);
	}

	public virtual void visit_throw_statement (ThrowStatement stmt) {
		next.visit_throw_statement (stmt);
	}

	public virtual void visit_try_statement (TryStatement stmt) {
		next.visit_try_statement (stmt);
	}

	public virtual void visit_catch_clause (CatchClause clause) {
		next.visit_catch_clause (clause);
	}

	public virtual void visit_lock_statement (LockStatement stmt) {
		next.visit_lock_statement (stmt);
	}

	public virtual void visit_delete_statement (DeleteStatement stmt) {
		next.visit_delete_statement (stmt);
	}

	public virtual void visit_expression (Expression expr) {
		next.visit_expression (expr);
	}

	public virtual void visit_array_creation_expression (ArrayCreationExpression expr) {
		next.visit_array_creation_expression (expr);
	}

	public virtual void visit_boolean_literal (BooleanLiteral expr) {
		next.visit_boolean_literal (expr);
	}

	public virtual void visit_character_literal (CharacterLiteral expr) {
		next.visit_character_literal (expr);
	}

	public virtual void visit_integer_literal (IntegerLiteral expr) {
		next.visit_integer_literal (expr);
	}

	public virtual void visit_real_literal (RealLiteral expr) {
		next.visit_real_literal (expr);
	}

	public virtual void visit_string_literal (StringLiteral expr) {
		next.visit_string_literal (expr);
	}

	public virtual void visit_null_literal (NullLiteral expr) {
		next.visit_null_literal (expr);
	}

	public virtual void visit_parenthesized_expression (ParenthesizedExpression expr) {
		next.visit_parenthesized_expression (expr);
265 266
	}

267 268 269 270
	public virtual void visit_member_access (MemberAccess expr) {
		next.visit_member_access (expr);
	}

271 272
	public virtual void visit_method_call (MethodCall expr) {
		next.visit_method_call (expr);
273 274
	}
	
275 276 277 278
	public virtual void visit_element_access (ElementAccess expr) {
		next.visit_element_access (expr);
	}

279 280
	public virtual void visit_base_access (BaseAccess expr) {
		next.visit_base_access (expr);
281 282
	}

283 284
	public virtual void visit_postfix_expression (PostfixExpression expr) {
		next.visit_postfix_expression (expr);
285 286
	}

287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332
	public virtual void visit_object_creation_expression (ObjectCreationExpression expr) {
		next.visit_object_creation_expression (expr);
	}

	public virtual void visit_sizeof_expression (SizeofExpression expr) {
		next.visit_sizeof_expression (expr);
	}

	public virtual void visit_typeof_expression (TypeofExpression expr) {
		next.visit_typeof_expression (expr);
	}

	public virtual void visit_unary_expression (UnaryExpression expr) {
		next.visit_unary_expression (expr);
	}

	public virtual void visit_cast_expression (CastExpression expr) {
		next.visit_cast_expression (expr);
	}
	
	public virtual void visit_pointer_indirection (PointerIndirection expr) {
		next.visit_pointer_indirection (expr);
	}

	public virtual void visit_addressof_expression (AddressofExpression expr) {
		next.visit_addressof_expression (expr);
	}

	public virtual void visit_reference_transfer_expression (ReferenceTransferExpression expr) {
		next.visit_reference_transfer_expression (expr);
	}

	public virtual void visit_binary_expression (BinaryExpression expr) {
		next.visit_binary_expression (expr);
	}

	public virtual void visit_type_check (TypeCheck expr) {
		next.visit_type_check (expr);
	}

	public virtual void visit_lambda_expression (LambdaExpression l) {
		next.visit_lambda_expression (l);
	}

	public virtual void visit_assignment (Assignment a) {
		next.visit_assignment (a);
Jürg Billeter's avatar
Jürg Billeter committed
333 334
	}

335 336
	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) {
		next.generate_cparameters (m, creturn_type, in_gtypeinstance_creation_method, cparam_map, func, vdeclarator, carg_map, vcall, direction);
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356
	}

	public virtual string? get_custom_creturn_type (Method m) {
		return next.get_custom_creturn_type (m);
	}

	public virtual void generate_dynamic_method_wrapper (DynamicMethod method) {
		next.generate_dynamic_method_wrapper (method);
	}

	public virtual bool method_has_wrapper (Method method) {
		return next.method_has_wrapper (method);
	}

	public virtual CCodeIdentifier get_value_setter_function (DataType type_reference) {
		return next.get_value_setter_function (type_reference);
	}

	public virtual CCodeExpression get_construct_property_assignment (CCodeConstant canonical_cconstant, DataType property_type, CCodeExpression value) {
		return next.get_construct_property_assignment (canonical_cconstant, property_type, value);
357
	}
Jürg Billeter's avatar
Jürg Billeter committed
358 359 360 361 362 363 364 365

	public virtual CCodeFunctionCall get_param_spec (Property prop) {
		return next.get_param_spec (prop);
	}

	public virtual CCodeFunctionCall get_signal_creation (Signal sig, TypeSymbol type) {
		return next.get_signal_creation (sig, type);
	}
366 367 368 369

	public virtual CCodeFragment register_dbus_info (ObjectTypeSymbol bindable) {
		return next.register_dbus_info (bindable);
	}
370 371 372 373 374 375 376 377

	public virtual string get_dynamic_property_getter_cname (DynamicProperty node) {
		return next.get_dynamic_property_getter_cname (node);
	}

	public virtual string get_dynamic_property_setter_cname (DynamicProperty node) {
		return next.get_dynamic_property_setter_cname (node);
	}
378 379 380 381 382 383 384 385 386 387 388 389

	public virtual string get_dynamic_signal_cname (DynamicSignal node) {
		return next.get_dynamic_signal_cname (node);
	}

	public virtual string get_dynamic_signal_connect_wrapper_name (DynamicSignal node) {
		return next.get_dynamic_signal_connect_wrapper_name (node);
	}

	public virtual string get_dynamic_signal_disconnect_wrapper_name (DynamicSignal node) {
		return next.get_dynamic_signal_disconnect_wrapper_name (node);
	}
Jürg Billeter's avatar
Jürg Billeter committed
390 391 392 393 394 395 396 397

	public virtual void generate_marshaller (Gee.List<FormalParameter> params, DataType return_type, bool dbus = false) {
		next.generate_marshaller (params, return_type, dbus);
	}
	
	public virtual string get_marshaller_function (Gee.List<FormalParameter> params, DataType return_type, string? prefix = null, bool dbus = false) {
		return next.get_marshaller_function (params, return_type, prefix, dbus);
	}
398 399 400 401 402 403 404 405

	public virtual string get_array_length_cname (string array_cname, int dim) {
		return next.get_array_length_cname (array_cname, dim);
	}

	public virtual CCodeExpression get_array_length_cexpression (Expression array_expr, int dim = -1) {
		return next.get_array_length_cexpression (array_expr, dim);
	}
Jürg Billeter's avatar
Jürg Billeter committed
406 407 408 409

	public virtual void add_simple_check (CodeNode node, CCodeFragment cfrag) {
		next.add_simple_check (node, cfrag);
	}
410
}