Commit 7fb398dc authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter

remove option to disable automatic memory management, manual memory

2007-12-15  Juerg Billeter  <j@bitron.ch>

	* vala/valasemanticanalyzer.vala,
	  gobject/valaccodeassignmentbinding.vala,
	  gobject/valaccodegenerator.vala, gobject/valaccodegeneratorclass.vala,
	  compiler/valacompiler.vala, doc/valac.1: remove option to disable
	  automatic memory management, manual memory management is now possible
	  with pointers

svn path=/trunk/; revision=776
parent ddac3afc
2007-12-15 Jürg Billeter <j@bitron.ch>
* vala/valasemanticanalyzer.vala,
gobject/valaccodeassignmentbinding.vala,
gobject/valaccodegenerator.vala, gobject/valaccodegeneratorclass.vala,
compiler/valacompiler.vala, doc/valac.1: remove option to disable
automatic memory management, manual memory management is now possible
with pointers
2007-12-15 Jürg Billeter <j@bitron.ch>
* vala/Makefile.am, vala/valadatatype.vala, vala/valanulltype.vala,
......
......@@ -34,7 +34,6 @@ class Vala.Compiler : Object {
static string library;
[NoArrayLength ()]
static string[] packages;
static bool disable_memory_management;
static bool ccode_only;
static bool compile_only;
......@@ -58,7 +57,6 @@ class Vala.Compiler : Object {
{ "basedir", 'b', 0, OptionArg.FILENAME, out basedir, "Base source directory", "DIRECTORY" },
{ "directory", 'd', 0, OptionArg.FILENAME, out directory, "Output directory", "DIRECTORY" },
{ "version", 0, 0, OptionArg.NONE, ref version, "Display version number", null },
{ "disable-memory-management", 0, 0, OptionArg.NONE, ref disable_memory_management, "Disable memory management", null },
{ "ccode", 'C', 0, OptionArg.NONE, ref ccode_only, "Output C code", null },
{ "compile", 'c', 0, OptionArg.NONE, ref compile_only, "Compile but do not link", null },
{ "output", 'o', 0, OptionArg.FILENAME, out output, "Place output in file FILE", "FILE" },
......@@ -160,7 +158,6 @@ class Vala.Compiler : Object {
}
context.library = library;
context.memory_management = !disable_memory_management;
context.assert = !disable_assert;
context.checking = !disable_checking;
......@@ -180,7 +177,7 @@ class Vala.Compiler : Object {
context.optlevel = optlevel;
context.save_temps = save_temps;
context.codegen = new CCodeGenerator (!disable_memory_management);
context.codegen = new CCodeGenerator ();
/* default package */
if (!add_package (context, "glib-2.0")) {
......@@ -246,23 +243,21 @@ class Vala.Compiler : Object {
var dbus_binding_provider = new DBusBindingProvider ();
dbus_binding_provider.context = context;
var analyzer = new SemanticAnalyzer (!disable_memory_management);
var analyzer = new SemanticAnalyzer ();
analyzer.add_binding_provider (dbus_binding_provider);
analyzer.analyze (context);
if (Report.get_errors () > 0) {
return quit ();
}
if (!disable_memory_management) {
var memory_manager = new MemoryManager ();
memory_manager.analyze (context);
if (Report.get_errors () > 0) {
return quit ();
}
var memory_manager = new MemoryManager ();
memory_manager.analyze (context);
if (Report.get_errors () > 0) {
return quit ();
}
context.codegen.emit (context);
if (Report.get_errors () > 0) {
......
......@@ -34,9 +34,6 @@ Output directory
.TP
.B \---version
Display version number
.TP
.B \---disable-memory-management
Disable memory management
.SH FEATURES
Interfaces, Properties, Signals, Foreach, Lambda expressions, Type
inference for local variables, Assisted memory management
......
......@@ -337,7 +337,7 @@ public class Vala.CCodeAssignmentBinding : CCodeExpressionBinding {
rhs = codegen.get_implicit_cast_expression (rhs, assignment.right.static_type, assignment.left.static_type);
bool unref_old = (codegen.memory_management && assignment.left.static_type.takes_ownership);
bool unref_old = (assignment.left.static_type.takes_ownership);
bool array = false;
if (assignment.left.static_type.data_type is Array) {
array = !(codegen.get_array_length_cexpression (assignment.left, 1) is CCodeConstant);
......
......@@ -28,11 +28,6 @@ using Gee;
* Code visitor generating C Code.
*/
public class Vala.CCodeGenerator : CodeGenerator {
/**
* Specifies whether automatic memory management is active.
*/
public bool memory_management { get; set; }
private CodeContext context;
Symbol root_symbol;
......@@ -123,8 +118,7 @@ public class Vala.CCodeGenerator : CodeGenerator {
private bool requires_array_free;
private bool requires_array_move;
public CCodeGenerator (bool manage_memory = true) {
memory_management = manage_memory;
public CCodeGenerator () {
}
construct {
......@@ -779,17 +773,15 @@ public class Vala.CCodeGenerator : CodeGenerator {
cblock.add_statement ((CCodeStatement) stmt.ccodenode);
}
}
if (memory_management) {
foreach (VariableDeclarator decl in local_vars) {
if (decl.type_reference.takes_ownership) {
var ma = new MemberAccess.simple (decl.name);
ma.symbol_reference = decl;
cblock.add_statement (new CCodeExpressionStatement (get_unref_expression (new CCodeIdentifier (get_variable_cname (decl.name)), decl.type_reference, ma)));
}
foreach (VariableDeclarator decl in local_vars) {
if (decl.type_reference.takes_ownership) {
var ma = new MemberAccess.simple (decl.name);
ma.symbol_reference = decl;
cblock.add_statement (new CCodeExpressionStatement (get_unref_expression (new CCodeIdentifier (get_variable_cname (decl.name)), decl.type_reference, ma)));
}
}
b.ccodenode = cblock;
current_symbol = current_symbol.parent_symbol;
......@@ -1087,12 +1079,6 @@ public class Vala.CCodeGenerator : CodeGenerator {
}
public override void visit_end_full_expression (Expression! expr) {
if (!memory_management) {
temp_vars.clear ();
temp_ref_vars.clear ();
return;
}
/* expr is a full expression, i.e. an initializer, the
* expression in an expression statement, the controlling
* expression in if, while, for, or foreach statements
......@@ -1245,12 +1231,7 @@ public class Vala.CCodeGenerator : CodeGenerator {
}
/* free temporary objects */
if (!memory_management) {
temp_vars.clear ();
temp_ref_vars.clear ();
return;
}
if (((Gee.List<VariableDeclarator>) temp_vars).size == 0) {
/* nothing to do without temporary variables */
return;
......@@ -1706,15 +1687,13 @@ public class Vala.CCodeGenerator : CodeGenerator {
cblock.add_statement (cwhile);
}
if (memory_management) {
foreach (VariableDeclarator decl in stmt.get_local_variables ()) {
if (decl.type_reference.takes_ownership) {
var ma = new MemberAccess.simple (decl.name);
ma.symbol_reference = decl;
var cunref = new CCodeExpressionStatement (get_unref_expression (new CCodeIdentifier (get_variable_cname (decl.name)), decl.type_reference, ma));
cunref.line = cblock.line;
cblock.add_statement (cunref);
}
foreach (VariableDeclarator decl in stmt.get_local_variables ()) {
if (decl.type_reference.takes_ownership) {
var ma = new MemberAccess.simple (decl.name);
ma.symbol_reference = decl;
var cunref = new CCodeExpressionStatement (get_unref_expression (new CCodeIdentifier (get_variable_cname (decl.name)), decl.type_reference, ma));
cunref.line = cblock.line;
cblock.add_statement (cunref);
}
}
}
......@@ -1757,10 +1736,6 @@ public class Vala.CCodeGenerator : CodeGenerator {
}
private void create_local_free (CodeNode stmt, bool stop_at_loop = false) {
if (!memory_management) {
return;
}
var cfrag = new CCodeFragment ();
append_local_free (current_symbol, cfrag, stop_at_loop);
......@@ -1792,10 +1767,6 @@ public class Vala.CCodeGenerator : CodeGenerator {
}
private void create_local_free_expr (Expression expr) {
if (!memory_management) {
return;
}
var return_expr_decl = get_temp_variable_declarator (expr.static_type, true, expr);
var ccomma = new CCodeCommaExpression ();
......@@ -1893,20 +1864,16 @@ public class Vala.CCodeGenerator : CodeGenerator {
var cfrag = new CCodeFragment ();
if (memory_management) {
/* declare temporary objects */
append_temp_decl (cfrag, temp_vars);
}
/* declare temporary objects */
append_temp_decl (cfrag, temp_vars);
cfrag.append (new CCodeExpressionStatement ((CCodeExpression) stmt.error_expression.ccodenode));
if (memory_management) {
/* free temporary objects */
foreach (VariableDeclarator decl in temp_ref_vars) {
var ma = new MemberAccess.simple (decl.name);
ma.symbol_reference = decl;
cfrag.append (new CCodeExpressionStatement (get_unref_expression (new CCodeIdentifier (decl.name), decl.type_reference, ma)));
}
/* free temporary objects */
foreach (VariableDeclarator decl in temp_ref_vars) {
var ma = new MemberAccess.simple (decl.name);
ma.symbol_reference = decl;
cfrag.append (new CCodeExpressionStatement (get_unref_expression (new CCodeIdentifier (decl.name), decl.type_reference, ma)));
}
temp_vars.clear ();
......
......@@ -162,7 +162,7 @@ public class Vala.CCodeGenerator {
add_instance_init_function (cl);
if (is_gobject) {
if ((memory_management && cl.get_fields ().size > 0) || cl.destructor != null) {
if (cl.get_fields ().size > 0 || cl.destructor != null) {
add_dispose_function (cl);
}
}
......@@ -330,7 +330,7 @@ public class Vala.CCodeGenerator {
}
/* set dispose function */
if (memory_management && cl.get_fields ().size > 0) {
if (cl.get_fields ().size > 0) {
var ccast = new CCodeFunctionCall (new CCodeIdentifier ("G_OBJECT_CLASS"));
ccast.add_argument (new CCodeIdentifier ("klass"));
init_block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeMemberAccess.pointer (ccast, "dispose"), new CCodeIdentifier ("%s_dispose".printf (cl.get_lower_case_cname (null))))));
......
......@@ -28,11 +28,6 @@ using Gee;
* Code visitor analyzing and checking code.
*/
public class Vala.SemanticAnalyzer : CodeVisitor {
/**
* Specifies whether automatic memory management is active.
*/
public bool memory_management { get; set; }
private CodeContext context;
Symbol root_symbol;
......@@ -66,8 +61,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
private Collection<BindingProvider> binding_providers = new ArrayList<BindingProvider> ();
public SemanticAnalyzer (bool manage_memory = true) {
memory_management = manage_memory;
public SemanticAnalyzer () {
}
public void add_binding_provider (BindingProvider! binding_provider) {
......@@ -705,15 +699,13 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
}
}
if (memory_management) {
if (decl.initializer.static_type.transfers_ownership) {
/* rhs transfers ownership of the expression */
if (!(decl.type_reference is PointerType) && !decl.type_reference.takes_ownership) {
/* lhs doesn't own the value */
decl.error = true;
Report.error (decl.source_reference, "Invalid assignment from owned expression to unowned variable");
return;
}
if (decl.initializer.static_type.transfers_ownership) {
/* rhs transfers ownership of the expression */
if (!(decl.type_reference is PointerType) && !decl.type_reference.takes_ownership) {
/* lhs doesn't own the value */
decl.error = true;
Report.error (decl.source_reference, "Invalid assignment from owned expression to unowned variable");
return;
}
}
}
......@@ -2697,20 +2689,18 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
return;
}
if (memory_management) {
if (a.right.static_type.transfers_ownership) {
/* rhs transfers ownership of the expression */
if (!(a.left.static_type is PointerType) && !a.left.static_type.takes_ownership) {
/* 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
* rhs doesn't transfer the ownership
* code generator needs to add reference
* increment calls */
if (a.right.static_type.transfers_ownership) {
/* rhs transfers ownership of the expression */
if (!(a.left.static_type is PointerType) && !a.left.static_type.takes_ownership) {
/* 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
* rhs doesn't transfer the ownership
* code generator needs to add reference
* increment calls */
}
}
} else if (a.left is ElementAccess) {
......@@ -2724,30 +2714,28 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
return;
}
if (memory_management) {
if (a.right.static_type.transfers_ownership) {
/* rhs transfers ownership of the expression */
if (a.right.static_type.transfers_ownership) {
/* rhs transfers ownership of the expression */
var args = ea.container.static_type.get_type_arguments ();
if (args.size != 1) {
a.error = true;
Report.error (ea.source_reference, "internal error: array reference without type arguments");
return;
}
var element_type = args.get (0);
var args = ea.container.static_type.get_type_arguments ();
if (args.size != 1) {
a.error = true;
Report.error (ea.source_reference, "internal error: array reference without type arguments");
return;
}
var element_type = args.get (0);
if (!(element_type is PointerType) && !element_type.takes_ownership) {
/* lhs doesn't own the value */
a.error = true;
Report.error (a.source_reference, "Invalid assignment from owned expression to unowned variable");
return;
}
} else if (a.left.static_type.takes_ownership) {
/* lhs wants to own the value
* rhs doesn't transfer the ownership
* code generator needs to add reference
* increment calls */
if (!(element_type is PointerType) && !element_type.takes_ownership) {
/* lhs doesn't own the value */
a.error = true;
Report.error (a.source_reference, "Invalid assignment from owned expression to unowned variable");
return;
}
} else if (a.left.static_type.takes_ownership) {
/* lhs wants to own the value
* rhs doesn't transfer the ownership
* code generator needs to add reference
* increment calls */
}
} else {
return;
......
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