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 visit_error_domain(ErrorDomain edomain) { var edomain_dbus_name = get_dbus_name(edomain); if (edomain_dbus_name == null) { base.visit_error_domain(edomain); return; } cfile.add_include("gio/gio.h"); generate_error_domain_declaration(edomain, cfile); if (!edomain.is_internal_symbol()) { generate_error_domain_declaration(edomain, header_file); } if (!edomain.is_private_symbol()) { generate_error_domain_declaration(edomain, internal_header_file); } var error_entries = new CCodeInitializerList(); foreach (ErrorCode ecode in edomain.get_codes()) { var ecode_dbus_name = get_dbus_name(ecode); if (ecode_dbus_name == null) { ecode_dbus_name = Symbol.lower_case_to_camel_case(ecode.name.ToLower()); } var error_entry = new CCodeInitializerList(); error_entry.append(new CCodeIdentifier(get_ccode_name(ecode))); error_entry.append(new CCodeConstant("\"%s.%s\"".printf(edomain_dbus_name, ecode_dbus_name))); error_entries.append(error_entry); } var cdecl = new CCodeDeclaration("const GDBusErrorEntry"); cdecl.add_declarator(new CCodeVariableDeclarator(get_ccode_lower_case_name(edomain) + "_entries[]", error_entries)); cdecl.modifiers = CCodeModifiers.STATIC; cfile.add_constant_declaration(cdecl); string quark_fun_name = get_ccode_lower_case_prefix(edomain) + "quark"; var cquark_fun = new CCodeFunction(quark_fun_name, get_ccode_name(gquark_type.data_type)); push_function(cquark_fun); string quark_name = "%squark_volatile".printf(get_ccode_lower_case_prefix(edomain)); ccode.add_declaration("gsize", new CCodeVariableDeclarator(quark_name, new CCodeConstant("0")), CCodeModifiers.STATIC | CCodeModifiers.VOLATILE); var register_call = new CCodeFunctionCall(new CCodeIdentifier("g_dbus_error_register_error_domain")); register_call.add_argument(new CCodeConstant("\"" + CCodeBaseModule.get_quark_name(edomain) + "\"")); register_call.add_argument(new CCodeUnaryExpression(CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier(quark_name))); register_call.add_argument(new CCodeIdentifier(get_ccode_lower_case_name(edomain) + "_entries")); var nentries = new CCodeFunctionCall(new CCodeIdentifier("G_N_ELEMENTS")); nentries.add_argument(new CCodeIdentifier(get_ccode_lower_case_name(edomain) + "_entries")); register_call.add_argument(nentries); ccode.add_expression(register_call); ccode.add_return(new CCodeCastExpression(new CCodeIdentifier(quark_name), "GQuark")); pop_function(); cfile.add_function(cquark_fun); }