Fixes bug 641543.
/* valaccodebasemodule.vala
*
- * Copyright (C) 2006-2010 Jürg Billeter
+ * Copyright (C) 2006-2011 Jürg Billeter
* Copyright (C) 2006-2008 Raffaele Sandrini
*
* This library is free software; you can redistribute it and/or
public override void visit_string_literal (StringLiteral expr) {
set_cvalue (expr, new CCodeConstant.string (expr.value.replace ("\n", "\\n")));
+
+ if (expr.translate) {
+ // translated string constant
+
+ var m = (Method) root_symbol.scope.lookup ("GLib").scope.lookup ("_");
+ add_symbol_declaration (cfile, m, m.get_cname ());
+
+ var translate = new CCodeFunctionCall (new CCodeIdentifier ("_"));
+ translate.add_argument (get_cvalue (expr));
+ set_cvalue (expr, translate);
+ }
}
public override void visit_regex_literal (RegexLiteral expr) {
return false;
}
+ // support translated string constants for efficiency / convenience
+ // even though the expression is not a compile-time constant
+ var call = value as MethodCall;
+ if (call != null) {
+ var method_type = call.call.value_type as MethodType;
+ if (method_type != null && method_type.method_symbol.get_full_name () == "GLib._") {
+ // first argument is string
+ var literal = call.get_argument_list ().get (0) as StringLiteral;
+ if (literal != null) {
+ value = literal;
+ literal.translate = true;
+ }
+ }
+ }
+
if (!value.is_constant ()) {
error = true;
Report.error (value.source_reference, "Value must be constant");
/* valastringliteral.vala
*
- * Copyright (C) 2006-2010 Jürg Billeter
+ * Copyright (C) 2006-2011 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
*/
public string value { get; set; }
+ public bool translate { get; set; }
+
/**
* Creates a new string literal.
*