get_captured_variables ((Collection<LocalVariable>) collection);
}
}
+
+ public int get_format_arg_index () {
+ for (int i = 0; i < parameters.size; i++) {
+ if (parameters[i].format_arg) {
+ return i;
+ }
+ }
+ return -1;
+ }
}
// vim:sw=8 noet
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\"");
// 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) {
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;
+ }
}
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 == m.get_parameters ().size - 1) {
// insert "%s" to avoid issues with embedded %
format_literal = new StringLiteral ("\"%s\"");
Report.error (source_reference, "Invalid type for argument 1");
}
- var format_literal = ex as StringLiteral;
+ var format_literal = StringLiteral.get_format_literal (ex);
if (format_literal != null) {
var format = format_literal.eval ();
if (!context.analyzer.check_print_format (format, arg_it, source_reference)) {
public bool captured { get; set; }
+ public bool format_arg {
+ get {
+ return get_attribute ("FormatArg") != null;
+ }
+ }
+
/**
* The base parameter of this parameter relative to the base method.
*/
codegen.visit_expression (this);
}
+
+ public static StringLiteral? get_format_literal (Expression expr) {
+ var format_literal = expr as StringLiteral;
+ if (format_literal != null) {
+ return format_literal;
+ }
+
+ var call = expr as MethodCall;
+ if (call != null) {
+ return call.get_format_literal ();
+ }
+
+ return null;
+ }
}
"SimpleType", "",
"PrintfFormat", "",
"ScanfFormat", "",
+ "FormatArg", "",
"GtkChild", "name", "internal", "",
"GtkTemplate", "ui", "",