[vala] codegen: Add helper functions to work with TargetValue
- From: Jürg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] codegen: Add helper functions to work with TargetValue
- Date: Thu, 21 Oct 2010 18:04:26 +0000 (UTC)
commit 526b5ec0173349bb5b2464224c2dd97e20900382
Author: Jürg Billeter <j bitron ch>
Date: Thu Oct 21 13:20:02 2010 +0200
codegen: Add helper functions to work with TargetValue
codegen/valaccodearraymodule.vala | 12 +++++--
codegen/valaccodebasemodule.vala | 53 +++++++++++++++++++++++----------
codegen/valaccodedelegatemodule.vala | 11 ++++++-
codegen/valadovabasemodule.vala | 13 ++++++--
4 files changed, 63 insertions(+), 26 deletions(-)
---
diff --git a/codegen/valaccodearraymodule.vala b/codegen/valaccodearraymodule.vala
index 4e938f6..ec375c3 100644
--- a/codegen/valaccodearraymodule.vala
+++ b/codegen/valaccodearraymodule.vala
@@ -135,7 +135,11 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
}
public override CCodeExpression get_array_length_cexpression (Expression array_expr, int dim = -1) {
- var array_type = array_expr.value_type as ArrayType;
+ return get_array_length_cvalue (array_expr.target_value, dim);
+ }
+
+ public override CCodeExpression get_array_length_cvalue (TargetValue value, int dim = -1) {
+ var array_type = value.value_type as ArrayType;
if (array_type != null && array_type.fixed_length) {
return new CCodeConstant (array_type.length.to_string ());
@@ -144,9 +148,9 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
// dim == -1 => total size over all dimensions
if (dim == -1) {
if (array_type != null && array_type.rank > 1) {
- CCodeExpression cexpr = get_array_length_cexpression (array_expr, 1);
+ CCodeExpression cexpr = get_array_length_cvalue (value, 1);
for (dim = 2; dim <= array_type.rank; dim++) {
- cexpr = new CCodeBinaryExpression (CCodeBinaryOperator.MUL, cexpr, get_array_length_cexpression (array_expr, dim));
+ cexpr = new CCodeBinaryExpression (CCodeBinaryOperator.MUL, cexpr, get_array_length_cvalue (value, dim));
}
return cexpr;
} else {
@@ -154,7 +158,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
}
}
- List<CCodeExpression> size = get_array_sizes (array_expr);
+ List<CCodeExpression> size = ((GLibValue) value).array_length_cvalues;
assert (size != null && size.size >= dim);
return size[dim - 1];
}
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 0d07ae5..abebbcf 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -3614,6 +3614,14 @@ public class Vala.CCodeBaseModule : CodeGenerator {
assert_not_reached ();
}
+ public virtual CCodeExpression get_delegate_target_cvalue (TargetValue value) {
+ return new CCodeInvalidExpression ();
+ }
+
+ public virtual CCodeExpression get_delegate_target_destroy_notify_cvalue (TargetValue value) {
+ return new CCodeInvalidExpression ();
+ }
+
public virtual string get_delegate_target_destroy_notify_cname (string delegate_cname) {
assert_not_reached ();
}
@@ -5793,6 +5801,10 @@ public class Vala.CCodeBaseModule : CodeGenerator {
return new CCodeConstant ("");
}
+ public virtual CCodeExpression get_array_length_cvalue (TargetValue value, int dim = -1) {
+ return new CCodeInvalidExpression ();
+ }
+
public virtual string get_array_size_cname (string array_cname) {
return "";
}
@@ -5809,7 +5821,12 @@ public class Vala.CCodeBaseModule : CodeGenerator {
return null;
}
var glib_value = (GLibValue) expr.target_value;
- return glib_value.ccodenode;
+ return glib_value.cvalue;
+ }
+
+ public CCodeExpression? get_cvalue_ (TargetValue value) {
+ var glib_value = (GLibValue) value;
+ return glib_value.cvalue;
}
public void set_cvalue (Expression expr, CCodeExpression? cvalue) {
@@ -5818,7 +5835,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
glib_value = new GLibValue (expr.value_type);
expr.target_value = glib_value;
}
- glib_value.ccodenode = cvalue;
+ glib_value.cvalue = cvalue;
}
public CCodeExpression? get_delegate_target (Expression expr) {
@@ -5826,7 +5843,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
return null;
}
var glib_value = (GLibValue) expr.target_value;
- return glib_value.delegate_target;
+ return glib_value.delegate_target_cvalue;
}
public void set_delegate_target (Expression expr, CCodeExpression? delegate_target) {
@@ -5835,7 +5852,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
glib_value = new GLibValue (expr.value_type);
expr.target_value = glib_value;
}
- glib_value.delegate_target = delegate_target;
+ glib_value.delegate_target_cvalue = delegate_target;
}
public CCodeExpression? get_delegate_target_destroy_notify (Expression expr) {
@@ -5843,7 +5860,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
return null;
}
var glib_value = (GLibValue) expr.target_value;
- return glib_value.delegate_target_destroy_notify;
+ return glib_value.delegate_target_destroy_notify_cvalue;
}
public void set_delegate_target_destroy_notify (Expression expr, CCodeExpression destroy_notify) {
@@ -5852,7 +5869,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
glib_value = new GLibValue (expr.value_type);
expr.target_value = glib_value;
}
- glib_value.delegate_target_destroy_notify = destroy_notify;
+ glib_value.delegate_target_destroy_notify_cvalue = destroy_notify;
}
public void append_array_size (Expression expr, CCodeExpression size) {
@@ -5861,10 +5878,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
glib_value = new GLibValue (expr.value_type);
expr.target_value = glib_value;
}
- if (glib_value.array_sizes == null) {
- glib_value.array_sizes = new ArrayList<CCodeExpression> ();
- }
- glib_value.array_sizes.add (size);
+ glib_value.append_array_length_cvalue (size);
}
public List<CCodeExpression>? get_array_sizes (Expression expr) {
@@ -5873,20 +5887,27 @@ public class Vala.CCodeBaseModule : CodeGenerator {
glib_value = new GLibValue (expr.value_type);
expr.target_value = glib_value;
}
- return glib_value.array_sizes;
+ return glib_value.array_length_cvalues;
}
}
public class Vala.GLibValue : TargetValue {
- public CCodeExpression ccodenode;
+ public CCodeExpression cvalue;
- public List<CCodeExpression> array_sizes;
+ public List<CCodeExpression> array_length_cvalues;
- public CCodeExpression? delegate_target;
- public CCodeExpression? delegate_target_destroy_notify;
+ public CCodeExpression? delegate_target_cvalue;
+ public CCodeExpression? delegate_target_destroy_notify_cvalue;
public GLibValue (DataType? value_type = null, CCodeExpression? cvalue = null) {
base (value_type);
- this.ccodenode = cvalue;
+ this.cvalue = cvalue;
+ }
+
+ public void append_array_length_cvalue (CCodeExpression length_cvalue) {
+ if (array_length_cvalues == null) {
+ array_length_cvalues = new ArrayList<CCodeExpression> ();
+ }
+ array_length_cvalues.add (length_cvalue);
}
}
diff --git a/codegen/valaccodedelegatemodule.vala b/codegen/valaccodedelegatemodule.vala
index 8fc1610..ff3c5ff 100644
--- a/codegen/valaccodedelegatemodule.vala
+++ b/codegen/valaccodedelegatemodule.vala
@@ -129,9 +129,16 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
}
public override CCodeExpression get_delegate_target_cexpression (Expression delegate_expr, out CCodeExpression delegate_target_destroy_notify) {
- delegate_target_destroy_notify = get_delegate_target_destroy_notify (delegate_expr);
+ delegate_target_destroy_notify = get_delegate_target_destroy_notify_cvalue (delegate_expr.target_value);
+ return get_delegate_target_cvalue (delegate_expr.target_value);
+ }
+
+ public override CCodeExpression get_delegate_target_cvalue (TargetValue value) {
+ return ((GLibValue) value).delegate_target_cvalue;
+ }
- return get_delegate_target (delegate_expr);
+ public override CCodeExpression get_delegate_target_destroy_notify_cvalue (TargetValue value) {
+ return ((GLibValue) value).delegate_target_destroy_notify_cvalue;
}
public override string get_delegate_target_destroy_notify_cname (string delegate_cname) {
diff --git a/codegen/valadovabasemodule.vala b/codegen/valadovabasemodule.vala
index c421cbe..0ae752e 100644
--- a/codegen/valadovabasemodule.vala
+++ b/codegen/valadovabasemodule.vala
@@ -2271,7 +2271,12 @@ public class Vala.DovaBaseModule : CodeGenerator {
return null;
}
var dova_value = (DovaValue) expr.target_value;
- return dova_value.ccodenode;
+ return dova_value.cvalue;
+ }
+
+ public CCodeExpression? get_cvalue_ (TargetValue value) {
+ var dova_value = (DovaValue) value;
+ return dova_value.cvalue;
}
public void set_cvalue (Expression expr, CCodeExpression? cvalue) {
@@ -2280,15 +2285,15 @@ public class Vala.DovaBaseModule : CodeGenerator {
dova_value = new DovaValue (expr.value_type);
expr.target_value = dova_value;
}
- dova_value.ccodenode = cvalue;
+ dova_value.cvalue = cvalue;
}
}
public class Vala.DovaValue : TargetValue {
- public CCodeExpression ccodenode;
+ public CCodeExpression cvalue;
public DovaValue (DataType? value_type = null, CCodeExpression? cvalue = null) {
base (value_type);
- this.ccodenode = cvalue;
+ this.cvalue = cvalue;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]