public override bool generate_enum_declaration(ValaEnum en, CCodeFile decl_space) { if (base.generate_enum_declaration(en, decl_space)) { if (is_string_marshalled_enum(en)) { decl_space.add_function_declaration(generate_enum_from_string_function_declaration(en)); decl_space.add_function_declaration(generate_enum_to_string_function_declaration(en)); } return(true); } return(false); }
public override void generate_error_domain_declaration(ErrorDomain edomain, CCodeFile decl_space) { if (add_symbol_declaration(decl_space, edomain, get_ccode_name(edomain))) { return; } var cenum = new CCodeEnum(get_ccode_name(edomain)); foreach (ErrorCode ecode in edomain.get_codes()) { if (ecode.value == null) { cenum.add_value(new CCodeEnumValue(get_ccode_name(ecode))); } else { ecode.value.emit(this); cenum.add_value(new CCodeEnumValue(get_ccode_name(ecode), get_cvalue(ecode.value))); } } decl_space.add_type_definition(cenum); string quark_fun_name = get_ccode_lower_case_prefix(edomain) + "quark"; var error_domain_define = new CCodeMacroReplacement(get_ccode_upper_case_name(edomain), quark_fun_name + " ()"); decl_space.add_type_definition(error_domain_define); var cquark_fun = new CCodeFunction(quark_fun_name, get_ccode_name(gquark_type.data_type)); decl_space.add_function_declaration(cquark_fun); }
public override void generate_struct_declaration(Struct st, CCodeFile decl_space) { if (add_symbol_declaration(decl_space, st, get_ccode_name(st))) { return; } if (st.is_boolean_type() || st.is_integer_type() || st.is_floating_type()) { if (st.base_struct != null) { generate_struct_declaration(st.base_struct, decl_space); decl_space.add_type_declaration(new CCodeTypeDefinition(get_ccode_name(st.base_struct), new CCodeVariableDeclarator(get_ccode_name(st)))); } else { string typename = null; if (st.is_boolean_type()) { // typedef for boolean types decl_space.add_include("stdbool.h"); typename = "bool"; } else if (st.is_integer_type()) { // typedef for integral types decl_space.add_include("stdint.h"); typename = "%sint%d_t".printf(st.signed ? "" : "u", st.width); } else if (st.is_floating_type()) { // typedef for floating types typename = (st.width == 64 ? "double" : "float"); } decl_space.add_type_declaration(new CCodeTypeDefinition(typename, new CCodeVariableDeclarator(get_ccode_name(st)))); } return; } if (get_ccode_has_type_id(st)) { decl_space.add_include("glib-object.h"); decl_space.add_type_declaration(new CCodeNewline()); var macro = "(%s_get_type ())".printf(get_ccode_lower_case_name(st, null)); decl_space.add_type_declaration(new CCodeMacroReplacement(get_ccode_type_id(st), macro)); var type_fun = new StructRegisterFunction(st, context); type_fun.init_from_type(false, true); decl_space.add_type_member_declaration(type_fun.get_declaration()); } var instance_struct = new CCodeStruct("_%s".printf(get_ccode_name(st))); instance_struct.modifiers |= (st.version.deprecated ? CCodeModifiers.DEPRECATED : 0); foreach (Field f in st.get_fields()) { if (f.binding == MemberBinding.INSTANCE) { generate_type_declaration(f.variable_type, decl_space); CCodeModifiers modifiers = (f.is_volatile ? CCodeModifiers.VOLATILE : 0) | (f.version.deprecated ? CCodeModifiers.DEPRECATED : 0); instance_struct.add_field(get_ccode_name(f.variable_type), get_ccode_name(f), modifiers, get_ccode_declarator_suffix(f.variable_type)); if (f.variable_type is ArrayType && get_ccode_array_length(f)) { // create fields to store array dimensions var array_type = (ArrayType)f.variable_type; if (!array_type.fixed_length) { var len_type = int_type.copy(); for (int dim = 1; dim <= array_type.rank; dim++) { string length_cname; if (get_ccode_array_length_name(f) != null) { length_cname = get_ccode_array_length_name(f); } else { length_cname = get_array_length_cname(get_ccode_name(f), dim); } instance_struct.add_field(get_ccode_name(len_type), length_cname); } if (array_type.rank == 1 && f.is_internal_symbol()) { instance_struct.add_field(get_ccode_name(len_type), get_array_size_cname(get_ccode_name(f))); } } } else if (f.variable_type is DelegateType) { var delegate_type = (DelegateType)f.variable_type; if (delegate_type.delegate_symbol.has_target) { // create field to store delegate target instance_struct.add_field("gpointer", get_ccode_delegate_target_name(f)); if (delegate_type.is_disposable()) { instance_struct.add_field("GDestroyNotify", get_delegate_target_destroy_notify_cname(get_ccode_name(f))); } } } } } if (st.base_struct == null) { decl_space.add_type_declaration(new CCodeTypeDefinition("struct _%s".printf(get_ccode_name(st)), new CCodeVariableDeclarator(get_ccode_name(st)))); decl_space.add_type_definition(instance_struct); } else { decl_space.add_type_declaration(new CCodeTypeDefinition(get_ccode_name(st.base_struct), new CCodeVariableDeclarator(get_ccode_name(st)))); } var function = new CCodeFunction(get_ccode_dup_function(st), get_ccode_name(st) + "*"); if (st.is_private_symbol()) { function.modifiers = CCodeModifiers.STATIC; } else if (context.hide_internal && st.is_internal_symbol()) { function.modifiers = CCodeModifiers.INTERNAL; } function.add_parameter(new CCodeParameter("self", "const " + get_ccode_name(st) + "*")); decl_space.add_function_declaration(function); function = new CCodeFunction(get_ccode_free_function(st), "void"); if (st.is_private_symbol()) { function.modifiers = CCodeModifiers.STATIC; } else if (context.hide_internal && st.is_internal_symbol()) { function.modifiers = CCodeModifiers.INTERNAL; } function.add_parameter(new CCodeParameter("self", get_ccode_name(st) + "*")); decl_space.add_function_declaration(function); if (st.is_disposable()) { function = new CCodeFunction(get_ccode_copy_function(st), "void"); if (st.is_private_symbol()) { function.modifiers = CCodeModifiers.STATIC; } else if (context.hide_internal && st.is_internal_symbol()) { function.modifiers = CCodeModifiers.INTERNAL; } function.add_parameter(new CCodeParameter("self", "const " + get_ccode_name(st) + "*")); function.add_parameter(new CCodeParameter("dest", get_ccode_name(st) + "*")); decl_space.add_function_declaration(function); function = new CCodeFunction(get_ccode_destroy_function(st), "void"); if (st.is_private_symbol()) { function.modifiers = CCodeModifiers.STATIC; } else if (context.hide_internal && st.is_internal_symbol()) { function.modifiers = CCodeModifiers.INTERNAL; } function.add_parameter(new CCodeParameter("self", get_ccode_name(st) + "*")); decl_space.add_function_declaration(function); } }
public override void generate_method_declaration(Method m, CCodeFile decl_space) { if (m.coroutine) { if (add_symbol_declaration(decl_space, m, get_ccode_name(m))) { return; } var cl = m.parent_symbol as Class; var asyncfunc = new CCodeFunction(get_ccode_name(m), "void"); var cparam_map = new Dictionary <int, CCodeParameter>(); var carg_map = new Dictionary <int, CCodeExpression>(); if (m.is_private_symbol()) { asyncfunc.modifiers |= CCodeModifiers.STATIC; } else if (context.hide_internal && m.is_internal_symbol()) { asyncfunc.modifiers |= CCodeModifiers.INTERNAL; } // do not generate _new functions for creation methods of abstract classes if (!(m is CreationMethod && cl != null && cl.is_abstract)) { generate_cparameters(m, decl_space, cparam_map, asyncfunc, null, carg_map, new CCodeFunctionCall(new CCodeIdentifier("fake")), 1); decl_space.add_function_declaration(asyncfunc); } var finishfunc = new CCodeFunction(get_ccode_finish_name(m)); cparam_map = new Dictionary <int, CCodeParameter>(); carg_map = new Dictionary <int, CCodeExpression>(); if (m.is_private_symbol()) { finishfunc.modifiers |= CCodeModifiers.STATIC; } else if (context.hide_internal && m.is_internal_symbol()) { finishfunc.modifiers |= CCodeModifiers.INTERNAL; } // do not generate _new functions for creation methods of abstract classes if (!(m is CreationMethod && cl != null && cl.is_abstract)) { generate_cparameters(m, decl_space, cparam_map, finishfunc, null, carg_map, new CCodeFunctionCall(new CCodeIdentifier("fake")), 2); decl_space.add_function_declaration(finishfunc); } if (m is CreationMethod && cl != null) { // _construct function var function = new CCodeFunction(get_ccode_real_name(m)); if (m.is_private_symbol()) { function.modifiers |= CCodeModifiers.STATIC; } else if (context.hide_internal && m.is_internal_symbol()) { function.modifiers |= CCodeModifiers.INTERNAL; } cparam_map = new Dictionary <int, CCodeParameter>(); generate_cparameters(m, decl_space, cparam_map, function, null, null, null, 1); decl_space.add_function_declaration(function); function = new CCodeFunction(get_ccode_finish_real_name(m)); if (m.is_private_symbol()) { function.modifiers |= CCodeModifiers.STATIC; } else if (context.hide_internal && m.is_internal_symbol()) { function.modifiers |= CCodeModifiers.INTERNAL; } cparam_map = new Dictionary <int, CCodeParameter>(); generate_cparameters(m, decl_space, cparam_map, function, null, null, null, 2); decl_space.add_function_declaration(function); } } else { base.generate_method_declaration(m, decl_space); } }