From: Luca Bruno Date: Sun, 26 Jan 2014 14:47:28 +0000 (+0100) Subject: Add create_temp_access to properly access a temp variable after transformation X-Git-Tag: 0.23.2~21 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d70bff7cc4f131e3b69e871af770b5d9caf653cf;p=thirdparty%2Fvala.git Add create_temp_access to properly access a temp variable after transformation --- diff --git a/vala/valasemanticanalyzer.vala b/vala/valasemanticanalyzer.vala index 8244896d0..97dad79bf 100644 --- a/vala/valasemanticanalyzer.vala +++ b/vala/valasemanticanalyzer.vala @@ -271,7 +271,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor { } else if (sym is LocalVariable) { var local = (LocalVariable) sym; var type = local.variable_type.copy (); - if (!lvalue && !local.floating) { + if (!lvalue) { type.value_owned = false; } return type; @@ -764,6 +764,22 @@ public class Vala.SemanticAnalyzer : CodeVisitor { return false; } + // Create an access to a temporary variable, with proper reference transfer if needed + public static Expression create_temp_access (LocalVariable local, DataType? target_type) { + Expression temp_access = new MemberAccess.simple (local.name, local.source_reference); + + var target_owned = target_type == null || target_type.value_owned; + if (target_owned && local.variable_type.is_disposable ()) { + temp_access = new ReferenceTransferExpression (temp_access, local.source_reference); + temp_access.target_type = target_type != null ? target_type.copy () : local.variable_type.copy (); + temp_access.target_type.value_owned = true; + } else { + temp_access.target_type = target_type != null ? target_type.copy () : null; + } + + return temp_access; + } + public void visit_member_initializer (MemberInitializer init, DataType type) { init.symbol_reference = symbol_lookup_inherited (type.data_type, init.name); if (!(init.symbol_reference is Field || init.symbol_reference is Property)) {