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
+
+2008-10-17 Jürg Billeter <j@bitron.ch>
+
* vala/valasemanticanalyzer.vala:
* gobject/valaccodegenerator.vala:
&& !(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
return _left.to_string () + get_operator_string () + _right.to_string ();
}
+ public override bool is_constant () {
+ return left.is_constant () && right.is_constant ();
+ }
+
public override bool is_pure () {
return left.is_pure () && right.is_pure ();
}
public ArrayList<LocalVariable> temp_vars = new ArrayList<LocalVariable> ();
/**
+ * Returns whether this expression is constant, i.e. whether this
+ * expression only consists of literals and other constants.
+ */
+ public virtual bool is_constant () {
+ return false;
+ }
+
+ /**
* Returns whether this expression is pure, i.e. whether this expression
* is free of side-effects.
*/
* Base class for all literals in the source code.
*/
public abstract class Vala.Literal : Expression {
+ public override bool is_constant () {
+ return true;
+ }
+
public override bool is_pure () {
return true;
}
public override CodeBinding? create_code_binding (CodeGenerator codegen) {
return codegen.create_member_access_binding (this);
}
+
+ public override bool is_constant () {
+ if (symbol_reference is Constant) {
+ return true;
+ } else {
+ return false;
+ }
+ }
}
}
expr.value_type = string_type.copy ();
- expr.value_type.value_owned = true;
+ if (expr.left.is_constant () && expr.right.is_constant ()) {
+ expr.value_type.value_owned = false;
+ } else {
+ expr.value_type.value_owned = true;
+ }
} else if (expr.operator == BinaryOperator.PLUS
|| expr.operator == BinaryOperator.MINUS
|| expr.operator == BinaryOperator.MUL