31
31
public Symbol? current_symbol;
32
32
public ArrayList<Symbol> symbol_stack = new ArrayList<Symbol> ();
33
33
public TryStatement current_try;
34
public CatchClause current_catch;
34
35
public CCodeFunction ccode;
35
36
public ArrayList<CCodeFunction> ccode_stack = new ArrayList<CCodeFunction> ();
36
37
public ArrayList<LocalVariable> temp_ref_vars = new ArrayList<LocalVariable> ();
69
70
set { emit_context.current_try = value; }
73
public CatchClause current_catch {
74
get { return emit_context.current_catch; }
75
set { emit_context.current_catch = value; }
72
78
public TypeSymbol? current_type_symbol {
74
80
var sym = current_symbol;
268
274
public TypeSymbol gbytearray_type;
269
275
public TypeSymbol gptrarray_type;
270
276
public TypeSymbol gthreadpool_type;
277
public DataType gdestroynotify_type;
271
278
public DataType gquark_type;
272
279
public Struct gvalue_type;
273
280
public Class gvariant_type;
406
413
gbytearray_type = (TypeSymbol) glib_ns.scope.lookup ("ByteArray");
407
414
gptrarray_type = (TypeSymbol) glib_ns.scope.lookup ("PtrArray");
408
415
gthreadpool_type = (TypeSymbol) glib_ns.scope.lookup ("ThreadPool");
416
gdestroynotify_type = new DelegateType ((Delegate) glib_ns.scope.lookup ("DestroyNotify"));
410
418
gquark_type = new IntegerType ((Struct) glib_ns.scope.lookup ("Quark"));
411
419
gvalue_type = (Struct) glib_ns.scope.lookup ("Value");
2044
2052
var target_var = new LocalVariable (new PointerType (new VoidType ()), get_delegate_target_cname (get_variable_cname (local.name)));
2045
2053
emit_temp_var (target_var);
2046
2054
if (deleg_type.value_owned) {
2047
var target_destroy_notify_var = new LocalVariable (new DelegateType ((Delegate) context.root.scope.lookup ("GLib").scope.lookup ("DestroyNotify")), get_delegate_target_destroy_notify_cname (get_variable_cname (local.name)));
2055
var target_destroy_notify_var = new LocalVariable (gdestroynotify_type, get_delegate_target_destroy_notify_cname (get_variable_cname (local.name)));
2048
2056
emit_temp_var (target_destroy_notify_var);
3188
3196
temp_ref_vars.clear ();
3191
public virtual void append_local_free (Symbol sym, bool stop_at_loop = false) {
3199
public virtual void append_local_free (Symbol sym, bool stop_at_loop = false, CodeNode? stop_at = null) {
3192
3200
var b = (Block) sym;
3194
3202
var local_vars = b.get_local_variables ();
3223
if (sym.parent_symbol is Block) {
3224
append_local_free (sym.parent_symbol, stop_at_loop);
3225
} else if (sym.parent_symbol is Method) {
3226
append_param_free ((Method) sym.parent_symbol);
3230
public void append_error_free (Symbol sym, TryStatement current_try) {
3231
var b = (Block) sym;
3233
var local_vars = b.get_local_variables ();
3234
// free in reverse order
3235
for (int i = local_vars.size - 1; i >= 0; i--) {
3236
var local = local_vars[i];
3237
if (!local.unreachable && local.active && !local.floating && !local.captured && requires_destroy (local.variable_type)) {
3238
var ma = new MemberAccess.simple (local.name);
3239
ma.symbol_reference = local;
3240
ma.value_type = local.variable_type.copy ();
3241
visit_member_access (ma);
3242
ccode.add_expression (get_unref_expression (get_variable_cexpression (local.name), local.variable_type, ma));
3247
int block_id = get_block_id (b);
3249
var data_unref = new CCodeFunctionCall (new CCodeIdentifier ("block%d_data_unref".printf (block_id)));
3250
data_unref.add_argument (get_variable_cexpression ("_data%d_".printf (block_id)));
3251
ccode.add_expression (data_unref);
3254
if (sym == current_try.body) {
3231
if (b.parent_node == stop_at) {
3258
3235
if (sym.parent_symbol is Block) {
3259
append_error_free (sym.parent_symbol, current_try);
3236
append_local_free (sym.parent_symbol, stop_at_loop, stop_at);
3260
3237
} else if (sym.parent_symbol is Method) {
3261
3238
append_param_free ((Method) sym.parent_symbol);
4642
public virtual CCodeExpression? deserialize_expression (DataType type, CCodeExpression variant_expr, CCodeExpression? expr) {
4619
public virtual CCodeExpression? deserialize_expression (DataType type, CCodeExpression variant_expr, CCodeExpression? expr, CCodeExpression? error_expr = null, out bool may_fail = null) {
4756
4733
var cvar = get_variable_cexpression (temp_decl.name);
4758
4735
ccode.add_expression (new CCodeAssignment (cvar, get_cvalue (expr.inner)));
4759
ccode.add_expression (new CCodeAssignment (get_cvalue (expr.inner), new CCodeConstant ("NULL")));
4736
if (!(expr.value_type is DelegateType)) {
4737
ccode.add_expression (new CCodeAssignment (get_cvalue (expr.inner), new CCodeConstant ("NULL")));
4761
4740
set_cvalue (expr, cvar);
4770
4749
var delegate_type = expr.value_type as DelegateType;
4771
4750
if (delegate_type != null && delegate_type.delegate_symbol.has_target) {
4751
var temp_target_decl = get_temp_variable (new PointerType (new VoidType ()), true, expr, false);
4752
emit_temp_var (temp_target_decl);
4753
var target_cvar = get_variable_cexpression (temp_target_decl.name);
4772
4754
CCodeExpression target_destroy_notify;
4773
set_delegate_target (expr, get_delegate_target_cexpression (expr.inner, out target_destroy_notify));
4755
var target = get_delegate_target_cexpression (expr.inner, out target_destroy_notify);
4756
ccode.add_expression (new CCodeAssignment (target_cvar, target));
4757
set_delegate_target (expr, target_cvar);
4774
4758
if (target_destroy_notify != null) {
4775
set_delegate_target_destroy_notify (expr, target_destroy_notify);
4759
var temp_target_destroy_notify_decl = get_temp_variable (gdestroynotify_type, true, expr, false);
4760
emit_temp_var (temp_target_destroy_notify_decl);
4761
var target_destroy_notify_cvar = get_variable_cexpression (temp_target_destroy_notify_decl.name);
4762
ccode.add_expression (new CCodeAssignment (target_destroy_notify_cvar, target_destroy_notify));
4763
ccode.add_expression (new CCodeAssignment (target_destroy_notify, new CCodeConstant ("NULL")));
4764
set_delegate_target_destroy_notify (expr, target_destroy_notify_cvar);
5223
5212
} else if (expression_type is DelegateType && expr != null) {
5224
5213
var target_decl = new LocalVariable (new PointerType (new VoidType ()), get_delegate_target_cname (decl.name));
5225
5214
emit_temp_var (target_decl);
5226
var target_destroy_notify_decl = new LocalVariable (new DelegateType ((Delegate) context.root.scope.lookup ("GLib").scope.lookup ("DestroyNotify")), get_delegate_target_destroy_notify_cname (decl.name));
5215
var target_destroy_notify_decl = new LocalVariable (gdestroynotify_type, get_delegate_target_destroy_notify_cname (decl.name));
5227
5216
emit_temp_var (target_destroy_notify_decl);
5228
5217
CCodeExpression target_destroy_notify;
5229
5218
ccode.add_expression (new CCodeAssignment (get_variable_cexpression (target_decl.name), get_delegate_target_cexpression (expr, out target_destroy_notify)));
5860
5849
return new CCodeFunctionCall (new CCodeIdentifier (""));
5863
public virtual void register_dbus_info (ObjectTypeSymbol bindable) {
5852
public virtual void register_dbus_info (CCodeBlock block, ObjectTypeSymbol bindable) {
5866
5855
public virtual string get_dynamic_property_getter_cname (DynamicProperty node) {