improve cast support fix ownership handling of local arrays skip code
authorJürg Billeter <j@bitron.ch>
Wed, 4 Apr 2007 20:52:30 +0000 (20:52 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Wed, 4 Apr 2007 20:52:30 +0000 (20:52 +0000)
2007-04-04  Jürg Billeter  <j@bitron.ch>

* vala/scanner.l: improve cast support
* vala/valasemanticanalyzer.vala: fix ownership handling of local arrays
* vala/valacodegenerator.vala: skip code generation for static
  interfaces, downgrade generic management support message to warning
* vala/valacallback.vala: support callbacks as property type

svn path=/trunk/; revision=278

vala/ChangeLog
vala/vala/scanner.l
vala/vala/valacallback.vala
vala/vala/valacodegenerator.vala
vala/vala/valasemanticanalyzer.vala

index 6114ad8..738ec0c 100644 (file)
@@ -1,5 +1,13 @@
 2007-04-04  Jürg Billeter  <j@bitron.ch>
 
+       * vala/scanner.l: improve cast support
+       * vala/valasemanticanalyzer.vala: fix ownership handling of local arrays
+       * vala/valacodegenerator.vala: skip code generation for static
+         interfaces, downgrade generic management support message to warning
+       * vala/valacallback.vala: support callbacks as property type
+
+2007-04-04  Jürg Billeter  <j@bitron.ch>
+
        * vala/scanner.l: support casts to generic types
        * vala/valasymbolresolver.vala, vala/valatypereference.vala: support
          arrays of generic types
index 52a20a0..ab73ec7 100644 (file)
@@ -73,7 +73,7 @@ literal                               ({integer_literal}|{real_literal}|{character_literal}|{string_literal
 
 "{"            { uploc; return OPEN_BRACE; }
 "}"            { uploc; return CLOSE_BRACE; }
-"("{space}{ident}("."{ident})?("<"({ident}".")?{ident}">")?("["{space}"]")*{space}")"{space}("("|{ident}|{literal})    { yyless (1); uploc; return OPEN_CAST_PARENS; }
+"("({space}"weak")?{space}{ident}("."{ident})?("<"({ident}".")?{ident}(","({ident}".")?{ident})*">")?("["{space}"]")*{space}")"{space}("("|{ident}|{literal})  { yyless (1); uploc; return OPEN_CAST_PARENS; }
 "("            { uploc; return OPEN_PARENS; }
 ")"            { uploc; return CLOSE_PARENS; }
 "[]"           { uploc; return BRACKET_PAIR; }
index b9023ab..e2af311 100644 (file)
@@ -1,6 +1,6 @@
 /* valacallback.vala
  *
- * Copyright (C) 2006  Jürg Billeter
+ * Copyright (C) 2006-2007  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
@@ -157,4 +157,20 @@ public class Vala.Callback : DataType {
        public override bool is_reference_type () {
                return false;
        }
+
+       public override string get_type_id () {
+               return "G_TYPE_POINTER";
+       }
+
+       public override string get_marshaller_type_name () {
+               return "POINTER";
+       }
+
+       public override string get_get_value_function () {
+               return "g_value_get_pointer";
+       }
+       
+       public override string get_set_value_function () {
+               return "g_value_set_pointer";
+       }
 }
index c54e8dc..0b94c3a 100644 (file)
@@ -845,6 +845,10 @@ public class Vala.CodeGenerator : CodeVisitor {
                current_symbol = iface.symbol;
                current_type_symbol = iface.symbol;
 
+               if (iface.is_static) {
+                       return;
+               }
+
                type_struct = new CCodeStruct ("_%s".printf (iface.get_type_cname ()));
                
                header_type_declaration.append (new CCodeNewline ());
@@ -876,12 +880,14 @@ public class Vala.CodeGenerator : CodeVisitor {
        }
 
        public override void visit_end_interface (Interface! iface) {
-               add_interface_base_init_function (iface);
+               if (!iface.is_static) {
+                       add_interface_base_init_function (iface);
 
-               var type_fun = new InterfaceRegisterFunction (iface);
-               type_fun.init_from_type ();
-               header_type_member_declaration.append (type_fun.get_declaration ());
-               source_type_member_definition.append (type_fun.get_definition ());
+                       var type_fun = new InterfaceRegisterFunction (iface);
+                       type_fun.init_from_type ();
+                       header_type_member_declaration.append (type_fun.get_declaration ());
+                       source_type_member_definition.append (type_fun.get_definition ());
+               }
 
                current_type_symbol = null;
        }
@@ -1244,6 +1250,13 @@ public class Vala.CodeGenerator : CodeVisitor {
                current_symbol = current_symbol.parent_symbol;
                current_return_type = null;
 
+               if (current_type_symbol != null && current_type_symbol.node is Interface) {
+                       var iface = (Interface) current_type_symbol.node;
+                       if (iface.is_static) {
+                               return;
+                       }
+               }
+
                if (current_symbol.parent_symbol != null &&
                    current_symbol.parent_symbol.node is Method) {
                        /* lambda expressions produce nested methods */
@@ -3400,9 +3413,8 @@ public class Vala.CodeGenerator : CodeVisitor {
                 
                if (expr.static_type.data_type == null &&
                    expr.static_type.type_parameter != null) {
-                       expr.error = true;
-                       Report.error (expr.source_reference, "Missing generics support for memory management");
-                       return null;
+                       Report.warning (expr.source_reference, "Missing generics support for memory management");
+                       return (CCodeExpression) expr.ccodenode;
                }
        
                string ref_function;
index 4e30fe2..ae8956a 100644 (file)
@@ -628,10 +628,10 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
                                if (decl.initializer.static_type.transfers_ownership) {
                                        /* rhs transfers ownership of the expression */
                                        if (!decl.type_reference.takes_ownership) {
-                                               /* lhs doesn't own the value
-                                                * promote lhs type */
-                                               
-                                               decl.type_reference.takes_ownership = true;
+                                               /* lhs doesn't own the value */
+                                               decl.error = true;
+                                               Report.error (decl.source_reference, "Invalid assignment from owned expression to unowned variable");
+                                               return;
                                        }
                                }
                        }
@@ -1625,14 +1625,16 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
        }
 
        public override void visit_cast_expression (CastExpression! expr) {
-               if (expr.type_reference.data_type == null) {
+               if (expr.type_reference.data_type == null && expr.type_reference.type_parameter == null) {
                        /* if type resolving didn't succeed, skip this check */
                        return;
                }
                
                // FIXME: check whether cast is allowed
-       
-               current_source_file.add_symbol_dependency (expr.type_reference.data_type.symbol, SourceFileDependencyType.SOURCE);
+
+               if (expr.type_reference.data_type != null) {
+                       current_source_file.add_symbol_dependency (expr.type_reference.data_type.symbol, SourceFileDependencyType.SOURCE);
+               }
 
                expr.static_type = expr.type_reference;
        }
@@ -2160,16 +2162,10 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
                                        var element_type = (TypeReference) args.data;
 
                                        if (!element_type.takes_ownership) {
-                                               /* lhs doesn't own the value
-                                                * promote lhs type if it is a local variable
-                                                * error if it's not a local variable */
-                                               if (!(ea.container.symbol_reference.node is VariableDeclarator)) {
-                                                       a.error = true;
-                                                       Report.error (a.source_reference, "Invalid assignment from owned expression to unowned variable");
-                                                       return;
-                                               }
-                                               
-                                               element_type.takes_ownership = true;
+                                               /* lhs doesn't own the value */
+                                               a.error = true;
+                                               Report.error (a.source_reference, "Invalid assignment from owned expression to unowned variable");
+                                               return;
                                        }
                                } else if (a.left.static_type.takes_ownership) {
                                        /* lhs wants to own the value