Commit 4c1bb6f1 authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter

Use lazy initialization for code bindings

2008-04-19  Juerg Billeter  <j@bitron.ch>

	* vala/valaarraycreationexpression.vala, vala/valaassignment.vala,
	  vala/valacodebinding.vala, vala/valacodecontext.vala,
	  vala/valacodenode.vala, vala/valaelementaccess.vala,
	  vala/valamethod.vala, vala/valaparser.vala,
	  vala/valasemanticanalyzer.vala,
	  gobject/valaccodearraycreationexpressionbinding.vala,
	  gobject/valaccodeassignmentbinding.vala,
	  gobject/valaccodebinding.vala,
	  gobject/valaccodeelementaccessbinding.vala,
	  gobject/valaccodegenerator.vala,
	  gobject/valaccodegeneratormemberaccess.vala,
	  gobject/valaccodemethodbinding.vala,
	  gobject/valadbusbindingprovider.vala:

	  Use lazy initialization for code bindings

svn path=/trunk/; revision=1259
parent de625c6f
2008-04-19 Jürg Billeter <j@bitron.ch>
* vala/valaarraycreationexpression.vala, vala/valaassignment.vala,
vala/valacodebinding.vala, vala/valacodecontext.vala,
vala/valacodenode.vala, vala/valaelementaccess.vala,
vala/valamethod.vala, vala/valaparser.vala,
vala/valasemanticanalyzer.vala,
gobject/valaccodearraycreationexpressionbinding.vala,
gobject/valaccodeassignmentbinding.vala,
gobject/valaccodebinding.vala,
gobject/valaccodeelementaccessbinding.vala,
gobject/valaccodegenerator.vala,
gobject/valaccodegeneratormemberaccess.vala,
gobject/valaccodemethodbinding.vala,
gobject/valadbusbindingprovider.vala:
Use lazy initialization for code bindings
2008-04-19 Jürg Billeter <j@bitron.ch>
* gobject/valaccodegenerator.vala: fix casts to GTypeInstance
......
......@@ -30,7 +30,7 @@ using Gee;
public class Vala.CCodeArrayCreationExpressionBinding : CCodeExpressionBinding {
public ArrayCreationExpression array_creation_expression { get; set; }
public CCodeArrayCreationExpressionBinding (CodeGenerator codegen, ArrayCreationExpression array_creation_expression) {
public CCodeArrayCreationExpressionBinding (CCodeGenerator codegen, ArrayCreationExpression array_creation_expression) {
this.array_creation_expression = array_creation_expression;
this.codegen = codegen;
}
......
......@@ -30,7 +30,7 @@ using Gee;
public class Vala.CCodeAssignmentBinding : CCodeExpressionBinding {
public Assignment assignment { get; set; }
public CCodeAssignmentBinding (CodeGenerator codegen, Assignment assignment) {
public CCodeAssignmentBinding (CCodeGenerator codegen, Assignment assignment) {
this.assignment = assignment;
this.codegen = codegen;
}
......
/* valaccodebinding.vala
*
* Copyright (C) 2007 Jürg Billeter
* Copyright (C) 2007-2008 Jürg Billeter
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -30,4 +30,29 @@ public abstract class Vala.CCodeBinding : CodeBinding {
* The C Code generator.
*/
public CCodeGenerator codegen { get; set; }
/**
* Generate code for this source code node.
*/
public abstract void emit ();
public CCodeBinding? code_binding (CodeNode node) {
return (CCodeBinding) node.get_code_binding (codegen);
}
public CCodeMethodBinding method_binding (Method node) {
return (CCodeMethodBinding) node.get_code_binding (codegen);
}
public CCodeArrayCreationExpressionBinding array_creation_expression_binding (ArrayCreationExpression node) {
return (CCodeArrayCreationExpressionBinding) node.get_code_binding (codegen);
}
public CCodeElementAccessBinding element_access_binding (ElementAccess node) {
return (CCodeElementAccessBinding) node.get_code_binding (codegen);
}
public CCodeAssignmentBinding assignment_binding (Assignment node) {
return (CCodeAssignmentBinding) node.get_code_binding (codegen);
}
}
......@@ -30,7 +30,7 @@ using Gee;
public class Vala.CCodeElementAccessBinding : CCodeExpressionBinding {
public ElementAccess element_access { get; set; }
public CCodeElementAccessBinding (CodeGenerator codegen, ElementAccess element_access) {
public CCodeElementAccessBinding (CCodeGenerator codegen, ElementAccess element_access) {
this.element_access = element_access;
this.codegen = codegen;
}
......
......@@ -2321,7 +2321,7 @@ public class Vala.CCodeGenerator : CodeGenerator {
}
public override void visit_array_creation_expression (ArrayCreationExpression expr) {
expr.code_binding.emit ();
code_binding (expr).emit ();
}
public override void visit_boolean_literal (BooleanLiteral expr) {
......@@ -2624,7 +2624,7 @@ public class Vala.CCodeGenerator : CodeGenerator {
}
public override void visit_element_access (ElementAccess expr) {
expr.code_binding.emit ();
code_binding (expr).emit ();
}
public override void visit_base_access (BaseAccess expr) {
......@@ -3451,7 +3451,7 @@ public class Vala.CCodeGenerator : CodeGenerator {
}
public override void visit_assignment (Assignment a) {
a.code_binding.emit ();
code_binding (a).emit ();
}
public CCodeFunctionCall get_property_set_call (Property prop, MemberAccess ma, CCodeExpression cexpr) {
......@@ -3844,4 +3844,24 @@ public class Vala.CCodeGenerator : CodeGenerator {
public override CodeBinding? create_assignment_binding (Assignment node) {
return new CCodeAssignmentBinding (this, node);
}
public CCodeBinding? code_binding (CodeNode node) {
return (CCodeBinding) node.get_code_binding (this);
}
public CCodeMethodBinding method_binding (Method node) {
return (CCodeMethodBinding) node.get_code_binding (this);
}
public CCodeArrayCreationExpressionBinding array_creation_expression_binding (ArrayCreationExpression node) {
return (CCodeArrayCreationExpressionBinding) node.get_code_binding (this);
}
public CCodeElementAccessBinding element_access_binding (ElementAccess node) {
return (CCodeElementAccessBinding) node.get_code_binding (this);
}
public CCodeAssignmentBinding assignment_binding (Assignment node) {
return (CCodeAssignmentBinding) node.get_code_binding (this);
}
}
......@@ -46,7 +46,7 @@ public class Vala.CCodeGenerator {
}
if (m.base_method != null) {
var binding = CCodeMethodBinding.get (m.base_method);
var binding = method_binding (m.base_method);
if (!binding.has_wrapper) {
var inst = pub_inst;
if (expr.inner != null && !expr.inner.is_pure ()) {
......
/* valaccodemethodbinding.vala
*
* Copyright (C) 2007 Jürg Billeter
* Copyright (C) 2007-2008 Jürg Billeter
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -33,15 +33,11 @@ public class Vala.CCodeMethodBinding : CCodeBinding {
get { return (method.get_attribute ("NoWrapper") == null); }
}
public CCodeMethodBinding (CodeGenerator codegen, Method method) {
public CCodeMethodBinding (CCodeGenerator codegen, Method method) {
this.method = method;
this.codegen = codegen;
}
public static CCodeMethodBinding get (Method method) {
return (CCodeMethodBinding) method.code_binding;
}
public override void emit () {
}
}
......@@ -63,13 +63,13 @@ public class Vala.DBusBindingProvider : Object, BindingProvider {
if (!is_dbus_interface (ret_type)) {
return null;
}
var m = _context.create_method ("get_object", ret_type, ma.source_reference);
var m = new Method ("get_object", ret_type, ma.source_reference);
m.set_cname ("dbus_g_proxy_new_for_name");
m.add_cheader_filename ("dbus/dbus-glib.h");
m.access = SymbolAccessibility.PUBLIC;
var string_type_ref = new ClassType (string_type);
m.add_parameter (_context.create_formal_parameter ("name", string_type_ref));
m.add_parameter (_context.create_formal_parameter ("path", string_type_ref));
m.add_parameter (new FormalParameter ("name", string_type_ref));
m.add_parameter (new FormalParameter ("path", string_type_ref));
symbols.add (m);
return m;
} else if (ma.inner != null && ma.inner.static_type != null && is_dbus_interface (ma.inner.static_type)) {
......
......@@ -104,4 +104,8 @@ public class Vala.ArrayCreationExpression : Expression {
element_type = new_type;
}
}
public override CodeBinding? create_code_binding (CodeGenerator codegen) {
return codegen.create_array_creation_expression_binding (this);
}
}
......@@ -95,6 +95,10 @@ public class Vala.Assignment : Expression {
public override bool is_pure () {
return false;
}
public override CodeBinding? create_code_binding (CodeGenerator codegen) {
return codegen.create_assignment_binding (this);
}
}
public enum Vala.AssignmentOperator {
......
/* valacodebinding.vala
*
* Copyright (C) 2007 Jürg Billeter
* Copyright (C) 2007-2008 Jürg Billeter
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -26,8 +26,4 @@ using GLib;
* The link between a source code node and generated code.
*/
public abstract class Vala.CodeBinding : Object {
/**
* Generate code for this source code node.
*/
public abstract void emit ();
}
This diff is collapsed.
......@@ -63,11 +63,6 @@ public abstract class Vala.CodeNode : Object {
}
}
/**
* Binding to the generated code.
*/
public CodeBinding? code_binding { get; set; }
/**
* Specifies whether a fatal error has been detected in this code node.
*/
......@@ -116,7 +111,8 @@ public abstract class Vala.CodeNode : Object {
return null;
}
private CodeBinding? code_binding;
private CCodeNode? _ccodenode;
/**
......@@ -135,4 +131,23 @@ public abstract class Vala.CodeNode : Object {
return str.append (" */").str;
}
/**
* Returns the binding to the generated code.
*
* @return code binding
*/
public CodeBinding? get_code_binding (CodeGenerator codegen) {
if (code_binding == null) {
code_binding = create_code_binding (codegen);
}
return code_binding;
}
/**
* Creates the binding to the generated code.
*/
public virtual CodeBinding? create_code_binding (CodeGenerator codegen) {
return null;
}
}
......@@ -81,4 +81,8 @@ public class Vala.ElementAccess : Expression {
}
return container.is_pure ();
}
public override CodeBinding? create_code_binding (CodeGenerator codegen) {
return codegen.create_element_access_binding (this);
}
}
......@@ -504,4 +504,8 @@ public class Vala.Method : Member {
}
}
}
public override CodeBinding? create_code_binding (CodeGenerator codegen) {
return codegen.create_method_binding (this);
}
}
This diff is collapsed.
......@@ -583,7 +583,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
var left = new MemberAccess (new MemberAccess.simple ("this"), p.name);
var right = new MemberAccess.simple (p.name);
method_body.add_statement (new ExpressionStatement (context.create_assignment (left, right), p.source_reference));
method_body.add_statement (new ExpressionStatement (new Assignment (left, right), p.source_reference));
}
}
......@@ -731,12 +731,12 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
}
acc.automatic_body = true;
acc.body = new Block ();
var ma = context.create_member_access_simple ("_%s".printf (acc.prop.name), acc.source_reference);
var ma = new MemberAccess.simple ("_%s".printf (acc.prop.name), acc.source_reference);
if (acc.readable) {
acc.body.add_statement (context.create_return_statement (ma, acc.source_reference));
acc.body.add_statement (new ReturnStatement (ma, acc.source_reference));
} else {
var assignment = context.create_assignment (ma, context.create_member_access_simple ("value", acc.source_reference), AssignmentOperator.SIMPLE, acc.source_reference);
acc.body.add_statement (context.create_expression_statement (assignment));
var assignment = new Assignment (ma, new MemberAccess.simple ("value", acc.source_reference), AssignmentOperator.SIMPLE, acc.source_reference);
acc.body.add_statement (new ExpressionStatement (assignment));
}
}
......@@ -1721,7 +1721,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
if (expr.call is MemberAccess &&
(expr.call.symbol_reference is CreationMethod
|| expr.call.symbol_reference is Struct)) {
var struct_creation_expression = context.create_object_creation_expression ((MemberAccess) expr.call, expr.source_reference);
var struct_creation_expression = new ObjectCreationExpression ((MemberAccess) expr.call, expr.source_reference);
struct_creation_expression.struct_creation = true;
foreach (Expression arg in expr.get_argument_list ()) {
struct_creation_expression.add_argument (arg);
......@@ -2496,7 +2496,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
var old_value = new MemberAccess (ma.inner, ma.member_name, expr.inner.source_reference);
var bin = new BinaryExpression (expr.operator == UnaryOperator.INCREMENT ? BinaryOperator.PLUS : BinaryOperator.MINUS, old_value, new IntegerLiteral ("1"), expr.source_reference);
var assignment = context.create_assignment (ma, bin, AssignmentOperator.SIMPLE, expr.source_reference);
var assignment = new Assignment (ma, bin, AssignmentOperator.SIMPLE, expr.source_reference);
var parenthexp = new ParenthesizedExpression (assignment, expr.source_reference);
expr.parent_node.replace_expression (expr, parenthexp);
parenthexp.accept (this);
......
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