]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Move C-specific string concatenation from semantic analyzer to code
authorJürg Billeter <j@bitron.ch>
Fri, 17 Oct 2008 11:42:40 +0000 (11:42 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Fri, 17 Oct 2008 11:42:40 +0000 (11:42 +0000)
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

svn path=/trunk/; revision=1847

ChangeLog
gobject/valaccodegenerator.vala
vala/valasemanticanalyzer.vala

index defec09ae7e42ffd891b0fddaa6afc94fdb902f9..d34702be40b47d8288cb704e82b61698f9af7eeb 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+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/:
index 2c586300247a06cee021ad6dfd4d9644804895f1..4412dffd2f9ac489d2d31275fae86f0adeff6ada 100644 (file)
@@ -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);
index f45c6e406406e6e92f89c96452c09e83577783b1..2d1704a16218a256baf0c18f1e2870b368203395 100644 (file)
@@ -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