}
void store_variable (Variable variable, TargetValue lvalue, TargetValue value, bool initializer) {
- if (!initializer && requires_destroy (variable.variable_type)) {
- /* unref old value */
- ccode.add_expression (destroy_value (lvalue));
- }
-
ccode.add_assignment (get_cvalue_ (lvalue), get_cvalue_ (value));
var array_type = variable.variable_type as ArrayType;
}
public override void store_local (LocalVariable local, TargetValue value, bool initializer) {
+ if (!initializer && requires_destroy (local.variable_type)) {
+ /* unref old value */
+ ccode.add_expression (destroy_local (local));
+ }
+
store_variable (local, get_local_cvalue (local), value, initializer);
}
public override void store_parameter (Parameter param, TargetValue value) {
+ if (requires_destroy (param.variable_type)) {
+ /* unref old value */
+ ccode.add_expression (destroy_parameter (param));
+ }
+
store_variable (param, get_parameter_cvalue (param), value, false);
}
+
+ public override void store_field (Field field, Expression? instance, TargetValue value) {
+ if (requires_destroy (field.variable_type)) {
+ /* unref old value */
+ ccode.add_expression (destroy_field (field, instance));
+ }
+
+ store_variable (field, get_field_cvalue (field, instance), value, false);
+ }
}
}
/* Returns unowned access to the given field */
- public TargetValue load_field (Field field, Expression? instance) {
+ public override TargetValue load_field (Field field, Expression? instance) {
return load_variable (field, get_field_cvalue (field, instance));
}
}
public override void store_parameter (Parameter param, TargetValue value) {
store_variable (param, get_parameter_cvalue (param), value, false);
}
+
+ public override void store_field (Field field, Expression? instance, TargetValue value) {
+ store_variable (field, get_field_cvalue (field, instance), value, false);
+ }
}
return load_variable (param, get_parameter_cvalue (param));
}
- public TargetValue load_field (Field field, Expression? instance) {
+ public override TargetValue load_field (Field field, Expression? instance) {
return load_variable (field, get_field_cvalue (field, instance));
}
}
var field = ma.symbol_reference as Field;
var property = ma.symbol_reference as Property;
- bool instance = (field != null && field.binding == MemberBinding.INSTANCE)
- || (property != null && property.binding == MemberBinding.INSTANCE);
+ bool instance = (field != null && field.binding != MemberBinding.STATIC)
+ || (property != null && property.binding != MemberBinding.STATIC);
if (operator == AssignmentOperator.SIMPLE &&
- (local != null || param != null) &&
+ (local != null || param != null || field != null) &&
!is_array_add ()) {
// visit_assignment not necessary
- if (instance) {
+ if (instance && ma.inner != null) {
ma.inner.emit (codegen);
}
codegen.store_local (local, new_value, false);
} else if (param != null) {
codegen.store_parameter (param, new_value);
+ } else if (field != null) {
+ codegen.store_field (field, instance ? ma.inner : null, new_value);
}
// when load_variable is changed to use temporary
target_value = codegen.load_local (local);
} else if (param != null) {
target_value = codegen.load_parameter (param);
+ } else if (field != null) {
+ target_value = codegen.load_field (field, instance ? ma.inner : null);
}
codegen.visit_expression (this);
// should be removed when moving codegen from
// visit_assignment to emit_store_field
ma.emit (codegen);
- } else if (instance) {
+ } else if (instance && ma.inner != null) {
ma.inner.emit (codegen);
}
} else if (ea != null) {
public abstract TargetValue load_parameter (Parameter param);
public abstract void store_parameter (Parameter param, TargetValue value);
+
+ public abstract TargetValue load_field (Field field, Expression? instance);
+
+ public abstract void store_field (Field field, Expression? instance, TargetValue value);
}