]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
ccode: Use __attribute__ replacements of G_GNUC_* for posix profile
authorRico Tzschichholz <ricotz@ubuntu.com>
Sun, 15 Nov 2020 15:58:15 +0000 (16:58 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sun, 15 Nov 2020 16:08:42 +0000 (17:08 +0100)
ccode/Makefile.am
ccode/valaccode.vala [new file with mode: 0644]
ccode/valaccodedeclaration.vala
ccode/valaccodeenum.vala
ccode/valaccodeenumvalue.vala
ccode/valaccodefunction.vala
ccode/valaccodefunctiondeclarator.vala
ccode/valaccodestruct.vala
ccode/valaccodetypedefinition.vala
codegen/valaccodebasemodule.vala

index a5defb0bb7144556cbcad458cf976ac80f3c6937..9ba6607608f056711afa1a5f4ad68ef05d27f883 100644 (file)
@@ -17,6 +17,7 @@ noinst_LTLIBRARIES = \
        $(NULL)
 
 libvalaccode_la_VALASOURCES = \
+       valaccode.vala \
        valaccodeassignment.vala \
        valaccodebinaryexpression.vala \
        valaccodeblock.vala \
diff --git a/ccode/valaccode.vala b/ccode/valaccode.vala
new file mode 100644 (file)
index 0000000..07f4bed
--- /dev/null
@@ -0,0 +1,59 @@
+/* valaccode.vala
+ *
+ * Copyright (C) 2020  Rico Tzschichholz
+ *
+ * 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:
+ *     Rico Tzschichholz <ricotz@ubuntu.com>
+ */
+
+namespace Vala {
+       public unowned string GNUC_CONST;
+       public unowned string GNUC_DEPRECATED;
+       public unowned string GNUC_FORMAT;
+       public unowned string GNUC_INTERNAL;
+       public unowned string GNUC_NO_INLINE;
+       public unowned string GNUC_PRINTF;
+       public unowned string GNUC_SCANF;
+       public unowned string GNUC_UNUSED;
+
+       public static void ccode_init (Vala.Profile profile) {
+               switch (profile) {
+               case Vala.Profile.GOBJECT:
+                       GNUC_CONST = " G_GNUC_CONST ";
+                       GNUC_DEPRECATED = " G_GNUC_DEPRECATED ";
+                       GNUC_FORMAT = " G_GNUC_FORMAT(%d) ";
+                       GNUC_INTERNAL = " G_GNUC_INTERNAL ";
+                       GNUC_NO_INLINE = " G_GNUC_NO_INLINE ";
+                       GNUC_PRINTF = "  G_GNUC_PRINTF(%d,%d) ";
+                       GNUC_SCANF = " G_GNUC_SCANF(%d,%d) ";
+                       GNUC_UNUSED = " G_GNUC_UNUSED ";
+                       break;
+               case Vala.Profile.POSIX:
+                       GNUC_CONST = " __attribute__((__const__)) ";
+                       GNUC_DEPRECATED = " __attribute__((__deprecated__)) ";
+                       GNUC_FORMAT = " __attribute__((__format_arg__ (arg_idx))) ";
+                       GNUC_INTERNAL = " __attribute__((visibility(\"hidden\"))) ";
+                       GNUC_NO_INLINE = " __attribute__((noinline)) ";
+                       GNUC_PRINTF = " __attribute__((__format__ (__printf__, %d, %d))) ";
+                       GNUC_SCANF = " __attribute__((__format__ (__scanf__, %d, %d))) ";
+                       GNUC_UNUSED = " __attribute__((__unused__)) ";
+                       break;
+               default:
+                       assert_not_reached ();
+               }
+       }
+}
index eb69c6a61660330eef2c54d1209faab6118b579f..6295477b31424b8b1354928298375c3ecc0421d5 100644 (file)
@@ -69,7 +69,7 @@ public class Vala.CCodeDeclaration : CCodeStatement {
                        // combined declaration and initialization for static and extern variables
                        writer.write_indent (line);
                        if ((modifiers & CCodeModifiers.INTERNAL) != 0) {
-                               writer.write_string ("G_GNUC_INTERNAL ");
+                               writer.write_string (GNUC_INTERNAL);
                        }
                        if ((modifiers & CCodeModifiers.STATIC) != 0) {
                                writer.write_string ("static ");
@@ -122,7 +122,7 @@ public class Vala.CCodeDeclaration : CCodeStatement {
                }
 
                if (CCodeModifiers.DEPRECATED in modifiers) {
-                       writer.write_string (" G_GNUC_DEPRECATED");
+                       writer.write_string (GNUC_DEPRECATED);
                }
 
                writer.write_string (";");
index c94ad02aeb862dff8585af6d8438aec6ce7b8261..d59db0e5a4e163568cf2f7c3892dc8d60c07fcd3 100644 (file)
@@ -71,7 +71,7 @@ public class Vala.CCodeEnum : CCodeNode {
                        writer.write_string (name);
                }
                if (CCodeModifiers.DEPRECATED in modifiers) {
-                       writer.write_string (" G_GNUC_DEPRECATED");
+                       writer.write_string (GNUC_DEPRECATED);
                }
                writer.write_string (";");
                writer.write_newline ();
index f11326f56ce90d3148983d05cfd98a8ff8a9fa2f..23d37c49262eefda048419c5a1291f35236c7f97 100644 (file)
@@ -46,7 +46,7 @@ public class Vala.CCodeEnumValue : CCodeNode {
                if (CCodeModifiers.DEPRECATED in modifiers) {
                        // FIXME Requires GCC 6.0 to work at this place
                        // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47043
-                       //writer.write_string (" G_GNUC_DEPRECATED");
+                       //writer.write_string (GNUC_DEPRECATED);
                }
                if (value != null) {
                        writer.write_string (" = ");
index 7d29de9fd9a3ebeb802777a9d17ab6da215306a7..b1a52971118f109cd29f4174e32318f0195f01bb 100644 (file)
@@ -109,10 +109,10 @@ public class Vala.CCodeFunction : CCodeNode {
        public override void write (CCodeWriter writer) {
                writer.write_indent (line);
                if (CCodeModifiers.INTERNAL in modifiers) {
-                       writer.write_string ("G_GNUC_INTERNAL ");
+                       writer.write_string (GNUC_INTERNAL);
                }
                if (!is_declaration && CCodeModifiers.NO_INLINE in modifiers) {
-                       writer.write_string ("G_GNUC_NO_INLINE ");
+                       writer.write_string (GNUC_NO_INLINE);
                }
                if (CCodeModifiers.STATIC in modifiers) {
                        writer.write_string ("static ");
@@ -159,24 +159,24 @@ public class Vala.CCodeFunction : CCodeNode {
 
                if (is_declaration) {
                        if (CCodeModifiers.DEPRECATED in modifiers) {
-                               writer.write_string (" G_GNUC_DEPRECATED");
+                               writer.write_string (GNUC_DEPRECATED);
                        }
 
                        if (CCodeModifiers.PRINTF in modifiers) {
                                format_arg_index = (format_arg_index >= 0 ? format_arg_index + 1 : args_index);
-                               writer.write_string (" G_GNUC_PRINTF(%d,%d)".printf (format_arg_index, args_index + 1));
+                               writer.write_string (GNUC_PRINTF.printf (format_arg_index, args_index + 1));
                        } else if (CCodeModifiers.SCANF in modifiers) {
                                format_arg_index = (format_arg_index >= 0 ? format_arg_index + 1 : args_index);
-                               writer.write_string (" G_GNUC_SCANF(%d,%d)".printf (format_arg_index, args_index + 1));
+                               writer.write_string (GNUC_SCANF.printf (format_arg_index, args_index + 1));
                        } else if (format_arg_index >= 0) {
-                               writer.write_string (" G_GNUC_FORMAT(%d)".printf (format_arg_index + 1));
+                               writer.write_string (GNUC_FORMAT.printf (format_arg_index + 1));
                        }
 
                        if (CCodeModifiers.CONST in modifiers) {
-                               writer.write_string (" G_GNUC_CONST");
+                               writer.write_string (GNUC_CONST);
                        }
                        if (CCodeModifiers.UNUSED in modifiers) {
-                               writer.write_string (" G_GNUC_UNUSED");
+                               writer.write_string (GNUC_UNUSED);
                        }
 
                        if (CCodeModifiers.CONSTRUCTOR in modifiers) {
index c67a087a18c8fdae7ba246aa5324cba4ed85c4f5..e9d634411f0333a09f254b192f83d1550c88b4c2 100644 (file)
@@ -81,17 +81,17 @@ public class Vala.CCodeFunctionDeclarator : CCodeDeclarator {
                writer.write_string (")");
 
                if (CCodeModifiers.DEPRECATED in modifiers) {
-                       writer.write_string (" G_GNUC_DEPRECATED");
+                       writer.write_string (GNUC_DEPRECATED);
                }
 
                if (CCodeModifiers.PRINTF in modifiers) {
                        format_arg_index = (format_arg_index >= 0 ? format_arg_index + 1 : args_index);
-                       writer.write_string (" G_GNUC_PRINTF(%d,%d)".printf (format_arg_index, args_index + 1));
+                       writer.write_string (GNUC_PRINTF.printf (format_arg_index, args_index + 1));
                } else if (CCodeModifiers.SCANF in modifiers) {
                        format_arg_index = (format_arg_index >= 0 ? format_arg_index + 1 : args_index);
-                       writer.write_string (" G_GNUC_SCANF(%d,%d)".printf (format_arg_index, args_index + 1));
+                       writer.write_string (GNUC_SCANF.printf (format_arg_index, args_index + 1));
                } else if (format_arg_index >= 0) {
-                       writer.write_string (" G_GNUC_FORMAT(%d)".printf (format_arg_index + 1));
+                       writer.write_string (GNUC_FORMAT.printf (format_arg_index + 1));
                }
        }
 }
index 50af6a2bf0e479b9355dd4a06b0ad646445766e8..9630a37c4468dad1a71a12c96c77d113f1eb80aa 100644 (file)
@@ -71,7 +71,7 @@ public class Vala.CCodeStruct : CCodeNode {
 
                writer.write_end_block ();
                if (CCodeModifiers.DEPRECATED in modifiers) {
-                       writer.write_string (" G_GNUC_DEPRECATED");
+                       writer.write_string (GNUC_DEPRECATED);
                }
                writer.write_string (";");
                writer.write_newline ();
index f476ad12b1076e6c6c2c5e9199c445332e5985db..39f014a9ceb15a6f114adfd49400e48dce6fb4a8 100644 (file)
@@ -55,7 +55,7 @@ public class Vala.CCodeTypeDefinition : CCodeNode {
                declarator.write_declaration (writer);
 
                if (CCodeModifiers.DEPRECATED in modifiers) {
-                       writer.write_string (" G_GNUC_DEPRECATED");
+                       writer.write_string (GNUC_DEPRECATED);
                }
 
                writer.write_string (";");
index 9a801e36986d26fe98ccff3d133d6a0643a548de..469282a0a40d2819be6cf5da4ef3e2ec99659c62 100644 (file)
@@ -463,6 +463,8 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
        public override void emit (CodeContext context) {
                this.context = context;
 
+               ccode_init (context.profile);
+
                root_symbol = context.root;
 
                bool_type = new BooleanType ((Struct) root_symbol.scope.lookup ("bool"));