From 25077891fea80182ca1e2e0dd8a06d0ed111bd80 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=BCrg=20Billeter?= Date: Wed, 16 Feb 2011 10:25:49 +0100 Subject: [PATCH] Use store_local and store_parameter for simple assignments --- codegen/valaccodeassignmentmodule.vala | 4 +++ codegen/valaccodebasemodule.vala | 4 --- codegen/valadovaassignmentmodule.vala | 4 +++ codegen/valadovamemberaccessmodule.vala | 2 +- vala/valaassignment.vala | 47 ++++++++++++++++++++++++++++++++- vala/valacodegenerator.vala | 6 ++++- 6 files changed, 60 insertions(+), 7 deletions(-) diff --git a/codegen/valaccodeassignmentmodule.vala b/codegen/valaccodeassignmentmodule.vala index 657d0e48..136712ea 100644 --- a/codegen/valaccodeassignmentmodule.vala +++ b/codegen/valaccodeassignmentmodule.vala @@ -223,4 +223,8 @@ public class Vala.CCodeAssignmentModule : CCodeMemberAccessModule { public override void store_local (LocalVariable local, TargetValue value, bool initializer) { store_variable (local, get_local_cvalue (local), value, initializer); } + + public override void store_parameter (Parameter param, TargetValue value) { + store_variable (param, get_parameter_cvalue (param), value, false); + } } diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala index bc8604e8..35d098ba 100644 --- a/codegen/valaccodebasemodule.vala +++ b/codegen/valaccodebasemodule.vala @@ -3706,10 +3706,6 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { assert_not_reached (); } - public virtual TargetValue load_parameter (Parameter param) { - assert_not_reached (); - } - public virtual string get_delegate_target_cname (string delegate_cname) { assert_not_reached (); } diff --git a/codegen/valadovaassignmentmodule.vala b/codegen/valadovaassignmentmodule.vala index 837c873a..1338b024 100644 --- a/codegen/valadovaassignmentmodule.vala +++ b/codegen/valadovaassignmentmodule.vala @@ -144,4 +144,8 @@ public class Vala.DovaAssignmentModule : DovaMemberAccessModule { public override void store_local (LocalVariable local, TargetValue value, bool initializer) { store_variable (local, get_local_cvalue (local), value, initializer); } + + public override void store_parameter (Parameter param, TargetValue value) { + store_variable (param, get_parameter_cvalue (param), value, false); + } } diff --git a/codegen/valadovamemberaccessmodule.vala b/codegen/valadovamemberaccessmodule.vala index 9fa27aac..7cc3d675 100644 --- a/codegen/valadovamemberaccessmodule.vala +++ b/codegen/valadovamemberaccessmodule.vala @@ -291,7 +291,7 @@ public abstract class Vala.DovaMemberAccessModule : DovaControlFlowModule { return load_variable (local, get_local_cvalue (local)); } - public TargetValue load_parameter (Parameter param) { + public override TargetValue load_parameter (Parameter param) { return load_variable (param, get_parameter_cvalue (param)); } diff --git a/vala/valaassignment.vala b/vala/valaassignment.vala index f9590609..199226fd 100644 --- a/vala/valaassignment.vala +++ b/vala/valaassignment.vala @@ -1,6 +1,6 @@ /* valaassignment.vala * - * Copyright (C) 2006-2010 Jürg Billeter + * Copyright (C) 2006-2011 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 @@ -443,17 +443,62 @@ public class Vala.Assignment : Expression { return !error; } + bool is_array_add () { + var binary = right as BinaryExpression; + if (binary != null && binary.left.value_type is ArrayType) { + if (binary.operator == BinaryOperator.PLUS) { + if (left.symbol_reference == binary.left.symbol_reference) { + return true; + } + } + } + + return false; + } + public override void emit (CodeGenerator codegen) { var ma = left as MemberAccess; var ea = left as ElementAccess; var pi = left as PointerIndirection; if (ma != null) { + var local = ma.symbol_reference as LocalVariable; + var param = ma.symbol_reference as Parameter; var field = ma.symbol_reference as Field; var property = ma.symbol_reference as Property; bool instance = (field != null && field.binding == MemberBinding.INSTANCE) || (property != null && property.binding == MemberBinding.INSTANCE); + if (operator == AssignmentOperator.SIMPLE && + (local != null || param != null) && + !is_array_add ()) { + // visit_assignment not necessary + if (instance) { + ma.inner.emit (codegen); + } + + right.emit (codegen); + var new_value = right.target_value; + + if (local != null) { + codegen.store_local (local, new_value, false); + } else if (param != null) { + codegen.store_parameter (param, new_value); + } + + // when load_variable is changed to use temporary + // variables, replace following code with this line + // target_value = new_value; + if (local != null) { + target_value = codegen.load_local (local); + } else if (param != null) { + target_value = codegen.load_parameter (param); + } + + codegen.visit_expression (this); + return; + } + if (field != null) { // always process full lvalue // current codegen depends on it diff --git a/vala/valacodegenerator.vala b/vala/valacodegenerator.vala index 65624f4f..d3ca065d 100644 --- a/vala/valacodegenerator.vala +++ b/vala/valacodegenerator.vala @@ -1,6 +1,6 @@ /* valacodegenerator.vala * - * Copyright (C) 2007-2010 Jürg Billeter + * Copyright (C) 2007-2011 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 @@ -37,4 +37,8 @@ public abstract class Vala.CodeGenerator : CodeVisitor { public abstract TargetValue load_local (LocalVariable local); public abstract void store_local (LocalVariable local, TargetValue value, bool initializer); + + public abstract TargetValue load_parameter (Parameter param); + + public abstract void store_parameter (Parameter param, TargetValue value); } -- 2.11.4.GIT