[vala/0.48] codegen: Add CCode.type_get_function and get_ccode_type_get_function()
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/0.48] codegen: Add CCode.type_get_function and get_ccode_type_get_function()
- Date: Sun, 28 Feb 2021 17:26:26 +0000 (UTC)
commit d9a8adf45605092ccb7a74a1a3da0ec78377e7af
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Sat Jan 30 21:17:25 2021 +0100
codegen: Add CCode.type_get_function and get_ccode_type_get_function()
Allow to overide the macro name, and join get_ccode_class_get_function ()
and get_ccode_interface_get_function().
codegen/valaccode.vala | 21 ++++++++++++++-------
codegen/valaccodebasemodule.vala | 10 +++++-----
codegen/valaccodememberaccessmodule.vala | 4 ++--
codegen/valaccodemethodmodule.vala | 4 ++--
codegen/valagtypemodule.vala | 8 ++++----
libvaladoc/api/class.vala | 2 +-
libvaladoc/api/interface.vala | 2 +-
vala/valausedattr.vala | 2 +-
8 files changed, 30 insertions(+), 23 deletions(-)
---
diff --git a/codegen/valaccode.vala b/codegen/valaccode.vala
index d89d7219e..3284647c3 100644
--- a/codegen/valaccode.vala
+++ b/codegen/valaccode.vala
@@ -54,13 +54,20 @@ namespace Vala {
return get_ccode_upper_case_name (sym);
}
- public static string get_ccode_interface_get_function (Interface iface) {
- return "%s_GET_INTERFACE".printf (get_ccode_upper_case_name (iface));
- }
-
- public static string get_ccode_class_get_function (Class cl) {
- assert (!cl.is_compact);
- return "%s_GET_CLASS".printf (get_ccode_upper_case_name (cl));
+ public static string get_ccode_type_get_function (ObjectTypeSymbol sym) {
+ var func_name = sym.get_attribute_string ("CCode", "type_get_function");
+ if (func_name != null) {
+ return func_name;
+ }
+ if (sym is Class) {
+ assert (!((Class) sym).is_compact);
+ return "%s_GET_CLASS".printf (get_ccode_upper_case_name (sym));
+ } else if (sym is Interface) {
+ return "%s_GET_INTERFACE".printf (get_ccode_upper_case_name (sym));
+ } else {
+ Report.error (sym.source_reference, "`CCode.type_get_function' not supported");
+ return "";
+ }
}
public static string get_ccode_class_get_private_function (Class cl) {
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 93dfbfe46..67d483d1d 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -1767,12 +1767,12 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
if (prop.parent_symbol is Interface) {
var iface = (Interface) prop.parent_symbol;
- vcast = new CCodeFunctionCall (new CCodeIdentifier
(get_ccode_interface_get_function (iface)));
+ vcast = new CCodeFunctionCall (new CCodeIdentifier
(get_ccode_type_get_function (iface)));
((CCodeFunctionCall) vcast).add_argument (new CCodeIdentifier ("self"));
} else {
var cl = (Class) prop.parent_symbol;
if (!cl.is_compact) {
- vcast = new CCodeFunctionCall (new CCodeIdentifier
(get_ccode_class_get_function (cl)));
+ vcast = new CCodeFunctionCall (new CCodeIdentifier
(get_ccode_type_get_function (cl)));
((CCodeFunctionCall) vcast).add_argument (new CCodeIdentifier
("self"));
} else {
vcast = new CCodeIdentifier ("self");
@@ -2827,7 +2827,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
require_generic_accessors (iface);
string method_name = "get_%s_type".printf (type_parameter.name.ascii_down ());
- var cast_self = new CCodeFunctionCall (new CCodeIdentifier
(get_ccode_interface_get_function (iface)));
+ var cast_self = new CCodeFunctionCall (new CCodeIdentifier
(get_ccode_type_get_function (iface)));
cast_self.add_argument (new CCodeIdentifier ("self"));
var function_call = new CCodeFunctionCall (new CCodeMemberAccess.pointer
(cast_self, method_name));
function_call.add_argument (new CCodeIdentifier ("self"));
@@ -2897,7 +2897,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
require_generic_accessors (iface);
string method_name = "get_%s_dup_func".printf (type_parameter.name.ascii_down
());
- var cast_self = new CCodeFunctionCall (new CCodeIdentifier
(get_ccode_interface_get_function (iface)));
+ var cast_self = new CCodeFunctionCall (new CCodeIdentifier
(get_ccode_type_get_function (iface)));
cast_self.add_argument (new CCodeIdentifier ("self"));
var function_call = new CCodeFunctionCall (new CCodeMemberAccess.pointer
(cast_self, method_name));
function_call.add_argument (new CCodeIdentifier ("self"));
@@ -3453,7 +3453,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
require_generic_accessors (iface);
string method_name = "get_%s_destroy_func".printf
(type_parameter.name.ascii_down ());
- var cast_self = new CCodeFunctionCall (new CCodeIdentifier
(get_ccode_interface_get_function (iface)));
+ var cast_self = new CCodeFunctionCall (new CCodeIdentifier
(get_ccode_type_get_function (iface)));
cast_self.add_argument (new CCodeIdentifier ("self"));
var function_call = new CCodeFunctionCall (new CCodeMemberAccess.pointer
(cast_self, method_name));
function_call.add_argument (new CCodeIdentifier ("self"));
diff --git a/codegen/valaccodememberaccessmodule.vala b/codegen/valaccodememberaccessmodule.vala
index f2177027f..0e995d3c9 100644
--- a/codegen/valaccodememberaccessmodule.vala
+++ b/codegen/valaccodememberaccessmodule.vala
@@ -68,7 +68,7 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
if (!method_has_wrapper (m.base_method)) {
var base_class = (Class) m.base_method.parent_symbol;
if (!base_class.is_compact) {
- var vclass = new CCodeFunctionCall (new CCodeIdentifier
(get_ccode_class_get_function (base_class)));
+ var vclass = new CCodeFunctionCall (new CCodeIdentifier
(get_ccode_type_get_function (base_class)));
vclass.add_argument (pub_inst);
set_cvalue (expr, new CCodeMemberAccess.pointer (vclass,
get_ccode_vfunc_name (m)));
} else {
@@ -80,7 +80,7 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
} else if (m.base_interface_method != null) {
if (m.base_interface_method.get_attribute ("NoWrapper") != null) {
var base_iface = (Interface) m.base_interface_method.parent_symbol;
- var vclass = new CCodeFunctionCall (new CCodeIdentifier
(get_ccode_interface_get_function (base_iface)));
+ var vclass = new CCodeFunctionCall (new CCodeIdentifier
(get_ccode_type_get_function (base_iface)));
vclass.add_argument (pub_inst);
set_cvalue (expr, new CCodeMemberAccess.pointer (vclass,
get_ccode_vfunc_name (m)));
} else {
diff --git a/codegen/valaccodemethodmodule.vala b/codegen/valaccodemethodmodule.vala
index 96ffce6a0..fecaf1b70 100644
--- a/codegen/valaccodemethodmodule.vala
+++ b/codegen/valaccodemethodmodule.vala
@@ -1091,12 +1091,12 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
if (m.parent_symbol is Interface) {
var iface = (Interface) m.parent_symbol;
- vcast = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_interface_get_function
(iface)));
+ vcast = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_type_get_function
(iface)));
((CCodeFunctionCall) vcast).add_argument (new CCodeIdentifier ("self"));
} else {
var cl = (Class) m.parent_symbol;
if (!cl.is_compact) {
- vcast = new CCodeFunctionCall (new CCodeIdentifier
(get_ccode_class_get_function (cl)));
+ vcast = new CCodeFunctionCall (new CCodeIdentifier
(get_ccode_type_get_function (cl)));
((CCodeFunctionCall) vcast).add_argument (new CCodeIdentifier ("self"));
} else {
vcast = new CCodeIdentifier ("self");
diff --git a/codegen/valagtypemodule.vala b/codegen/valagtypemodule.vala
index 6dc16817a..a39dab353 100644
--- a/codegen/valagtypemodule.vala
+++ b/codegen/valagtypemodule.vala
@@ -85,7 +85,7 @@ public class Vala.GTypeModule : GErrorModule {
decl_space.add_type_declaration (new CCodeMacroReplacement ("%s(klass)".printf
(get_ccode_class_type_check_function (cl)), macro));
macro = "(G_TYPE_INSTANCE_GET_CLASS ((obj), %s, %sClass))".printf (get_ccode_type_id
(cl), get_ccode_name (cl));
- decl_space.add_type_declaration (new CCodeMacroReplacement ("%s(obj)".printf
(get_ccode_class_get_function (cl)), macro));
+ decl_space.add_type_declaration (new CCodeMacroReplacement ("%s(obj)".printf
(get_ccode_type_get_function (cl)), macro));
decl_space.add_type_declaration (new CCodeNewline ());
}
@@ -748,11 +748,11 @@ public class Vala.GTypeModule : GErrorModule {
ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF,
ref_count));
ccode.open_if (ccall);
- var get_class = new CCodeFunctionCall (new CCodeIdentifier
(get_ccode_class_get_function (cl)));
+ var get_class = new CCodeFunctionCall (new CCodeIdentifier
(get_ccode_type_get_function (cl)));
get_class.add_argument (new CCodeIdentifier ("self"));
// finalize class
- var ccast = new CCodeFunctionCall (new CCodeIdentifier
(get_ccode_class_get_function (cl)));
+ var ccast = new CCodeFunctionCall (new CCodeIdentifier
(get_ccode_type_get_function (cl)));
ccast.add_argument (new CCodeIdentifier ("self"));
ccall = new CCodeFunctionCall (new CCodeMemberAccess.pointer (ccast,
"finalize"));
ccall.add_argument (new CCodeIdentifier ("self"));
@@ -2058,7 +2058,7 @@ public class Vala.GTypeModule : GErrorModule {
decl_space.add_type_declaration (new CCodeMacroReplacement ("%s(obj)".printf
(get_ccode_type_check_function (iface)), macro));
macro = "(G_TYPE_INSTANCE_GET_INTERFACE ((obj), %s, %s))".printf (get_ccode_type_id (iface),
get_ccode_type_name (iface));
- decl_space.add_type_declaration (new CCodeMacroReplacement ("%s(obj)".printf
(get_ccode_interface_get_function (iface)), macro));
+ decl_space.add_type_declaration (new CCodeMacroReplacement ("%s(obj)".printf
(get_ccode_type_get_function (iface)), macro));
decl_space.add_type_declaration (new CCodeNewline ());
decl_space.add_type_declaration (new CCodeTypeDefinition ("struct _%s".printf (get_ccode_name
(iface)), new CCodeVariableDeclarator (get_ccode_name (iface))));
diff --git a/libvaladoc/api/class.vala b/libvaladoc/api/class.vala
index 83af272a4..ac44471ee 100644
--- a/libvaladoc/api/class.vala
+++ b/libvaladoc/api/class.vala
@@ -58,7 +58,7 @@ public class Valadoc.Api.Class : TypeSymbol {
if (!data.is_compact) {
this.is_class_type_macro_name = Vala.get_ccode_class_type_check_function (data);
this.class_type_macro_name = Vala.get_ccode_class_type_function (data);
- this.class_macro_name = Vala.get_ccode_class_get_function (data);
+ this.class_macro_name = Vala.get_ccode_type_get_function (data);
this.private_cname = _get_private_cname (data);
}
this.dbus_name = Vala.GDBusModule.get_dbus_name (data);
diff --git a/libvaladoc/api/interface.vala b/libvaladoc/api/interface.vala
index 3b336bdfc..bcc751196 100644
--- a/libvaladoc/api/interface.vala
+++ b/libvaladoc/api/interface.vala
@@ -38,7 +38,7 @@ public class Valadoc.Api.Interface : TypeSymbol {
{
base (parent, file, name, accessibility, comment, false, data);
- this.interface_macro_name = Vala.get_ccode_interface_get_function (data);
+ this.interface_macro_name = Vala.get_ccode_type_get_function (data);
this.dbus_name = Vala.GDBusModule.get_dbus_name (data);
this.cname = Vala.get_ccode_name (data);
this.type_id = Vala.get_ccode_type_id (data);
diff --git a/vala/valausedattr.vala b/vala/valausedattr.vala
index ce9fbaf1d..616dced9b 100644
--- a/vala/valausedattr.vala
+++ b/vala/valausedattr.vala
@@ -35,7 +35,7 @@ public class Vala.UsedAttr : CodeVisitor {
"has_type_id", "instance_pos", "const_cname", "take_value_function", "copy_function",
"free_function",
"param_spec_function", "has_target", "has_typedef", "type_cname", "ref_function",
"ref_function_void", "unref_function", "type",
"has_construct_function", "returns_floating_reference", "gir_namespace", "gir_version",
"construct_function",
- "lower_case_cprefix", "simple_generics", "sentinel", "scope", "has_destroy_function",
"ordering", "type_check_function",
+ "lower_case_cprefix", "simple_generics", "sentinel", "scope", "has_destroy_function",
"ordering", "type_check_function", "type_get_function",
"has_copy_function", "lower_case_csuffix", "ref_sink_function", "dup_function",
"finish_function", "generic_type_pos",
"array_length_type", "array_length", "array_length_cname", "array_length_cexpr",
"array_null_terminated",
"vfunc_name", "finish_vfunc_name", "finish_name", "free_function_address_of", "pos",
"delegate_target", "delegate_target_cname",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]