Commit afccf51c authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter

Remove CCodeExpressionBinding

2008-10-24  Jürg Billeter  <j@bitron.ch>

	* gobject/Makefile.am:
	* gobject/valaccodearraycreationexpressionbinding.vala:
	* gobject/valaccodeassignmentbinding.vala:
	* gobject/valaccodeelementaccessbinding.vala:
	* gobject/valaccodeexpressionbinding.vala:
	* gobject/valaccodeinvocationexpressionbinding.vala:
	* gobject/valaccodememberaccessbinding.vala:

	Remove CCodeExpressionBinding

svn path=/trunk/; revision=1889
parent 4b8375f8
2008-10-24 Jürg Billeter <j@bitron.ch>
* gobject/Makefile.am:
* gobject/valaccodearraycreationexpressionbinding.vala:
* gobject/valaccodeassignmentbinding.vala:
* gobject/valaccodeelementaccessbinding.vala:
* gobject/valaccodeexpressionbinding.vala:
* gobject/valaccodeinvocationexpressionbinding.vala:
* gobject/valaccodememberaccessbinding.vala:
Remove CCodeExpressionBinding
2008-10-24 Jürg Billeter <j@bitron.ch>
* vala/valaclass.vala:
......
......@@ -20,7 +20,6 @@ libvala_la_VALASOURCES = \
valaccodedynamicpropertybinding.vala \
valaccodedynamicsignalbinding.vala \
valaccodeelementaccessbinding.vala \
valaccodeexpressionbinding.vala \
valaccodegenerator.vala \
valaccodegeneratorsignal.vala \
valaccodegeneratorsourcefile.vala \
......
......@@ -27,7 +27,7 @@ using Gee;
/**
* The link between an assignment and generated code.
*/
public class Vala.CCodeArrayCreationExpressionBinding : CCodeExpressionBinding {
public class Vala.CCodeArrayCreationExpressionBinding : CCodeBinding {
public ArrayCreationExpression array_creation_expression { get; set; }
public CCodeArrayCreationExpressionBinding (CCodeGenerator codegen, ArrayCreationExpression array_creation_expression) {
......@@ -97,11 +97,9 @@ public class Vala.CCodeArrayCreationExpressionBinding : CCodeExpressionBinding {
ce.append_expression (name_cnode);
codenode = ce;
expr.ccodenode = ce;
} else {
codenode = gnew;
expr.ccodenode = gnew;
}
expr.ccodenode = codenode;
}
}
......@@ -27,7 +27,7 @@ using Gee;
/**
* The link between an assignment and generated code.
*/
public class Vala.CCodeAssignmentBinding : CCodeExpressionBinding {
public class Vala.CCodeAssignmentBinding : CCodeBinding {
public Assignment assignment { get; set; }
public CCodeAssignmentBinding (CCodeGenerator codegen, Assignment assignment) {
......@@ -35,13 +35,13 @@ public class Vala.CCodeAssignmentBinding : CCodeExpressionBinding {
this.codegen = codegen;
}
private void emit_property_assignment () {
CCodeExpression emit_property_assignment () {
var ma = assignment.left as MemberAccess;
var prop = (Property) assignment.left.symbol_reference;
if (prop.set_accessor.construction && codegen.current_type_symbol is Class && codegen.current_class.is_subtype_of (codegen.gobject_type) && codegen.in_creation_method) {
codenode = head.get_construct_property_assignment (prop.get_canonical_cconstant (), prop.property_type, (CCodeExpression) assignment.right.ccodenode);
return head.get_construct_property_assignment (prop.get_canonical_cconstant (), prop.property_type, (CCodeExpression) assignment.right.ccodenode);
} else {
CCodeExpression cexpr = (CCodeExpression) assignment.right.ccodenode;
......@@ -85,14 +85,14 @@ public class Vala.CCodeAssignmentBinding : CCodeExpressionBinding {
ccomma.append_expression (ccall); // update property
ccomma.append_expression ((CCodeExpression) codegen.get_ccodenode (ma)); // current property value
codenode = ccomma;
return ccomma;
} else {
codenode = ccall;
return ccall;
}
}
}
private void emit_signal_assignment () {
CCodeExpression? emit_signal_assignment () {
var sig = (Signal) assignment.left.symbol_reference;
var m = (Method) assignment.right.symbol_reference;
......@@ -119,7 +119,7 @@ public class Vala.CCodeAssignmentBinding : CCodeExpressionBinding {
} else {
assignment.error = true;
Report.error (assignment.source_reference, "Specified compound assignment type for signals not supported.");
return;
return null;
}
var ccall = new CCodeFunctionCall (new CCodeIdentifier (connect_func));
......@@ -135,7 +135,7 @@ public class Vala.CCodeAssignmentBinding : CCodeExpressionBinding {
if (detail_expr == null) {
assignment.error = true;
Report.error (detail_expr.source_reference, "internal error: only literal string details supported");
return;
return null;
}
signal_detail = detail_expr.eval ();
} else {
......@@ -228,10 +228,10 @@ public class Vala.CCodeAssignmentBinding : CCodeExpressionBinding {
ccall.add_argument (new CCodeConstant ("NULL"));
}
codenode = ccall;
return ccall;
}
private void emit_non_array_element_access () {
private CCodeExpression? emit_non_array_element_access () {
// custom element access
CCodeExpression rhs = (CCodeExpression) assignment.right.ccodenode;
......@@ -269,14 +269,15 @@ public class Vala.CCodeAssignmentBinding : CCodeExpressionBinding {
set_ccall.add_argument (cindex);
set_ccall.add_argument (codegen.convert_to_generic_pointer (rhs, expr.value_type));
codenode = set_ccall;
return set_ccall;
} else {
Report.error (assignment.source_reference, "internal error: unsupported element access");
assignment.error = true;
return null;
}
}
private void emit_simple_assignment () {
CCodeExpression emit_simple_assignment () {
CCodeExpression rhs = (CCodeExpression) assignment.right.ccodenode;
bool unref_old = codegen.requires_destroy (assignment.left.value_type);
......@@ -342,7 +343,7 @@ public class Vala.CCodeAssignmentBinding : CCodeExpressionBinding {
cop = CCodeAssignmentOperator.SHIFT_RIGHT;
}
codenode = new CCodeAssignment ((CCodeExpression) codegen.get_ccodenode (assignment.left), rhs, cop);
CCodeExpression codenode = new CCodeAssignment ((CCodeExpression) codegen.get_ccodenode (assignment.left), rhs, cop);
if (unref_old && codegen.get_ccodenode (assignment.left) is CCodeElementAccess) {
// ensure that index expression in element access doesn't get evaluated more than once
......@@ -361,6 +362,8 @@ public class Vala.CCodeAssignmentBinding : CCodeExpressionBinding {
codenode = ccomma;
}
}
return codenode;
}
public override void emit () {
......@@ -372,17 +375,15 @@ public class Vala.CCodeAssignmentBinding : CCodeExpressionBinding {
}
if (assignment.left.symbol_reference is Property) {
emit_property_assignment ();
assignment.ccodenode = emit_property_assignment ();
} else if (assignment.left.symbol_reference is Signal) {
emit_signal_assignment ();
assignment.ccodenode = emit_signal_assignment ();
} else if (assignment.left is ElementAccess
&& !(((ElementAccess) assignment.left).container.value_type is ArrayType)
&& !(((ElementAccess) assignment.left).container.value_type is PointerType)) {
emit_non_array_element_access ();
assignment.ccodenode = emit_non_array_element_access ();
} else {
emit_simple_assignment ();
assignment.ccodenode = emit_simple_assignment ();
}
assignment.ccodenode = codenode;
}
}
......@@ -27,7 +27,7 @@ using Gee;
/**
* The link between an element access and generated code.
*/
public class Vala.CCodeElementAccessBinding : CCodeExpressionBinding {
public class Vala.CCodeElementAccessBinding : CCodeBinding {
public ElementAccess element_access { get; set; }
public CCodeElementAccessBinding (CCodeGenerator codegen, ElementAccess element_access) {
......@@ -51,7 +51,7 @@ public class Vala.CCodeElementAccessBinding : CCodeExpressionBinding {
var memberaccess = expr.container as MemberAccess;
if (lit != null && memberaccess != null) {
int dim = lit.value.to_int ();
codenode = codegen.get_array_length_cexpression (memberaccess.inner, dim + 1);
expr.ccodenode = codegen.get_array_length_cexpression (memberaccess.inner, dim + 1);
}
} else if (container_type == codegen.string_type.data_type) {
// access to unichar in a string
......@@ -62,7 +62,7 @@ public class Vala.CCodeElementAccessBinding : CCodeExpressionBinding {
var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_utf8_get_char"));
ccall.add_argument (coffsetcall);
codenode = ccall;
expr.ccodenode = ccall;
} else if (container_type != null && codegen.list_type != null && codegen.map_type != null &&
(container_type.is_subtype_of (codegen.list_type) || container_type.is_subtype_of (codegen.map_type))) {
TypeSymbol collection_iface = null;
......@@ -86,7 +86,7 @@ public class Vala.CCodeElementAccessBinding : CCodeExpressionBinding {
get_ccall.add_argument (new CCodeCastExpression (ccontainer, collection_iface.get_cname () + "*"));
get_ccall.add_argument (cindex);
codenode = codegen.convert_from_generic_pointer (get_ccall, expr.value_type);
expr.ccodenode = codegen.convert_from_generic_pointer (get_ccall, expr.value_type);
} else if (expr.container is MemberAccess && expr.container.symbol_reference is Signal) {
// detailed signal emission
var sig = (Signal) expr.symbol_reference;
......@@ -104,16 +104,14 @@ public class Vala.CCodeElementAccessBinding : CCodeExpressionBinding {
ccall.add_argument (sig.get_canonical_cconstant (signal_detail));
codenode = ccall;
expr.ccodenode = ccall;
} else {
// access to element in an array
for (int i = 1; i < rank; i++) {
var cmul = new CCodeBinaryExpression (CCodeBinaryOperator.MUL, new CCodeParenthesizedExpression (cindex), codegen.get_array_length_cexpression (expr.container, i + 1));
cindex = new CCodeBinaryExpression (CCodeBinaryOperator.PLUS, cmul, new CCodeParenthesizedExpression ((CCodeExpression) indices[i].ccodenode));
}
codenode = new CCodeElementAccess (ccontainer, cindex);
expr.ccodenode = new CCodeElementAccess (ccontainer, cindex);
}
expr.ccodenode = codenode;
}
}
/* valaccodeexpressionbinding.vala
*
* Copyright (C) 2007 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
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Author:
* Jürg Billeter <j@bitron.ch>
*/
using GLib;
/**
* The link between an expression and generated code.
*/
public abstract class Vala.CCodeExpressionBinding : CCodeBinding {
public CCodeExpression codenode { get; set; }
}
......@@ -24,7 +24,7 @@
using GLib;
using Gee;
public class Vala.CCodeInvocationExpressionBinding : CCodeExpressionBinding {
public class Vala.CCodeInvocationExpressionBinding : CCodeBinding {
public InvocationExpression invocation_expression { get; set; }
public CCodeInvocationExpressionBinding (CCodeGenerator codegen, InvocationExpression invocation_expression) {
......
......@@ -23,7 +23,7 @@
using GLib;
public class Vala.CCodeMemberAccessBinding : CCodeExpressionBinding {
public class Vala.CCodeMemberAccessBinding : CCodeBinding {
public MemberAccess member_access { get; set; }
public CCodeMemberAccessBinding (CCodeGenerator codegen, MemberAccess member_access) {
......
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