add limited support for defining methods with variable argument list
authorJuerg Billeter <j@bitron.ch>
Thu, 3 Jan 2008 14:50:03 +0000 (14:50 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Thu, 3 Jan 2008 14:50:03 +0000 (14:50 +0000)
2008-01-03  Juerg Billeter  <j@bitron.ch>

* gobject/valaccodegenerator.vala,
  gobject/valaccodegeneratormethod.vala,
  ccode/valaccodeformalparameter.vala: add limited support for defining
  methods with variable argument list

svn path=/trunk/; revision=800

ChangeLog
ccode/valaccodeformalparameter.vala
gobject/valaccodegenerator.vala
gobject/valaccodegeneratormethod.vala

index cf6e476..e0941e1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2008-01-03  Jürg Billeter  <j@bitron.ch>
 
+       * gobject/valaccodegenerator.vala,
+         gobject/valaccodegeneratormethod.vala,
+         ccode/valaccodeformalparameter.vala: add limited support for defining
+         methods with variable argument list
+
+2008-01-03  Jürg Billeter  <j@bitron.ch>
+
        * vapi/glib-2.0.vapi: remove close method from FileStream class as it's
          also the implicitly called free function, fixes bug 506817
 
index 006ea9c..307bc90 100644 (file)
@@ -1,6 +1,6 @@
 /* valaccodeformalparameter.vala
  *
- * Copyright (C) 2006  Jürg Billeter
+ * Copyright (C) 2006-2008  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
@@ -29,21 +29,35 @@ public class Vala.CCodeFormalParameter : CCodeNode {
        /**
         * The parameter name.
         */
-       public string! name { get; set construct; }
+       public string name { get; set; }
        
        /**
         * The parameter type.
         */
-       public string! type_name { get; set construct; }
-       
+       public string type_name { get; set; }
+
+       /**
+        * Specifies whether the function accepts an indefinite number of
+        * arguments.
+        */
+       public bool ellipsis { get; set; }
+
        public CCodeFormalParameter (string! n, string! type) {
                name = n;
                type_name = type;
        }
-       
+
+       public CCodeFormalParameter.with_ellipsis () {
+               ellipsis = true;
+       }
+
        public override void write (CCodeWriter! writer) {
-               writer.write_string (type_name);
-               writer.write_string (" ");
-               writer.write_string (name);
+               if (!ellipsis) {
+                       writer.write_string (type_name);
+                       writer.write_string (" ");
+                       writer.write_string (name);
+               } else {
+                       writer.write_string ("...");
+               }
        }
 }
index d29ea7e..0c7e789 100644 (file)
@@ -1,6 +1,6 @@
 /* valaccodegenerator.vala
  *
- * Copyright (C) 2006-2007  Jürg Billeter, Raffaele Sandrini
+ * Copyright (C) 2006-2008  Jürg Billeter, Raffaele Sandrini
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -503,6 +503,8 @@ public class Vala.CCodeGenerator : CodeGenerator {
                        }
 
                        p.ccodenode = new CCodeFormalParameter (cname, ctypename);
+               } else {
+                       p.ccodenode = new CCodeFormalParameter.with_ellipsis ();
                }
        }
 
index cb21180..7154a35 100644 (file)
@@ -1,6 +1,6 @@
 /* valaccodegeneratormethod.vala
  *
- * Copyright (C) 2006-2007  Jürg Billeter, Raffaele Sandrini
+ * Copyright (C) 2006-2008  Jürg Billeter, Raffaele Sandrini
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -176,7 +176,7 @@ public class Vala.CCodeGenerator {
 
                var params = m.get_parameters ();
                foreach (FormalParameter param in params) {
-                       if (!param.no_array_length && param.type_reference.data_type is Array) {
+                       if (!param.no_array_length && param.type_reference != null && param.type_reference.data_type is Array) {
                                var arr = (Array) param.type_reference.data_type;
                                
                                var length_ctype = "int";
@@ -275,6 +275,10 @@ public class Vala.CCodeGenerator {
                                        }
                                }
                                foreach (FormalParameter param in m.get_parameters ()) {
+                                       if (param.ellipsis) {
+                                               break;
+                                       }
+
                                        var t = param.type_reference.data_type;
                                        if (t != null && t.is_reference_type () && !param.type_reference.is_out) {
                                                var type_check = create_method_type_check_statement (m, creturn_type, t, param.type_reference.non_null, param.name);