]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codewriter: Support fixed-length arrays
authorJürg Billeter <j@bitron.ch>
Mon, 6 Aug 2012 20:18:49 +0000 (22:18 +0200)
committerJürg Billeter <j@bitron.ch>
Mon, 6 Aug 2012 20:18:49 +0000 (22:18 +0200)
Fixes bug 618689.

vala/valaarraytype.vala
vala/valacodewriter.vala

index 6654870838ac12bf0631a53679f22dc16a2f2dbc..f1bcba10893627648b979b7aa01c519cf307f51e 100644 (file)
@@ -1,6 +1,6 @@
 /* valaarraytype.vala
  *
- * Copyright (C) 2007-2011  Jürg Billeter
+ * Copyright (C) 2007-2012  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
@@ -153,7 +153,11 @@ public class Vala.ArrayType : ReferenceType {
        }
 
        public override string to_qualified_string (Scope? scope) {
-               return "%s[%s]%s".printf (element_type.to_qualified_string (scope), string.nfill (rank - 1, ','), nullable ? "?" : "");
+               if (!fixed_length) {
+                       return "%s[%s]%s".printf (element_type.to_qualified_string (scope), string.nfill (rank - 1, ','), nullable ? "?" : "");
+               } else {
+                       return element_type.to_qualified_string (scope);
+               }
        }
 
        public override bool compatible (DataType target_type) {
index 7a79614950cf34a28346e70e338003a4944458f7..30c36f4a06946409e0f037fc6777693a975bf27f 100644 (file)
@@ -1,6 +1,6 @@
 /* valacodewriter.vala
  *
- * Copyright (C) 2006-2010  Jürg Billeter
+ * Copyright (C) 2006-2012  Jürg Billeter
  * Copyright (C) 2006-2008  Raffaele Sandrini
  *
  * This library is free software; you can redistribute it and/or
@@ -509,6 +509,7 @@ public class Vala.CodeWriter : CodeVisitor {
                        
                write_string (" ");
                write_identifier (c.name);
+               write_type_suffix (c.type_reference);
                if (type == CodeWriterType.FAST && c.value != null) {
                        write_string(" = ");
                        c.value.accept (this);
@@ -545,6 +546,7 @@ public class Vala.CodeWriter : CodeVisitor {
                        
                write_string (" ");
                write_identifier (f.name);
+               write_type_suffix (f.variable_type);
                write_string (";");
                write_newline ();
        }
@@ -605,6 +607,7 @@ public class Vala.CodeWriter : CodeVisitor {
 
                        write_string (" ");
                        write_identifier (param.name);
+                       write_type_suffix (param.variable_type);
                        
                        if (param.initializer != null) {
                                write_string (" = ");
@@ -847,6 +850,7 @@ public class Vala.CodeWriter : CodeVisitor {
                write_type (local.variable_type);
                write_string (" ");
                write_identifier (local.name);
+               write_type_suffix (local.variable_type);
                if (local.initializer != null) {
                        write_string (" = ");
                        local.initializer.accept (this);
@@ -1446,6 +1450,13 @@ public class Vala.CodeWriter : CodeVisitor {
                write_string (type.to_qualified_string (current_scope));
        }
 
+       private void write_type_suffix (DataType type) {
+               var array_type = type as ArrayType;
+               if (array_type != null && array_type.fixed_length) {
+                       write_string ("[%d]".printf (array_type.length));
+               }
+       }
+
        private void write_string (string s) {
                stream.printf ("%s", s);
                bol = false;