Commit 06d51a09 authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter

use weak local variables where appropriate default local variables to

2007-03-20  Jürg Billeter  <j@bitron.ch>

	* vala/valaparser.vala, vala/valasemanticanalyzer.vala,
	  vala/valamemorymanager.vala, vala/valacodegenerator.vala,
	  vala/valacallback.vala, vala/valainvocationexpression.vala,
	  vala/valamethod.vala, vala/valaobjectcreationexpression.vala: use weak
	  local variables where appropriate
	* vala/parser.y, vala/valasemanticanalyzer.vala: default local variables
	  to strong reference
	* vala/valasemanticanalyzer.vala: don't promote local variables from
	  weak to strong reference
	* vala/valacodegenerator.vala: warn when duplicating non-reference
	  counted structs implicitly

svn path=/trunk/; revision=247
parent f15e20a7
2007-03-20 Jürg Billeter <j@bitron.ch>
* vala/valaparser.vala, vala/valasemanticanalyzer.vala,
vala/valamemorymanager.vala, vala/valacodegenerator.vala,
vala/valacallback.vala, vala/valainvocationexpression.vala,
vala/valamethod.vala, vala/valaobjectcreationexpression.vala: use weak
local variables where appropriate
* vala/parser.y, vala/valasemanticanalyzer.vala: default local variables
to strong reference
* vala/valasemanticanalyzer.vala: don't promote local variables from
weak to strong reference
* vala/valacodegenerator.vala: warn when duplicating non-reference
counted structs implicitly
2007-03-20 Jürg Billeter <j@bitron.ch>
* tests/testrunner.sh: run with /bin/bash due to bashism, patch by
......
......@@ -1464,6 +1464,7 @@ local_variable_type
$$ = vala_type_reference_new_from_expression ($1);
g_object_unref ($1);
g_object_unref (src);
vala_type_reference_set_takes_ownership ($$, TRUE);
if ($2) {
vala_type_reference_set_non_null ($$, TRUE);
}
......
......@@ -98,7 +98,7 @@ public class Vala.Callback : DataType {
}
var method_params = m.get_parameters ();
var method_params_it = method_params;
weak List<weak FormalParameter> method_params_it = method_params;
bool first = true;
foreach (FormalParameter param in parameters) {
/* use first callback parameter as instance parameter if
......
......@@ -3157,13 +3157,14 @@ public class Vala.CodeGenerator : CodeVisitor {
bool ellipsis = false;
var i = 1;
weak List<weak FormalParameter> params_it = params;
foreach (Expression arg in expr.get_argument_list ()) {
/* explicitly use strong reference as ccall gets
* unrefed at end of inner block
*/
ref CCodeExpression cexpr = (CCodeExpression) arg.ccodenode;
if (params != null) {
var param = (FormalParameter) params.data;
if (params_it != null) {
var param = (FormalParameter) params_it.data;
ellipsis = param.ellipsis;
if (!ellipsis) {
if (param.type_reference.data_type != null
......@@ -3199,12 +3200,12 @@ public class Vala.CodeGenerator : CodeVisitor {
ccall.add_argument (cexpr);
i++;
if (params != null) {
params = params.next;
if (params_it != null) {
params_it = params_it.next;
}
}
while (params != null) {
var param = (FormalParameter) params.data;
while (params_it != null) {
var param = (FormalParameter) params_it.data;
if (param.ellipsis) {
ellipsis = true;
......@@ -3232,7 +3233,7 @@ public class Vala.CodeGenerator : CodeVisitor {
ccall.add_argument ((CCodeExpression) param.default_expression.ccodenode);
i++;
params = params.next;
params_it = params_it.next;
}
if (m != null && m.instance && m.instance_last) {
......@@ -3366,6 +3367,10 @@ public class Vala.CodeGenerator : CodeVisitor {
if (expr.static_type.data_type.is_reference_counting ()) {
ref_function = expr.static_type.data_type.get_ref_function ();
} else {
if (expr.static_type.data_type != string_type.data_type) {
// duplicating non-reference counted structs may cause side-effects (and performance issues)
Report.warning (expr.source_reference, "duplicating %s instance, use weak variable or explicitly invoke copy method".printf (expr.static_type.data_type.name));
}
ref_function = expr.static_type.data_type.get_dup_function ();
}
......@@ -3418,7 +3423,7 @@ public class Vala.CodeGenerator : CodeVisitor {
public override void visit_end_object_creation_expression (ObjectCreationExpression! expr) {
if (expr.symbol_reference == null) {
// no construction method
// no creation method
if (expr.type_reference.data_type is Class) {
var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_object_new"));
......@@ -3441,22 +3446,23 @@ public class Vala.CodeGenerator : CodeVisitor {
expr.ccodenode = ccall;
}
} else {
// use construction method
// use creation method
var m = (Method) expr.symbol_reference.node;
var params = m.get_parameters ();
var ccall = new CCodeFunctionCall (new CCodeIdentifier (m.get_cname ()));
bool ellipsis = false;
int i = 1;
weak List<weak FormalParameter> params_it = params;
foreach (Expression arg in expr.get_argument_list ()) {
/* explicitly use strong reference as ccall gets
* unrefed at end of inner block
*/
ref CCodeExpression cexpr = (CCodeExpression) arg.ccodenode;
if (params != null) {
var param = (FormalParameter) params.data;
if (params_it != null) {
var param = (FormalParameter) params_it.data;
ellipsis = param.ellipsis;
if (!param.ellipsis
&& param.type_reference.data_type != null
......@@ -3473,12 +3479,12 @@ public class Vala.CodeGenerator : CodeVisitor {
ccall.add_argument (cexpr);
i++;
if (params != null) {
params = params.next;
if (params_it != null) {
params_it = params_it.next;
}
}
while (params != null) {
var param = (FormalParameter) params.data;
while (params_it != null) {
var param = (FormalParameter) params_it.data;
if (param.ellipsis) {
ellipsis = true;
......@@ -3498,7 +3504,7 @@ public class Vala.CodeGenerator : CodeVisitor {
ccall.add_argument ((CCodeExpression) param.default_expression.ccodenode);
i++;
params = params.next;
params_it = params_it.next;
}
if (ellipsis) {
......
......@@ -92,7 +92,7 @@ public class Vala.InvocationExpression : Expression {
call = (Expression) new_node;
}
List l = argument_list.find (old_node);
weak List<Expression> l = argument_list.find (old_node);
if (l != null) {
if (new_node.parent_node != null) {
return;
......
......@@ -147,9 +147,10 @@ public class Vala.MemoryManager : CodeVisitor {
var sig = (Signal) msym.node;
params = sig.get_parameters ();
}
weak List<weak FormalParameter> params_it = params;
foreach (Expression arg in expr.get_argument_list ()) {
if (params != null) {
var param = (FormalParameter) params.data;
if (params_it != null) {
var param = (FormalParameter) params_it.data;
if (!param.ellipsis
&& ((param.type_reference.data_type != null
&& param.type_reference.data_type.is_reference_type ())
......@@ -226,7 +227,7 @@ public class Vala.MemoryManager : CodeVisitor {
visit_possibly_leaked_expression (arg);
}
params = params.next;
params_it = params_it.next;
} else {
visit_possibly_leaked_expression (arg);
}
......
......@@ -293,7 +293,7 @@ public class Vala.Method : Member, Invokable {
}
var method_params = m2.get_parameters ();
var method_params_it = method_params;
weak List<weak FormalParameter> method_params_it = method_params;
foreach (FormalParameter param in parameters) {
/* method may not expect less arguments */
if (method_params_it == null) {
......
......@@ -96,7 +96,7 @@ public class Vala.ObjectCreationExpression : Expression {
}
public override void replace (CodeNode! old_node, CodeNode! new_node) {
List l = argument_list.find (old_node);
weak List<Expression> l = argument_list.find (old_node);
if (l != null) {
if (new_node.parent_node != null) {
return;
......
......@@ -81,7 +81,7 @@ public class Vala.Parser : CodeVisitor {
String result = new String (comment);
comment = null;
string index;
weak string index;
while ((index = result.str.chr (-1, '\t')) != null) {
result.erase (result.str.pointer_to_offset (index), 1);
}
......
......@@ -119,7 +119,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
}
private ref List<DataType> get_all_prerequisites (Interface! iface) {
List<DataType> ret = null;
weak List<DataType> ret = null;
foreach (TypeReference prereq in iface.get_prerequisites ()) {
DataType type = prereq.data_type;
......@@ -593,7 +593,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
}
decl.type_reference = decl.initializer.static_type.copy ();
decl.type_reference.takes_ownership = decl.type_reference.transfers_ownership;
decl.type_reference.takes_ownership = (decl.type_reference.data_type == null || decl.type_reference.data_type.is_reference_type ());
decl.type_reference.transfers_ownership = false;
}
......@@ -1182,7 +1182,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
}
var args = expr.get_argument_list ();
List arg_it = args;
weak List<weak Expression> arg_it = args;
foreach (FormalParameter param in params) {
if (param.ellipsis) {
break;
......@@ -1200,8 +1200,8 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
}
private bool check_arguments (Expression! expr, Symbol! msym, List<FormalParameter> params, List<Expression> args) {
List prev_arg_it = null;
List arg_it = args;
weak List<weak Expression> prev_arg_it = null;
weak List<weak Expression> arg_it = args;
bool diag = (msym.node.get_attribute ("Diagnostics") != null);
......@@ -1910,7 +1910,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
l.method.symbol.parent_symbol = current_symbol;
var lambda_params = l.get_parameters ();
var lambda_param_it = lambda_params;
weak List<weak FormalParameter> lambda_param_it = lambda_params;
foreach (FormalParameter cb_param in cb.get_parameters ()) {
if (lambda_param_it == null) {
/* lambda expressions are allowed to have less parameters */
......@@ -2125,14 +2125,9 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
if (a.right.static_type.transfers_ownership) {
/* rhs transfers ownership of the expression */
if (!a.left.static_type.takes_ownership) {
/* lhs doesn't own the value
* promote lhs type if it is a local variable
* error if it's not a local variable */
if (!(ma.symbol_reference.node is VariableDeclarator)) {
Report.error (a.source_reference, "Invalid assignment from owned expression to unowned variable");
}
a.left.static_type.takes_ownership = true;
/* lhs doesn't own the value */
a.error = true;
Report.error (a.source_reference, "Invalid assignment from owned expression to unowned variable");
}
} else if (a.left.static_type.takes_ownership) {
/* lhs wants to own the value
......
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