]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Add CCodeNode "modifiers" and transform CCodeFunction's "attributes" to it
authorRico Tzschichholz <ricotz@ubuntu.com>
Tue, 8 Nov 2016 11:00:48 +0000 (12:00 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Tue, 8 Nov 2016 11:40:17 +0000 (12:40 +0100)
ccode/valaccodedeclaration.vala
ccode/valaccodefunction.vala
ccode/valaccodemodifiers.vala
ccode/valaccodenode.vala
codegen/valaccodebasemodule.vala
codegen/valaccodemethodmodule.vala
codegen/valagdbusclientmodule.vala
codegen/valagtypemodule.vala
codegen/valatyperegisterfunction.vala

index 634165a69df8611aa5fc79845e721d39b716436b..4d0fa742568fea84228e0a00038f6b4b8e1eb823 100644 (file)
@@ -31,11 +31,6 @@ public class Vala.CCodeDeclaration : CCodeStatement {
         */
        public string type_name { get; set; }
 
-       /**
-        * The declaration modifier.
-        */
-       public CCodeModifiers modifiers { get; set; }
-       
        private List<CCodeDeclarator> declarators = new ArrayList<CCodeDeclarator> ();
        
        public CCodeDeclaration (string type_name) {
index 44dd5b9560e52ab3e998396e50ac400558c2c87b..43bfb6cbb6fcde187fc5ef2fe923bad8833ab7eb 100644 (file)
@@ -31,18 +31,11 @@ public class Vala.CCodeFunction : CCodeNode {
         */
        public string name { get; set; }
        
-       /**
-        * The function modifiers.
-        */
-       public CCodeModifiers modifiers { get; set; }
-       
        /**
         * The function return type.
         */
        public string return_type { get; set; }
 
-       public string attributes { get; set; }
-
        public bool is_declaration { get; set; }
 
        /**
@@ -96,7 +89,6 @@ public class Vala.CCodeFunction : CCodeNode {
        public CCodeFunction copy () {
                var func = new CCodeFunction (name, return_type);
                func.modifiers = modifiers;
-               func.attributes = attributes;
 
                /* no deep copy for lists available yet
                 * func.parameters = parameters.copy ();
@@ -153,9 +145,17 @@ public class Vala.CCodeFunction : CCodeNode {
                                writer.write_string (" G_GNUC_FORMAT(%d)".printf (format_arg_index + 1));
                        }
 
-                       if (attributes != null) {
-                               writer.write_string (" ");
-                               writer.write_string (attributes);
+                       if (CCodeModifiers.CONST in modifiers) {
+                               writer.write_string (" G_GNUC_CONST");
+                       }
+                       if (CCodeModifiers.UNUSED in modifiers) {
+                               writer.write_string (" G_GNUC_UNUSED");
+                       }
+
+                       if (CCodeModifiers.CONSTRUCTOR in modifiers) {
+                               writer.write_string (" __attribute__((constructor))");
+                       } else if (CCodeModifiers.DESTRUCTOR in modifiers) {
+                               writer.write_string (" __attribute__((destructor))");
                        }
 
                        writer.write_string (";");
index 600751d6c8486a6c6b85a3bd339b6068336e0fd8..086056f677b5f4e7c633c57cf8342ecfb0519b9e 100644 (file)
@@ -34,5 +34,9 @@ public enum Vala.CCodeModifiers {
        VOLATILE = 1 << 4,
        DEPRECATED = 1 << 5,
        THREAD_LOCAL = 1 << 6,
-       INTERNAL = 1 << 7
+       INTERNAL = 1 << 7,
+       CONST = 1 << 8,
+       UNUSED = 1 << 9,
+       CONSTRUCTOR = 1 << 10,
+       DESTRUCTOR = 1 << 11
 }
index 6ab095f6049d108af7e0393580577d35cb1c55b9..d8c3e5cdfac44de28eca893693d720a9e9b0be63 100644 (file)
@@ -32,6 +32,12 @@ public abstract class Vala.CCodeNode {
         */
        public CCodeLineDirective line { get; set; }
 
+       /**
+        * The modifiers for this code node which will be handled as needed
+        * in every subclass.
+        */
+       public CCodeModifiers modifiers { get; set; }
+
        /**
         * Writes this code node and all children with the specified C code
         * writer.
index cdab6f1c82efaa59ca9cee189c267d7084e2bbc5..adccba732c67daa194d51af7b1a272673542c624 100644 (file)
@@ -827,14 +827,13 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 
                var fun_name = "%s_get_type".printf (get_ccode_lower_case_name (en, null));
                var regfun = new CCodeFunction (fun_name, "GType");
-               regfun.attributes = "G_GNUC_CONST";
+               regfun.modifiers = CCodeModifiers.CONST;
 
                if (en.is_private_symbol ()) {
-                       regfun.modifiers = CCodeModifiers.STATIC;
                        // avoid C warning as this function is not always used
-                       regfun.attributes += " G_GNUC_UNUSED";
+                       regfun.modifiers |= CCodeModifiers.STATIC | CCodeModifiers.UNUSED;
                } else if (context.hide_internal && en.is_internal_symbol ()) {
-                       regfun.modifiers = CCodeModifiers.INTERNAL;
+                       regfun.modifiers |= CCodeModifiers.INTERNAL;
                }
 
                decl_space.add_function_declaration (regfun);
index b50380a9ab16cdc7ef1f397c09c8a99172819afa..195592ff73eb798fd3f696758ee3f95e1fc8fb3c 100644 (file)
@@ -369,8 +369,7 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
                        cfile.add_type_member_declaration (timer_decl);
 
                        var constructor = new CCodeFunction (prefix + "_init");
-                       constructor.modifiers = CCodeModifiers.STATIC;
-                       constructor.attributes = "__attribute__((constructor))";
+                       constructor.modifiers = CCodeModifiers.STATIC | CCodeModifiers.CONSTRUCTOR;
                        cfile.add_function_declaration (constructor);
                        push_function (constructor);
 
@@ -385,8 +384,7 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
 
 
                        var destructor = new CCodeFunction (prefix + "_exit");
-                       destructor.modifiers = CCodeModifiers.STATIC;
-                       destructor.attributes = "__attribute__((destructor))";
+                       destructor.modifiers = CCodeModifiers.STATIC | CCodeModifiers.DESTRUCTOR;
                        cfile.add_function_declaration (destructor);
                        push_function (destructor);
 
index 079ac52b80ac2de8857f13781b79873701c263c4..20229fdea72f711f50197401e9632dc46e2658e5 100644 (file)
@@ -163,7 +163,7 @@ public class Vala.GDBusClientModule : GDBusModule {
 
                // declare proxy_get_type function
                var proxy_get_type = new CCodeFunction (get_type_name, "GType");
-               proxy_get_type.attributes = "G_GNUC_CONST";
+               proxy_get_type.modifiers = CCodeModifiers.CONST;
                decl_space.add_function_declaration (proxy_get_type);
 
                if (in_plugin) {
index 692a9bd33106938f363b0dcded6a5e58480b3072..d4313d1632ef9fc54ad36980b4f50c72ee72ad07 100644 (file)
@@ -119,9 +119,8 @@ public class Vala.GTypeModule : GErrorModule {
                        function.add_parameter (new CCodeParameter ("flags", "GParamFlags"));
 
                        if (cl.is_private_symbol ()) {
-                               function.modifiers = CCodeModifiers.STATIC;
                                // avoid C warning as this function is not always used
-                               function.attributes = "G_GNUC_UNUSED";
+                               function.modifiers = CCodeModifiers.STATIC | CCodeModifiers.UNUSED;
                        } else if (context.hide_internal && cl.is_internal_symbol ()) {
                                function.modifiers = CCodeModifiers.INTERNAL;
                        }
@@ -133,13 +132,11 @@ public class Vala.GTypeModule : GErrorModule {
                        function.add_parameter (new CCodeParameter ("v_object", "gpointer"));
 
                        if (cl.is_private_symbol ()) {
-                               function.modifiers = CCodeModifiers.STATIC;
                                // avoid C warning as this function is not always used
-                               function.attributes = "G_GNUC_UNUSED";
+                               function.modifiers = CCodeModifiers.STATIC | CCodeModifiers.UNUSED;
                        } else if (context.hide_internal && cl.is_internal_symbol ()) {
-                               function.modifiers = CCodeModifiers.INTERNAL;
                                // avoid C warning as this function is not always used
-                               function.attributes = "G_GNUC_UNUSED";
+                               function.modifiers = CCodeModifiers.INTERNAL | CCodeModifiers.UNUSED;
                        }
 
                        decl_space.add_function_declaration (function);
@@ -149,9 +146,8 @@ public class Vala.GTypeModule : GErrorModule {
                        function.add_parameter (new CCodeParameter ("v_object", "gpointer"));
 
                        if (cl.is_private_symbol ()) {
-                               function.modifiers = CCodeModifiers.STATIC;
                                // avoid C warning as this function is not always used
-                               function.attributes = "G_GNUC_UNUSED";
+                               function.modifiers = CCodeModifiers.STATIC | CCodeModifiers.UNUSED;
                        } else if (context.hide_internal && cl.is_internal_symbol ()) {
                                function.modifiers = CCodeModifiers.INTERNAL;
                        }
@@ -162,13 +158,11 @@ public class Vala.GTypeModule : GErrorModule {
                        function.add_parameter (new CCodeParameter ("value", "const GValue*"));
 
                        if (cl.is_private_symbol ()) {
-                               function.modifiers = CCodeModifiers.STATIC;
                                // avoid C warning as this function is not always used
-                               function.attributes = "G_GNUC_UNUSED";
+                               function.modifiers = CCodeModifiers.STATIC | CCodeModifiers.UNUSED;
                        } else if (context.hide_internal && cl.is_internal_symbol ()) {
-                               function.modifiers = CCodeModifiers.INTERNAL;
                                // avoid C warning as this function is not always used
-                               function.attributes = "G_GNUC_UNUSED";
+                               function.modifiers = CCodeModifiers.INTERNAL | CCodeModifiers.UNUSED;
                        }
 
                        decl_space.add_function_declaration (function);
index b7c18f8a25c6c770c408c78a4d3a629af3f84b52..9617f8240e254172bd9a81ff586edb573d241f33 100644 (file)
@@ -68,24 +68,22 @@ public abstract class Vala.TypeRegisterFunction {
                CCodeFunction fun;
                if (!plugin) {
                        fun = new CCodeFunction ("%s_get_type".printf (CCodeBaseModule.get_ccode_lower_case_name (get_type_declaration ())), "GType");
-                       fun.attributes = "G_GNUC_CONST";
+                       fun.modifiers = CCodeModifiers.CONST;
 
                        /* Function will not be prototyped anyway */
                        if (get_accessibility () == SymbolAccessibility.PRIVATE) {
-                               fun.modifiers = CCodeModifiers.STATIC;
                                // avoid C warning as this function is not always used
-                               fun.attributes += " G_GNUC_UNUSED";
+                               fun.modifiers |= CCodeModifiers.STATIC | CCodeModifiers.UNUSED;
                        } else if (context.hide_internal && get_accessibility () == SymbolAccessibility.INTERNAL) {
-                               fun.modifiers = CCodeModifiers.INTERNAL;
                                // avoid C warning as this function is not always used
-                               fun.attributes += " G_GNUC_UNUSED";
+                               fun.modifiers |= CCodeModifiers.INTERNAL | CCodeModifiers.UNUSED;
                        }
                } else {
                        fun = new CCodeFunction ("%s_register_type".printf (CCodeBaseModule.get_ccode_lower_case_name (get_type_declaration ())), "GType");
                        fun.add_parameter (new CCodeParameter ("module", "GTypeModule *"));
 
                        var get_fun = new CCodeFunction ("%s_get_type".printf (CCodeBaseModule.get_ccode_lower_case_name (get_type_declaration ())), "GType");
-                       get_fun.attributes = "G_GNUC_CONST";
+                       get_fun.modifiers = CCodeModifiers.CONST;
 
                        get_fun.is_declaration = true;
                        declaration_fragment.append (get_fun.copy ());