[vala/emit-let: 1/4] codegen: Guard access to array length of TargetValue
- From: Luca Bruno <lucabru src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/emit-let: 1/4] codegen: Guard access to array length of TargetValue
- Date: Thu, 20 Jan 2011 08:50:55 +0000 (UTC)
commit 2be2dc12ce6c16b7fc5151c1f6247a2c20f8540d
Author: Luca Bruno <lucabru src gnome org>
Date: Thu Jan 20 00:31:41 2011 +0100
codegen: Guard access to array length of TargetValue
codegen/valaccodeassignmentmodule.vala | 8 +++-----
codegen/valaccodebasemodule.vala | 32 +++++++++++++++++++-------------
2 files changed, 22 insertions(+), 18 deletions(-)
---
diff --git a/codegen/valaccodeassignmentmodule.vala b/codegen/valaccodeassignmentmodule.vala
index cf8e217..08d4544 100644
--- a/codegen/valaccodeassignmentmodule.vala
+++ b/codegen/valaccodeassignmentmodule.vala
@@ -67,7 +67,7 @@ public class Vala.CCodeAssignmentModule : CCodeMemberAccessModule {
ccode.add_expression (get_unref_expression (lhs, assignment.left.value_type, assignment.left));
}
- if (array) {
+ if (array && has_array_length (assignment.left.target_value)) {
var array_type = (ArrayType) assignment.left.value_type;
for (int dim = 1; dim <= array_type.rank; dim++) {
var lhs_array_len = get_array_length_cexpression (assignment.left, dim);
@@ -195,11 +195,9 @@ public class Vala.CCodeAssignmentModule : CCodeMemberAccessModule {
ccopy.add_argument (get_cvalue_ (value));
ccopy.add_argument (size);
ccode.add_expression (ccopy);
- } else {
+ } else if (has_array_length (lvalue)) {
for (int dim = 1; dim <= array_type.rank; dim++) {
- if (get_array_length_cvalue (lvalue, dim) != null) {
- ccode.add_assignment (get_array_length_cvalue (lvalue, dim), get_array_length_cvalue (value, dim));
- }
+ ccode.add_assignment (get_array_length_cvalue (lvalue, dim), get_array_length_cvalue (value, dim));
}
if (array_type.rank == 1) {
if (get_array_size_cvalue (lvalue) != null) {
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 00b1f40..3c0ae16 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -2886,7 +2886,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
ccall.add_argument (new CCodeConstant ("TRUE"));
} else if (type is ArrayType) {
var array_type = (ArrayType) type;
- if (requires_destroy (array_type.element_type)) {
+ if (requires_destroy (array_type.element_type) && has_array_length (value)) {
CCodeExpression csizeexpr = null;
bool first = true;
for (int dim = 1; dim <= array_type.rank; dim++) {
@@ -3168,13 +3168,15 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
var array_type = (ArrayType) current_return_type;
- for (int dim = 1; dim <= array_type.rank; dim++) {
- var len_l = get_result_cexpression (get_array_length_cname ("result", dim));
- if (!is_in_coroutine ()) {
- len_l = new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, len_l);
+ if (has_array_length (stmt.return_expression.target_value)) {
+ for (int dim = 1; dim <= array_type.rank; dim++) {
+ var len_l = get_result_cexpression (get_array_length_cname ("result", dim));
+ if (!is_in_coroutine ()) {
+ len_l = new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, len_l);
+ }
+ var len_r = get_array_length_cexpression (stmt.return_expression, dim);
+ ccode.add_assignment (len_l, len_r);
}
- var len_r = get_array_length_cexpression (stmt.return_expression, dim);
- ccode.add_assignment (len_l, len_r);
}
set_cvalue (stmt.return_expression, get_variable_cexpression (return_expr_decl.name));
@@ -3775,7 +3777,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
ccall.add_argument (ctemp);
}
- if (expression_type is ArrayType) {
+ if (expression_type is ArrayType && has_array_length (expr.target_value)) {
var array_type = (ArrayType) expression_type;
bool first = true;
CCodeExpression csizeexpr = null;
@@ -4329,7 +4331,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
set_cvalue (expr, new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, get_cvalue (expr.inner)));
var array_type = expr.value_type as ArrayType;
- if (array_type != null) {
+ if (array_type != null && has_array_length (expr.inner.target_value)) {
for (int dim = 1; dim <= array_type.rank; dim++) {
append_array_length (expr, new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, get_array_length_cexpression (expr.inner, dim)));
}
@@ -4514,7 +4516,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
// retain array length
var array_type = expr.type_reference as ArrayType;
- if (array_type != null && expr.inner.value_type is ArrayType) {
+ if (array_type != null && has_array_length (expr.inner.target_value)) {
for (int dim = 1; dim <= array_type.rank; dim++) {
append_array_length (expr, get_array_length_cexpression (expr.inner, dim));
}
@@ -4583,7 +4585,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
set_cvalue (expr, cvar);
var array_type = expr.value_type as ArrayType;
- if (array_type != null) {
+ if (array_type != null && has_array_length (expr.inner.target_value)) {
for (int dim = 1; dim <= array_type.rank; dim++) {
append_array_length (expr, get_array_length_cexpression (expr.inner, dim));
}
@@ -5045,7 +5047,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
ccode.add_assignment (get_variable_cexpression (decl.name), cexpr);
cexpr = get_variable_cexpression (decl.name);
- if (expression_type is ArrayType && expr != null) {
+ if (expression_type is ArrayType && expr != null && has_array_length (expr.target_value)) {
var array_type = (ArrayType) expression_type;
for (int dim = 1; dim <= array_type.rank; dim++) {
var len_decl = new LocalVariable (int_type.copy (), get_array_length_cname (decl.name, dim));
@@ -5129,7 +5131,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
cfunc.modifiers = CCodeModifiers.STATIC;
cfunc.add_parameter (new CCodeParameter ("value", expression_type.get_cname ()));
- if (expression_type is ArrayType) {
+ if (expression_type is ArrayType && has_array_length (expr.target_value)) {
// return array length if appropriate
var array_type = (ArrayType) expression_type;
@@ -5838,6 +5840,10 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
}
return glib_value.array_length_cvalues;
}
+
+ public bool has_array_length (TargetValue value) {
+ return value != null && ((GLibValue) value).array_length_cvalues != null;
+ }
}
public class Vala.GLibValue : TargetValue {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]