]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
dova: Do not let Value subclass Object
authorJürg Billeter <j@bitron.ch>
Sun, 18 Jul 2010 13:10:38 +0000 (15:10 +0200)
committerJürg Billeter <j@bitron.ch>
Sun, 18 Jul 2010 13:10:38 +0000 (15:10 +0200)
codegen/valadovabasemodule.vala
codegen/valadovamemberaccessmodule.vala
codegen/valadovaobjectmodule.vala
codegen/valadovavaluemodule.vala
vala/valaclass.vala
vala/valastringliteral.vala

index f8f4eab9db625e045d3c3b8089b635b8058cde16..8db548811b602fbce7eb3243e55520d9d535d998 100644 (file)
@@ -135,7 +135,6 @@ internal class Vala.DovaBaseModule : CCodeModule {
 
        public int next_temp_var_id = 0;
        public int next_wrapper_id = 0;
-       public int next_string_const_id = 0;
        public bool in_creation_method { get { return current_method is CreationMethod; } }
        public bool current_method_inner_error = false;
        int next_block_id = 0;
@@ -1543,20 +1542,11 @@ internal class Vala.DovaBaseModule : CCodeModule {
        }
 
        public override void visit_string_literal (StringLiteral expr) {
-               var val = new CCodeInitializerList ();
-               val.append (new CCodeConstant ("0"));
+               var ccall = new CCodeFunctionCall (new CCodeIdentifier ("string_create_from_cstring"));
                // FIXME handle escaped characters in scanner/parser and escape them here again for C
-               val.append (new CCodeConstant ((expr.eval ().size ()).to_string ()));
-               val.append (new CCodeConstant (expr.value));
+               ccall.add_argument (new CCodeConstant (expr.value));
 
-               var cdecl = new CCodeDeclaration ("const string");
-               cdecl.add_declarator (new CCodeVariableDeclarator ("_string%d_".printf (next_string_const_id), val));
-               cdecl.modifiers = CCodeModifiers.STATIC;
-               source_declarations.add_constant_declaration (cdecl);
-
-               expr.ccodenode = new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeConstant ("_string%d_".printf (next_string_const_id)));
-
-               next_string_const_id++;
+               expr.ccodenode = ccall;
        }
 
        public override void visit_null_literal (NullLiteral expr) {
@@ -1637,7 +1627,7 @@ internal class Vala.DovaBaseModule : CCodeModule {
                }
 
                var array_type = type as ArrayType;
-               if (array_type != null && array_type.fixed_length) {
+               if (array_type != null && array_type.inline_allocated) {
                        return requires_destroy (array_type.element_type);
                }
 
index 8a3ade78a7b1984ec074574f01920f1cd041ab83..0d11f22d1b160e64e1d766ed48690cc5db1abe84 100644 (file)
@@ -109,8 +109,7 @@ internal class Vala.DovaMemberAccessModule : DovaControlFlowModule {
 
                                var cl = instance_target_type.data_type as Class;
                                bool dova_priv = false;
-                               if ((f.access == SymbolAccessibility.PRIVATE || f.access == SymbolAccessibility.INTERNAL) &&
-                                   (cl.base_class == null || cl.base_class.get_full_name () != "Dova.Value")) {
+                               if ((f.access == SymbolAccessibility.PRIVATE || f.access == SymbolAccessibility.INTERNAL)) {
                                        dova_priv = true;
                                }
 
index 6def09e336030bd3ac83dba0143b61ad14a5dc21..d023792e155fbe5e26576a745db835051d0d2441 100644 (file)
@@ -547,6 +547,7 @@ internal class Vala.DovaObjectModule : DovaArrayModule {
                type_init_fun.block = new CCodeBlock ();
 
                if (base_class == null) {
+               } else if (cl == object_class || cl == value_class) {
                        var sizeof_call = new CCodeFunctionCall (new CCodeIdentifier ("sizeof"));
                        sizeof_call.add_argument (new CCodeIdentifier ("void *"));
 
@@ -559,14 +560,14 @@ internal class Vala.DovaObjectModule : DovaArrayModule {
 
                        var value_copy_call = new CCodeFunctionCall (new CCodeIdentifier ("dova_type_set_value_copy"));
                        value_copy_call.add_argument (new CCodeIdentifier ("type"));
-                       value_copy_call.add_argument (new CCodeCastExpression (new CCodeIdentifier ("dova_object_copy"), "void (*)(void *, int32_t,  void *, int32_t)"));
+                       value_copy_call.add_argument (new CCodeCastExpression (new CCodeIdentifier ("%s_copy".printf (cl.get_lower_case_cname ())), "void (*)(void *, int32_t,  void *, int32_t)"));
                        type_init_fun.block.add_statement (new CCodeExpressionStatement (value_copy_call));
 
-                       var function = new CCodeFunction ("dova_object_copy", "void");
+                       var function = new CCodeFunction ("%s_copy".printf (cl.get_lower_case_cname ()), "void");
                        function.modifiers = CCodeModifiers.STATIC;
-                       function.add_parameter (new CCodeFormalParameter ("dest", "DovaObject **"));
+                       function.add_parameter (new CCodeFormalParameter ("dest", "any **"));
                        function.add_parameter (new CCodeFormalParameter ("dest_index", "int32_t"));
-                       function.add_parameter (new CCodeFormalParameter ("src", "DovaObject **"));
+                       function.add_parameter (new CCodeFormalParameter ("src", "any **"));
                        function.add_parameter (new CCodeFormalParameter ("src_index", "int32_t"));
 
                        function.block = new CCodeBlock ();
@@ -576,20 +577,103 @@ internal class Vala.DovaObjectModule : DovaArrayModule {
                        var dest = new CCodeBinaryExpression (CCodeBinaryOperator.PLUS, new CCodeIdentifier ("dest"), new CCodeIdentifier ("dest_index"));
                        var src = new CCodeBinaryExpression (CCodeBinaryOperator.PLUS, new CCodeIdentifier ("src"), new CCodeIdentifier ("src_index"));
 
-                       var unref_call = new CCodeFunctionCall (new CCodeIdentifier ("dova_object_unref"));
+                       var unref_call = new CCodeFunctionCall (new CCodeIdentifier ("%s_unref".printf (cl.get_lower_case_cname ())));
                        unref_call.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, dest));
                        var unref_block = new CCodeBlock ();
                        unref_block.add_statement (new CCodeExpressionStatement (unref_call));
                        unref_block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, dest), new CCodeConstant ("NULL"))));
                        function.block.add_statement (new CCodeIfStatement (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, dest), unref_block));
 
-                       var ref_call = new CCodeFunctionCall (new CCodeIdentifier ("dova_object_ref"));
+                       var ref_call = new CCodeFunctionCall (new CCodeIdentifier ("%s_ref".printf (cl.get_lower_case_cname ())));
                        ref_call.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, src));
                        var ref_block = new CCodeBlock ();
                        ref_block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, dest), ref_call)));
                        function.block.add_statement (new CCodeIfStatement (new CCodeIdentifier ("src"), ref_block));
 
                        source_type_member_definition.append (function);
+
+                       {
+                               var value_equals_fun = new CCodeFunction ("%s_value_equals".printf (cl.get_lower_case_cname ()), "bool");
+                               value_equals_fun.modifiers = CCodeModifiers.STATIC;
+                               value_equals_fun.add_parameter (new CCodeFormalParameter ("value", cl.get_cname () + "**"));
+                               value_equals_fun.add_parameter (new CCodeFormalParameter ("value_index", "int32_t"));
+                               value_equals_fun.add_parameter (new CCodeFormalParameter ("other", cl.get_cname () + "**"));
+                               value_equals_fun.add_parameter (new CCodeFormalParameter ("other_index", "int32_t"));
+                               value_equals_fun.block = new CCodeBlock ();
+                               var val = new CCodeBinaryExpression (CCodeBinaryOperator.PLUS, new CCodeIdentifier ("value"), new CCodeIdentifier ("value_index"));
+                               var other = new CCodeBinaryExpression (CCodeBinaryOperator.PLUS, new CCodeIdentifier ("other"), new CCodeIdentifier ("other_index"));
+                               var ccall = new CCodeFunctionCall (new CCodeIdentifier ("any_equals"));
+                               ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, val));
+                               ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, other));
+                               value_equals_fun.block.add_statement (new CCodeReturnStatement (ccall));
+                               source_type_member_definition.append (value_equals_fun);
+
+                               declare_set_value_equals_function (source_declarations);
+
+                               var value_equals_call = new CCodeFunctionCall (new CCodeIdentifier ("dova_type_set_value_equals"));
+                               value_equals_call.add_argument (new CCodeIdentifier ("type"));
+                               value_equals_call.add_argument (new CCodeCastExpression (new CCodeIdentifier ("%s_value_equals".printf (cl.get_lower_case_cname ())), "bool (*)(void *, int32_t,  void *, int32_t)"));
+                               type_init_fun.block.add_statement (new CCodeExpressionStatement (value_equals_call));
+                       }
+
+                       {
+                               var value_hash_fun = new CCodeFunction ("%s_value_hash".printf (cl.get_lower_case_cname ()), "uint32_t");
+                               value_hash_fun.modifiers = CCodeModifiers.STATIC;
+                               value_hash_fun.add_parameter (new CCodeFormalParameter ("value", cl.get_cname () + "**"));
+                               value_hash_fun.add_parameter (new CCodeFormalParameter ("value_index", "int32_t"));
+                               value_hash_fun.block = new CCodeBlock ();
+                               var val = new CCodeBinaryExpression (CCodeBinaryOperator.PLUS, new CCodeIdentifier ("value"), new CCodeIdentifier ("value_index"));
+                               var ccall = new CCodeFunctionCall (new CCodeIdentifier ("any_hash"));
+                               ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, val));
+                               value_hash_fun.block.add_statement (new CCodeReturnStatement (ccall));
+                               source_type_member_definition.append (value_hash_fun);
+
+                               declare_set_value_hash_function (source_declarations);
+
+                               var value_hash_call = new CCodeFunctionCall (new CCodeIdentifier ("dova_type_set_value_hash"));
+                               value_hash_call.add_argument (new CCodeIdentifier ("type"));
+                               value_hash_call.add_argument (new CCodeCastExpression (new CCodeIdentifier ("%s_value_hash".printf (cl.get_lower_case_cname ())), "uint32_t (*)(void *, int32_t)"));
+                               type_init_fun.block.add_statement (new CCodeExpressionStatement (value_hash_call));
+                       }
+
+                       // generate method to box value
+                       var value_to_any_fun = new CCodeFunction ("%s_value_to_any".printf (cl.get_lower_case_cname ()), "any*");
+                       value_to_any_fun.modifiers = CCodeModifiers.STATIC;
+                       value_to_any_fun.add_parameter (new CCodeFormalParameter ("value", cl.get_cname () + "**"));
+                       value_to_any_fun.add_parameter (new CCodeFormalParameter ("value_index", "int32_t"));
+                       value_to_any_fun.block = new CCodeBlock ();
+                       var val = new CCodeBinaryExpression (CCodeBinaryOperator.PLUS, new CCodeIdentifier ("value"), new CCodeIdentifier ("value_index"));
+                       var ccall = new CCodeFunctionCall (new CCodeIdentifier ("%s_ref".printf (cl.get_lower_case_cname ())));
+                       ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, val));
+                       value_to_any_fun.block.add_statement (new CCodeReturnStatement (ccall));
+                       source_type_member_definition.append (value_to_any_fun);
+
+                       declare_set_value_to_any_function (source_declarations);
+
+                       var value_to_any_call = new CCodeFunctionCall (new CCodeIdentifier ("dova_type_set_value_to_any"));
+                       value_to_any_call.add_argument (new CCodeIdentifier ("type"));
+                       value_to_any_call.add_argument (new CCodeIdentifier ("%s_value_to_any".printf (cl.get_lower_case_cname ())));
+                       type_init_fun.block.add_statement (new CCodeExpressionStatement (value_to_any_call));
+
+                       // generate method to unbox value
+                       var value_from_any_fun = new CCodeFunction ("%s_value_from_any".printf (cl.get_lower_case_cname ()));
+                       value_from_any_fun.modifiers = CCodeModifiers.STATIC;
+                       value_from_any_fun.add_parameter (new CCodeFormalParameter ("any", "DovaObject *"));
+                       value_from_any_fun.add_parameter (new CCodeFormalParameter ("value", cl.get_cname () + "**"));
+                       value_from_any_fun.add_parameter (new CCodeFormalParameter ("value_index", "int32_t"));
+                       value_from_any_fun.block = new CCodeBlock ();
+                       ccall = new CCodeFunctionCall (new CCodeIdentifier ("%s_ref".printf (cl.get_lower_case_cname ())));
+                       ccall.add_argument (new CCodeIdentifier ("any"));
+                       value_from_any_fun.block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, val), ccall)));
+                       value_from_any_fun.block.add_statement (new CCodeReturnStatement (ccall));
+                       source_type_member_definition.append (value_from_any_fun);
+
+                       declare_set_value_from_any_function (source_declarations);
+
+                       var value_from_any_call = new CCodeFunctionCall (new CCodeIdentifier ("dova_type_set_value_from_any"));
+                       value_from_any_call.add_argument (new CCodeIdentifier ("type"));
+                       value_from_any_call.add_argument (new CCodeIdentifier ("%s_value_from_any".printf (cl.get_lower_case_cname ())));
+                       type_init_fun.block.add_statement (new CCodeExpressionStatement (value_from_any_call));
                } else {
                        type_init_call = new CCodeFunctionCall (new CCodeIdentifier ("%s_type_init".printf (base_class.get_lower_case_cname ())));
                        type_init_call.add_argument (new CCodeIdentifier ("type"));
@@ -684,7 +768,7 @@ internal class Vala.DovaObjectModule : DovaArrayModule {
                }
 
                // finalizer
-               if (cl != object_class && cl.base_class != null && (cl.get_fields ().size > 0 || cl.destructor != null)) {
+               if (cl.base_class != null && !cl.is_fundamental () && (cl.get_fields ().size > 0 || cl.destructor != null)) {
                        add_finalize_function (cl);
 
                        generate_method_declaration ((Method) object_class.scope.lookup ("finalize"), source_declarations);
index 3cef0e937343ce7d21252ff1bc1b4564061565cd..ddb2d9214ffb91b89653be07edf7ec51bdc59843 100644 (file)
@@ -25,321 +25,6 @@ internal class Vala.DovaValueModule : DovaObjectModule {
                base (codegen, next);
        }
 
-       public override void generate_class_declaration (Class cl, CCodeDeclarationSpace decl_space) {
-               if (cl.base_class == null ||
-                   cl.base_class.get_full_name () != "Dova.Value") {
-                       base.generate_class_declaration (cl, decl_space);
-                       return;
-               }
-
-               if (decl_space.add_symbol_declaration (cl, cl.get_cname ())) {
-                       return;
-               }
-
-               var type_fun = new CCodeFunction ("%s_type_get".printf (cl.get_lower_case_cname ()), "DovaType *");
-               if (cl.is_internal_symbol ()) {
-                       type_fun.modifiers = CCodeModifiers.STATIC;
-               }
-               decl_space.add_type_member_declaration (type_fun);
-
-               var type_init_fun = new CCodeFunction ("%s_type_init".printf (cl.get_lower_case_cname ()));
-               type_init_fun.add_parameter (new CCodeFormalParameter ("type", "DovaType *"));
-               if (cl.is_internal_symbol ()) {
-                       type_init_fun.modifiers = CCodeModifiers.STATIC;
-               }
-               decl_space.add_type_member_declaration (type_init_fun);
-
-               var instance_struct = new CCodeStruct ("_%s".printf (cl.get_cname ()));
-
-               foreach (Field f in cl.get_fields ()) {
-                       if (f.binding == MemberBinding.INSTANCE)  {
-                               generate_type_declaration (f.field_type, decl_space);
-
-                               string field_ctype = f.field_type.get_cname ();
-                               if (f.is_volatile) {
-                                       field_ctype = "volatile " + field_ctype;
-                               }
-
-                               string cname = f.get_cname ();
-                               var array_type = f.field_type as ArrayType;
-                               if (array_type != null && array_type.inline_allocated) {
-                                       cname += "[]";
-                               }
-
-                               instance_struct.add_field (field_ctype, cname);
-                       }
-               }
-
-               decl_space.add_type_declaration (new CCodeTypeDefinition ("struct _%s".printf (cl.get_cname ()), new CCodeVariableDeclarator (cl.get_cname ())));
-               decl_space.add_type_definition (instance_struct);
-
-               if (cl.get_full_name () == "string") {
-                       generate_method_declaration ((Method) cl.scope.lookup ("ref"), decl_space);
-                       generate_method_declaration ((Method) cl.scope.lookup ("unref"), decl_space);
-               }
-
-               add_value_assert (cl, decl_space);
-       }
-
-       public override void visit_class (Class cl) {
-               if (cl.base_class == null ||
-                   cl.base_class.get_full_name () != "Dova.Value") {
-                       base.visit_class (cl);
-                       return;
-               }
-
-               var old_symbol = current_symbol;
-               current_symbol = cl;
-
-               generate_class_declaration (cl, source_declarations);
-
-               if (!cl.is_internal_symbol ()) {
-                       generate_class_declaration (cl, header_declarations);
-               }
-
-
-               var cdecl = new CCodeDeclaration ("DovaType *");
-               cdecl.add_declarator (new CCodeVariableDeclarator ("%s_type".printf (cl.get_lower_case_cname ()), new CCodeConstant ("NULL")));
-               cdecl.modifiers = CCodeModifiers.STATIC;
-               source_declarations.add_type_member_declaration (cdecl);
-
-               var type_fun = new CCodeFunction ("%s_type_get".printf (cl.get_lower_case_cname ()), "DovaType *");
-               type_fun.block = new CCodeBlock ();
-
-               var type_init_block = new CCodeBlock ();
-
-               generate_method_declaration ((Method) object_class.scope.lookup ("alloc"), source_declarations);
-               generate_property_accessor_declaration (((Property) type_class.scope.lookup ("base_type")).set_accessor, source_declarations);
-               generate_property_accessor_declaration (((Property) type_class.scope.lookup ("type_size")).get_accessor, source_declarations);
-               generate_property_accessor_declaration (((Property) type_class.scope.lookup ("type_size")).set_accessor, source_declarations);
-               generate_property_accessor_declaration (((Property) type_class.scope.lookup ("value_size")).set_accessor, source_declarations);
-
-               generate_class_declaration ((Class) context.root.scope.lookup ("Dova").scope.lookup ("Value"), source_declarations);
-
-               var base_type = new CCodeFunctionCall (new CCodeIdentifier ("dova_value_type_get"));
-
-               var base_type_size = new CCodeFunctionCall (new CCodeIdentifier ("dova_type_get_type_size"));
-               base_type_size.add_argument (base_type);
-
-               var calloc_call = new CCodeFunctionCall (new CCodeIdentifier ("calloc"));
-               calloc_call.add_argument (new CCodeConstant ("1"));
-               calloc_call.add_argument (base_type_size);
-
-               type_init_block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeIdentifier ("%s_type".printf (cl.get_lower_case_cname ())), calloc_call)));
-
-               generate_class_declaration ((Class) object_class, source_declarations);
-
-               type_init_block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeMemberAccess.pointer (new CCodeCastExpression (new CCodeIdentifier ("%s_type".printf (cl.get_lower_case_cname ())), "DovaObject *"), "type"), new CCodeFunctionCall (new CCodeIdentifier ("dova_type_type_get")))));
-
-               var set_base_type = new CCodeFunctionCall (new CCodeIdentifier ("dova_type_set_base_type"));
-               set_base_type.add_argument (new CCodeIdentifier ("%s_type".printf (cl.get_lower_case_cname ())));
-               set_base_type.add_argument (base_type);
-               type_init_block.add_statement (new CCodeExpressionStatement (set_base_type));
-
-               var set_size = new CCodeFunctionCall (new CCodeIdentifier ("dova_type_set_type_size"));
-               set_size.add_argument (new CCodeIdentifier ("%s_type".printf (cl.get_lower_case_cname ())));
-               set_size.add_argument (base_type_size);
-               type_init_block.add_statement (new CCodeExpressionStatement (set_size));
-
-               var type_init_call = new CCodeFunctionCall (new CCodeIdentifier ("%s_type_init".printf (cl.get_lower_case_cname ())));
-               type_init_call.add_argument (new CCodeIdentifier ("%s_type".printf (cl.get_lower_case_cname ())));
-               type_init_block.add_statement (new CCodeExpressionStatement (type_init_call));
-
-               type_fun.block.add_statement (new CCodeIfStatement (new CCodeUnaryExpression (CCodeUnaryOperator.LOGICAL_NEGATION, new CCodeIdentifier ("%s_type".printf (cl.get_lower_case_cname ()))), type_init_block));
-
-               type_fun.block.add_statement (new CCodeReturnStatement (new CCodeIdentifier ("%s_type".printf (cl.get_lower_case_cname ()))));
-
-               source_type_member_definition.append (type_fun);
-
-               var type_init_fun = new CCodeFunction ("%s_type_init".printf (cl.get_lower_case_cname ()));
-               type_init_fun.add_parameter (new CCodeFormalParameter ("type", "DovaType *"));
-               type_init_fun.block = new CCodeBlock ();
-
-               type_init_call = new CCodeFunctionCall (new CCodeIdentifier ("dova_value_type_init"));
-               type_init_call.add_argument (new CCodeIdentifier ("type"));
-               type_init_fun.block.add_statement (new CCodeExpressionStatement (type_init_call));
-
-               declare_set_value_copy_function (source_declarations);
-
-               var value_copy_call = new CCodeFunctionCall (new CCodeIdentifier ("dova_type_set_value_copy"));
-               value_copy_call.add_argument (new CCodeIdentifier ("%s_type".printf (cl.get_lower_case_cname ())));
-               value_copy_call.add_argument (new CCodeCastExpression (new CCodeIdentifier ("string_copy"), "void (*)(void *, int32_t,  void *, int32_t)"));
-               type_init_fun.block.add_statement (new CCodeExpressionStatement (value_copy_call));
-
-               var function = new CCodeFunction ("string_copy", "void");
-               function.modifiers = CCodeModifiers.STATIC;
-               function.add_parameter (new CCodeFormalParameter ("dest", "string **"));
-               function.add_parameter (new CCodeFormalParameter ("dest_index", "int32_t"));
-               function.add_parameter (new CCodeFormalParameter ("src", "string **"));
-               function.add_parameter (new CCodeFormalParameter ("src_index", "int32_t"));
-
-               function.block = new CCodeBlock ();
-               var cfrag = new CCodeFragment ();
-               function.block.add_statement (cfrag);
-
-               var dest = new CCodeBinaryExpression (CCodeBinaryOperator.PLUS, new CCodeIdentifier ("dest"), new CCodeIdentifier ("dest_index"));
-               var src = new CCodeBinaryExpression (CCodeBinaryOperator.PLUS, new CCodeIdentifier ("src"), new CCodeIdentifier ("src_index"));
-
-               var unref_call = new CCodeFunctionCall (new CCodeIdentifier ("string_unref"));
-               unref_call.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, dest));
-               var unref_block = new CCodeBlock ();
-               unref_block.add_statement (new CCodeExpressionStatement (unref_call));
-               unref_block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, dest), new CCodeConstant ("NULL"))));
-               function.block.add_statement (new CCodeIfStatement (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, dest), unref_block));
-
-               var ref_call = new CCodeFunctionCall (new CCodeIdentifier ("string_ref"));
-               ref_call.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, src));
-               var ref_block = new CCodeBlock ();
-               ref_block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, dest), ref_call)));
-               function.block.add_statement (new CCodeIfStatement (new CCodeIdentifier ("src"), ref_block));
-
-               source_type_member_definition.append (function);
-
-               if (cl.scope.lookup ("equals") is Method) {
-                       var value_equals_fun = new CCodeFunction ("%s_value_equals".printf (cl.get_lower_case_cname ()), "bool");
-                       value_equals_fun.modifiers = CCodeModifiers.STATIC;
-                       value_equals_fun.add_parameter (new CCodeFormalParameter ("value", cl.get_cname () + "**"));
-                       value_equals_fun.add_parameter (new CCodeFormalParameter ("value_index", "int32_t"));
-                       value_equals_fun.add_parameter (new CCodeFormalParameter ("other", cl.get_cname () + "**"));
-                       value_equals_fun.add_parameter (new CCodeFormalParameter ("other_index", "int32_t"));
-                       value_equals_fun.block = new CCodeBlock ();
-                       var val = new CCodeBinaryExpression (CCodeBinaryOperator.PLUS, new CCodeIdentifier ("value"), new CCodeIdentifier ("value_index"));
-                       var other = new CCodeBinaryExpression (CCodeBinaryOperator.PLUS, new CCodeIdentifier ("other"), new CCodeIdentifier ("other_index"));
-                       var ccall = new CCodeFunctionCall (new CCodeIdentifier ("%s_equals".printf (cl.get_lower_case_cname ())));
-                       ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, val));
-                       ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, other));
-                       value_equals_fun.block.add_statement (new CCodeReturnStatement (ccall));
-                       source_type_member_definition.append (value_equals_fun);
-
-                       declare_set_value_equals_function (source_declarations);
-
-                       var value_equals_call = new CCodeFunctionCall (new CCodeIdentifier ("dova_type_set_value_equals"));
-                       value_equals_call.add_argument (new CCodeIdentifier ("type"));
-                       value_equals_call.add_argument (new CCodeCastExpression (new CCodeIdentifier ("%s_value_equals".printf (cl.get_lower_case_cname ())), "bool (*)(void *, int32_t,  void *, int32_t)"));
-                       type_init_fun.block.add_statement (new CCodeExpressionStatement (value_equals_call));
-               }
-
-               if (cl.scope.lookup ("hash") is Method) {
-                       var value_hash_fun = new CCodeFunction ("%s_value_hash".printf (cl.get_lower_case_cname ()), "uint32_t");
-                       value_hash_fun.modifiers = CCodeModifiers.STATIC;
-                       value_hash_fun.add_parameter (new CCodeFormalParameter ("value", cl.get_cname () + "**"));
-                       value_hash_fun.add_parameter (new CCodeFormalParameter ("value_index", "int32_t"));
-                       value_hash_fun.block = new CCodeBlock ();
-                       var val = new CCodeBinaryExpression (CCodeBinaryOperator.PLUS, new CCodeIdentifier ("value"), new CCodeIdentifier ("value_index"));
-                       var ccall = new CCodeFunctionCall (new CCodeIdentifier ("%s_hash".printf (cl.get_lower_case_cname ())));
-                       ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, val));
-                       value_hash_fun.block.add_statement (new CCodeReturnStatement (ccall));
-                       source_type_member_definition.append (value_hash_fun);
-
-                       declare_set_value_hash_function (source_declarations);
-
-                       var value_hash_call = new CCodeFunctionCall (new CCodeIdentifier ("dova_type_set_value_hash"));
-                       value_hash_call.add_argument (new CCodeIdentifier ("type"));
-                       value_hash_call.add_argument (new CCodeCastExpression (new CCodeIdentifier ("%s_value_hash".printf (cl.get_lower_case_cname ())), "uint32_t (*)(void *, int32_t)"));
-                       type_init_fun.block.add_statement (new CCodeExpressionStatement (value_hash_call));
-               }
-
-#if true
-               // generate method to box values
-               var value_to_any_fun = new CCodeFunction ("%s_value_to_any".printf (cl.get_lower_case_cname ()), "DovaObject*");
-               value_to_any_fun.modifiers = CCodeModifiers.STATIC;
-               value_to_any_fun.add_parameter (new CCodeFormalParameter ("value", "void *"));
-               value_to_any_fun.add_parameter (new CCodeFormalParameter ("value_index", "int32_t"));
-               value_to_any_fun.block = new CCodeBlock ();
-               var alloc_call = new CCodeFunctionCall (new CCodeIdentifier ("dova_object_alloc"));
-               alloc_call.add_argument (new CCodeFunctionCall (new CCodeIdentifier ("%s_type_get".printf (cl.get_lower_case_cname ()))));
-               cdecl = new CCodeDeclaration ("DovaObject *");
-               cdecl.add_declarator (new CCodeVariableDeclarator ("result", alloc_call));
-               value_to_any_fun.block.add_statement (cdecl);
-               var priv_call = new CCodeFunctionCall (new CCodeIdentifier ("DOVA_VALUE_GET_PRIVATE"));
-               priv_call.add_argument (new CCodeIdentifier ("result"));
-               var copy_call = new CCodeFunctionCall (new CCodeIdentifier ("%s_copy".printf (cl.get_lower_case_cname ())));
-               copy_call.add_argument (priv_call);
-               copy_call.add_argument (new CCodeConstant ("0"));
-               copy_call.add_argument (new CCodeIdentifier ("value"));
-               copy_call.add_argument (new CCodeIdentifier ("value_index"));
-               value_to_any_fun.block.add_statement (new CCodeExpressionStatement (copy_call));
-               value_to_any_fun.block.add_statement (new CCodeReturnStatement (new CCodeIdentifier ("result")));
-               source_type_member_definition.append (value_to_any_fun);
-
-               declare_set_value_to_any_function (source_declarations);
-
-               var value_to_any_call = new CCodeFunctionCall (new CCodeIdentifier ("dova_type_set_value_to_any"));
-               value_to_any_call.add_argument (new CCodeIdentifier ("type"));
-               value_to_any_call.add_argument (new CCodeIdentifier ("%s_value_to_any".printf (cl.get_lower_case_cname ())));
-               type_init_fun.block.add_statement (new CCodeExpressionStatement (value_to_any_call));
-
-               // generate method to unbox values
-               var value_from_any_fun = new CCodeFunction ("%s_value_from_any".printf (cl.get_lower_case_cname ()));
-               value_from_any_fun.modifiers = CCodeModifiers.STATIC;
-               value_from_any_fun.add_parameter (new CCodeFormalParameter ("any", "DovaObject *"));
-               value_from_any_fun.add_parameter (new CCodeFormalParameter ("value", cl.get_cname () + "*"));
-               value_from_any_fun.add_parameter (new CCodeFormalParameter ("value_index", "int32_t"));
-               value_from_any_fun.block = new CCodeBlock ();
-               priv_call = new CCodeFunctionCall (new CCodeIdentifier ("DOVA_VALUE_GET_PRIVATE"));
-               priv_call.add_argument (new CCodeIdentifier ("any"));
-               copy_call = new CCodeFunctionCall (new CCodeIdentifier ("%s_copy".printf (cl.get_lower_case_cname ())));
-               copy_call.add_argument (new CCodeIdentifier ("value"));
-               copy_call.add_argument (new CCodeIdentifier ("value_index"));
-               copy_call.add_argument (priv_call);
-               copy_call.add_argument (new CCodeConstant ("0"));
-               value_from_any_fun.block.add_statement (new CCodeExpressionStatement (copy_call));
-               source_type_member_definition.append (value_from_any_fun);
-
-               declare_set_value_from_any_function (source_declarations);
-
-               var value_from_any_call = new CCodeFunctionCall (new CCodeIdentifier ("dova_type_set_value_from_any"));
-               value_from_any_call.add_argument (new CCodeIdentifier ("type"));
-               value_from_any_call.add_argument (new CCodeIdentifier ("%s_value_from_any".printf (cl.get_lower_case_cname ())));
-               type_init_fun.block.add_statement (new CCodeExpressionStatement (value_from_any_call));
-#else
-               // generate method to box value
-               var value_to_any_fun = new CCodeFunction ("%s_value_to_any".printf (cl.get_lower_case_cname ()), "DovaObject*");
-               value_to_any_fun.modifiers = CCodeModifiers.STATIC;
-               value_to_any_fun.add_parameter (new CCodeFormalParameter ("value", cl.get_cname () + "**"));
-               value_to_any_fun.add_parameter (new CCodeFormalParameter ("value_index", "int32_t"));
-               value_to_any_fun.block = new CCodeBlock ();
-               var val = new CCodeBinaryExpression (CCodeBinaryOperator.PLUS, new CCodeIdentifier ("value"), new CCodeIdentifier ("value_index"));
-               var ccall = new CCodeFunctionCall (new CCodeIdentifier ("dova_object_ref"));
-               ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, val));
-               value_to_any_fun.block.add_statement (new CCodeReturnStatement (ccall));
-               source_type_member_definition.append (value_to_any_fun);
-
-               declare_set_value_to_any_function (source_declarations);
-
-               var value_to_any_call = new CCodeFunctionCall (new CCodeIdentifier ("dova_type_set_value_to_any"));
-               value_to_any_call.add_argument (new CCodeIdentifier ("type"));
-               value_to_any_call.add_argument (new CCodeIdentifier ("%s_value_to_any".printf (cl.get_lower_case_cname ())));
-               type_init_fun.block.add_statement (new CCodeExpressionStatement (value_to_any_call));
-
-               // generate method to unbox value
-               var value_from_any_fun = new CCodeFunction ("%s_value_from_any".printf (cl.get_lower_case_cname ()));
-               value_from_any_fun.modifiers = CCodeModifiers.STATIC;
-               value_from_any_fun.add_parameter (new CCodeFormalParameter ("any", "DovaObject *"));
-               value_from_any_fun.add_parameter (new CCodeFormalParameter ("value", cl.get_cname () + "**"));
-               value_from_any_fun.add_parameter (new CCodeFormalParameter ("value_index", "int32_t"));
-               value_from_any_fun.block = new CCodeBlock ();
-               ccall = new CCodeFunctionCall (new CCodeIdentifier ("dova_object_ref"));
-               ccall.add_argument (new CCodeIdentifier ("any"));
-               value_from_any_fun.block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, val), ccall)));
-               value_from_any_fun.block.add_statement (new CCodeReturnStatement (ccall));
-               source_type_member_definition.append (value_from_any_fun);
-
-               declare_set_value_from_any_function (source_declarations);
-
-               var value_from_any_call = new CCodeFunctionCall (new CCodeIdentifier ("dova_type_set_value_from_any"));
-               value_from_any_call.add_argument (new CCodeIdentifier ("type"));
-               value_from_any_call.add_argument (new CCodeIdentifier ("%s_value_from_any".printf (cl.get_lower_case_cname ())));
-               type_init_fun.block.add_statement (new CCodeExpressionStatement (value_from_any_call));
-#endif
-
-               source_type_member_definition.append (type_init_fun);
-
-               cl.accept_children (codegen);
-
-               current_symbol = old_symbol;
-       }
-
        public override void visit_creation_method (CreationMethod m) {
                if (current_type_symbol is Class &&
                    (current_class.base_class == null ||
index 22c3e0ce58b3e9dda47d55c890befa81c68c67d9..fb0ce37cccddaf92047120c5738c3024bb5885d4 100644 (file)
@@ -288,7 +288,7 @@ public class Vala.Class : ObjectTypeSymbol {
                if (CodeContext.get ().profile == Profile.DOVA &&
                    f.binding == MemberBinding.INSTANCE &&
                    (f.access == SymbolAccessibility.PUBLIC || f.access == SymbolAccessibility.PROTECTED) &&
-                   name != "string" && name != "any" /* temporary workaround */) {
+                   name != "any" /* temporary workaround */) {
                        // public/protected instance fields not supported, convert to automatic property
 
                        var prop = new Property (f.name, f.field_type.copy (), null, null, f.source_reference, comment);
index d6fc9ac4df61d274aa6c3d25f278cbe23c92e60c..94c4d99fb2a773846b2dafe69f050d56b964ba04 100644 (file)
@@ -1,6 +1,6 @@
 /* valastringliteral.vala
  *
- * Copyright (C) 2006-2008  Jürg Billeter
+ * Copyright (C) 2006-2010  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
@@ -85,6 +85,9 @@ public class Vala.StringLiteral : Literal {
                checked = true;
 
                value_type = analyzer.string_type.copy ();
+               if (analyzer.context.profile == Profile.DOVA) {
+                       value_type.value_owned = true;
+               }
 
                return !error;
        }