+2008-10-17 Jürg Billeter <j@bitron.ch>
+
+ * vala/valasemanticanalyzer.vala:
+ * gobject/valaccodegenerator.vala:
+
+ Move C-specific string concatenation from semantic analyzer to
+ code generator, patch by Andrea Del Signore
+
2008-10-17 Jürg Billeter <j@bitron.ch>
* vapi/packages/gtk+-2.0/:
if (!(expr.left.value_type is NullType)
&& expr.left.value_type.compatible (string_type)
&& !(expr.right.value_type is NullType)
- && expr.right.value_type.compatible (string_type)
- && (expr.operator == BinaryOperator.EQUALITY
- || expr.operator == BinaryOperator.INEQUALITY
- || expr.operator == BinaryOperator.LESS_THAN
- || expr.operator == BinaryOperator.GREATER_THAN
- || expr.operator == BinaryOperator.LESS_THAN_OR_EQUAL
- || expr.operator == BinaryOperator.GREATER_THAN_OR_EQUAL)) {
- requires_strcmp0 = true;
- var ccall = new CCodeFunctionCall (new CCodeIdentifier ("_vala_strcmp0"));
- ccall.add_argument (cleft);
- ccall.add_argument (cright);
- cleft = ccall;
- cright = new CCodeConstant ("0");
+ && 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;
+ } else if (expr.operator == BinaryOperator.EQUALITY
+ || expr.operator == BinaryOperator.INEQUALITY
+ || expr.operator == BinaryOperator.LESS_THAN
+ || expr.operator == BinaryOperator.GREATER_THAN
+ || expr.operator == BinaryOperator.LESS_THAN_OR_EQUAL
+ || expr.operator == BinaryOperator.GREATER_THAN_OR_EQUAL) {
+ requires_strcmp0 = true;
+ var ccall = new CCodeFunctionCall (new CCodeIdentifier ("_vala_strcmp0"));
+ ccall.add_argument (cleft);
+ ccall.add_argument (cright);
+ cleft = ccall;
+ cright = new CCodeConstant ("0");
+ }
}
expr.ccodenode = new CCodeBinaryExpression (op, cleft, cright);
if (expr.left.value_type.data_type == string_type.data_type
&& expr.operator == BinaryOperator.PLUS) {
+ // string concatenation
+
if (expr.right.value_type == null || expr.right.value_type.data_type != string_type.data_type) {
expr.error = true;
Report.error (expr.source_reference, "Operands must be strings");
return;
}
- /* string concatenation: convert to a.concat (b) */
-
- var concat_call = new InvocationExpression (new MemberAccess (expr.left, "concat"));
- concat_call.add_argument (expr.right);
- concat_call.target_type = expr.target_type;
-
- replaced_nodes.add (expr);
- expr.parent_node.replace_expression (expr, concat_call);
-
- concat_call.accept (this);
+ expr.value_type = string_type.copy ();
+ expr.value_type.value_owned = true;
} else if (expr.operator == BinaryOperator.PLUS
|| expr.operator == BinaryOperator.MINUS
|| expr.operator == BinaryOperator.MUL