[vala] Arrays: Add array_length_type annotation to methods
- From: Jürg Billeter <juergbi src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [vala] Arrays: Add array_length_type annotation to methods
- Date: Sat, 15 Aug 2009 12:09:33 +0000 (UTC)
commit 74f2e47906a490f6ae11c058818afc761709a34c
Author: Mark Lee <marklee src gnome org>
Date: Wed Aug 12 13:53:25 2009 -0700
Arrays: Add array_length_type annotation to methods
Adds support for the array_length_type CCode annotation, which allows
methods with non-int array length parameters to be declared properly.
Fixes possible crashes.
Also adds Vala.CType, to work around the temporary variable type
limitations.
This fix only works with array return types, not with array parameters.
Partially fixes bug 529866.
codegen/Makefile.am | 1 +
codegen/valaccodemethodcallmodule.vala | 8 +++++-
codegen/valactype.vala | 43 ++++++++++++++++++++++++++++++++
vala/valamethod.vala | 8 ++++++
4 files changed, 59 insertions(+), 1 deletions(-)
---
diff --git a/codegen/Makefile.am b/codegen/Makefile.am
index 5a6dc0f..8f9401f 100644
--- a/codegen/Makefile.am
+++ b/codegen/Makefile.am
@@ -28,6 +28,7 @@ libvala_la_VALASOURCES = \
valaccodemodule.vala \
valaccodestructmodule.vala \
valaclassregisterfunction.vala \
+ valactype.vala \
valadbusclientmodule.vala \
valadbusinterfaceregisterfunction.vala \
valadbusmodule.vala \
diff --git a/codegen/valaccodemethodcallmodule.vala b/codegen/valaccodemethodcallmodule.vala
index de38521..519d5d6 100644
--- a/codegen/valaccodemethodcallmodule.vala
+++ b/codegen/valaccodemethodcallmodule.vala
@@ -456,7 +456,13 @@ internal class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
expr.append_array_size (len_call);
} else if (!m.no_array_length) {
- var temp_var = get_temp_variable (int_type);
+ LocalVariable temp_var;
+
+ if (m.array_length_type == null) {
+ temp_var = get_temp_variable (int_type);
+ } else {
+ temp_var = get_temp_variable (new CType (m.array_length_type));
+ }
var temp_ref = get_variable_cexpression (temp_var.name);
temp_vars.insert (0, temp_var);
diff --git a/codegen/valactype.vala b/codegen/valactype.vala
new file mode 100644
index 0000000..c29438c
--- /dev/null
+++ b/codegen/valactype.vala
@@ -0,0 +1,43 @@
+/* valactype.vala
+ *
+ * Copyright (C) 2009 Mark Lee
+ *
+ * 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:
+ * Mark Lee <marklee src gnome org>
+ */
+
+/**
+ * A C type, used only for code generation purposes.
+ */
+public class Vala.CType : DataType {
+ /**
+ * The name of the C type.
+ */
+ public string ctype_name { get; set; }
+
+ public CType (string ctype_name) {
+ this.ctype_name = ctype_name;
+ }
+
+ public override DataType copy () {
+ return new CType (ctype_name);
+ }
+
+ public override string? get_cname () {
+ return ctype_name;
+ }
+}
diff --git a/vala/valamethod.vala b/vala/valamethod.vala
index bd3a5da..b575c8f 100644
--- a/vala/valamethod.vala
+++ b/vala/valamethod.vala
@@ -190,6 +190,11 @@ public class Vala.Method : Member {
public bool array_null_terminated { get; set; }
/**
+ * Specified a custom type for the array length parameter.
+ */
+ public string? array_length_type { get; set; default = null; }
+
+ /**
* Specifies whether this method expects printf-style format arguments.
*/
public bool printf_format { get; set; }
@@ -379,6 +384,9 @@ public class Vala.Method : Member {
if (a.has_argument ("array_length")) {
no_array_length = !a.get_bool ("array_length");
}
+ if (a.has_argument ("array_length_type")) {
+ array_length_type = a.get_string ("array_length_type");
+ }
if (a.has_argument ("array_null_terminated")) {
array_null_terminated = a.get_bool ("array_null_terminated");
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]