From: Jürg Billeter Date: Fri, 17 Oct 2008 11:42:40 +0000 (+0000) Subject: Move C-specific string concatenation from semantic analyzer to code X-Git-Tag: VALA_0_4_0~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c068ebcb238d772c166366cabf3e4ffa834a9cee;p=thirdparty%2Fvala.git Move C-specific string concatenation from semantic analyzer to code 2008-10-17 Jürg Billeter * vala/valasemanticanalyzer.vala: * gobject/valaccodegenerator.vala: Move C-specific string concatenation from semantic analyzer to code generator, patch by Andrea Del Signore svn path=/trunk/; revision=1847 --- diff --git a/ChangeLog b/ChangeLog index defec09ae..d34702be4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2008-10-17 Jürg Billeter + + * 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 * vapi/packages/gtk+-2.0/: diff --git a/gobject/valaccodegenerator.vala b/gobject/valaccodegenerator.vala index 2c5863002..4412dffd2 100644 --- a/gobject/valaccodegenerator.vala +++ b/gobject/valaccodegenerator.vala @@ -3663,19 +3663,28 @@ public class Vala.CCodeGenerator : CodeGenerator { 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); diff --git a/vala/valasemanticanalyzer.vala b/vala/valasemanticanalyzer.vala index f45c6e406..2d1704a16 100644 --- a/vala/valasemanticanalyzer.vala +++ b/vala/valasemanticanalyzer.vala @@ -3147,22 +3147,16 @@ public class Vala.SemanticAnalyzer : CodeVisitor { 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