[vala/wip/transform2: 4/4] Move MethodCall transformation into emit()



commit 0f9e219a990b803937fe06465ada55db8c94f81e
Author: Luca Bruno <lucabru src gnome org>
Date:   Sun Aug 28 20:52:10 2011 +0200

    Move MethodCall transformation into emit()

 vala/valamethodcall.vala |   56 ++++++++++++++++++++++++---------------------
 1 files changed, 30 insertions(+), 26 deletions(-)
---
diff --git a/vala/valamethodcall.vala b/vala/valamethodcall.vala
index 132cc67..0c577d1 100644
--- a/vala/valamethodcall.vala
+++ b/vala/valamethodcall.vala
@@ -588,8 +588,6 @@ public class Vala.MethodCall : Expression {
 		formal_value_type = ret_type;
 		value_type = formal_value_type.get_actual_type (target_object_type, call as MemberAccess, this);
 
-		bool may_throw = false;
-
 		if (mtype is MethodType) {
 			var m = ((MethodType) mtype).method_symbol;
 			if (is_yield_expression) {
@@ -698,6 +696,32 @@ public class Vala.MethodCall : Expression {
 			return false;
 		}
 
+		return !error;
+	}
+
+	public override void emit (CodeGenerator codegen) {
+		var method_type = call.value_type as MethodType;
+
+		if (method_type != null) {
+			// N_ and NC_ do not have any effect on the C code,
+			// they are only interpreted by xgettext
+			// this means that it is ok to use them in constant initializers
+			// however, we must avoid generating regular method call code
+			// as that may include temporary variables
+			if (method_type.method_symbol.get_full_name () == "GLib.N_") {
+				// first argument is string
+				argument_list[0].emit (codegen);
+				this.target_value = argument_list[0].target_value;
+				return;
+			} else if (method_type.method_symbol.get_full_name () == "GLib.NC_") {
+				// second argument is string
+				argument_list[1].emit (codegen);
+				this.target_value = argument_list[1].target_value;
+				return;
+			}
+		}
+
+		var context = CodeContext.get ();
 		if (tree_can_fail) {
 			if (parent_node is LocalVariable || parent_node is ExpressionStatement) {
 				// simple statements, no side effects after method call
@@ -723,6 +747,7 @@ public class Vala.MethodCall : Expression {
 				// don't set initializer earlier as this changes parent_node and parent_statement
 				local.initializer = this;
 				decl.check (context);
+				decl.emit (codegen);
 
 				// move temp variable to insert block to ensure
 				// variable is in the same block as the declarat
@@ -731,32 +756,11 @@ public class Vala.MethodCall : Expression {
 				block.remove_local_variable (local);
 				context.analyzer.get_insert_block (this).add_local_variable (local);
 
+				// needed to correct error_types in the parent node
 				old_parent_node.replace_expression (this, temp_access);
 				temp_access.check (context);
-			}
-		}
-
-		return !error;
-	}
-
-	public override void emit (CodeGenerator codegen) {
-		var method_type = call.value_type as MethodType;
-
-		if (method_type != null) {
-			// N_ and NC_ do not have any effect on the C code,
-			// they are only interpreted by xgettext
-			// this means that it is ok to use them in constant initializers
-			// however, we must avoid generating regular method call code
-			// as that may include temporary variables
-			if (method_type.method_symbol.get_full_name () == "GLib.N_") {
-				// first argument is string
-				argument_list[0].emit (codegen);
-				this.target_value = argument_list[0].target_value;
-				return;
-			} else if (method_type.method_symbol.get_full_name () == "GLib.NC_") {
-				// second argument is string
-				argument_list[1].emit (codegen);
-				this.target_value = argument_list[1].target_value;
+				temp_access.emit (codegen);
+				target_value = temp_access.target_value;
 				return;
 			}
 		}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]