[vala] Add support for [Print] method attribute



commit ea8cd97480a7a560cfd8ae3f060f63638b7d9de4
Author: Jürg Billeter <j bitron ch>
Date:   Fri Jul 2 10:02:30 2010 +0200

    Add support for [Print] method attribute
    
    This stringifies and concatenates all arguments you pass to the method.

 vala/valacodewriter.vala |    4 ++++
 vala/valamethodcall.vala |   11 +++++++++++
 vala/valatemplate.vala   |    5 +++--
 3 files changed, 18 insertions(+), 2 deletions(-)
---
diff --git a/vala/valacodewriter.vala b/vala/valacodewriter.vala
index c039ae7..e27b981 100644
--- a/vala/valacodewriter.vala
+++ b/vala/valacodewriter.vala
@@ -936,6 +936,10 @@ public class Vala.CodeWriter : CodeVisitor {
 			write_indent ();
 			write_string ("[ScanfFormat]");
 		}
+		if (m.get_attribute ("Print") != null) {
+			write_indent ();
+			write_string ("[Print]");
+		}
 
 		emit_deprecated_attribute (m);
 
diff --git a/vala/valamethodcall.vala b/vala/valamethodcall.vala
index 2684327..8f9940f 100644
--- a/vala/valamethodcall.vala
+++ b/vala/valamethodcall.vala
@@ -342,6 +342,17 @@ public class Vala.MethodCall : Expression {
 			}
 		}
 
+		// concatenate stringified arguments for methods with attribute [Print]
+		if (mtype is MethodType && ((MethodType) mtype).method_symbol.get_attribute ("Print") != null) {
+			var template = new Template (source_reference);
+			foreach (Expression arg in argument_list) {
+				arg.parent_node = null;
+				template.add_expression (arg);
+			}
+			argument_list.clear ();
+			add_argument (template);
+		}
+
 		// printf arguments
 		if (mtype is MethodType && ((MethodType) mtype).method_symbol.printf_format) {
 			StringLiteral format_literal = null;
diff --git a/vala/valatemplate.vala b/vala/valatemplate.vala
index 90cefe0..c329c5c 100644
--- a/vala/valatemplate.vala
+++ b/vala/valatemplate.vala
@@ -1,6 +1,6 @@
 /* valatemplate.vala
  *
- * Copyright (C) 2009  Jürg Billeter
+ * Copyright (C) 2009-2010  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
@@ -24,7 +24,8 @@
 public class Vala.Template : Expression {
 	private List<Expression> expression_list = new ArrayList<Expression> ();
 
-	public Template () {
+	public Template (SourceReference? source_reference = null) {
+		this.source_reference = source_reference;
 	}
 
 	public override void accept (CodeVisitor visitor) {



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