[vala/staging] codegen: Improve GValueModule.visit_cast_expression()
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging] codegen: Improve GValueModule.visit_cast_expression()
- Date: Sat, 14 Nov 2020 14:03:45 +0000 (UTC)
commit 87dd44b89e8330412ad349fdd4e97a8db71e59ff
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Fri Nov 13 17:15:37 2020 +0100
codegen: Improve GValueModule.visit_cast_expression()
Re-use the result of the GValue-getter invocation
codegen/valagvaluemodule.vala | 26 +++++++++++++++++++-------
1 file changed, 19 insertions(+), 7 deletions(-)
---
diff --git a/codegen/valagvaluemodule.vala b/codegen/valagvaluemodule.vala
index a6109fd40..0429085e6 100644
--- a/codegen/valagvaluemodule.vala
+++ b/codegen/valagvaluemodule.vala
@@ -44,29 +44,41 @@ public class Vala.GValueModule : GAsyncModule {
}
ccall.add_argument (gvalue);
- CCodeExpression rv = ccall;
+ CCodeExpression rv;
+ if (target_type is ArrayType) {
+ var temp_var = get_temp_variable (target_type, true, expr, false);
+ emit_temp_var (temp_var);
+ var temp_ref = get_variable_cexpression (temp_var.name);
+ ccode.add_assignment (temp_ref, ccall);
+ rv = temp_ref;
- if (expr != null && target_type is ArrayType) {
// null-terminated string array
var len_call = new CCodeFunctionCall (new CCodeIdentifier ("g_strv_length"));
len_call.add_argument (rv);
append_array_length (expr, len_call);
} else if (target_type is StructValueType) {
- CodeNode node = expr != null ? (CodeNode) expr : target_type;
- var temp_value = create_temp_value (target_type, true, node, true);
+ var temp_var = get_temp_variable (new PointerType (target_type), true, expr, false);
+ emit_temp_var (temp_var);
+ var temp_ref = get_variable_cexpression (temp_var.name);
+ ccode.add_assignment (temp_ref, ccall);
+ rv = temp_ref;
+
+ // default value to fallback to
+ var temp_value = create_temp_value (target_type, true, expr, true);
var ctemp = get_cvalue_ (temp_value);
- rv = new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, new
CCodeCastExpression (rv, get_ccode_name (new PointerType (target_type))));
var holds = new CCodeFunctionCall (new CCodeIdentifier ("G_VALUE_HOLDS"));
holds.add_argument (gvalue);
holds.add_argument (new CCodeIdentifier (get_ccode_type_id (target_type)));
- var cond = new CCodeBinaryExpression (CCodeBinaryOperator.AND, holds, ccall);
+ var cond = new CCodeBinaryExpression (CCodeBinaryOperator.AND, holds, rv);
var warn = new CCodeFunctionCall (new CCodeIdentifier ("g_warning"));
warn.add_argument (new CCodeConstant ("\"Invalid GValue unboxing (wrong type or
NULL)\""));
var fail = new CCodeCommaExpression ();
fail.append_expression (warn);
fail.append_expression (ctemp);
- rv = new CCodeConditionalExpression (cond, rv, fail);
+ rv = new CCodeConditionalExpression (cond, new CCodeUnaryExpression
(CCodeUnaryOperator.POINTER_INDIRECTION, rv), fail);
+ } else {
+ rv = ccall;
}
set_cvalue (expr, rv);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]