$(NULL)
libvalaccode_la_VALASOURCES = \
+ valaccode.vala \
valaccodeassignment.vala \
valaccodebinaryexpression.vala \
valaccodeblock.vala \
--- /dev/null
+/* 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 ();
+ }
+ }
+}
// 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 ");
}
if (CCodeModifiers.DEPRECATED in modifiers) {
- writer.write_string (" G_GNUC_DEPRECATED");
+ writer.write_string (GNUC_DEPRECATED);
}
writer.write_string (";");
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 ();
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 (" = ");
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 ");
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) {
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));
}
}
}
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 ();
declarator.write_declaration (writer);
if (CCodeModifiers.DEPRECATED in modifiers) {
- writer.write_string (" G_GNUC_DEPRECATED");
+ writer.write_string (GNUC_DEPRECATED);
}
writer.write_string (";");
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"));