Commit 69a4386f authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter
Browse files

simplify unref expression for non-null types don't mark fields as non-null

2007-04-18  Jürg Billeter  <j@bitron.ch>

	* vala/valacodegenerator.vala: simplify unref expression for non-null
	  types
	* vala/valaclass.vala: don't mark fields as non-null due to
	  initialization issue

svn path=/trunk/; revision=285
parent e5f72479
2007-04-18 Jürg Billeter <j@bitron.ch>
* vala/valacodegenerator.vala: simplify unref expression for non-null
types
* vala/valaclass.vala: don't mark fields as non-null due to
initialization issue
2007-04-12 Jürg Billeter <j@bitron.ch>
* vala/valatypereference.vala: add is_null property
......
......@@ -148,6 +148,8 @@ public class Vala.Class : DataType {
* @param f a field
*/
public void add_field (Field! f) {
// non_null fields not yet supported due to initialization issues
f.type_reference.non_null = false;
fields.append (f);
if (f.access == MemberAccessibility.PRIVATE && f.instance) {
_has_private_fields = true;
......@@ -192,7 +194,10 @@ public class Vala.Class : DataType {
if (prop.set_accessor != null && prop.set_accessor.body == null &&
source_reference != null && !source_reference.file.pkg) {
/* automatic property accessor body generation */
var f = new Field ("_%s".printf (prop.name), prop.type_reference, null, prop.source_reference);
var field_type = prop.type_reference.copy ();
// non_null fields not yet supported due to initialization issues
field_type.non_null = false;
var f = new Field ("_%s".printf (prop.name), field_type, null, prop.source_reference);
f.access = MemberAccessibility.PRIVATE;
add_field (f);
}
......
......@@ -2260,6 +2260,10 @@ public class Vala.CodeGenerator : CodeVisitor {
* if foo is of static type non-null
*/
if (type.is_null) {
return new CCodeConstant ("NULL");
}
var cisnull = new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, cvar, new CCodeConstant ("NULL"));
if (type.data_type == null) {
if (current_class == null) {
......@@ -2311,7 +2315,12 @@ public class Vala.CodeGenerator : CodeVisitor {
ccomma.append_expression (new CCodeConstant ("NULL"));
var cassign = new CCodeAssignment (cvar, ccomma);
// g_free (NULL) is allowed
if (type.non_null || (type.data_type != null && !type.data_type.is_reference_counting () && type.data_type.get_free_function () == "g_free")) {
return new CCodeParenthesizedExpression (cassign);
}
return new CCodeConditionalExpression (cisnull, new CCodeConstant ("NULL"), new CCodeParenthesizedExpression (cassign));
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment