]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Do not use GLib-specific code outside GObject profile
authorJürg Billeter <j@bitron.ch>
Sun, 26 Jul 2009 12:15:10 +0000 (14:15 +0200)
committerJürg Billeter <j@bitron.ch>
Sun, 26 Jul 2009 19:26:49 +0000 (21:26 +0200)
codegen/valaccodebasemodule.vala
codegen/valaccodecontrolflowmodule.vala
codegen/valaccodemethodcallmodule.vala
codegen/valaccodestructmodule.vala

index bea64e02bba8e4e69c09e70faf962bc219d4a024..bc6adf4154c95f13a882118db488016a9263d519 100644 (file)
@@ -1927,7 +1927,7 @@ internal class Vala.CCodeBaseModule : CCodeModule {
        }
 
        public CCodeExpression? get_destroy_func_expression (DataType type) {
-               if (type.data_type == glist_type || type.data_type == gslist_type) {
+               if (context.profile == Profile.GOBJECT && (type.data_type == glist_type || type.data_type == gslist_type)) {
                        // create wrapper function to free list elements if necessary
 
                        bool elements_require_free = false;
@@ -2041,7 +2041,7 @@ internal class Vala.CCodeBaseModule : CCodeModule {
                        // normal value type, no null check
                        ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, cvar));
 
-                       if (type.data_type == gvalue_type) {
+                       if (gvalue_type != null && type.data_type == gvalue_type) {
                                // g_value_unset must not be called for already unset values
                                var cisvalid = new CCodeFunctionCall (new CCodeIdentifier ("G_IS_VALUE"));
                                cisvalid.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, cvar));
@@ -2079,10 +2079,11 @@ internal class Vala.CCodeBaseModule : CCodeModule {
                /* set freed references to NULL to prevent further use */
                var ccomma = new CCodeCommaExpression ();
 
-               if (type.data_type == gstringbuilder_type
-                    || type.data_type == garray_type
-                    || type.data_type == gbytearray_type
-                    || type.data_type == gptrarray_type) {
+               if (context.profile == Profile.GOBJECT
+                   && (type.data_type == gstringbuilder_type
+                       || type.data_type == garray_type
+                       || type.data_type == gbytearray_type
+                       || type.data_type == gptrarray_type)) {
                        ccall.add_argument (new CCodeConstant ("TRUE"));
                } else if (type is ArrayType) {
                        var array_type = (ArrayType) type;
@@ -2760,7 +2761,7 @@ internal class Vala.CCodeBaseModule : CCodeModule {
                        ccomma.append_expression (copy_call);
                        ccomma.append_expression (ctemp);
 
-                       if (expression_type.data_type == gvalue_type) {
+                       if (gvalue_type != null && expression_type.data_type == gvalue_type) {
                                // g_value_init/copy must not be called for uninitialized values
                                var cisvalid = new CCodeFunctionCall (new CCodeIdentifier ("G_IS_VALUE"));
                                cisvalid.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, cexpr));
@@ -3303,7 +3304,7 @@ internal class Vala.CCodeBaseModule : CCodeModule {
        }
 
        public override void visit_cast_expression (CastExpression expr) {
-               if (expr.inner.value_type != null && expr.inner.value_type.data_type == gvalue_type
+               if (expr.inner.value_type != null && gvalue_type != null && expr.inner.value_type.data_type == gvalue_type
                    && expr.type_reference.get_type_id () != null) {
                        // explicit conversion from GValue
                        var ccall = new CCodeFunctionCall (new CCodeIdentifier (expr.type_reference.data_type.get_get_value_function ()));
@@ -3314,7 +3315,7 @@ internal class Vala.CCodeBaseModule : CCodeModule {
 
                var cl = expr.type_reference.data_type as Class;
                var iface = expr.type_reference.data_type as Interface;
-               if (iface != null || (cl != null && !cl.is_compact)) {
+               if (context.profile == Profile.GOBJECT && (iface != null || (cl != null && !cl.is_compact))) {
                        // checked cast for strict subtypes of GTypeInstance
                        if (expr.is_silent_cast) {
                                var ccomma = new CCodeCommaExpression ();
@@ -3614,7 +3615,8 @@ internal class Vala.CCodeBaseModule : CCodeModule {
                bool unboxing = (expression_type is ValueType && expression_type.nullable
                                 && target_type is ValueType && !target_type.nullable);
 
-               bool gvalue_boxing = (target_type != null
+               bool gvalue_boxing = (context.profile == Profile.GOBJECT
+                                     && target_type != null
                                      && target_type.data_type == gvalue_type
                                      && !(expression_type is NullType)
                                      && expression_type.get_type_id () != "G_TYPE_VALUE");
index b0c84c09514e07397917e4e5c92d721370557d3c..86a98e3db71b2b588ce12e917a6d4254ded6c2d6 100644 (file)
@@ -224,7 +224,12 @@ internal class Vala.CCodeControlFlowModule : CCodeMethodModule {
        public override void visit_loop (Loop stmt) {
                stmt.accept_children (codegen);
 
-               stmt.ccodenode = new CCodeWhileStatement (new CCodeConstant ("TRUE"), (CCodeStatement) stmt.body.ccodenode);
+               if (context.profile == Profile.GOBJECT) {
+                       stmt.ccodenode = new CCodeWhileStatement (new CCodeConstant ("TRUE"), (CCodeStatement) stmt.body.ccodenode);
+               } else {
+                       source_declarations.add_include ("stdbool.h");
+                       stmt.ccodenode = new CCodeWhileStatement (new CCodeConstant ("true"), (CCodeStatement) stmt.body.ccodenode);
+               }
        }
 
        public override void visit_foreach_statement (ForeachStatement stmt) {
index f62ff3acafa4a9b6c5e542d3d4c54ec3da56d9fa..8fc87db1bc0042280f1da03e7001eef9f5a45773 100644 (file)
@@ -94,7 +94,11 @@ internal class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
                }
 
                if (m is CreationMethod) {
-                       ccall.add_argument (new CCodeIdentifier ("object_type"));
+                       if (context.profile == Profile.GOBJECT) {
+                               ccall.add_argument (new CCodeIdentifier ("object_type"));
+                       } else {
+                               ccall.add_argument (new CCodeIdentifier ("self"));
+                       }
 
                        foreach (DataType base_type in current_class.get_base_types ()) {
                                if (base_type.data_type is Class) {
@@ -217,7 +221,7 @@ internal class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
                                param.accept (codegen);
                        }
                        head.generate_dynamic_method_wrapper ((DynamicMethod) m);
-               } else if (m is CreationMethod) {
+               } else if (m is CreationMethod && context.profile == Profile.GOBJECT) {
                        ccall_expr = new CCodeAssignment (new CCodeIdentifier ("self"), new CCodeCastExpression (ccall, current_class.get_cname () + "*"));
                }
 
index e449a7cc40db56a7c8cbd6d70809308db6e301ae..9ffc52aa7043bcf13b1abc339fda8c4cd220e635 100644 (file)
@@ -50,14 +50,16 @@ internal class Vala.CCodeStructModule : CCodeBaseModule {
                        return;
                }
 
-               if (st.has_type_id) {
-                       decl_space.add_type_declaration (new CCodeNewline ());
-                       var macro = "(%s_get_type ())".printf (st.get_lower_case_cname (null));
-                       decl_space.add_type_declaration (new CCodeMacroReplacement (st.get_type_id (), macro));
-
-                       var type_fun = new StructRegisterFunction (st, context);
-                       type_fun.init_from_type (false);
-                       decl_space.add_type_member_declaration (type_fun.get_declaration ());
+               if (context.profile == Profile.GOBJECT) {
+                       if (st.has_type_id) {
+                               decl_space.add_type_declaration (new CCodeNewline ());
+                               var macro = "(%s_get_type ())".printf (st.get_lower_case_cname (null));
+                               decl_space.add_type_declaration (new CCodeMacroReplacement (st.get_type_id (), macro));
+
+                               var type_fun = new StructRegisterFunction (st, context);
+                               type_fun.init_from_type (false);
+                               decl_space.add_type_member_declaration (type_fun.get_declaration ());
+                       }
                }
 
                var instance_struct = new CCodeStruct ("_%s".printf (st.get_cname ()));
@@ -151,7 +153,7 @@ internal class Vala.CCodeStructModule : CCodeBaseModule {
 
                st.accept_children (codegen);
 
-               if (!st.is_boolean_type () && !st.is_integer_type () && !st.is_floating_type ()) {
+               if (context.profile == Profile.GOBJECT && !st.is_boolean_type () && !st.is_integer_type () && !st.is_floating_type ()) {
                        if (st.is_disposable ()) {
                                add_struct_copy_function (st);
                                add_struct_destroy_function (st);