[vala] posix: Support string concatenation in POSIX profile
- From: Jürg Billeter <juergbi src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [vala] posix: Support string concatenation in POSIX profile
- Date: Mon, 12 Oct 2009 19:33:34 +0000 (UTC)
commit 293e26086ab62e8952c6f315a610772251c76a83
Author: pancake <pancake youterm com>
Date: Mon Oct 12 21:33:08 2009 +0200
posix: Support string concatenation in POSIX profile
codegen/valaccodebasemodule.vala | 34 ++++++++++++++++++++++++++++------
1 files changed, 28 insertions(+), 6 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index d146a61..a4fe54b 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -4141,12 +4141,34 @@ internal class Vala.CCodeBaseModule : CCodeModule {
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;
+ if (context.profile == Profile.POSIX) {
+ // convert to strcat(strcpy(malloc(1+strlen(a)+strlen(b)),a),b)
+ var strcat = new CCodeFunctionCall (new CCodeIdentifier ("strcat"));
+ var strcpy = new CCodeFunctionCall (new CCodeIdentifier ("strcpy"));
+ var malloc = new CCodeFunctionCall (new CCodeIdentifier ("malloc"));
+
+ var strlen_a = new CCodeFunctionCall (new CCodeIdentifier ("strlen"));
+ strlen_a.add_argument(cleft);
+ var strlen_b = new CCodeFunctionCall (new CCodeIdentifier ("strlen"));
+ strlen_b.add_argument(cright);
+ var newlength = new CCodeBinaryExpression (CCodeBinaryOperator.PLUS, new CCodeIdentifier("1"),
+ new CCodeBinaryExpression (CCodeBinaryOperator.PLUS, strlen_a, strlen_b));
+ malloc.add_argument(newlength);
+
+ strcpy.add_argument(malloc);
+ strcpy.add_argument(cleft);
+
+ strcat.add_argument(strcpy);
+ strcat.add_argument(cright);
+ expr.ccodenode = strcat;
+ } 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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]