public CCodeFunction generate_enum_to_string_function(ValaEnum en) { var to_string_name = "%s_to_string".printf(get_ccode_lower_case_name(en, null)); var to_string_func = new CCodeFunction(to_string_name, "const char*"); to_string_func.add_parameter(new CCodeParameter("value", get_ccode_name(en))); push_function(to_string_func); ccode.add_declaration("const char *", new CCodeVariableDeclarator("str")); ccode.open_switch(new CCodeIdentifier("value")); foreach (EnumValue enum_value in en.get_values()) { string dbus_value = get_dbus_value(enum_value, enum_value.name); ccode.add_case(new CCodeIdentifier(get_ccode_name(enum_value))); ccode.add_assignment(new CCodeIdentifier("str"), new CCodeConstant("\"%s\"".printf(dbus_value))); ccode.add_break(); } ccode.close(); ccode.add_return(new CCodeIdentifier("str")); pop_function(); return(to_string_func); }
public override void visit_enum(ValaEnum en) { current_scope = en.scope; en.accept_children(this); current_scope = current_scope.parent_scope; }
public CCodeFunction generate_enum_to_string_function_declaration(ValaEnum en) { var to_string_name = "%s_to_string".printf(get_ccode_lower_case_name(en, null)); var to_string_func = new CCodeFunction(to_string_name, "const char*"); to_string_func.add_parameter(new CCodeParameter("value", get_ccode_name(en))); return(to_string_func); }
public CCodeFunction generate_enum_from_string_function_declaration(ValaEnum en) { var from_string_name = "%s_from_string".printf(get_ccode_lower_case_name(en, null)); var from_string_func = new CCodeFunction(from_string_name, get_ccode_name(en)); from_string_func.add_parameter(new CCodeParameter("str", "const char*")); from_string_func.add_parameter(new CCodeParameter("error", "GError**")); return(from_string_func); }
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 CCodeFunction generate_enum_from_string_function(ValaEnum en) { var from_string_name = "%s_from_string".printf(get_ccode_lower_case_name(en, null)); var from_string_func = new CCodeFunction(from_string_name, get_ccode_name(en)); from_string_func.add_parameter(new CCodeParameter("str", "const char*")); from_string_func.add_parameter(new CCodeParameter("error", "GError**")); push_function(from_string_func); ccode.add_declaration(get_ccode_name(en), CCodeVariableDeclarator.zero("value", new CCodeConstant("0"))); bool firstif = true; foreach (EnumValue enum_value in en.get_values()) { string dbus_value = get_dbus_value(enum_value, enum_value.name); var string_comparison = new CCodeFunctionCall(new CCodeIdentifier("strcmp")); string_comparison.add_argument(new CCodeIdentifier("str")); string_comparison.add_argument(new CCodeConstant("\"%s\"".printf(dbus_value))); var cond = new CCodeBinaryExpression(CCodeBinaryOperator.EQUALITY, string_comparison, new CCodeConstant("0")); if (firstif) { ccode.open_if(cond); firstif = false; } else { ccode.else_if(cond); } ccode.add_assignment(new CCodeIdentifier("value"), new CCodeIdentifier(get_ccode_name(enum_value))); } ccode.add_else(); var set_error = new CCodeFunctionCall(new CCodeIdentifier("g_set_error")); set_error.add_argument(new CCodeIdentifier("error")); set_error.add_argument(new CCodeIdentifier("G_DBUS_ERROR")); set_error.add_argument(new CCodeIdentifier("G_DBUS_ERROR_INVALID_ARGS")); set_error.add_argument(new CCodeConstant("\"Invalid value for enum `%s'\"".printf(get_ccode_name(en)))); ccode.add_expression(set_error); ccode.close(); ccode.add_return(new CCodeIdentifier("value")); pop_function(); return(from_string_func); }
public override void visit_enum(ValaEnum en) { base.visit_enum(en); if (is_string_marshalled_enum(en)) { // strcmp cfile.add_include("string.h"); // for G_DBUS_ERROR cfile.add_include("gio/gio.h"); cfile.add_function(generate_enum_from_string_function(en)); cfile.add_function(generate_enum_to_string_function(en)); } }
/// <summary> /// Adds the specified enum to this namespace. /// /// <param name="en">an enum</param> /// </summary> public override void add_enum(ValaEnum en) { // namespaces do not support private memebers if (en.access == SymbolAccessibility.PRIVATE) { en.access = SymbolAccessibility.INTERNAL; } if (en.owner == null) { en.source_reference.file.add_node(en); } enums.Add(en); scope.add(en.name, en); }
public override void visit_enum(ValaEnum en) { en.accept_children(this); }
public EnumValueType(ValaEnum type_symbol) : base(type_symbol) { }
public virtual void add_enum(ValaEnum en) { Report.error(en.source_reference, "unexpected declaration"); }
public override void visit_enum(ValaEnum en) { check_unused_attr(en); en.accept_children(this); }
/// <summary> /// Creates a new C function to register the specified enum at runtime. /// /// <param name="en">an enum</param> /// <returns>newly created enum register function</returns> /// </summary> public EnumRegisterFunction(ValaEnum en, CodeContext context) { enum_reference = en; this.context = context; }
/// <summary> /// Visit operation called for enums. /// /// <param name="en">an enum</param> /// </summary> public virtual void visit_enum(ValaEnum en) { }