[vala] codegen: Add get_parameter_cvalue and load_parameter in dova
- From: Jürg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] codegen: Add get_parameter_cvalue and load_parameter in dova
- Date: Wed, 16 Feb 2011 10:31:28 +0000 (UTC)
commit 7e1aac5a2d5b4343e73baf64cee4ade6e5c2498d
Author: Jürg Billeter <j bitron ch>
Date: Wed Feb 16 10:18:46 2011 +0100
codegen: Add get_parameter_cvalue and load_parameter in dova
codegen/valadovamemberaccessmodule.vala | 110 +++++++++++++++++--------------
1 files changed, 61 insertions(+), 49 deletions(-)
---
diff --git a/codegen/valadovamemberaccessmodule.vala b/codegen/valadovamemberaccessmodule.vala
index d0993b0..aae5b0e 100644
--- a/codegen/valadovamemberaccessmodule.vala
+++ b/codegen/valadovamemberaccessmodule.vala
@@ -192,55 +192,7 @@ public abstract class Vala.DovaMemberAccessModule : DovaControlFlowModule {
expr.target_value = load_local (local);
} else if (expr.symbol_reference is Parameter) {
var p = (Parameter) expr.symbol_reference;
- if (p.name == "this") {
- if (current_method != null && current_method.coroutine) {
- // use closure
- set_cvalue (expr, new CCodeMemberAccess.pointer (new CCodeIdentifier ("data"), "this"));
- } else {
- var st = current_type_symbol as Struct;
- if (st != null && !st.is_boolean_type () && !st.is_integer_type () && !st.is_floating_type () && (!st.is_simple_type () || current_method is CreationMethod)) {
- set_cvalue (expr, new CCodeIdentifier ("(*this)"));
- } else {
- set_cvalue (expr, new CCodeIdentifier ("this"));
- }
- }
- } else {
- if (p.captured) {
- // captured variables are stored on the heap
- var block = p.parent_symbol as Block;
- if (block == null) {
- block = ((Method) p.parent_symbol).body;
- }
- set_cvalue (expr, new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (get_block_id (block))), get_variable_cname (p.name)));
- } else {
- if (current_method != null && current_method.coroutine) {
- // use closure
- set_cvalue (expr, get_variable_cexpression (p.name));
- } else {
- var type_as_struct = p.variable_type.data_type as Struct;
- if (p.direction != ParameterDirection.IN
- || (type_as_struct != null && !type_as_struct.is_simple_type () && !p.variable_type.nullable)) {
- if (p.variable_type is GenericType) {
- set_cvalue (expr, get_variable_cexpression (p.name));
- } else {
- set_cvalue (expr, new CCodeIdentifier ("(*%s)".printf (get_variable_cname (p.name))));
- }
- } else {
- // Property setters of non simple structs shall replace all occurences
- // of the "value" formal parameter with a dereferencing version of that
- // parameter.
- if (current_property_accessor != null &&
- current_property_accessor.writable &&
- current_property_accessor.value_parameter == p &&
- current_property_accessor.prop.property_type.is_real_struct_type ()) {
- set_cvalue (expr, new CCodeIdentifier ("(*value)"));
- } else {
- set_cvalue (expr, get_variable_cexpression (p.name));
- }
- }
- }
- }
- }
+ expr.target_value = load_parameter (p);
}
}
@@ -261,6 +213,62 @@ public abstract class Vala.DovaMemberAccessModule : DovaControlFlowModule {
return result;
}
+ public TargetValue get_parameter_cvalue (Parameter p) {
+ var result = new DovaValue (p.variable_type);
+
+ if (p.name == "this") {
+ if (current_method != null && current_method.coroutine) {
+ // use closure
+ result.cvalue = new CCodeMemberAccess.pointer (new CCodeIdentifier ("data"), "this");
+ } else {
+ var st = current_type_symbol as Struct;
+ if (st != null && !st.is_boolean_type () && !st.is_integer_type () && !st.is_floating_type () && (!st.is_simple_type () || current_method is CreationMethod)) {
+ result.cvalue = new CCodeIdentifier ("(*this)");
+ } else {
+ result.cvalue = new CCodeIdentifier ("this");
+ }
+ }
+ } else {
+ if (p.captured) {
+ // captured variables are stored on the heap
+ var block = p.parent_symbol as Block;
+ if (block == null) {
+ block = ((Method) p.parent_symbol).body;
+ }
+ result.cvalue = new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (get_block_id (block))), get_variable_cname (p.name));
+ } else {
+ if (current_method != null && current_method.coroutine) {
+ // use closure
+ result.cvalue = get_variable_cexpression (p.name);
+ } else {
+ var type_as_struct = p.variable_type.data_type as Struct;
+ if (p.direction != ParameterDirection.IN
+ || (type_as_struct != null && !type_as_struct.is_simple_type () && !p.variable_type.nullable)) {
+ if (p.variable_type is GenericType) {
+ result.cvalue = get_variable_cexpression (p.name);
+ } else {
+ result.cvalue = new CCodeIdentifier ("(*%s)".printf (get_variable_cname (p.name)));
+ }
+ } else {
+ // Property setters of non simple structs shall replace all occurences
+ // of the "value" formal parameter with a dereferencing version of that
+ // parameter.
+ if (current_property_accessor != null &&
+ current_property_accessor.writable &&
+ current_property_accessor.value_parameter == p &&
+ current_property_accessor.prop.property_type.is_real_struct_type ()) {
+ result.cvalue = new CCodeIdentifier ("(*value)");
+ } else {
+ result.cvalue = get_variable_cexpression (p.name);
+ }
+ }
+ }
+ }
+ }
+
+ return result;
+ }
+
TargetValue load_variable (Variable variable, TargetValue value) {
return value;
}
@@ -268,5 +276,9 @@ public abstract class Vala.DovaMemberAccessModule : DovaControlFlowModule {
public override TargetValue load_local (LocalVariable local) {
return load_variable (local, get_local_cvalue (local));
}
+
+ public TargetValue load_parameter (Parameter param) {
+ return load_variable (param, get_parameter_cvalue (param));
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]