Commit 6ab8723f authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter
Browse files

support non-GObject classes, will replace reference-type structs

2007-08-28  Juerg Billeter  <j@bitron.ch>

	* vala/valaclass.vala, vala/valaenum.vala,
	  gobject/valacodegenerator.vala, gobject/valacodegeneratorclass.vala,
	  gobject/valacodegeneratorinterface.vala,
	  gobject/valacodegeneratormethod.vala: support non-GObject classes,
	  will replace reference-type structs

svn path=/trunk/; revision=514
parent 78e8b3d4
2007-08-28 Jürg Billeter <j@bitron.ch>
* vala/valaclass.vala, vala/valaenum.vala,
gobject/valacodegenerator.vala, gobject/valacodegeneratorclass.vala,
gobject/valacodegeneratorinterface.vala,
gobject/valacodegeneratormethod.vala: support non-GObject classes,
will replace reference-type structs
2007-08-27 Mathias Hasselmann <mathias.hasselmann@gmx.de>
* vapi/packages/gtk+-2.0/gtk+-2.0-custom.vala,
......
......@@ -1788,7 +1788,8 @@ public class Vala.CodeGenerator : CodeVisitor {
if (stmt.return_expression.static_type != null &&
stmt.return_expression.static_type.data_type != current_return_type.data_type) {
/* cast required */
if (current_return_type.data_type is Class || current_return_type.data_type is Interface) {
if ((current_return_type.data_type is Class && ((Class) current_return_type.data_type).get_is_gobject ()) ||
current_return_type.data_type is Interface) {
stmt.return_expression.ccodenode = new InstanceCast ((CCodeExpression) stmt.return_expression.ccodenode, current_return_type.data_type);
}
}
......@@ -2489,7 +2490,7 @@ public class Vala.CodeGenerator : CodeVisitor {
}
public override void visit_cast_expression (CastExpression! expr) {
if (expr.type_reference.data_type is Class || expr.type_reference.data_type is Interface) {
if ((expr.type_reference.data_type is Class && ((Class) expr.type_reference.data_type).get_is_gobject ()) || expr.type_reference.data_type is Interface) {
// GObject cast
if (expr.is_silent_cast) {
var ccomma = new CCodeCommaExpression ();
......@@ -2586,7 +2587,8 @@ public class Vala.CodeGenerator : CodeVisitor {
if (expr.operator == BinaryOperator.EQUALITY ||
expr.operator == BinaryOperator.INEQUALITY) {
if (expr.left.static_type != null && expr.right.static_type != null &&
expr.left.static_type.data_type is Class && expr.right.static_type.data_type is Class) {
expr.left.static_type.data_type is Class && ((Class) expr.left.static_type.data_type).get_is_gobject () &&
expr.right.static_type.data_type is Class && ((Class) expr.right.static_type.data_type).get_is_gobject ()) {
var left_cl = (Class) expr.left.static_type.data_type;
var right_cl = (Class) expr.right.static_type.data_type;
......
......@@ -417,25 +417,8 @@ public class Vala.CodeGenerator {
}
private CCodeIdentifier! get_value_setter_function (TypeReference! type_reference) {
if (type_reference.data_type is Class || type_reference.data_type is Interface) {
return new CCodeIdentifier ("g_value_set_object");
} else if (type_reference.data_type == string_type.data_type) {
return new CCodeIdentifier ("g_value_set_string");
} else if (type_reference.data_type == int_type.data_type
|| type_reference.data_type is Enum) {
return new CCodeIdentifier ("g_value_set_int");
} else if (type_reference.data_type == uint_type.data_type) {
return new CCodeIdentifier ("g_value_set_uint");
} else if (type_reference.data_type == long_type.data_type) {
return new CCodeIdentifier ("g_value_set_long");
} else if (type_reference.data_type == ulong_type.data_type) {
return new CCodeIdentifier ("g_value_set_ulong");
} else if (type_reference.data_type == bool_type.data_type) {
return new CCodeIdentifier ("g_value_set_boolean");
} else if (type_reference.data_type == float_type.data_type) {
return new CCodeIdentifier ("g_value_set_float");
} else if (type_reference.data_type == double_type.data_type) {
return new CCodeIdentifier ("g_value_set_double");
if (type_reference.data_type != null) {
return new CCodeIdentifier (type_reference.data_type.get_set_value_function ());
} else {
return new CCodeIdentifier ("g_value_set_pointer");
}
......@@ -541,24 +524,8 @@ public class Vala.CodeGenerator {
var ccall = new CCodeFunctionCall (new CCodeIdentifier ("%s_set_%s".printf (prefix, prop.name)));
ccall.add_argument (new CCodeIdentifier ("self"));
var cgetcall = new CCodeFunctionCall ();
if (prop.type_reference.data_type is Class || prop.type_reference.data_type is Interface) {
cgetcall.call = new CCodeIdentifier ("g_value_get_object");
} else if (prop.type_reference.type_name == "string") {
cgetcall.call = new CCodeIdentifier ("g_value_get_string");
} else if (prop.type_reference.type_name == "int" || prop.type_reference.data_type is Enum) {
cgetcall.call = new CCodeIdentifier ("g_value_get_int");
} else if (prop.type_reference.type_name == "uint") {
cgetcall.call = new CCodeIdentifier ("g_value_get_uint");
} else if (prop.type_reference.type_name == "long") {
cgetcall.call = new CCodeIdentifier ("g_value_get_long");
} else if (prop.type_reference.type_name == "ulong") {
cgetcall.call = new CCodeIdentifier ("g_value_get_ulong");
} else if (prop.type_reference.type_name == "bool") {
cgetcall.call = new CCodeIdentifier ("g_value_get_boolean");
} else if (prop.type_reference.type_name == "float") {
cgetcall.call = new CCodeIdentifier ("g_value_get_float");
} else if (prop.type_reference.type_name == "double") {
cgetcall.call = new CCodeIdentifier ("g_value_get_double");
if (prop.type_reference.data_type != null) {
cgetcall.call = new CCodeIdentifier (prop.type_reference.data_type.get_get_value_function ());
} else {
cgetcall.call = new CCodeIdentifier ("g_value_get_pointer");
}
......
......@@ -92,7 +92,7 @@ public class Vala.CodeGenerator {
cspec.add_argument (prop.get_canonical_cconstant ());
cspec.add_argument (new CCodeConstant ("\"foo\""));
cspec.add_argument (new CCodeConstant ("\"bar\""));
if (prop.type_reference.data_type is Class || prop.type_reference.data_type is Interface) {
if ((prop.type_reference.data_type is Class && ((Class) prop.type_reference.data_type).get_is_gobject ()) || prop.type_reference.data_type is Interface) {
cspec.call = new CCodeIdentifier ("g_param_spec_object");
cspec.add_argument (new CCodeIdentifier (prop.type_reference.data_type.get_upper_case_cname ("TYPE_")));
} else if (prop.type_reference.data_type == string_type.data_type) {
......
......@@ -460,7 +460,7 @@ public class Vala.CodeGenerator {
private CCodeStatement create_type_check_statement (CodeNode! method_node, DataType ret_type, DataType! t, bool non_null, string! var_name) {
var ccheck = new CCodeFunctionCall ();
if (t is Class || (t is Interface && !((Interface) t).declaration_only)) {
if ((t is Class && ((Class) t).get_is_gobject ()) || (t is Interface && !((Interface) t).declaration_only)) {
var ctype_check = new CCodeFunctionCall (new CCodeIdentifier (t.get_upper_case_cname ("IS_")));
ctype_check.add_argument (new CCodeIdentifier (var_name));
......
......@@ -52,11 +52,21 @@ public class Vala.Class : DataType {
return _has_private_fields;
}
}
private bool is_gobject = true;
private string cname;
private string const_cname;
private string lower_case_cprefix;
private string lower_case_csuffix;
private string type_id;
private string ref_function;
private string unref_function;
private string copy_function;
private string free_function;
private string marshaller_type_name;
private string get_value_function;
private string set_value_function;
private bool _has_private_fields;
private Gee.List<TypeParameter> type_parameters = new ArrayList<TypeParameter> ();
......@@ -327,6 +337,10 @@ public class Vala.Class : DataType {
}
public override string get_cname (bool const_type = false) {
if (const_type && const_cname != null) {
return const_cname;
}
if (cname == null) {
cname = "%s%s".printf (parent_symbol.get_cprefix (), name);
}
......@@ -357,21 +371,67 @@ public class Vala.Class : DataType {
}
public override string! get_lower_case_cprefix () {
return "%s_".printf (get_lower_case_cname (null));
if (lower_case_cprefix == null) {
lower_case_cprefix = "%s_".printf (get_lower_case_cname (null));
}
return lower_case_cprefix;
}
public override string get_upper_case_cname (string infix) {
return get_lower_case_cname (infix).up ();
}
public bool get_is_gobject () {
return is_gobject;
}
public void set_is_gobject (bool is_gobject) {
this.is_gobject = is_gobject;
}
public override bool is_reference_type () {
return true;
}
private void process_ccode_attribute (Attribute! a) {
if (a.has_argument ("ctype")) {
if (a.get_string ("ctype") != "gobject") {
is_gobject = false;
if (a.has_argument ("ref_function")) {
set_ref_function (a.get_string ("ref_function"));
}
if (a.has_argument ("unref_function")) {
set_unref_function (a.get_string ("unref_function"));
}
if (a.has_argument ("copy_function")) {
set_dup_function (a.get_string ("copy_function"));
}
if (a.has_argument ("free_function")) {
set_free_function (a.get_string ("free_function"));
}
if (a.has_argument ("type_id")) {
type_id = a.get_string ("type_id");
}
if (a.has_argument ("marshaller_type_name")) {
marshaller_type_name = a.get_string ("marshaller_type_name");
}
if (a.has_argument ("get_value_function")) {
get_value_function = a.get_string ("get_value_function");
}
if (a.has_argument ("set_value_function")) {
set_value_function = a.get_string ("set_value_function");
}
}
}
if (a.has_argument ("cname")) {
set_cname (a.get_string ("cname"));
}
if (a.has_argument ("const_cname")) {
const_cname = a.get_string ("const_cname");
}
if (a.has_argument ("cprefix")) {
lower_case_cprefix = a.get_string ("cprefix");
}
if (a.has_argument ("lower_case_csuffix")) {
lower_case_csuffix = a.get_string ("lower_case_csuffix");
}
......@@ -403,27 +463,93 @@ public class Vala.Class : DataType {
}
public override string get_marshaller_type_name () {
return "OBJECT";
if (marshaller_type_name == null) {
if (is_gobject) {
marshaller_type_name = "OBJECT";
} else {
marshaller_type_name = "POINTER";
}
}
return marshaller_type_name;
}
public override string get_get_value_function () {
return "g_value_get_object";
if (get_value_function == null) {
if (is_gobject) {
get_value_function = "g_value_get_object";
} else {
get_value_function = "g_value_get_pointer";
}
}
return get_value_function;
}
public override string get_set_value_function () {
return "g_value_set_object";
if (set_value_function == null) {
if (is_gobject) {
set_value_function = "g_value_set_object";
} else {
set_value_function = "g_value_set_pointer";
}
}
return set_value_function;
}
public override bool is_reference_counting () {
return true;
return is_gobject || (ref_function != null && unref_function != null);
}
public override string get_ref_function () {
return "g_object_ref";
if (is_gobject) {
return "g_object_ref";
} else {
return ref_function;
}
}
public void set_ref_function (string! name) {
this.ref_function = name;
}
public override string get_unref_function () {
return "g_object_unref";
if (is_gobject) {
return "g_object_unref";
} else {
return unref_function;
}
}
public void set_unref_function (string! name) {
this.unref_function = name;
}
public override string get_dup_function () {
return copy_function;
}
public void set_dup_function (string! name) {
this.copy_function = name;
}
public string get_default_free_function () {
if (default_construction_method != null) {
return get_lower_case_cprefix () + "free";
}
return null;
}
public override string get_free_function () {
if (free_function == null) {
free_function = get_default_free_function ();
}
return free_function;
}
public void set_free_function (string! name) {
this.free_function = name;
}
public override bool is_subtype_of (DataType! t) {
......
......@@ -204,15 +204,18 @@ public class Vala.Enum : DataType {
}
public override string get_marshaller_type_name () {
return "ENUM";
// FIXME: use GType-registered enums
return "INT";
}
public override string get_get_value_function () {
return "g_value_get_enum";
// FIXME: use GType-registered enums
return "g_value_get_int";
}
public override string get_set_value_function () {
return "g_value_set_enum";
// FIXME: use GType-registered enums
return "g_value_set_int";
}
public override string get_default_value () {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment