+2008-06-23 Jürg Billeter <j@bitron.ch>
+
+ * vala/valaattribute.vala:
+ * vala/valafield.vala:
+ * vala/valainterfacewriter.vala:
+ * vala/valanamedargument.vala:
+ * vala/valastringliteral.vala:
+ * gobject/valaccodegenerator.vala:
+ * vapigen/valagidlparser.vala:
+
+ Support [CCode (type = "Foo")] to insert appropriate casts in
+ generated C Code
+
+ * vapi/packages/gtk+-2.0/:
+
+ Fix GtkActionEntry binding, fixes bug 526874
+
+ * vapi/gtk+-2.0.vapi: regenerated
+
2008-06-23 Jürg Billeter <j@bitron.ch>
* vala/valagenieparser.vala:
public override void visit_initializer_list (InitializerList list) {
list.accept_children (this);
- var clist = new CCodeInitializerList ();
- foreach (Expression expr in list.get_initializers ()) {
- clist.append ((CCodeExpression) expr.ccodenode);
+ if (list.target_type.data_type is Struct) {
+ /* initializer is used as struct initializer */
+ var st = (Struct) list.target_type.data_type;
+
+ var clist = new CCodeInitializerList ();
+
+ var field_it = st.get_fields ().iterator ();
+ foreach (Expression expr in list.get_initializers ()) {
+ Field field = null;
+ while (field == null) {
+ field_it.next ();
+ field = field_it.get ();
+ if (field.binding != MemberBinding.INSTANCE) {
+ // we only initialize instance fields
+ field = null;
+ }
+ }
+
+ var cexpr = (CCodeExpression) expr.ccodenode;
+
+ string ctype = field.get_ctype ();
+ if (ctype != null) {
+ cexpr = new CCodeCastExpression (cexpr, ctype);
+ }
+
+ clist.append (cexpr);
+ }
+
+ list.ccodenode = clist;
+ } else {
+ var clist = new CCodeInitializerList ();
+ foreach (Expression expr in list.get_initializers ()) {
+ clist.append ((CCodeExpression) expr.ccodenode);
+ }
+ list.ccodenode = clist;
}
- list.ccodenode = clist;
}
public LocalVariable get_temp_variable (DataType type, bool value_owned = true, CodeNode? node_reference = null) {
* @param source_reference reference to source code
* @return newly created attribute
*/
- public Attribute (string name, SourceReference? source_reference) {
+ public Attribute (string name, SourceReference? source_reference = null) {
this.name = name;
this.source_reference = source_reference;
}
field_type = new_type;
}
}
+
+ public string? get_ctype () {
+ var attr = get_attribute ("CCode");
+ if (attr == null) {
+ return null;
+ }
+ return attr.get_string ("type");
+ }
+
+ public void set_ctype (string ctype) {
+ var attr = get_attribute ("CCode");
+ if (attr == null) {
+ attr = new Attribute ("CCode");
+ attributes.append (attr);
+ }
+ attr.add_argument (new NamedArgument ("type", new StringLiteral ("\"%s\"".printf (ctype))));
+ }
}
}
bool custom_cname = (f.get_cname () != f.get_default_cname ());
+ bool custom_ctype = (f.get_ctype () != null);
bool custom_cheaders = (f.parent_symbol is Namespace);
- if (custom_cname || custom_cheaders) {
+ if (custom_cname || custom_ctype || custom_cheaders) {
write_indent ();
write_string ("[CCode (");
write_string ("cname = \"%s\"".printf (f.get_cname ()));
}
- if (custom_cheaders) {
+ if (custom_ctype) {
if (custom_cname) {
write_string (", ");
}
+ write_string ("type = \"%s\"".printf (f.get_ctype ()));
+ }
+
+ if (custom_cheaders) {
+ if (custom_cname || custom_ctype) {
+ write_string (", ");
+ }
+
bool first = true;
string cheaders;
foreach (string cheader in f.get_cheader_filenames ()) {
/* valanamedargument.vala
*
- * Copyright (C) 2006 Jürg Billeter
+ * Copyright (C) 2006-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
* @param source reference to source code
* @return newly created named argument
*/
- public NamedArgument (string _name, Expression arg, SourceReference source) {
- name = _name;
- argument = arg;
- source_reference = source;
+ public NamedArgument (string name, Expression argument, SourceReference? source_reference = null) {
+ this.name = name;
+ this.argument = argument;
+ this.source_reference = source_reference;
}
public override void accept (CodeVisitor visitor) {
* @param source reference to source code
* @return newly created string literal
*/
- public StringLiteral (string s, SourceReference source) {
- value = s;
- source_reference = source;
+ public StringLiteral (string value, SourceReference? source_reference = null) {
+ this.value = value;
+ this.source_reference = source_reference;
}
/**
public weak string label;
public weak string accelerator;
public weak string tooltip;
+ [CCode (type = "GCallback")]
public weak Gtk.ActionCallback callback;
}
[CCode (cheader_filename = "gtk/gtk.h")]
gtk_action_new.stock_id nullable="1"
GtkAction::activate has_emitter="1"
GtkActionEntry is_value_type="1"
-GtkActionEntry.callback type_name="ActionCallback"
+GtkActionEntry.callback type_name="ActionCallback" ctype="GCallback"
gtk_action_group_add_action_with_accel.accelerator nullable="1"
gtk_action_group_add_actions.user_data hidden="0"
gtk_action_group_add_actions_full.user_data hidden="0"
}
string cheader_filename = null;
+ string ctype = null;
var attributes = get_attributes ("%s.%s".printf (current_data_type.get_cname (), node.name));
if (attributes != null) {
}
} else if (nv[0] == "cheader_filename") {
cheader_filename = eval (nv[1]);
+ } else if (nv[0] == "ctype") {
+ ctype = eval (nv[1]);
}
}
}
field.set_cname (node.name);
}
+ if (ctype != null) {
+ field.set_ctype (ctype);
+ }
+
if (cheader_filename != null) {
field.add_cheader_filename (cheader_filename);
}