+2008-07-05 Jürg Billeter <j@bitron.ch>
+
+ * vala/valaattributeprocessor.vala:
+ * vala/valaparser.vala:
+ * vala/valapropertyaccessor.vala:
+ * gobject/valaccodegenerator.vala:
+ * gobject/valaccodememberaccessbinding.vala:
+
+ Add support for [CCode (cname = "foo")] to property accessors,
+ based on patch by Jared Moore
+
2008-07-05 Jared Moore <jaredm@svn.gnome.org>
* vala/valasemanticanalyzer.vala:
if (prop.is_abstract || prop.is_virtual) {
if (acc.readable) {
- function = new CCodeFunction ("%s_get_%s".printf (t.get_lower_case_cname (null), prop.name), prop.property_type.get_cname ());
+ function = new CCodeFunction (acc.get_cname (), prop.property_type.get_cname ());
} else {
- function = new CCodeFunction ("%s_set_%s".printf (t.get_lower_case_cname (null), prop.name), "void");
+ function = new CCodeFunction (acc.get_cname (), "void");
}
function.add_parameter (cselfparam);
if (acc.writable || acc.construction) {
if (!prop.is_abstract) {
bool is_virtual = prop.base_property != null || prop.base_interface_property != null;
- string prefix = t.get_lower_case_cname (null);
+ string cname;
if (is_virtual) {
- prefix += "_real";
+ if (acc.readable) {
+ cname = "%s_real_get_%s".printf (t.get_lower_case_cname (null), prop.name);
+ } else {
+ cname = "%s_real_set_%s".printf (t.get_lower_case_cname (null), prop.name);
+ }
+ } else {
+ cname = acc.get_cname ();
}
+
if (acc.readable) {
if (returns_real_struct) {
// return non simple structs as out parameter
- function = new CCodeFunction ("%s_get_%s".printf (prefix, prop.name), "void");
+ function = new CCodeFunction (cname, "void");
} else {
- function = new CCodeFunction ("%s_get_%s".printf (prefix, prop.name), prop.property_type.get_cname ());
+ function = new CCodeFunction (cname, prop.property_type.get_cname ());
}
} else {
- function = new CCodeFunction ("%s_set_%s".printf (prefix, prop.name), "void");
+ function = new CCodeFunction (cname, "void");
}
+
if (is_virtual) {
function.modifiers |= CCodeModifiers.STATIC;
}
} else if (expr.symbol_reference is Property) {
var prop = (Property) expr.symbol_reference;
- if (prop.get_accessor != null &&
- prop.get_accessor.automatic_body &&
+ if (prop.get_accessor == null) {
+ return;
+ }
+
+ if (prop.get_accessor.automatic_body &&
codegen.current_type_symbol == prop.parent_symbol &&
prop.base_property == null &&
prop.base_interface_property == null) {
} else if (prop.base_interface_property != null) {
base_property = prop.base_interface_property;
}
- var base_property_type = (TypeSymbol) base_property.parent_symbol;
string getter_cname;
if (prop is DynamicProperty) {
getter_cname = codegen.dynamic_property_binding ((DynamicProperty) prop).get_getter_cname ();
} else {
- getter_cname = "%s_get_%s".printf (base_property_type.get_lower_case_cname (null), base_property.name);
+ getter_cname = base_property.get_accessor.get_cname ();
}
var ccall = new CCodeFunctionCall (new CCodeIdentifier (getter_cname));
public override void visit_property (Property prop) {
prop.process_attributes ();
+
+ prop.accept_children (this);
+ }
+
+ public override void visit_property_accessor (PropertyAccessor p) {
+ p.process_attributes ();
}
public override void visit_delegate (Delegate d) {
expect (TokenType.SEMICOLON);
} else {
var accessor_begin = get_location ();
- parse_attributes ();
+ var attrs = parse_attributes ();
var accessor_access = parse_access_modifier (SymbolAccessibility.PUBLIC);
if (accept (TokenType.GET)) {
if (prop.get_accessor != null) {
block = parse_block ();
}
prop.get_accessor = new PropertyAccessor (true, false, false, block, get_src (accessor_begin));
+ set_attributes (prop.get_accessor, attrs);
prop.get_accessor.access = accessor_access;
} else {
bool writable, _construct;
block = parse_block ();
}
prop.set_accessor = new PropertyAccessor (false, writable, _construct, block, get_src (accessor_begin));
+ set_attributes (prop.set_accessor, attrs);
prop.set_accessor.access = accessor_access;
}
}
* Represents the generated value parameter in a set accessor.
*/
public FormalParameter value_parameter { get; set; }
+
+ /**
+ * The publicly accessible name of the function that performs the
+ * access in C code.
+ */
+ public string get_cname () {
+ if (_cname != null) {
+ return _cname;
+ }
+
+ var t = (TypeSymbol) prop.parent_symbol;
+
+ if (readable) {
+ return "%s_get_%s".printf (t.get_lower_case_cname (null), prop.name);
+ } else {
+ return "%s_set_%s".printf (t.get_lower_case_cname (null), prop.name);
+ }
+ }
+
+ private string? _cname;
/**
* Creates a new property accessor.
body.accept (visitor);
}
}
+
+ /**
+ * Process all associated attributes.
+ */
+ public void process_attributes () {
+ foreach (Attribute a in attributes) {
+ if (a.name == "CCode") {
+ if (a.has_argument ("cname")) {
+ _cname = a.get_string ("cname");
+ }
+ }
+ }
+ }
}