vala r1977 - in trunk: . gobject
- From: juergbi svn gnome org
- To: svn-commits-list gnome org
- Subject: vala r1977 - in trunk: . gobject
- Date: Tue, 4 Nov 2008 17:31:43 +0000 (UTC)
Author: juergbi
Date: Tue Nov 4 17:31:42 2008
New Revision: 1977
URL: http://svn.gnome.org/viewvc/vala?rev=1977&view=rev
Log:
2008-11-04 JÃrg Billeter <j bitron ch>
* gobject/valaccodearraymodule.vala:
* gobject/valaccodebasemodule.vala:
Move array dup wrapper generation to CCodeArrayModule
Modified:
trunk/ChangeLog
trunk/gobject/valaccodearraymodule.vala
trunk/gobject/valaccodebasemodule.vala
Modified: trunk/gobject/valaccodearraymodule.vala
==============================================================================
--- trunk/gobject/valaccodearraymodule.vala (original)
+++ trunk/gobject/valaccodearraymodule.vala Tue Nov 4 17:31:42 2008
@@ -28,6 +28,8 @@
* The link between an assignment and generated code.
*/
public class Vala.CCodeArrayModule : CCodeInvocationExpressionModule {
+ private int next_array_dup_id = 0;
+
public CCodeArrayModule (CCodeGenerator codegen, CCodeModule? next) {
base (codegen, next);
}
@@ -396,4 +398,84 @@
source_type_member_definition.append (fun);
}
+
+ public override CCodeExpression? get_dup_func_expression (DataType type, SourceReference? source_reference) {
+ if (type is ArrayType) {
+ return new CCodeIdentifier (generate_array_dup_wrapper ((ArrayType) type));
+ } else {
+ return base.get_dup_func_expression (type, source_reference);
+ }
+ }
+
+ string generate_array_dup_wrapper (ArrayType array_type) {
+ string dup_func = "_vala_array_dup%d".printf (++next_array_dup_id);
+
+ if (!add_wrapper (dup_func)) {
+ // wrapper already defined
+ return dup_func;
+ }
+
+ // declaration
+
+ var function = new CCodeFunction (dup_func, array_type.get_cname ());
+ function.modifiers = CCodeModifiers.STATIC;
+
+ function.add_parameter (new CCodeFormalParameter ("self", array_type.get_cname ()));
+ // total length over all dimensions
+ function.add_parameter (new CCodeFormalParameter ("length", "int"));
+
+ // definition
+
+ var block = new CCodeBlock ();
+
+ if (requires_copy (array_type.element_type)) {
+ var old_temp_vars = temp_vars;
+
+ var cdecl = new CCodeDeclaration (array_type.get_cname ());
+ var cvardecl = new CCodeVariableDeclarator ("result");
+ cdecl.add_declarator (cvardecl);
+ var gnew = new CCodeFunctionCall (new CCodeIdentifier ("g_new0"));
+ gnew.add_argument (new CCodeIdentifier (array_type.element_type.get_cname ()));
+ gnew.add_argument (new CCodeIdentifier ("length"));
+ cvardecl.initializer = gnew;
+ block.add_statement (cdecl);
+
+ var idx_decl = new CCodeDeclaration ("int");
+ idx_decl.add_declarator (new CCodeVariableDeclarator ("i"));
+ block.add_statement (idx_decl);
+
+ var loop_body = new CCodeBlock ();
+ loop_body.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeElementAccess (new CCodeIdentifier ("result"), new CCodeIdentifier ("i")), get_ref_cexpression (array_type.element_type, new CCodeElementAccess (new CCodeIdentifier ("self"), new CCodeIdentifier ("i")), null, array_type))));
+
+ var cfor = new CCodeForStatement (new CCodeBinaryExpression (CCodeBinaryOperator.LESS_THAN, new CCodeIdentifier ("i"), new CCodeIdentifier ("length")), loop_body);
+ cfor.add_initializer (new CCodeAssignment (new CCodeIdentifier ("i"), new CCodeConstant ("0")));
+ cfor.add_iterator (new CCodeUnaryExpression (CCodeUnaryOperator.POSTFIX_INCREMENT, new CCodeIdentifier ("i")));
+ block.add_statement (cfor);
+
+ block.add_statement (new CCodeReturnStatement (new CCodeIdentifier ("result")));
+
+ var cfrag = new CCodeFragment ();
+ append_temp_decl (cfrag, temp_vars);
+ block.add_statement (cfrag);
+ temp_vars = old_temp_vars;
+ } else {
+ var dup_call = new CCodeFunctionCall (new CCodeIdentifier ("g_memdup"));
+ dup_call.add_argument (new CCodeIdentifier ("self"));
+
+ var sizeof_call = new CCodeFunctionCall (new CCodeIdentifier ("sizeof"));
+ sizeof_call.add_argument (new CCodeIdentifier (array_type.element_type.get_cname ()));
+ dup_call.add_argument (new CCodeBinaryExpression (CCodeBinaryOperator.MUL, new CCodeIdentifier ("length"), sizeof_call));
+
+ block.add_statement (new CCodeReturnStatement (dup_call));
+ }
+
+ // append to file
+
+ source_type_member_declaration.append (function.copy ());
+
+ function.block = block;
+ source_type_member_definition.append (function);
+
+ return dup_func;
+ }
}
Modified: trunk/gobject/valaccodebasemodule.vala
==============================================================================
--- trunk/gobject/valaccodebasemodule.vala (original)
+++ trunk/gobject/valaccodebasemodule.vala Tue Nov 4 17:31:42 2008
@@ -78,7 +78,6 @@
public Gee.Set<string> c_keywords;
public int next_temp_var_id = 0;
- private int next_array_dup_id = 0;
public bool in_creation_method = false;
public bool in_constructor = false;
public bool in_static_or_class_ctor = false;
@@ -1570,12 +1569,12 @@
}
}
- public CCodeExpression? get_dup_func_expression (DataType type, SourceReference? source_reference) {
- var cl = type.data_type as Class;
+ public virtual CCodeExpression? get_dup_func_expression (DataType type, SourceReference? source_reference) {
if (type is ErrorType) {
return new CCodeIdentifier ("g_error_copy");
} else if (type.data_type != null) {
string dup_function;
+ var cl = type.data_type as Class;
if (type.data_type.is_reference_counting ()) {
dup_function = type.data_type.get_ref_function ();
if (type.data_type is Interface && dup_function == null) {
@@ -1601,8 +1600,6 @@
} else if (type.type_parameter != null && current_type_symbol is Class) {
string func_name = "%s_dup_func".printf (type.type_parameter.name.down ());
return new CCodeMemberAccess.pointer (new CCodeMemberAccess.pointer (new CCodeIdentifier ("self"), "priv"), func_name);
- } else if (type is ArrayType) {
- return new CCodeIdentifier (generate_array_dup_wrapper ((ArrayType) type));
} else if (type is PointerType) {
var pointer_type = (PointerType) type;
return get_dup_func_expression (pointer_type.base_type, source_reference);
@@ -1611,78 +1608,6 @@
}
}
- string generate_array_dup_wrapper (ArrayType array_type) {
- string dup_func = "_vala_array_dup%d".printf (++next_array_dup_id);
-
- if (!add_wrapper (dup_func)) {
- // wrapper already defined
- return dup_func;
- }
-
- // declaration
-
- var function = new CCodeFunction (dup_func, array_type.get_cname ());
- function.modifiers = CCodeModifiers.STATIC;
-
- function.add_parameter (new CCodeFormalParameter ("self", array_type.get_cname ()));
- // total length over all dimensions
- function.add_parameter (new CCodeFormalParameter ("length", "int"));
-
- // definition
-
- var block = new CCodeBlock ();
-
- if (requires_copy (array_type.element_type)) {
- var old_temp_vars = temp_vars;
-
- var cdecl = new CCodeDeclaration (array_type.get_cname ());
- var cvardecl = new CCodeVariableDeclarator ("result");
- cdecl.add_declarator (cvardecl);
- var gnew = new CCodeFunctionCall (new CCodeIdentifier ("g_new0"));
- gnew.add_argument (new CCodeIdentifier (array_type.element_type.get_cname ()));
- gnew.add_argument (new CCodeIdentifier ("length"));
- cvardecl.initializer = gnew;
- block.add_statement (cdecl);
-
- var idx_decl = new CCodeDeclaration ("int");
- idx_decl.add_declarator (new CCodeVariableDeclarator ("i"));
- block.add_statement (idx_decl);
-
- var loop_body = new CCodeBlock ();
- loop_body.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeElementAccess (new CCodeIdentifier ("result"), new CCodeIdentifier ("i")), get_ref_cexpression (array_type.element_type, new CCodeElementAccess (new CCodeIdentifier ("self"), new CCodeIdentifier ("i")), null, array_type))));
-
- var cfor = new CCodeForStatement (new CCodeBinaryExpression (CCodeBinaryOperator.LESS_THAN, new CCodeIdentifier ("i"), new CCodeIdentifier ("length")), loop_body);
- cfor.add_initializer (new CCodeAssignment (new CCodeIdentifier ("i"), new CCodeConstant ("0")));
- cfor.add_iterator (new CCodeUnaryExpression (CCodeUnaryOperator.POSTFIX_INCREMENT, new CCodeIdentifier ("i")));
- block.add_statement (cfor);
-
- block.add_statement (new CCodeReturnStatement (new CCodeIdentifier ("result")));
-
- var cfrag = new CCodeFragment ();
- append_temp_decl (cfrag, temp_vars);
- block.add_statement (cfrag);
- temp_vars = old_temp_vars;
- } else {
- var dup_call = new CCodeFunctionCall (new CCodeIdentifier ("g_memdup"));
- dup_call.add_argument (new CCodeIdentifier ("self"));
-
- var sizeof_call = new CCodeFunctionCall (new CCodeIdentifier ("sizeof"));
- sizeof_call.add_argument (new CCodeIdentifier (array_type.element_type.get_cname ()));
- dup_call.add_argument (new CCodeBinaryExpression (CCodeBinaryOperator.MUL, new CCodeIdentifier ("length"), sizeof_call));
-
- block.add_statement (new CCodeReturnStatement (dup_call));
- }
-
- // append to file
-
- source_type_member_declaration.append (function.copy ());
-
- function.block = block;
- source_type_member_definition.append (function);
-
- return dup_func;
- }
-
private string generate_struct_dup_wrapper (ValueType value_type) {
string dup_func = "_%sdup".printf (value_type.type_symbol.get_lower_case_cprefix ());
@@ -2962,7 +2887,7 @@
return true;
}
- private CCodeExpression? get_ref_cexpression (DataType expression_type, CCodeExpression cexpr, Expression? expr, CodeNode node) {
+ public CCodeExpression? get_ref_cexpression (DataType expression_type, CCodeExpression cexpr, Expression? expr, CodeNode node) {
if (expression_type is ValueType && !expression_type.nullable) {
// normal value type, no null check
// (copy (&expr, &temp), temp)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]