valaccodeenumvalue.vala \
valaccodeexpression.vala \
valaccodeexpressionstatement.vala \
+ valaccodefeaturetestmacro.vala \
valaccodefile.vala \
valaccodeforstatement.vala \
valaccodefragment.vala \
--- /dev/null
+/* valaccodefeaturetestmacro.vala
+ *
+ * Copyright (C) 2018 Dr. Michael 'Mickey' Lauer
+ *
+ * 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:
+ * Dr. Michael 'Mickey' Lauer <mickey@vanille-media.de>
+ */
+
+using GLib;
+
+/**
+ * Represents a feature test macro definition in the C code.
+ */
+public class Vala.CCodeFeatureTestMacro : CCodeNode {
+ /**
+ * The name of this macro.
+ */
+ public string name { get; set; }
+
+ public CCodeFeatureTestMacro (string name) {
+ this.name = name;
+ }
+
+ public override void write (CCodeWriter writer) {
+ writer.write_indent ();
+ writer.write_string ("#define ");
+ writer.write_string (name);
+ writer.write_newline ();
+ }
+}
public class Vala.CCodeFile {
public bool is_header { get; set; }
+ Set<string> features = new HashSet<string> (str_hash, str_equal);
Set<string> declarations = new HashSet<string> (str_hash, str_equal);
Set<string> includes = new HashSet<string> (str_hash, str_equal);
CCodeFragment comments = new CCodeFragment ();
+ CCodeFragment feature_test_macros = new CCodeFragment ();
CCodeFragment include_directives = new CCodeFragment ();
CCodeFragment type_declaration = new CCodeFragment ();
CCodeFragment type_definition = new CCodeFragment ();
comments.append (comment);
}
+ public void add_feature_test_macro (string feature_test_macro) {
+ if (!(feature_test_macro in features)) {
+ feature_test_macros.append (new CCodeFeatureTestMacro (feature_test_macro));
+ features.add (feature_test_macro);
+ }
+ }
+
public void add_include (string filename, bool local = false) {
if (!(filename in includes)) {
include_directives.append (new CCodeIncludeDirective (filename, local));
comments.write (writer);
writer.write_newline ();
+ feature_test_macros.write (writer);
+ writer.write_newline ();
include_directives.write (writer);
writer.write_newline ();
type_declaration.write_combined (writer);
return get_ccode_attribute(sym).header_filenames;
}
+ public static string get_ccode_feature_test_macros (Symbol sym) {
+ return get_ccode_attribute(sym).feature_test_macros;
+ }
+
public static string get_ccode_prefix (Symbol sym) {
return get_ccode_attribute(sym).prefix;
}
}
}
+ public string feature_test_macros {
+ get {
+ if (_feature_test_macros == null) {
+ if (ccode != null) {
+ _feature_test_macros = ccode.get_string ("feature_test_macro");
+ }
+ if (_feature_test_macros == null) {
+ _feature_test_macros = "";
+ }
+ }
+ return _feature_test_macros;
+ }
+ }
+
public string header_filenames {
get {
if (_header_filenames == null) {
private string _name;
private string _const_name;
private string _type_name;
+ private string _feature_test_macros;
private string _header_filenames;
private string _prefix;
private string _lower_case_prefix;
sym.source_reference.file.used = true;
}
if (sym.external_package || (!decl_space.is_header && CodeContext.get ().use_header && !sym.is_internal_symbol ())) {
+ // add feature test macros
+ foreach (unowned string feature_test_macro in get_ccode_feature_test_macros (sym).split (",")) {
+ decl_space.add_feature_test_macro (feature_test_macro);
+ }
// add appropriate include file
foreach (unowned string header_filename in get_ccode_header_filenames (sym).split (",")) {
decl_space.add_include (header_filename, !sym.external_package ||
"array_length_type", "array_length", "array_length_cname", "array_length_cexpr", "array_null_terminated",
"vfunc_name", "finish_vfunc_name", "finish_name", "free_function_address_of", "pos", "delegate_target", "delegate_target_cname",
"array_length_pos", "delegate_target_pos", "destroy_notify_pos", "ctype", "has_new_function", "notify", "finish_instance",
- "use_inplace", "",
+ "use_inplace", "feature_test_macro", "",
"Immutable", "",
"Compact", "",