]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
special case construction of GLib.List and GLib.SList (reported by Cayle
authorJürg Billeter <j@bitron.ch>
Sat, 2 Sep 2006 16:18:35 +0000 (16:18 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Sat, 2 Sep 2006 16:18:35 +0000 (16:18 +0000)
2006-09-02  Jürg Billeter  <j@bitron.ch>

* vala/valacodegenerator.vala: special case construction of GLib.List
  and GLib.SList (reported by Cayle Graumann)

svn path=/trunk/; revision=121

vala/ChangeLog
vala/vala/valacodegenerator.vala

index 8ecc7e78bef54ad158e7aed990ec3485ea0cdf83..d324b2c6eaf3c04d1385419a03cc4026c5da5860 100644 (file)
@@ -1,3 +1,8 @@
+2006-09-02  Jürg Billeter  <j@bitron.ch>
+
+       * vala/valacodegenerator.vala: special case construction of GLib.List
+         and GLib.SList (reported by Cayle Graumann)
+
 2006-09-02  Jürg Billeter  <j@bitron.ch>
 
        * vala/scanner.l, vala/parser.y, vala/valasemanticanalyzer.vala,
index e5675b5b831667c0025cc85b5b9b7397c1da403e..cbbff45cf3c15797e85a0cc2d5effcd3c533ef72 100644 (file)
@@ -70,6 +70,8 @@ public class Vala.CodeGenerator : CodeVisitor {
        TypeReference string_type;
        TypeReference float_type;
        TypeReference double_type;
+       DataType list_type;
+       DataType slist_type;
        
        public construct (bool manage_memory = true) {
                memory_management = manage_memory;
@@ -110,6 +112,11 @@ public class Vala.CodeGenerator : CodeVisitor {
 
                string_type = new TypeReference ();
                string_type.data_type = (DataType) root_symbol.lookup ("string").node;
+
+               var glib_ns = root_symbol.lookup ("GLib");
+               
+               list_type = (DataType) glib_ns.lookup ("List").node;
+               slist_type = (DataType) glib_ns.lookup ("SList").node;
        
                /* we're only interested in non-pkg source files */
                var source_files = context.get_source_files ();
@@ -1697,8 +1704,8 @@ public class Vala.CodeGenerator : CodeVisitor {
                        cfor.add_initializer (new CCodeAssignment (new CCodeIdentifier (it_name), (CCodeExpression) stmt.collection.ccodenode));
                        cfor.add_iterator (new CCodeAssignment (new CCodeIdentifier (it_name), new CCodeBinaryExpression (CCodeBinaryOperator.PLUS, new CCodeIdentifier (it_name), new CCodeConstant ("1"))));
                        cblock.add_statement (cfor);
-               } else if (stmt.collection.static_type.data_type.name == "List" ||
-                          stmt.collection.static_type.data_type.name == "SList") {
+               } else if (stmt.collection.static_type.data_type == list_type ||
+                          stmt.collection.static_type.data_type == slist_type) {
                        var it_name = "%s_it".printf (stmt.variable_name);
                
                        var citdecl = new CCodeDeclaration (stmt.collection.static_type.get_cname ());
@@ -2335,6 +2342,10 @@ public class Vala.CodeGenerator : CodeVisitor {
                                ccall.add_argument (new CCodeConstant ("NULL"));
                                
                                expr.ccodenode = ccall;
+                       } else if (expr.type_reference.data_type == list_type ||
+                                  expr.type_reference.data_type == slist_type) {
+                               // NULL is an empty list
+                               expr.ccodenode = new CCodeConstant ("NULL");
                        } else {
                                var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_new0"));