diff options
author | Dr. Michael Lauer <mickey@vanille-media.de> | 2018-02-20 16:47:34 +0100 |
---|---|---|
committer | Rico Tzschichholz <ricotz@ubuntu.com> | 2018-02-20 22:16:19 +0100 |
commit | fcda327ebfc946de971ce7fd9c2715b6d28b518b (patch) | |
tree | dc922404216544cff4f2b77175e436c4c5888cd2 /ccode | |
parent | 00791762328402bb337448b5082c4da126d8b29d (diff) | |
download | vala-fcda327ebfc946de971ce7fd9c2715b6d28b518b.tar.gz |
codegen: Add support for feature test macros
This adds new CCode string attribute 'feature_test_macro = "VALUE"'. Such
values will be added before the headers section as '#define VALUE'.
https://www.gnu.org/software/libc/manual/html_node/Feature-Test-Macros.html
https://bugzilla.gnome.org/show_bug.cgi?id=793444
Diffstat (limited to 'ccode')
-rw-r--r-- | ccode/Makefile.am | 1 | ||||
-rw-r--r-- | ccode/valaccodefeaturetestmacro.vala | 44 | ||||
-rw-r--r-- | ccode/valaccodefile.vala | 11 |
3 files changed, 56 insertions, 0 deletions
diff --git a/ccode/Makefile.am b/ccode/Makefile.am index 0f86b9646..3518c82fd 100644 --- a/ccode/Makefile.am +++ b/ccode/Makefile.am @@ -34,6 +34,7 @@ libvalaccode_la_VALASOURCES = \ valaccodeenumvalue.vala \ valaccodeexpression.vala \ valaccodeexpressionstatement.vala \ + valaccodefeaturetestmacro.vala \ valaccodefile.vala \ valaccodeforstatement.vala \ valaccodefragment.vala \ diff --git a/ccode/valaccodefeaturetestmacro.vala b/ccode/valaccodefeaturetestmacro.vala new file mode 100644 index 000000000..d18f28dcb --- /dev/null +++ b/ccode/valaccodefeaturetestmacro.vala @@ -0,0 +1,44 @@ +/* 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 (); + } +} diff --git a/ccode/valaccodefile.vala b/ccode/valaccodefile.vala index 128cd3938..aa5be219e 100644 --- a/ccode/valaccodefile.vala +++ b/ccode/valaccodefile.vala @@ -24,9 +24,11 @@ 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 (); @@ -46,6 +48,13 @@ public class Vala.CCodeFile { 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)); @@ -133,6 +142,8 @@ public class Vala.CCodeFile { 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); |