From: Jürg Billeter Date: Fri, 2 Jul 2010 08:02:30 +0000 (+0200) Subject: Add support for [Print] method attribute X-Git-Tag: 0.9.3~48 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fkeep-around%2Fea8cd97480a7a560cfd8ae3f060f63638b7d9de4;p=thirdparty%2Fvala.git Add support for [Print] method attribute This stringifies and concatenates all arguments you pass to the method. --- diff --git a/vala/valacodewriter.vala b/vala/valacodewriter.vala index c039ae7dd..e27b981dd 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 268432762..8f9940f5a 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 90cefe067..c329c5ca1 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_list = new ArrayList (); - public Template () { + public Template (SourceReference? source_reference = null) { + this.source_reference = source_reference; } public override void accept (CodeVisitor visitor) {