diff options
author | Jürg Billeter <j@bitron.ch> | 2016-11-01 17:48:15 +0100 |
---|---|---|
committer | Rico Tzschichholz <ricotz@ubuntu.com> | 2016-11-03 20:47:31 +0100 |
commit | a61dd80e4c4d25fe855692a0ddfded91999789bc (patch) | |
tree | 39b5c2c559f31110704be05e7576d9cfe7370609 /vala/valamethodcall.vala | |
parent | 7a5ff26e941f79e85d0bcba37b3c9ec7322e39c5 (diff) | |
download | vala-a61dd80e4c4d25fe855692a0ddfded91999789bc.tar.gz |
Support [FormatArg] attribute for parameters
This attribute specifies that the method takes and returns a printf
or scanf format string without modifying the order or types of expected
arguments, e.g., to translate the format string. This allows the
compiler to check the printf/scanf arguments.
Diffstat (limited to 'vala/valamethodcall.vala')
-rw-r--r-- | vala/valamethodcall.vala | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/vala/valamethodcall.vala b/vala/valamethodcall.vala index e604afe34..7bf0e49c3 100644 --- a/vala/valamethodcall.vala +++ b/vala/valamethodcall.vala @@ -434,7 +434,7 @@ public class Vala.MethodCall : Expression { StringLiteral format_literal = null; if (last_arg != null) { // use last argument as format string - format_literal = last_arg as StringLiteral; + format_literal = StringLiteral.get_format_literal (last_arg); if (format_literal == null && args.size == params.size - 1) { // insert "%s" to avoid issues with embedded % format_literal = new StringLiteral ("\"%s\""); @@ -454,7 +454,7 @@ public class Vala.MethodCall : Expression { // use instance as format string for string.printf (...) var ma = call as MemberAccess; if (ma != null) { - format_literal = ma.inner as StringLiteral; + format_literal = StringLiteral.get_format_literal (ma.inner); } } if (format_literal != null) { @@ -722,4 +722,16 @@ public class Vala.MethodCall : Expression { arg.get_used_variables (collection); } } + + public StringLiteral? get_format_literal () { + var mtype = this.call.value_type as MethodType; + if (mtype != null) { + int format_arg = mtype.method_symbol.get_format_arg_index (); + if (format_arg >= 0 && format_arg < argument_list.size) { + return StringLiteral.get_format_literal (argument_list[format_arg]); + } + } + + return null; + } } |