[vala] Add TargetValue class
- From: Jürg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] Add TargetValue class
- Date: Sat, 9 Oct 2010 13:49:29 +0000 (UTC)
commit cc9c261c76da96d590e8f7bd363eaf0cf022c832
Author: Jürg Billeter <j bitron ch>
Date: Sun Aug 15 15:00:00 2010 +0200
Add TargetValue class
codegen/valaccodearraymodule.vala | 17 +++--
codegen/valaccodebasemodule.vala | 103 +++++++++++++++++++++++++-----
codegen/valaccodedelegatemodule.vala | 32 +++++-----
codegen/valaccodememberaccessmodule.vala | 4 +-
codegen/valaccodemethodcallmodule.vala | 18 +++---
codegen/valaccodemethodmodule.vala | 11 ++-
codegen/valadbusservermodule.vala | 4 +-
codegen/valadovabasemodule.vala | 37 +++++++----
codegen/valagdbusservermodule.vala | 4 +-
codegen/valagtypemodule.vala | 11 ++--
vala/Makefile.am | 1 +
vala/valacodenode.vala | 20 ------
vala/valaexpression.vala | 23 +------
vala/valatargetvalue.vala | 25 +++++++
14 files changed, 190 insertions(+), 120 deletions(-)
---
diff --git a/codegen/valaccodearraymodule.vala b/codegen/valaccodearraymodule.vala
index 2fb6dc4..276f5c7 100644
--- a/codegen/valaccodearraymodule.vala
+++ b/codegen/valaccodearraymodule.vala
@@ -176,7 +176,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
var length_expr = size[dim - 1];
return (CCodeExpression) get_ccodenode (length_expr);
} else if (array_expr is MethodCall || array_expr is CastExpression || array_expr is SliceExpression) {
- List<CCodeExpression> size = array_expr.get_array_sizes ();
+ List<CCodeExpression> size = get_array_sizes (array_expr);
if (size != null && size.size >= dim) {
return size[dim - 1];
}
@@ -328,7 +328,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
} else if (array_expr.symbol_reference is Property) {
var prop = (Property) array_expr.symbol_reference;
if (!prop.no_array_length) {
- List<CCodeExpression> size = array_expr.get_array_sizes ();
+ List<CCodeExpression> size = get_array_sizes (array_expr);
if (size != null && size.size >= dim) {
return size[dim - 1];
}
@@ -463,7 +463,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
ccomma.append_expression (get_variable_cexpression (slice_var.name));
set_cvalue (expr, ccomma);
- expr.append_array_size (get_variable_cexpression (len_var.name));
+ append_array_size (expr, get_variable_cexpression (len_var.name));
}
private CCodeForStatement get_struct_array_free_loop (Struct st) {
@@ -980,10 +980,9 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
}
}
- public override void generate_parameter (FormalParameter param, CCodeFile decl_space, Map<int,CCodeFormalParameter> cparam_map, Map<int,CCodeExpression>? carg_map) {
+ public override CCodeFormalParameter generate_parameter (FormalParameter param, CCodeFile decl_space, Map<int,CCodeFormalParameter> cparam_map, Map<int,CCodeExpression>? carg_map) {
if (!(param.variable_type is ArrayType)) {
- base.generate_parameter (param, decl_space, cparam_map, carg_map);
- return;
+ return base.generate_parameter (param, decl_space, cparam_map, carg_map);
}
string ctypename = param.variable_type.get_cname ();
@@ -992,13 +991,13 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
ctypename += "*";
}
- param.ccodenode = new CCodeFormalParameter (get_variable_cname (param.name), ctypename);
+ var main_cparam = new CCodeFormalParameter (get_variable_cname (param.name), ctypename);
var array_type = (ArrayType) param.variable_type;
generate_type_declaration (array_type.element_type, decl_space);
- cparam_map.set (get_param_pos (param.cparameter_position), (CCodeFormalParameter) param.ccodenode);
+ cparam_map.set (get_param_pos (param.cparameter_position), main_cparam);
if (carg_map != null) {
carg_map.set (get_param_pos (param.cparameter_position), get_variable_cexpression (param.name));
}
@@ -1020,5 +1019,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
}
}
}
+
+ return main_cparam;
}
}
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 4acbaa1..e6947b1 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -3037,8 +3037,6 @@ public class Vala.CCodeBaseModule : CodeGenerator {
public void emit_temp_var (LocalVariable local) {
var vardecl = new CCodeVariableDeclarator (local.name, null, local.variable_type.get_cdeclarator_suffix ());
- // sets #line
- local.ccodenode = vardecl;
var st = local.variable_type.data_type as Struct;
var array_type = local.variable_type as ArrayType;
@@ -4375,7 +4373,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
// null-terminated string array
var len_call = new CCodeFunctionCall (new CCodeIdentifier ("g_strv_length"));
len_call.add_argument (rv);
- expr.append_array_size (len_call);
+ append_array_size (expr, len_call);
} else if (to is StructValueType) {
var temp_decl = get_temp_variable (to, true, null, true);
emit_temp_var (temp_decl);
@@ -4430,7 +4428,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, get_variable_cexpression (temp_decl.name)));
cfunc.add_parameter (new CCodeFormalParameter (get_array_length_cname ("result", dim), "int*"));
- expr.append_array_size (get_variable_cexpression (temp_decl.name));
+ append_array_size (expr, get_variable_cexpression (temp_decl.name));
}
}
@@ -4506,7 +4504,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
var array_type = expr.type_reference as ArrayType;
if (array_type != null && expr.inner.value_type is ArrayType) {
for (int dim = 1; dim <= array_type.rank; dim++) {
- expr.append_array_size (get_array_length_cexpression (expr.inner, dim));
+ append_array_size (expr, get_array_length_cexpression (expr.inner, dim));
}
}
@@ -5435,19 +5433,11 @@ public class Vala.CCodeBaseModule : CodeGenerator {
}
}
- public CCodeExpression? get_cvalue (Expression expr) {
- return (CCodeExpression) expr.ccodenode;
- }
-
- public void set_cvalue (Expression expr, CCodeExpression? cvalue) {
- expr.ccodenode = cvalue;
- }
-
- public CCodeNode? get_ccodenode (CodeNode node) {
- if (node.ccodenode == null) {
+ public CCodeExpression? get_ccodenode (Expression node) {
+ if (get_cvalue (node) == null) {
node.emit (this);
}
- return node.ccodenode;
+ return get_cvalue (node);
}
public override void visit_class (Class cl) {
@@ -5655,6 +5645,85 @@ public class Vala.CCodeBaseModule : CodeGenerator {
public virtual void add_simple_check (CodeNode node, bool always_fails = false) {
}
+
+ public CCodeExpression? get_cvalue (Expression expr) {
+ if (expr.target_value == null) {
+ return null;
+ }
+ var glib_value = (GLibValue) expr.target_value;
+ return glib_value.ccodenode;
+ }
+
+ public void set_cvalue (Expression expr, CCodeExpression cvalue) {
+ var glib_value = (GLibValue) expr.target_value;
+ if (glib_value == null) {
+ glib_value = new GLibValue ();
+ expr.target_value = glib_value;
+ }
+ glib_value.ccodenode = cvalue;
+ }
+
+ public CCodeExpression? get_delegate_target (Expression expr) {
+ if (expr.target_value == null) {
+ return null;
+ }
+ var glib_value = (GLibValue) expr.target_value;
+ return glib_value.delegate_target;
+ }
+
+ public void set_delegate_target (Expression expr, CCodeExpression delegate_target) {
+ var glib_value = (GLibValue) expr.target_value;
+ if (glib_value == null) {
+ glib_value = new GLibValue ();
+ expr.target_value = glib_value;
+ }
+ glib_value.delegate_target = delegate_target;
+ }
+
+ public CCodeExpression? get_delegate_target_destroy_notify (Expression expr) {
+ if (expr.target_value == null) {
+ return null;
+ }
+ var glib_value = (GLibValue) expr.target_value;
+ return glib_value.delegate_target_destroy_notify;
+ }
+
+ public void set_delegate_target_destroy_notify (Expression expr, CCodeExpression destroy_notify) {
+ var glib_value = (GLibValue) expr.target_value;
+ if (glib_value == null) {
+ glib_value = new GLibValue ();
+ expr.target_value = glib_value;
+ }
+ glib_value.delegate_target_destroy_notify = destroy_notify;
+ }
+
+ public void append_array_size (Expression expr, CCodeExpression size) {
+ var glib_value = (GLibValue) expr.target_value;
+ if (glib_value == null) {
+ glib_value = new GLibValue ();
+ expr.target_value = glib_value;
+ }
+ if (glib_value.array_sizes == null) {
+ glib_value.array_sizes = new ArrayList<CCodeExpression> ();
+ }
+ glib_value.array_sizes.add (size);
+ }
+
+ public List<CCodeExpression>? get_array_sizes (Expression expr) {
+ var glib_value = (GLibValue) expr.target_value;
+ if (glib_value == null) {
+ glib_value = new GLibValue ();
+ expr.target_value = glib_value;
+ }
+ return glib_value.array_sizes;
+ }
}
-// vim:sw=8 noet
+public class Vala.GLibValue : TargetValue {
+ public CCodeExpression ccodenode;
+
+ public List<CCodeExpression> array_sizes;
+
+ public CCodeExpression? delegate_target;
+ public CCodeExpression? delegate_target_destroy_notify;
+}
diff --git a/codegen/valaccodedelegatemodule.vala b/codegen/valaccodedelegatemodule.vala
index 2102371..5fab0a1 100644
--- a/codegen/valaccodedelegatemodule.vala
+++ b/codegen/valaccodedelegatemodule.vala
@@ -48,9 +48,9 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
var cfundecl = new CCodeFunctionDeclarator (d.get_cname ());
foreach (FormalParameter param in d.get_parameters ()) {
- generate_parameter (param, decl_space, new HashMap<int,CCodeFormalParameter> (), null);
+ var cparam = generate_parameter (param, decl_space, new HashMap<int,CCodeFormalParameter> (), null);
- cfundecl.add_parameter ((CCodeFormalParameter) param.ccodenode);
+ cfundecl.add_parameter (cparam);
// handle array parameters
if (!param.no_array_length && param.variable_type is ArrayType) {
@@ -62,7 +62,7 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
}
for (int dim = 1; dim <= array_type.rank; dim++) {
- var cparam = new CCodeFormalParameter (get_parameter_array_length_cname (param, dim), length_ctype);
+ cparam = new CCodeFormalParameter (get_parameter_array_length_cname (param, dim), length_ctype);
cfundecl.add_parameter (cparam);
}
}
@@ -71,7 +71,7 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
var deleg_type = (DelegateType) param.variable_type;
var param_d = deleg_type.delegate_symbol;
if (param_d.has_target) {
- var cparam = new CCodeFormalParameter (get_delegate_target_cname (get_variable_cname (param.name)), "void*");
+ cparam = new CCodeFormalParameter (get_delegate_target_cname (get_variable_cname (param.name)), "void*");
cfundecl.add_parameter (cparam);
}
}
@@ -150,10 +150,10 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
if (delegate_expr is MethodCall) {
var invocation_expr = (MethodCall) delegate_expr;
- if (invocation_expr.delegate_target_destroy_notify != null) {
- delegate_target_destroy_notify = invocation_expr.delegate_target_destroy_notify;
+ if (get_delegate_target_destroy_notify (invocation_expr) != null) {
+ delegate_target_destroy_notify = get_delegate_target_destroy_notify (invocation_expr);
}
- return invocation_expr.delegate_target;
+ return get_delegate_target (invocation_expr);
} else if (delegate_expr is LambdaExpression) {
var lambda = (LambdaExpression) delegate_expr;
var delegate_type = (DelegateType) delegate_expr.target_type;
@@ -317,7 +317,7 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
return delegate_target;
}
} else if (delegate_expr.symbol_reference is Property) {
- return delegate_expr.delegate_target;
+ return get_delegate_target (delegate_expr);
}
}
@@ -377,7 +377,6 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
var function = new CCodeFunction (wrapper_name, return_type_cname);
function.modifiers = CCodeModifiers.STATIC;
- m.ccodenode = function;
var cparam_map = new HashMap<int,CCodeFormalParameter> (direct_hash, direct_equal);
@@ -462,7 +461,7 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
Report.error (expr != null ? expr.source_reference : null, "Cannot create delegate without target for instance method or closure");
arg = new CCodeConstant ("NULL");
} else {
- arg = new CCodeIdentifier ((d_params.get (0).ccodenode as CCodeFormalParameter).name);
+ arg = new CCodeIdentifier (d_params.get (0).name);
i = 1;
}
}
@@ -481,7 +480,7 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
}
CCodeExpression arg;
- arg = new CCodeIdentifier ((d_params.get (i).ccodenode as CCodeFormalParameter).name);
+ arg = new CCodeIdentifier (d_params.get (i).name);
carg_map.set (get_param_pos (param.cparameter_position), arg);
// handle array arguments
@@ -608,10 +607,9 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
return wrapper_name;
}
- public override void generate_parameter (FormalParameter param, CCodeFile decl_space, Map<int,CCodeFormalParameter> cparam_map, Map<int,CCodeExpression>? carg_map) {
+ public override CCodeFormalParameter generate_parameter (FormalParameter param, CCodeFile decl_space, Map<int,CCodeFormalParameter> cparam_map, Map<int,CCodeExpression>? carg_map) {
if (!(param.variable_type is DelegateType || param.variable_type is MethodType)) {
- base.generate_parameter (param, decl_space, cparam_map, carg_map);
- return;
+ return base.generate_parameter (param, decl_space, cparam_map, carg_map);
}
string ctypename = param.variable_type.get_cname ();
@@ -630,9 +628,9 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
target_destroy_notify_ctypename += "*";
}
- param.ccodenode = new CCodeFormalParameter (get_variable_cname (param.name), ctypename);
+ var main_cparam = new CCodeFormalParameter (get_variable_cname (param.name), ctypename);
- cparam_map.set (get_param_pos (param.cparameter_position), (CCodeFormalParameter) param.ccodenode);
+ cparam_map.set (get_param_pos (param.cparameter_position), main_cparam);
if (carg_map != null) {
carg_map.set (get_param_pos (param.cparameter_position), get_variable_cexpression (param.name));
}
@@ -664,5 +662,7 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
carg_map.set (get_param_pos (param.cdelegate_target_parameter_position), get_variable_cexpression (cparam.name));
}
}
+
+ return main_cparam;
}
}
diff --git a/codegen/valaccodememberaccessmodule.vala b/codegen/valaccodememberaccessmodule.vala
index 9b20ebe..c5be348 100644
--- a/codegen/valaccodememberaccessmodule.vala
+++ b/codegen/valaccodememberaccessmodule.vala
@@ -294,7 +294,7 @@ public class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
var ctemp = get_variable_cexpression (temp_var.name);
emit_temp_var (temp_var);
ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, ctemp));
- expr.append_array_size (ctemp);
+ append_array_size (expr, ctemp);
}
} else {
var delegate_type = base_property.property_type as DelegateType;
@@ -303,7 +303,7 @@ public class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
var ctemp = get_variable_cexpression (temp_var.name);
emit_temp_var (temp_var);
ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, ctemp));
- expr.delegate_target = ctemp;
+ set_delegate_target (expr, ctemp);
}
}
diff --git a/codegen/valaccodemethodcallmodule.vala b/codegen/valaccodemethodcallmodule.vala
index 5c6d483..5e318c1 100644
--- a/codegen/valaccodemethodcallmodule.vala
+++ b/codegen/valaccodemethodcallmodule.vala
@@ -546,7 +546,7 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
var len_call = new CCodeFunctionCall (new CCodeIdentifier ("_vala_array_length"));
len_call.add_argument (temp_ref);
- expr.append_array_size (len_call);
+ append_array_size (expr, len_call);
} else if (!m.no_array_length) {
LocalVariable temp_var;
@@ -561,9 +561,9 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
out_arg_map.set (get_param_pos (m.carray_length_parameter_position + 0.01 * dim), new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, temp_ref));
- expr.append_array_size (temp_ref);
+ append_array_size (expr, temp_ref);
} else {
- expr.append_array_size (new CCodeConstant ("-1"));
+ append_array_size (expr, new CCodeConstant ("-1"));
}
}
} else if (m != null && m.return_type is DelegateType && async_call != ccall) {
@@ -577,7 +577,7 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
out_arg_map.set (get_param_pos (m.cdelegate_target_parameter_position), new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, temp_ref));
- expr.delegate_target = temp_ref;
+ set_delegate_target (expr, temp_ref);
if (deleg_type.value_owned) {
temp_var = get_temp_variable (new DelegateType ((Delegate) context.root.scope.lookup ("GLib").scope.lookup ("DestroyNotify")));
@@ -587,7 +587,7 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
out_arg_map.set (get_param_pos (m.cdelegate_target_parameter_position + 0.01), new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, temp_ref));
- expr.delegate_target_destroy_notify = temp_ref;
+ set_delegate_target_destroy_notify (expr, temp_ref);
}
}
}
@@ -610,7 +610,7 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
var len_call = new CCodeFunctionCall (new CCodeIdentifier ("_vala_array_length"));
len_call.add_argument (temp_ref);
- expr.append_array_size (len_call);
+ append_array_size (expr, len_call);
} else if (!deleg.no_array_length) {
var temp_var = get_temp_variable (int_type);
var temp_ref = get_variable_cexpression (temp_var.name);
@@ -619,9 +619,9 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
out_arg_map.set (get_param_pos (deleg.carray_length_parameter_position + 0.01 * dim), new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, temp_ref));
- expr.append_array_size (temp_ref);
+ append_array_size (expr, temp_ref);
} else {
- expr.append_array_size (new CCodeConstant ("-1"));
+ append_array_size (expr, new CCodeConstant ("-1"));
}
}
} else if (deleg != null && deleg.return_type is DelegateType) {
@@ -635,7 +635,7 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
out_arg_map.set (get_param_pos (deleg.cdelegate_target_parameter_position), new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, temp_ref));
- expr.delegate_target = temp_ref;
+ set_delegate_target (expr, temp_ref);
}
}
diff --git a/codegen/valaccodemethodmodule.vala b/codegen/valaccodemethodmodule.vala
index 55c31e4..3b462c8 100644
--- a/codegen/valaccodemethodmodule.vala
+++ b/codegen/valaccodemethodmodule.vala
@@ -719,7 +719,8 @@ public class Vala.CCodeMethodModule : CCodeStructModule {
}
}
- public virtual void generate_parameter (FormalParameter param, CCodeFile decl_space, Map<int,CCodeFormalParameter> cparam_map, Map<int,CCodeExpression>? carg_map) {
+ public virtual CCodeFormalParameter generate_parameter (FormalParameter param, CCodeFile decl_space, Map<int,CCodeFormalParameter> cparam_map, Map<int,CCodeExpression>? carg_map) {
+ CCodeFormalParameter cparam;
if (!param.ellipsis) {
string ctypename = param.variable_type.get_cname ();
@@ -743,15 +744,17 @@ public class Vala.CCodeMethodModule : CCodeStructModule {
ctypename += "*";
}
- param.ccodenode = new CCodeFormalParameter (get_variable_cname (param.name), ctypename);
+ cparam = new CCodeFormalParameter (get_variable_cname (param.name), ctypename);
} else {
- param.ccodenode = new CCodeFormalParameter.with_ellipsis ();
+ cparam = new CCodeFormalParameter.with_ellipsis ();
}
- cparam_map.set (get_param_pos (param.cparameter_position, param.ellipsis), (CCodeFormalParameter) param.ccodenode);
+ cparam_map.set (get_param_pos (param.cparameter_position, param.ellipsis), cparam);
if (carg_map != null && !param.ellipsis) {
carg_map.set (get_param_pos (param.cparameter_position, param.ellipsis), get_variable_cexpression (param.name));
}
+
+ return cparam;
}
public override void generate_cparameters (Method m, CCodeFile decl_space, Map<int,CCodeFormalParameter> cparam_map, CCodeFunction func, CCodeFunctionDeclarator? vdeclarator = null, Map<int,CCodeExpression>? carg_map = null, CCodeFunctionCall? vcall = null, int direction = 3) {
diff --git a/codegen/valadbusservermodule.vala b/codegen/valadbusservermodule.vala
index cbf770d..edf5e5a 100644
--- a/codegen/valadbusservermodule.vala
+++ b/codegen/valadbusservermodule.vala
@@ -489,9 +489,9 @@ public class Vala.DBusServerModule : DBusClientModule {
foreach (var param in sig.get_parameters ()) {
// ensure ccodenode of parameter is set
- generate_parameter (param, cfile, new HashMap<int,CCodeFormalParameter> (), null);
+ var cparam = generate_parameter (param, cfile, new HashMap<int,CCodeFormalParameter> (), null);
- function.add_parameter ((CCodeFormalParameter) get_ccodenode (param));
+ function.add_parameter (cparam);
if (param.variable_type is ArrayType) {
var array_type = (ArrayType) param.variable_type;
for (int dim = 1; dim <= array_type.rank; dim++) {
diff --git a/codegen/valadovabasemodule.vala b/codegen/valadovabasemodule.vala
index 4c55c25..64fcfbc 100644
--- a/codegen/valadovabasemodule.vala
+++ b/codegen/valadovabasemodule.vala
@@ -1133,8 +1133,6 @@ public class Vala.DovaBaseModule : CodeGenerator {
var cdecl = new CCodeDeclaration (local.variable_type.get_cname ());
var vardecl = new CCodeVariableDeclarator (local.name, null, local.variable_type.get_cdeclarator_suffix ());
- // sets #line
- local.ccodenode = vardecl;
cdecl.add_declarator (vardecl);
var st = local.variable_type.data_type as Struct;
@@ -2231,19 +2229,11 @@ public class Vala.DovaBaseModule : CodeGenerator {
return null;
}
- public CCodeExpression? get_cvalue (Expression expr) {
- return (CCodeExpression) expr.ccodenode;
- }
-
- public void set_cvalue (Expression expr, CCodeExpression? cvalue) {
- expr.ccodenode = cvalue;
- }
-
- public CCodeNode? get_ccodenode (CodeNode node) {
- if (node.ccodenode == null) {
+ public CCodeExpression? get_ccodenode (Expression node) {
+ if (get_cvalue (node) == null) {
node.emit (this);
}
- return node.ccodenode;
+ return get_cvalue (node);
}
public DataType? get_this_type () {
@@ -2269,4 +2259,25 @@ public class Vala.DovaBaseModule : CodeGenerator {
public virtual void add_simple_check (CodeNode node, bool always_fails = false) {
}
+
+ public CCodeExpression? get_cvalue (Expression expr) {
+ if (expr.target_value == null) {
+ return null;
+ }
+ var dova_value = (DovaValue) expr.target_value;
+ return dova_value.ccodenode;
+ }
+
+ public void set_cvalue (Expression expr, CCodeExpression cvalue) {
+ var dova_value = (DovaValue) expr.target_value;
+ if (dova_value == null) {
+ dova_value = new DovaValue ();
+ expr.target_value = dova_value;
+ }
+ dova_value.ccodenode = cvalue;
+ }
+}
+
+public class Vala.DovaValue : TargetValue {
+ public CCodeExpression ccodenode;
}
diff --git a/codegen/valagdbusservermodule.vala b/codegen/valagdbusservermodule.vala
index 9ac6487..abe9ed1 100644
--- a/codegen/valagdbusservermodule.vala
+++ b/codegen/valagdbusservermodule.vala
@@ -375,9 +375,9 @@ public class Vala.GDBusServerModule : GDBusClientModule {
foreach (var param in sig.get_parameters ()) {
// ensure ccodenode of parameter is set
- generate_parameter (param, cfile, new HashMap<int,CCodeFormalParameter> (), null);
+ var cparam = generate_parameter (param, cfile, new HashMap<int,CCodeFormalParameter> (), null);
- function.add_parameter ((CCodeFormalParameter) get_ccodenode (param));
+ function.add_parameter (cparam);
if (param.variable_type is ArrayType) {
var array_type = (ArrayType) param.variable_type;
for (int dim = 1; dim <= array_type.rank; dim++) {
diff --git a/codegen/valagtypemodule.vala b/codegen/valagtypemodule.vala
index bca6263..6612f86 100644
--- a/codegen/valagtypemodule.vala
+++ b/codegen/valagtypemodule.vala
@@ -24,10 +24,9 @@
public class Vala.GTypeModule : GErrorModule {
- public override void generate_parameter (FormalParameter param, CCodeFile decl_space, Map<int,CCodeFormalParameter> cparam_map, Map<int,CCodeExpression>? carg_map) {
+ public override CCodeFormalParameter generate_parameter (FormalParameter param, CCodeFile decl_space, Map<int,CCodeFormalParameter> cparam_map, Map<int,CCodeExpression>? carg_map) {
if (!(param.variable_type is ObjectType)) {
- base.generate_parameter (param, decl_space, cparam_map, carg_map);
- return;
+ return base.generate_parameter (param, decl_space, cparam_map, carg_map);
}
generate_type_declaration (param.variable_type, decl_space);
@@ -38,12 +37,14 @@ public class Vala.GTypeModule : GErrorModule {
ctypename += "*";
}
- param.ccodenode = new CCodeFormalParameter (get_variable_cname (param.name), ctypename);
+ var cparam = new CCodeFormalParameter (get_variable_cname (param.name), ctypename);
- cparam_map.set (get_param_pos (param.cparameter_position), (CCodeFormalParameter) param.ccodenode);
+ cparam_map.set (get_param_pos (param.cparameter_position), cparam);
if (carg_map != null) {
carg_map.set (get_param_pos (param.cparameter_position), get_variable_cexpression (param.name));
}
+
+ return cparam;
}
public override void generate_class_declaration (Class cl, CCodeFile decl_space) {
diff --git a/vala/Makefile.am b/vala/Makefile.am
index 83acbd5..a2e0ede 100644
--- a/vala/Makefile.am
+++ b/vala/Makefile.am
@@ -141,6 +141,7 @@ libvalacore_la_VALASOURCES = \
valaswitchstatement.vala \
valasymbol.vala \
valasymbolresolver.vala \
+ valatargetvalue.vala \
valatemplate.vala \
valathrowstatement.vala \
valatokentype.vala \
diff --git a/vala/valacodenode.vala b/vala/valacodenode.vala
index 0b047c0..62508c7 100644
--- a/vala/valacodenode.vala
+++ b/vala/valacodenode.vala
@@ -50,24 +50,6 @@ public abstract class Vala.CodeNode {
public string type_name {
get { return Type.from_instance (this).name (); }
}
-
- /**
- * Generated CCodeNode that corresponds to this code node.
- */
- public CCodeNode? ccodenode {
- get {
- return _ccodenode;
- }
- set {
- if (value != null && source_reference != null && CodeContext.get ().debug) {
- value.line = new CCodeLineDirective (
- Path.get_basename (source_reference.file.filename),
- source_reference.first_line);
- }
-
- _ccodenode = value;
- }
- }
public bool checked { get; set; }
@@ -86,8 +68,6 @@ public abstract class Vala.CodeNode {
private List<DataType> _error_types;
private static List<DataType> _empty_type_list;
- private CCodeNode? _ccodenode;
-
static int last_temp_nr = 0;
/**
diff --git a/vala/valaexpression.vala b/vala/valaexpression.vala
index eafb202..dd005af 100644
--- a/vala/valaexpression.vala
+++ b/vala/valaexpression.vala
@@ -55,10 +55,7 @@ public abstract class Vala.Expression : CodeNode {
*/
public bool lvalue { get; set; }
- private List<CCodeExpression> array_sizes;
-
- public CCodeExpression? delegate_target { get; set; }
- public CCodeExpression? delegate_target_destroy_notify { get; set; }
+ public TargetValue? target_value { get; set; }
/**
* Returns whether this expression is constant, i.e. whether this
@@ -81,24 +78,6 @@ public abstract class Vala.Expression : CodeNode {
return false;
}
- /**
- * Add an array size C code expression.
- */
- public void append_array_size (CCodeExpression size) {
- if (array_sizes == null) {
- array_sizes = new ArrayList<CCodeExpression> ();
- }
- array_sizes.add (size);
- }
-
- /**
- * Get the C code expression for array sizes for all dimensions
- * ascending from left to right.
- */
- public List<CCodeExpression>? get_array_sizes () {
- return array_sizes;
- }
-
public Statement? parent_statement {
get {
var expr = parent_node as Expression;
diff --git a/vala/valatargetvalue.vala b/vala/valatargetvalue.vala
new file mode 100644
index 0000000..e84913a
--- /dev/null
+++ b/vala/valatargetvalue.vala
@@ -0,0 +1,25 @@
+/* valatargetvalue.vala
+ *
+ * Copyright (C) 2010 Jürg Billeter
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Author:
+ * Jürg Billeter <j bitron ch>
+ */
+
+public abstract class Vala.TargetValue {
+ public DataType value_type { get; set; }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]