tests: Add "while (false)" test to increase coverage
[vala-gnome.git] / codegen / valainterfaceregisterfunction.vala
blob0b900ea43479e7fb2950dfe1feca20c5b009a2c3
1 /* valainterfaceregisterfunction.vala
3 * Copyright (C) 2006-2011 Jürg Billeter
4 * Copyright (C) 2006-2007 Raffaele Sandrini
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 * Author:
21 * Jürg Billeter <j@bitron.ch>
22 * Raffaele Sandrini <raffaele@sandrini.ch>
25 using GLib;
27 /**
28 * C function to register an interface at runtime.
30 public class Vala.InterfaceRegisterFunction : TypeRegisterFunction {
31 /**
32 * Specifies the interface to be registered.
34 public weak Interface interface_reference { get; set; }
36 public InterfaceRegisterFunction (Interface iface, CodeContext context) {
37 interface_reference = iface;
38 this.context = context;
41 public override TypeSymbol get_type_declaration () {
42 return interface_reference;
45 public override string get_type_struct_name () {
46 return CCodeBaseModule.get_ccode_type_name (interface_reference);
49 public override string get_base_init_func_name () {
50 return "%s_base_init".printf (CCodeBaseModule.get_ccode_lower_case_name (interface_reference));
53 public override string get_class_finalize_func_name () {
54 return "NULL";
57 public override string get_base_finalize_func_name () {
58 return "NULL";
61 public override string get_class_init_func_name () {
62 return "NULL";
65 public override string get_instance_struct_size () {
66 return "0";
69 public override string get_instance_init_func_name () {
70 return "NULL";
73 public override string get_parent_type_name () {
74 return "G_TYPE_INTERFACE";
77 public override SymbolAccessibility get_accessibility () {
78 return interface_reference.access;
81 public override void get_type_interface_init_statements (CCodeBlock block, bool plugin) {
82 /* register all prerequisites */
83 foreach (DataType prereq_ref in interface_reference.get_prerequisites ()) {
84 var prereq = prereq_ref.data_type;
86 var func = new CCodeFunctionCall (new CCodeIdentifier ("g_type_interface_add_prerequisite"));
87 func.add_argument (new CCodeIdentifier ("%s_type_id".printf (CCodeBaseModule.get_ccode_lower_case_name (interface_reference))));
88 func.add_argument (new CCodeIdentifier (CCodeBaseModule.get_ccode_type_id (prereq)));
90 block.add_statement (new CCodeExpressionStatement (func));
93 ((CCodeBaseModule) context.codegen).register_dbus_info (block, interface_reference);