vala r1969 - in trunk: . gobject
- From: juergbi svn gnome org
- To: svn-commits-list gnome org
- Subject: vala r1969 - in trunk: . gobject
- Date: Mon, 3 Nov 2008 21:41:40 +0000 (UTC)
Author: juergbi
Date: Mon Nov 3 21:41:39 2008
New Revision: 1969
URL: http://svn.gnome.org/viewvc/vala?rev=1969&view=rev
Log:
2008-11-03 JÃrg Billeter <j bitron ch>
* gobject/Makefile.am:
* gobject/valaccodebasemodule.vala:
* gobject/valaccodedelegatemodule.vala:
* gobject/valaccodedynamicpropertymodule.vala:
* gobject/valaccodegenerator.vala:
* gobject/valagerrormodule.vala:
Add CCodeDelegateModule, move more code to GErrorModule
Added:
trunk/gobject/valaccodedelegatemodule.vala
Modified:
trunk/ChangeLog
trunk/gobject/Makefile.am
trunk/gobject/valaccodebasemodule.vala
trunk/gobject/valaccodedynamicpropertymodule.vala
trunk/gobject/valaccodegenerator.vala
trunk/gobject/valagerrormodule.vala
Modified: trunk/gobject/Makefile.am
==============================================================================
--- trunk/gobject/Makefile.am (original)
+++ trunk/gobject/Makefile.am Mon Nov 3 21:41:39 2008
@@ -16,6 +16,7 @@
valaccodeassignmentmodule.vala \
valaccodebasemodule.vala \
valaccodecompiler.vala \
+ valaccodedelegatemodule.vala \
valaccodedynamicpropertymodule.vala \
valaccodedynamicsignalmodule.vala \
valaccodegenerator.vala \
Modified: trunk/gobject/valaccodebasemodule.vala
==============================================================================
--- trunk/gobject/valaccodebasemodule.vala (original)
+++ trunk/gobject/valaccodebasemodule.vala Mon Nov 3 21:41:39 2008
@@ -80,7 +80,7 @@
public int next_temp_var_id = 0;
private int next_array_dup_id = 0;
public bool in_creation_method = false;
- private bool in_constructor = false;
+ public bool in_constructor = false;
public bool in_static_or_class_ctor = false;
public bool current_method_inner_error = false;
public int next_coroutine_state = 1;
@@ -710,80 +710,6 @@
cenum.add_value (new CCodeEnumValue (ev.get_cname (), (CCodeExpression) ev.value.ccodenode));
}
}
-
- public override void visit_error_domain (ErrorDomain edomain) {
- cenum = new CCodeEnum (edomain.get_cname ());
-
- if (edomain.source_reference.comment != null) {
- header_type_definition.append (new CCodeComment (edomain.source_reference.comment));
- }
- header_type_definition.append (cenum);
-
- edomain.accept_children (codegen);
-
- string quark_fun_name = edomain.get_lower_case_cprefix () + "quark";
-
- var error_domain_define = new CCodeMacroReplacement (edomain.get_upper_case_cname (), quark_fun_name + " ()");
- header_type_definition.append (error_domain_define);
-
- var cquark_fun = new CCodeFunction (quark_fun_name, gquark_type.data_type.get_cname ());
- var cquark_block = new CCodeBlock ();
-
- var cquark_call = new CCodeFunctionCall (new CCodeIdentifier ("g_quark_from_static_string"));
- cquark_call.add_argument (new CCodeConstant ("\"" + edomain.get_lower_case_cname () + "-quark\""));
-
- cquark_block.add_statement (new CCodeReturnStatement (cquark_call));
-
- header_type_member_declaration.append (cquark_fun.copy ());
-
- cquark_fun.block = cquark_block;
- source_type_member_definition.append (cquark_fun);
- }
-
- public override void visit_error_code (ErrorCode ecode) {
- if (ecode.value == null) {
- cenum.add_value (new CCodeEnumValue (ecode.get_cname ()));
- } else {
- ecode.value.accept (codegen);
- cenum.add_value (new CCodeEnumValue (ecode.get_cname (), (CCodeExpression) ecode.value.ccodenode));
- }
- }
-
- public override void visit_delegate (Delegate d) {
- d.accept_children (codegen);
-
- var cfundecl = new CCodeFunctionDeclarator (d.get_cname ());
- foreach (FormalParameter param in d.get_parameters ()) {
- cfundecl.add_parameter ((CCodeFormalParameter) param.ccodenode);
-
- // handle array parameters
- if (!param.no_array_length && param.parameter_type is ArrayType) {
- var array_type = (ArrayType) param.parameter_type;
-
- var length_ctype = "int";
- if (param.direction != ParameterDirection.IN) {
- length_ctype = "int*";
- }
-
- for (int dim = 1; dim <= array_type.rank; dim++) {
- var cparam = new CCodeFormalParameter (head.get_array_length_cname (param.name, dim), length_ctype);
- cfundecl.add_parameter (cparam);
- }
- }
- }
- if (d.has_target) {
- var cparam = new CCodeFormalParameter ("user_data", "void*");
- cfundecl.add_parameter (cparam);
- }
-
- var ctypedef = new CCodeTypeDefinition (d.return_type.get_cname (), cfundecl);
-
- if (!d.is_internal_symbol ()) {
- header_type_declaration.append (ctypedef);
- } else {
- source_type_declaration.append (ctypedef);
- }
- }
public override void visit_member (Member m) {
/* stuff meant for all lockable members */
@@ -2973,104 +2899,16 @@
expr.ccodenode = new CCodeParenthesizedExpression ((CCodeExpression) expr.inner.ccodenode);
}
- public string get_delegate_target_cname (string delegate_cname) {
- return "%s_target".printf (delegate_cname);
+ public virtual string get_delegate_target_cname (string delegate_cname) {
+ assert_not_reached ();
}
- public CCodeExpression get_delegate_target_cexpression (Expression delegate_expr) {
- bool is_out = false;
-
- if (delegate_expr is UnaryExpression) {
- var unary_expr = (UnaryExpression) delegate_expr;
- if (unary_expr.operator == UnaryOperator.OUT || unary_expr.operator == UnaryOperator.REF) {
- delegate_expr = unary_expr.inner;
- is_out = true;
- }
- }
-
- if (delegate_expr is InvocationExpression) {
- var invocation_expr = (InvocationExpression) delegate_expr;
- return invocation_expr.delegate_target;
- } else if (delegate_expr is LambdaExpression) {
- if ((current_method != null && current_method.binding == MemberBinding.INSTANCE) || in_constructor) {
- return new CCodeIdentifier ("self");
- } else {
- return new CCodeConstant ("NULL");
- }
- } else if (delegate_expr.symbol_reference != null) {
- if (delegate_expr.symbol_reference is FormalParameter) {
- var param = (FormalParameter) delegate_expr.symbol_reference;
- CCodeExpression target_expr = new CCodeIdentifier (get_delegate_target_cname (param.name));
- if (param.direction != ParameterDirection.IN) {
- // accessing argument of out/ref param
- target_expr = new CCodeParenthesizedExpression (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, target_expr));
- }
- if (is_out) {
- // passing array as out/ref
- return new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, target_expr);
- } else {
- return target_expr;
- }
- } else if (delegate_expr.symbol_reference is LocalVariable) {
- var local = (LocalVariable) delegate_expr.symbol_reference;
- var target_expr = new CCodeIdentifier (get_delegate_target_cname (local.name));
- if (is_out) {
- return new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, target_expr);
- } else {
- return target_expr;
- }
- } else if (delegate_expr.symbol_reference is Field) {
- var field = (Field) delegate_expr.symbol_reference;
- var target_cname = get_delegate_target_cname (field.name);
-
- var ma = (MemberAccess) delegate_expr;
-
- var base_type = ma.inner.value_type;
- CCodeExpression target_expr = null;
-
- var pub_inst = (CCodeExpression) get_ccodenode (ma.inner);
-
- if (field.binding == MemberBinding.INSTANCE) {
- var instance_expression_type = base_type;
- var instance_target_type = get_data_type_for_symbol ((TypeSymbol) field.parent_symbol);
- CCodeExpression typed_inst = transform_expression (pub_inst, instance_expression_type, instance_target_type);
-
- CCodeExpression inst;
- if (field.access == SymbolAccessibility.PRIVATE) {
- inst = new CCodeMemberAccess.pointer (typed_inst, "priv");
- } else {
- inst = typed_inst;
- }
- if (((TypeSymbol) field.parent_symbol).is_reference_type ()) {
- target_expr = new CCodeMemberAccess.pointer (inst, target_cname);
- } else {
- target_expr = new CCodeMemberAccess (inst, target_cname);
- }
- } else {
- target_expr = new CCodeIdentifier (target_cname);
- }
-
- if (is_out) {
- return new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, target_expr);
- } else {
- return target_expr;
- }
- } else if (delegate_expr.symbol_reference is Method) {
- var m = (Method) delegate_expr.symbol_reference;
- var ma = (MemberAccess) delegate_expr;
- if (m.binding == MemberBinding.STATIC) {
- return new CCodeConstant ("NULL");
- } else {
- return (CCodeExpression) get_ccodenode (ma.inner);
- }
- }
- }
-
- return new CCodeConstant ("NULL");
+ public virtual CCodeExpression get_delegate_target_cexpression (Expression delegate_expr) {
+ assert_not_reached ();
}
- public string get_delegate_target_destroy_notify_cname (string delegate_cname) {
- return "%s_target_destroy_notify".printf (delegate_cname);
+ public virtual string get_delegate_target_destroy_notify_cname (string delegate_cname) {
+ assert_not_reached ();
}
public override void visit_base_access (BaseAccess expr) {
Added: trunk/gobject/valaccodedelegatemodule.vala
==============================================================================
--- (empty file)
+++ trunk/gobject/valaccodedelegatemodule.vala Mon Nov 3 21:41:39 2008
@@ -0,0 +1,169 @@
+/* valaccodedelegatemodule.vala
+ *
+ * Copyright (C) 2006-2008 JÃrg Billeter, Raffaele Sandrini
+ *
+ * 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>
+ * Raffaele Sandrini <raffaele sandrini ch>
+ */
+
+using GLib;
+
+/**
+ * The link between an assignment and generated code.
+ */
+public class Vala.CCodeDelegateModule : CCodeArrayModule {
+ public CCodeDelegateModule (CCodeGenerator codegen, CCodeModule? next) {
+ base (codegen, next);
+ }
+
+ public override void visit_delegate (Delegate d) {
+ d.accept_children (codegen);
+
+ var cfundecl = new CCodeFunctionDeclarator (d.get_cname ());
+ foreach (FormalParameter param in d.get_parameters ()) {
+ cfundecl.add_parameter ((CCodeFormalParameter) param.ccodenode);
+
+ // handle array parameters
+ if (!param.no_array_length && param.parameter_type is ArrayType) {
+ var array_type = (ArrayType) param.parameter_type;
+
+ var length_ctype = "int";
+ if (param.direction != ParameterDirection.IN) {
+ length_ctype = "int*";
+ }
+
+ for (int dim = 1; dim <= array_type.rank; dim++) {
+ var cparam = new CCodeFormalParameter (head.get_array_length_cname (param.name, dim), length_ctype);
+ cfundecl.add_parameter (cparam);
+ }
+ }
+ }
+ if (d.has_target) {
+ var cparam = new CCodeFormalParameter ("user_data", "void*");
+ cfundecl.add_parameter (cparam);
+ }
+
+ var ctypedef = new CCodeTypeDefinition (d.return_type.get_cname (), cfundecl);
+
+ if (!d.is_internal_symbol ()) {
+ header_type_declaration.append (ctypedef);
+ } else {
+ source_type_declaration.append (ctypedef);
+ }
+ }
+
+ public override string get_delegate_target_cname (string delegate_cname) {
+ return "%s_target".printf (delegate_cname);
+ }
+
+ public override CCodeExpression get_delegate_target_cexpression (Expression delegate_expr) {
+ bool is_out = false;
+
+ if (delegate_expr is UnaryExpression) {
+ var unary_expr = (UnaryExpression) delegate_expr;
+ if (unary_expr.operator == UnaryOperator.OUT || unary_expr.operator == UnaryOperator.REF) {
+ delegate_expr = unary_expr.inner;
+ is_out = true;
+ }
+ }
+
+ if (delegate_expr is InvocationExpression) {
+ var invocation_expr = (InvocationExpression) delegate_expr;
+ return invocation_expr.delegate_target;
+ } else if (delegate_expr is LambdaExpression) {
+ if ((current_method != null && current_method.binding == MemberBinding.INSTANCE) || in_constructor) {
+ return new CCodeIdentifier ("self");
+ } else {
+ return new CCodeConstant ("NULL");
+ }
+ } else if (delegate_expr.symbol_reference != null) {
+ if (delegate_expr.symbol_reference is FormalParameter) {
+ var param = (FormalParameter) delegate_expr.symbol_reference;
+ CCodeExpression target_expr = new CCodeIdentifier (get_delegate_target_cname (param.name));
+ if (param.direction != ParameterDirection.IN) {
+ // accessing argument of out/ref param
+ target_expr = new CCodeParenthesizedExpression (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, target_expr));
+ }
+ if (is_out) {
+ // passing array as out/ref
+ return new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, target_expr);
+ } else {
+ return target_expr;
+ }
+ } else if (delegate_expr.symbol_reference is LocalVariable) {
+ var local = (LocalVariable) delegate_expr.symbol_reference;
+ var target_expr = new CCodeIdentifier (get_delegate_target_cname (local.name));
+ if (is_out) {
+ return new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, target_expr);
+ } else {
+ return target_expr;
+ }
+ } else if (delegate_expr.symbol_reference is Field) {
+ var field = (Field) delegate_expr.symbol_reference;
+ var target_cname = get_delegate_target_cname (field.name);
+
+ var ma = (MemberAccess) delegate_expr;
+
+ var base_type = ma.inner.value_type;
+ CCodeExpression target_expr = null;
+
+ var pub_inst = (CCodeExpression) get_ccodenode (ma.inner);
+
+ if (field.binding == MemberBinding.INSTANCE) {
+ var instance_expression_type = base_type;
+ var instance_target_type = get_data_type_for_symbol ((TypeSymbol) field.parent_symbol);
+ CCodeExpression typed_inst = transform_expression (pub_inst, instance_expression_type, instance_target_type);
+
+ CCodeExpression inst;
+ if (field.access == SymbolAccessibility.PRIVATE) {
+ inst = new CCodeMemberAccess.pointer (typed_inst, "priv");
+ } else {
+ inst = typed_inst;
+ }
+ if (((TypeSymbol) field.parent_symbol).is_reference_type ()) {
+ target_expr = new CCodeMemberAccess.pointer (inst, target_cname);
+ } else {
+ target_expr = new CCodeMemberAccess (inst, target_cname);
+ }
+ } else {
+ target_expr = new CCodeIdentifier (target_cname);
+ }
+
+ if (is_out) {
+ return new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, target_expr);
+ } else {
+ return target_expr;
+ }
+ } else if (delegate_expr.symbol_reference is Method) {
+ var m = (Method) delegate_expr.symbol_reference;
+ var ma = (MemberAccess) delegate_expr;
+ if (m.binding == MemberBinding.STATIC) {
+ return new CCodeConstant ("NULL");
+ } else {
+ return (CCodeExpression) get_ccodenode (ma.inner);
+ }
+ }
+ }
+
+ return new CCodeConstant ("NULL");
+ }
+
+ public override string get_delegate_target_destroy_notify_cname (string delegate_cname) {
+ return "%s_target_destroy_notify".printf (delegate_cname);
+ }
+}
Modified: trunk/gobject/valaccodedynamicpropertymodule.vala
==============================================================================
--- trunk/gobject/valaccodedynamicpropertymodule.vala (original)
+++ trunk/gobject/valaccodedynamicpropertymodule.vala Mon Nov 3 21:41:39 2008
@@ -26,7 +26,7 @@
/**
* The link between a dynamic property and generated code.
*/
-public class Vala.CCodeDynamicPropertyModule : CCodeArrayModule {
+public class Vala.CCodeDynamicPropertyModule : CCodeDelegateModule {
int dynamic_property_id;
public CCodeDynamicPropertyModule (CCodeGenerator codegen, CCodeModule? next) {
Modified: trunk/gobject/valaccodegenerator.vala
==============================================================================
--- trunk/gobject/valaccodegenerator.vala (original)
+++ trunk/gobject/valaccodegenerator.vala Mon Nov 3 21:41:39 2008
@@ -39,6 +39,7 @@
head = new CCodeAssignmentModule (this, head);
head = new CCodeInvocationExpressionModule (this, head);
head = new CCodeArrayModule (this, head);
+ head = new CCodeDelegateModule (this, head);
head = new CCodeDynamicPropertyModule (this, head);
head = new CCodeDynamicSignalModule (this, head);
head = new GErrorModule (this, head);
Modified: trunk/gobject/valagerrormodule.vala
==============================================================================
--- trunk/gobject/valagerrormodule.vala (original)
+++ trunk/gobject/valagerrormodule.vala Mon Nov 3 21:41:39 2008
@@ -31,6 +31,44 @@
base (codegen, next);
}
+ public override void visit_error_domain (ErrorDomain edomain) {
+ cenum = new CCodeEnum (edomain.get_cname ());
+
+ if (edomain.source_reference.comment != null) {
+ header_type_definition.append (new CCodeComment (edomain.source_reference.comment));
+ }
+ header_type_definition.append (cenum);
+
+ edomain.accept_children (codegen);
+
+ string quark_fun_name = edomain.get_lower_case_cprefix () + "quark";
+
+ var error_domain_define = new CCodeMacroReplacement (edomain.get_upper_case_cname (), quark_fun_name + " ()");
+ header_type_definition.append (error_domain_define);
+
+ var cquark_fun = new CCodeFunction (quark_fun_name, gquark_type.data_type.get_cname ());
+ var cquark_block = new CCodeBlock ();
+
+ var cquark_call = new CCodeFunctionCall (new CCodeIdentifier ("g_quark_from_static_string"));
+ cquark_call.add_argument (new CCodeConstant ("\"" + edomain.get_lower_case_cname () + "-quark\""));
+
+ cquark_block.add_statement (new CCodeReturnStatement (cquark_call));
+
+ header_type_member_declaration.append (cquark_fun.copy ());
+
+ cquark_fun.block = cquark_block;
+ source_type_member_definition.append (cquark_fun);
+ }
+
+ public override void visit_error_code (ErrorCode ecode) {
+ if (ecode.value == null) {
+ cenum.add_value (new CCodeEnumValue (ecode.get_cname ()));
+ } else {
+ ecode.value.accept (codegen);
+ cenum.add_value (new CCodeEnumValue (ecode.get_cname (), (CCodeExpression) ecode.value.ccodenode));
+ }
+ }
+
public override void visit_throw_statement (ThrowStatement stmt) {
stmt.accept_children (codegen);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]