diff options
author | Jürg Billeter <j@bitron.ch> | 2008-10-17 11:57:31 +0000 |
---|---|---|
committer | Jürg Billeter <juergbi@src.gnome.org> | 2008-10-17 11:57:31 +0000 |
commit | f3e347b5f8d1a24b9c9068c56092f6bb3f3c41e7 (patch) | |
tree | e8fe673bf3ae0e5bec9cbcdd5761b3f14e1dbc8f /gobject | |
parent | c068ebcb238d772c166366cabf3e4ffa834a9cee (diff) | |
download | vala-f3e347b5f8d1a24b9c9068c56092f6bb3f3c41e7.tar.gz |
Treat the result of two concatenated string constants as constant, fixes
2008-10-17 Jürg Billeter <j@bitron.ch>
* vala/valabinaryexpression.vala:
* vala/valaexpression.vala:
* vala/valaliteral.vala:
* vala/valamemberaccess.vala:
* vala/valasemanticanalyzer.vala:
* gobject/valaccodegenerator.vala:
Treat the result of two concatenated string constants as constant,
fixes bug 516287
svn path=/trunk/; revision=1848
Diffstat (limited to 'gobject')
-rw-r--r-- | gobject/valaccodegenerator.vala | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/gobject/valaccodegenerator.vala b/gobject/valaccodegenerator.vala index 4412dffd2..2d5d45f99 100644 --- a/gobject/valaccodegenerator.vala +++ b/gobject/valaccodegenerator.vala @@ -3665,13 +3665,32 @@ public class Vala.CCodeGenerator : CodeGenerator { && !(expr.right.value_type is NullType) && expr.right.value_type.compatible (string_type)) { if (expr.operator == BinaryOperator.PLUS) { - /* string concatenation: convert to g_strconcat (a, b, NULL) */ - var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_strconcat")); - ccall.add_argument (cleft); - ccall.add_argument (cright); - ccall.add_argument (new CCodeConstant("NULL")); - expr.ccodenode = ccall; - return; + // string concatenation + if (expr.left.is_constant () && expr.right.is_constant ()) { + string left, right; + + if (cleft is CCodeIdentifier) { + left = ((CCodeIdentifier) cleft).name; + } else if (cleft is CCodeConstant) { + left = ((CCodeConstant) cleft).name; + } + if (cright is CCodeIdentifier) { + right = ((CCodeIdentifier) cright).name; + } else if (cright is CCodeConstant) { + right = ((CCodeConstant) cright).name; + } + + expr.ccodenode = new CCodeConstant ("%s %s".printf (left, right)); + return; + } else { + // convert to g_strconcat (a, b, NULL) + var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_strconcat")); + ccall.add_argument (cleft); + ccall.add_argument (cright); + ccall.add_argument (new CCodeConstant("NULL")); + expr.ccodenode = ccall; + return; + } } else if (expr.operator == BinaryOperator.EQUALITY || expr.operator == BinaryOperator.INEQUALITY || expr.operator == BinaryOperator.LESS_THAN |