[vala/wip/attributes: 22/100] codegen: Add get_ccode_type_check_function
- From: Luca Bruno <lucabru src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/attributes: 22/100] codegen: Add get_ccode_type_check_function
- Date: Sat, 2 Jul 2011 12:27:09 +0000 (UTC)
commit 31549743d14b05cc3b62c948eaedaee68c0de1d8
Author: Luca Bruno <lucabru src gnome org>
Date: Tue Jun 28 14:49:22 2011 +0200
codegen: Add get_ccode_type_check_function
codegen/valaccodebasemodule.vala | 29 +++++++++++++++--------------
codegen/valagtypemodule.vala | 6 +++---
2 files changed, 18 insertions(+), 17 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index cfb2b73..e36e935 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -4865,17 +4865,6 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
}
}
- public string? get_type_check_function (TypeSymbol type) {
- var cl = type as Class;
- if (cl != null && cl.type_check_function != null) {
- return cl.type_check_function;
- } else if ((cl != null && cl.is_compact) || type is Struct || type is Enum || type is Delegate) {
- return null;
- } else {
- return type.get_upper_case_cname ("IS_");
- }
- }
-
CCodeExpression? create_type_check (CCodeNode ccodenode, DataType type) {
var et = type as ErrorType;
if (et != null && et.error_code != null) {
@@ -4889,8 +4878,8 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
var type_domain = new CCodeIdentifier (et.error_domain.get_upper_case_cname ());
return new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, instance_domain, type_domain);
} else {
- string type_check_func = get_type_check_function (type.data_type);
- if (type_check_func == null) {
+ string type_check_func = get_ccode_type_check_function (type.data_type);
+ if (type_check_func == "") {
return new CCodeInvalidExpression ();
}
var ccheck = new CCodeFunctionCall (new CCodeIdentifier (type_check_func));
@@ -5489,7 +5478,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
if (!context.assert) {
return;
} else if (context.checking && ((t is Class && !((Class) t).is_compact) || t is Interface)) {
- var ctype_check = new CCodeFunctionCall (new CCodeIdentifier (get_type_check_function (t)));
+ var ctype_check = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_type_check_function (t)));
ctype_check.add_argument (new CCodeIdentifier (var_name));
CCodeExpression cexpr = ctype_check;
@@ -5673,6 +5662,18 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
return get_ccode_attribute(sym).take_value_function;
}
+ public static string get_ccode_type_check_function (TypeSymbol sym) {
+ var cl = sym as Class;
+ var a = sym.get_attribute ("CCode");
+ if (cl != null && a != null && a.has_argument ("type_check_function")) {
+ return a.get_string ("type_check_function");
+ } else if ((cl != null && cl.is_compact) || sym is Struct || sym is Enum || sym is Delegate) {
+ return null;
+ } else {
+ return get_ccode_upper_case_cname (sym, "IS_");
+ }
+ }
+
public override void visit_class (Class cl) {
}
diff --git a/codegen/valagtypemodule.vala b/codegen/valagtypemodule.vala
index b542c2f..1bdcca0 100644
--- a/codegen/valagtypemodule.vala
+++ b/codegen/valagtypemodule.vala
@@ -73,10 +73,10 @@ public class Vala.GTypeModule : GErrorModule {
decl_space.add_type_declaration (new CCodeMacroReplacement ("%s_CLASS(klass)".printf (cl.get_upper_case_cname (null)), macro));
macro = "(G_TYPE_CHECK_INSTANCE_TYPE ((obj), %s))".printf (get_ccode_type_id (cl));
- decl_space.add_type_declaration (new CCodeMacroReplacement ("%s(obj)".printf (get_type_check_function (cl)), macro));
+ decl_space.add_type_declaration (new CCodeMacroReplacement ("%s(obj)".printf (get_ccode_type_check_function (cl)), macro));
macro = "(G_TYPE_CHECK_CLASS_TYPE ((klass), %s))".printf (get_ccode_type_id (cl));
- decl_space.add_type_declaration (new CCodeMacroReplacement ("%s_CLASS(klass)".printf (get_type_check_function (cl)), macro));
+ decl_space.add_type_declaration (new CCodeMacroReplacement ("%s_CLASS(klass)".printf (get_ccode_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_GET_CLASS(obj)".printf (cl.get_upper_case_cname (null)), macro));
@@ -1858,7 +1858,7 @@ public class Vala.GTypeModule : GErrorModule {
decl_space.add_type_declaration (new CCodeMacroReplacement ("%s(obj)".printf (iface.get_upper_case_cname (null)), macro));
macro = "(G_TYPE_CHECK_INSTANCE_TYPE ((obj), %s))".printf (get_ccode_type_id (iface));
- decl_space.add_type_declaration (new CCodeMacroReplacement ("%s(obj)".printf (get_type_check_function (iface)), macro));
+ 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), iface.get_type_cname ());
decl_space.add_type_declaration (new CCodeMacroReplacement ("%s_GET_INTERFACE(obj)".printf (iface.get_upper_case_cname (null)), macro));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]