From: Jürg Billeter Date: Wed, 4 Apr 2007 20:52:30 +0000 (+0000) Subject: improve cast support fix ownership handling of local arrays skip code X-Git-Tag: VALA_0_0_9~18 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9ebb2dc1b2056d02f6e856321ef8a2cef3ac853c;p=platform%2Fupstream%2Fvala.git improve cast support fix ownership handling of local arrays skip code 2007-04-04 Jürg Billeter * 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 --- diff --git a/vala/ChangeLog b/vala/ChangeLog index 6114ad8..738ec0c 100644 --- a/vala/ChangeLog +++ b/vala/ChangeLog @@ -1,5 +1,13 @@ 2007-04-04 Jürg Billeter + * 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 + * vala/scanner.l: support casts to generic types * vala/valasymbolresolver.vala, vala/valatypereference.vala: support arrays of generic types diff --git a/vala/vala/scanner.l b/vala/vala/scanner.l index 52a20a0..ab73ec7 100644 --- a/vala/vala/scanner.l +++ b/vala/vala/scanner.l @@ -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; } diff --git a/vala/vala/valacallback.vala b/vala/vala/valacallback.vala index b9023ab..e2af311 100644 --- a/vala/vala/valacallback.vala +++ b/vala/vala/valacallback.vala @@ -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"; + } } diff --git a/vala/vala/valacodegenerator.vala b/vala/vala/valacodegenerator.vala index c54e8dc..0b94c3a 100644 --- a/vala/vala/valacodegenerator.vala +++ b/vala/vala/valacodegenerator.vala @@ -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; diff --git a/vala/vala/valasemanticanalyzer.vala b/vala/vala/valasemanticanalyzer.vala index 4e30fe2..ae8956a 100644 --- a/vala/vala/valasemanticanalyzer.vala +++ b/vala/vala/valasemanticanalyzer.vala @@ -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