[vala/wip/attributes: 28/119] codegen: Add get_ccode_no_array_length
- From: Luca Bruno <lucabru src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/attributes: 28/119] codegen: Add get_ccode_no_array_length
- Date: Mon, 4 Jul 2011 10:24:27 +0000 (UTC)
commit 3c3c3e84863b45c097ebd52d48266ccedfc65b6f
Author: Luca Bruno <lucabru src gnome org>
Date: Tue Jun 28 16:25:33 2011 +0200
codegen: Add get_ccode_no_array_length
codegen/valaccodearraymodule.vala | 2 +-
codegen/valaccodeassignmentmodule.vala | 4 +-
codegen/valaccodebasemodule.vala | 31 +++++++++++++++++++----------
codegen/valaccodedelegatemodule.vala | 21 ++++++++++++-------
codegen/valaccodememberaccessmodule.vala | 12 +++++-----
codegen/valaccodemethodcallmodule.vala | 8 +++---
codegen/valaccodemethodmodule.vala | 2 +-
codegen/valaccodestructmodule.vala | 2 +-
codegen/valagasyncmodule.vala | 6 ++--
codegen/valagtypemodule.vala | 4 +-
10 files changed, 53 insertions(+), 39 deletions(-)
---
diff --git a/codegen/valaccodearraymodule.vala b/codegen/valaccodearraymodule.vala
index 59d569e..1f2dd56 100644
--- a/codegen/valaccodearraymodule.vala
+++ b/codegen/valaccodearraymodule.vala
@@ -732,7 +732,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
carg_map.set (get_param_pos (param.cparameter_position), get_variable_cexpression (param.name));
}
- if (!param.no_array_length) {
+ if (!get_ccode_no_array_length (param)) {
string length_ctype = "int";
if (param.array_length_type != null) {
length_ctype = param.array_length_type;
diff --git a/codegen/valaccodeassignmentmodule.vala b/codegen/valaccodeassignmentmodule.vala
index de8eaa0..53826e7 100644
--- a/codegen/valaccodeassignmentmodule.vala
+++ b/codegen/valaccodeassignmentmodule.vala
@@ -38,7 +38,7 @@ public class Vala.CCodeAssignmentModule : CCodeMemberAccessModule {
bool array = false;
bool instance_delegate = false;
if (assignment.left.value_type is ArrayType) {
- array = !(variable is Field) || !variable.no_array_length;
+ array = !(variable is Field) || !get_ccode_no_array_length (variable);
} else if (assignment.left.value_type is DelegateType) {
var delegate_type = (DelegateType) assignment.left.value_type;
if (delegate_type.delegate_symbol.has_target) {
@@ -67,7 +67,7 @@ public class Vala.CCodeAssignmentModule : CCodeMemberAccessModule {
ccode.add_expression (destroy_value (value));
}
- if (array && !variable.no_array_length && !variable.array_null_terminated) {
+ if (array && !get_ccode_no_array_length (variable) && !variable.array_null_terminated) {
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);
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index c7aaa0d..0e5b0f2 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -891,7 +891,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
decl_space.add_type_member_declaration (flock);
}
- if (f.variable_type is ArrayType && !f.no_array_length) {
+ if (f.variable_type is ArrayType && !get_ccode_no_array_length (get_ccode) (f)) {
var array_type = (ArrayType) f.variable_type;
if (!array_type.fixed_length) {
@@ -967,7 +967,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
ccode.add_assignment (lhs, rhs);
- if (f.variable_type is ArrayType && !f.no_array_length &&
+ if (f.variable_type is ArrayType && !get_ccode_no_array_length (get_ccode) (f) &&
f.initializer is ArrayCreationExpression) {
var array_type = (ArrayType) f.variable_type;
var field_value = get_field_cvalue (f, load_this_parameter ((TypeSymbol) f.parent_symbol));
@@ -1072,7 +1072,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
cfile.add_type_member_declaration (var_def);
/* add array length fields where necessary */
- if (f.variable_type is ArrayType && !f.no_array_length) {
+ if (f.variable_type is ArrayType && !get_ccode_no_array_length (get_ccode) (f)) {
var array_type = (ArrayType) f.variable_type;
if (!array_type.fixed_length) {
@@ -1145,7 +1145,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
ccode.add_assignment (lhs, rhs);
}
- if (f.variable_type is ArrayType && !f.no_array_length &&
+ if (f.variable_type is ArrayType && !get_ccode_no_array_length (f) &&
f.initializer is ArrayCreationExpression) {
var array_type = (ArrayType) f.variable_type;
var field_value = get_field_cvalue (f, null);
@@ -1660,7 +1660,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
var array_type = param.variable_type as ArrayType;
var deleg_type = param.variable_type as DelegateType;
- if (array_type != null && !param.no_array_length) {
+ if (array_type != null && !get_ccode_no_array_length (param)) {
for (int dim = 1; dim <= array_type.rank; dim++) {
data.add_field ("gint", get_parameter_array_length_cname (param, dim));
}
@@ -2138,7 +2138,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
clist.append (cexpr);
var array_type = field.variable_type as ArrayType;
- if (array_type != null && !field.no_array_length && !field.array_null_terminated) {
+ if (array_type != null && !get_ccode_no_array_length (field) && !field.array_null_terminated) {
for (int dim = 1; dim <= array_type.rank; dim++) {
clist.append (get_array_length_cvalue (expr.target_value, dim));
}
@@ -3184,7 +3184,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
ccode.close ();
var array_type = param.variable_type as ArrayType;
- if (array_type != null && !array_type.fixed_length && !param.no_array_length) {
+ if (array_type != null && !array_type.fixed_length && !get_ccode_no_array_length (param)) {
for (int dim = 1; dim <= array_type.rank; dim++) {
ccode.open_if (get_variable_cexpression (get_parameter_array_length_cname (param, dim)));
ccode.add_assignment (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, get_variable_cexpression (get_parameter_array_length_cname (param, dim))), get_array_length_cvalue (value));
@@ -3210,7 +3210,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
}
// return array length if appropriate
- if (((current_method != null && !current_method.no_array_length) || current_property_accessor != null) && current_return_type is ArrayType) {
+ if (((current_method != null && !get_ccode_no_array_length (current_method) || current_property_accessor != null) && current_return_type is ArrayType) {
var return_expr_decl = get_temp_variable (stmt.return_expression.value_type, true, stmt, false);
ccode.add_assignment (get_variable_cexpression (return_expr_decl.name), get_cvalue (stmt.return_expression));
@@ -4150,7 +4150,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
cexpr = csizeof;
}
- if (!param.no_array_length && param.variable_type is ArrayType) {
+ if (!get_ccode_no_array_length (param) && param.variable_type is ArrayType) {
var array_type = (ArrayType) param.variable_type;
for (int dim = 1; dim <= array_type.rank; dim++) {
carg_map.set (get_param_pos (param.carray_length_parameter_position + 0.01 * dim), get_array_length_cexpression (arg, dim));
@@ -5374,7 +5374,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
var array_type = prop.property_type as ArrayType;
- if (array_type != null && !prop.no_array_length) {
+ if (array_type != null && !get_ccode_no_array_length (prop)) {
var temp_var = get_temp_variable (prop.property_type, true, null, false);
emit_temp_var (temp_var);
ccode.add_assignment (get_variable_cexpression (temp_var.name), cexpr);
@@ -5383,7 +5383,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
ccall.add_argument (cexpr);
}
- if (array_type != null && !prop.no_array_length) {
+ if (array_type != null && !get_ccode_no_array_length (prop)) {
for (int dim = 1; dim <= array_type.rank; dim++) {
ccall.add_argument (get_array_length_cvalue (value, dim));
}
@@ -5717,6 +5717,10 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
}
}
+ public static bool get_ccode_no_array_length (CodeNode node) {
+ return get_ccode_attribute(sym).no_array_length;
+ }
+
public override void visit_class (Class cl) {
}
@@ -6260,6 +6264,8 @@ public class Vala.CCodeAttribute : AttributeCache {
}
}
+ public bool no_array_length { get; private set; }
+
private string _name;
private string _const_name;
private string _type_name;
@@ -6318,6 +6324,9 @@ public class Vala.CCodeAttribute : AttributeCache {
_take_value_function = attr.get_string ("take_value_function");
_param_spec_function = attr.get_string ("param_spec_function");
_default_value = attr.get_string ("default_value");
+ if (attr.has_argument ("array_length")) {
+ no_array_length = !attr.get_bool ("array_length");
+ }
}
}
diff --git a/codegen/valaccodedelegatemodule.vala b/codegen/valaccodedelegatemodule.vala
index 761de09..26f1897 100644
--- a/codegen/valaccodedelegatemodule.vala
+++ b/codegen/valaccodedelegatemodule.vala
@@ -53,7 +53,7 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
cfundecl.add_parameter (cparam);
// handle array parameters
- if (!param.no_array_length && param.variable_type is ArrayType) {
+ if (!get_ccode_no_array_length (param) && param.variable_type is ArrayType) {
var array_type = (ArrayType) param.variable_type;
var length_ctype = "int";
@@ -80,7 +80,7 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
}
}
}
- if (!d.no_array_length && d.return_type is ArrayType) {
+ if (!get_ccode_no_array_length (d) && d.return_type is ArrayType) {
// return array length if appropriate
var array_type = (ArrayType) d.return_type;
var array_length_type = d.array_length_type != null ? d.array_length_type : "int";
@@ -225,13 +225,18 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
&& param.variable_type is ArrayType
&& ((ArrayType) param.variable_type).element_type.data_type == string_type.data_type) {
// use null-terminated string arrays for dynamic signals for compatibility reasons
- param.no_array_length = true;
+ var a = param.get_attribute ("CCode");
+ if (a == null) {
+ a = new Attribute ("CCode", param.source_reference);
+ param.attributes.append (a);
+ }
+ a.add_argument ("array_length", "false");
param.array_null_terminated = true;
}
generate_parameter (param, cfile, cparam_map, null);
}
- if (!d.no_array_length && d.return_type is ArrayType) {
+ if (!get_ccode_no_array_length (d) && d.return_type is ArrayType) {
// return array length if appropriate
var array_type = (ArrayType) d.return_type;
var array_length_type = d.array_length_type != null ? d.array_length_type : "int";
@@ -319,7 +324,7 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
carg_map.set (get_param_pos (param.cparameter_position), arg);
// handle array arguments
- if (!param.no_array_length && param.variable_type is ArrayType) {
+ if (!get_ccode_no_array_length (param) && param.variable_type is ArrayType) {
var array_type = (ArrayType) param.variable_type;
for (int dim = 1; dim <= array_type.rank; dim++) {
CCodeExpression clength;
@@ -328,7 +333,7 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
var len_call = new CCodeFunctionCall (new CCodeIdentifier ("_vala_array_length"));
len_call.add_argument (new CCodeIdentifier (d_params.get (i).name));
clength = len_call;
- } else if (d_params.get (i).no_array_length) {
+ } else if (get_ccode_no_array_length (d_params.get (i))) {
clength = new CCodeConstant ("-1");
} else {
clength = new CCodeIdentifier (get_parameter_array_length_cname (d_params.get (i), dim));
@@ -350,11 +355,11 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
i++;
}
- if (!m.no_array_length && m.return_type is ArrayType) {
+ if (!get_ccode_no_array_length (m) && m.return_type is ArrayType) {
var array_type = (ArrayType) m.return_type;
for (int dim = 1; dim <= array_type.rank; dim++) {
CCodeExpression clength;
- if (d.no_array_length) {
+ if (get_ccode_no_array_length (d)) {
clength = new CCodeConstant ("NULL");
} else {
clength = new CCodeIdentifier (get_array_length_cname ("result", dim));
diff --git a/codegen/valaccodememberaccessmodule.vala b/codegen/valaccodememberaccessmodule.vala
index 82decf0..c56af5e 100644
--- a/codegen/valaccodememberaccessmodule.vala
+++ b/codegen/valaccodememberaccessmodule.vala
@@ -257,7 +257,7 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
ccode.add_assignment (ctemp, ccall);
array_type = base_property.property_type as ArrayType;
- if (array_type != null && !base_property.no_array_length) {
+ if (array_type != null && !get_ccode_no_array_length (base_property)) {
for (int dim = 1; dim <= array_type.rank; dim++) {
temp_var = get_temp_variable (int_type);
ctemp = get_variable_cexpression (temp_var.name);
@@ -434,7 +434,7 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
block = ((Method) param.parent_symbol).body;
}
result.cvalue = new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (get_block_id (block))), get_variable_cname (param.name));
- if (array_type != null && !param.no_array_length) {
+ if (array_type != null && !get_ccode_no_array_length (param)) {
for (int dim = 1; dim <= array_type.rank; dim++) {
result.append_array_length_cvalue (new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (get_block_id (block))), get_parameter_array_length_cname (param, dim)));
}
@@ -492,7 +492,7 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
}
}
if (!param.captured && array_type != null) {
- if (!param.no_array_length && !param.array_null_terminated) {
+ if (!get_ccode_no_array_length (param) && !param.array_null_terminated) {
for (int dim = 1; dim <= array_type.rank; dim++) {
CCodeExpression length_expr = get_variable_cexpression (get_parameter_array_length_cname (param, dim));
if (param.direction == ParameterDirection.OUT) {
@@ -553,7 +553,7 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
result.cvalue = new CCodeMemberAccess (inst, get_ccode_name (field));
}
- if (array_type != null && !field.no_array_length) {
+ if (array_type != null && !get_ccode_no_array_length (field)) {
for (int dim = 1; dim <= array_type.rank; dim++) {
CCodeExpression length_expr = null;
@@ -633,7 +633,7 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
result.cvalue = new CCodeIdentifier (get_ccode_name (field));
- if (array_type != null && !field.no_array_length) {
+ if (array_type != null && !get_ccode_no_array_length (field)) {
for (int dim = 1; dim <= array_type.rank; dim++) {
string length_cname;
if (field.has_array_length_cname) {
@@ -678,7 +678,7 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
result.array_length_cvalues = null;
result.append_array_length_cvalue (length_expr);
- } else if (variable.no_array_length) {
+ } else if (get_ccode_no_array_length (variable)) {
result.array_length_cvalues = null;
for (int dim = 1; dim <= array_type.rank; dim++) {
result.append_array_length_cvalue (new CCodeConstant ("-1"));
diff --git a/codegen/valaccodemethodcallmodule.vala b/codegen/valaccodemethodcallmodule.vala
index ce9da2e..011a689 100644
--- a/codegen/valaccodemethodcallmodule.vala
+++ b/codegen/valaccodemethodcallmodule.vala
@@ -333,7 +333,7 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
var unary = arg as UnaryExpression;
if (unary == null || unary.operator != UnaryOperator.OUT) {
- if (!param.no_array_length && param.variable_type is ArrayType) {
+ if (!get_ccode_no_array_length (param) && param.variable_type is ArrayType) {
var array_type = (ArrayType) param.variable_type;
for (int dim = 1; dim <= array_type.rank; dim++) {
CCodeExpression? array_length_expr = null;
@@ -396,7 +396,7 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
cexpr = new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, get_cvalue (arg));
- if (!param.no_array_length && param.variable_type is ArrayType) {
+ if (!get_ccode_no_array_length (param) && param.variable_type is ArrayType) {
var array_type = (ArrayType) param.variable_type;
var array_length_type = int_type;
if (param.array_length_type != null) {
@@ -478,7 +478,7 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
len_call.add_argument (temp_ref);
append_array_length (expr, len_call);
- } else if (!m.no_array_length) {
+ } else if (!get_ccode_no_array_length (m)) {
LocalVariable temp_var;
if (m.array_length_type == null) {
@@ -546,7 +546,7 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
len_call.add_argument (temp_ref);
append_array_length (expr, len_call);
- } else if (!deleg.no_array_length) {
+ } else if (!get_ccode_no_array_length (deleg)) {
var temp_var = get_temp_variable (int_type);
var temp_ref = get_variable_cexpression (temp_var.name);
diff --git a/codegen/valaccodemethodmodule.vala b/codegen/valaccodemethodmodule.vala
index 7b9afc2..44beb73 100644
--- a/codegen/valaccodemethodmodule.vala
+++ b/codegen/valaccodemethodmodule.vala
@@ -78,7 +78,7 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
if (carg_map != null) {
carg_map.set (get_param_pos (-3), get_result_cexpression ());
}
- } else if (!m.no_array_length && m.return_type is ArrayType) {
+ } else if (!get_ccode_no_array_length (m) && m.return_type is ArrayType) {
// return array length if appropriate
var array_type = (ArrayType) m.return_type;
var array_length_type = m.array_length_type != null ? m.array_length_type : "int";
diff --git a/codegen/valaccodestructmodule.vala b/codegen/valaccodestructmodule.vala
index 6f8a7ad..f6b1d2c 100644
--- a/codegen/valaccodestructmodule.vala
+++ b/codegen/valaccodestructmodule.vala
@@ -71,7 +71,7 @@ public abstract class Vala.CCodeStructModule : CCodeBaseModule {
generate_type_declaration (f.variable_type, decl_space);
instance_struct.add_field (field_ctype, get_ccode_name (f) + f.variable_type.get_cdeclarator_suffix (), f.deprecated ? " G_GNUC_DEPRECATED" : null);
- if (f.variable_type is ArrayType && !f.no_array_length) {
+ if (f.variable_type is ArrayType && !get_ccode_no_array_length (f)) {
// create fields to store array dimensions
var array_type = (ArrayType) f.variable_type;
diff --git a/codegen/valagasyncmodule.vala b/codegen/valagasyncmodule.vala
index 52704e6..a9c3822 100644
--- a/codegen/valagasyncmodule.vala
+++ b/codegen/valagasyncmodule.vala
@@ -50,7 +50,7 @@ public class Vala.GAsyncModule : GSignalModule {
if (param.variable_type is ArrayType) {
var array_type = (ArrayType) param.variable_type;
- if (!param.no_array_length) {
+ if (!get_ccode_no_array_length (param)) {
for (int dim = 1; dim <= array_type.rank; dim++) {
data.add_field ("gint", get_parameter_array_length_cname (param, dim));
}
@@ -70,7 +70,7 @@ public class Vala.GAsyncModule : GSignalModule {
data.add_field (get_ccode_name (m.return_type), "result");
if (m.return_type is ArrayType) {
var array_type = (ArrayType) m.return_type;
- if (!m.no_array_length) {
+ if (!get_ccode_no_array_length (m)) {
for (int dim = 1; dim <= array_type.rank; dim++) {
data.add_field ("gint", get_array_length_cname ("result", dim));
}
@@ -436,7 +436,7 @@ public class Vala.GAsyncModule : GSignalModule {
ccode.add_assignment (new CCodeIdentifier ("result"), new CCodeMemberAccess.pointer (data_var, "result"));
if (return_type is ArrayType) {
var array_type = (ArrayType) return_type;
- if (!m.no_array_length) {
+ if (!get_ccode_no_array_length (m)) {
for (int dim = 1; dim <= array_type.rank; dim++) {
ccode.add_assignment (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, new CCodeIdentifier (get_array_length_cname ("result", dim))), new CCodeMemberAccess.pointer (data_var, get_array_length_cname ("result", dim)));
}
diff --git a/codegen/valagtypemodule.vala b/codegen/valagtypemodule.vala
index fabc6ce..122985c 100644
--- a/codegen/valagtypemodule.vala
+++ b/codegen/valagtypemodule.vala
@@ -313,7 +313,7 @@ public class Vala.GTypeModule : GErrorModule {
generate_type_declaration (f.variable_type, decl_space);
instance_struct.add_field (field_ctype, get_ccode_name (f), f.variable_type.get_cdeclarator_suffix ());
- if (f.variable_type is ArrayType && !f.no_array_length) {
+ if (f.variable_type is ArrayType && !get_ccode_no_array_length (f)) {
// create fields to store array dimensions
var array_type = (ArrayType) f.variable_type;
@@ -420,7 +420,7 @@ public class Vala.GTypeModule : GErrorModule {
generate_type_declaration (f.variable_type, decl_space);
instance_priv_struct.add_field (field_ctype, get_ccode_name (f), f.variable_type.get_cdeclarator_suffix ());
- if (f.variable_type is ArrayType && !f.no_array_length) {
+ if (f.variable_type is ArrayType && !get_ccode_no_array_length (f)) {
// create fields to store array dimensions
var array_type = (ArrayType) f.variable_type;
var len_type = int_type.copy ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]