[vala] Add support for generating of a C header file for the internal API
- From: Ali Sabil <asabil src gnome org>
- To: svn-commits-list gnome org
- Subject: [vala] Add support for generating of a C header file for the internal API
- Date: Thu, 2 Apr 2009 12:30:33 -0400 (EDT)
commit 5619447048854ba96079d349121dfd1f2a53ff25
Author: Ali Sabil <ali sabil gmail com>
Date: Thu Apr 2 18:26:47 2009 +0200
Add support for generating of a C header file for the internal API
Added the --internal-header compiler flag to enable the generation of a C
header file for the internal API.
---
compiler/valacompiler.vala | 3 ++
gobject/valaccodebasemodule.vala | 37 ++++++++++++++++++++++++++++++++++++
gobject/valaccodemethodmodule.vala | 1 +
gobject/valaccodestructmodule.vala | 1 +
gobject/valagobjectmodule.vala | 1 +
vala/valacodecontext.vala | 7 +++++-
6 files changed, 49 insertions(+), 1 deletions(-)
diff --git a/compiler/valacompiler.vala b/compiler/valacompiler.vala
index fe74b58..6becda9 100644
--- a/compiler/valacompiler.vala
+++ b/compiler/valacompiler.vala
@@ -41,6 +41,7 @@ class Vala.Compiler {
static bool ccode_only;
static string header_filename;
+ static string internal_header_filename;
static bool compile_only;
static string output;
static bool debug;
@@ -70,6 +71,7 @@ class Vala.Compiler {
{ "version", 0, 0, OptionArg.NONE, ref version, "Display version number", null },
{ "ccode", 'C', 0, OptionArg.NONE, ref ccode_only, "Output C code", null },
{ "header", 'H', 0, OptionArg.FILENAME, ref header_filename, "Output C header file", "FILE" },
+ { "internal-header", 'h', 0, OptionArg.FILENAME, ref internal_header_filename, "Output internal C header file", "FILE" },
{ "compile", 'c', 0, OptionArg.NONE, ref compile_only, "Compile but do not link", null },
{ "output", 'o', 0, OptionArg.FILENAME, ref output, "Place output in file FILE", "FILE" },
{ "debug", 'g', 0, OptionArg.NONE, ref debug, "Produce debug information", null },
@@ -170,6 +172,7 @@ class Vala.Compiler {
context.ccode_only = ccode_only;
context.compile_only = compile_only;
context.header_filename = header_filename;
+ context.internal_header_filename = internal_header_filename;
context.output = output;
if (basedir == null) {
context.basedir = realpath (".");
diff --git a/gobject/valaccodebasemodule.vala b/gobject/valaccodebasemodule.vala
index 23af714..c5d2df6 100644
--- a/gobject/valaccodebasemodule.vala
+++ b/gobject/valaccodebasemodule.vala
@@ -40,6 +40,7 @@ internal class Vala.CCodeBaseModule : CCodeModule {
public PropertyAccessor current_property_accessor;
public CCodeDeclarationSpace header_declarations;
+ public CCodeDeclarationSpace internal_header_declarations;
public CCodeDeclarationSpace source_declarations;
public CCodeFragment source_signal_marshaller_declaration;
@@ -266,6 +267,7 @@ internal class Vala.CCodeBaseModule : CCodeModule {
}
header_declarations = new CCodeDeclarationSpace ();
+ internal_header_declarations = new CCodeDeclarationSpace ();
/* we're only interested in non-pkg source files */
var source_files = context.get_source_files ();
@@ -344,6 +346,37 @@ internal class Vala.CCodeBaseModule : CCodeModule {
writer.close ();
}
}
+
+ // generate C header file for internal API
+ if (context.internal_header_filename != null) {
+ var writer = new CCodeWriter (context.internal_header_filename);
+ if (!writer.open ()) {
+ Report.error (null, "unable to open `%s' for writing".printf (writer.filename));
+ return;
+ }
+ writer.write_newline ();
+
+ var once = new CCodeOnceSection (get_define_for_filename (writer.filename));
+ once.append (new CCodeNewline ());
+ once.append (internal_header_declarations.include_directives);
+ once.append (new CCodeNewline ());
+ once.append (new CCodeIdentifier ("G_BEGIN_DECLS"));
+ once.append (new CCodeNewline ());
+ once.append (new CCodeNewline ());
+ once.append (internal_header_declarations.type_declaration);
+ once.append (new CCodeNewline ());
+ once.append (internal_header_declarations.type_definition);
+ once.append (new CCodeNewline ());
+ once.append (internal_header_declarations.type_member_declaration);
+ once.append (new CCodeNewline ());
+ once.append (internal_header_declarations.constant_declaration);
+ once.append (new CCodeNewline ());
+ once.append (new CCodeIdentifier ("G_END_DECLS"));
+ once.append (new CCodeNewline ());
+ once.append (new CCodeNewline ());
+ once.write (writer);
+ writer.close ();
+ }
}
public override CCodeIdentifier get_value_setter_function (DataType type_reference) {
@@ -424,6 +457,7 @@ internal class Vala.CCodeBaseModule : CCodeModule {
generated_external_symbols = new HashSet<Symbol> ();
header_declarations.add_include ("glib.h");
+ internal_header_declarations.add_include ("glib.h");
source_declarations.add_include ("glib.h");
source_declarations.add_include ("glib-object.h");
@@ -653,6 +687,7 @@ internal class Vala.CCodeBaseModule : CCodeModule {
if (!en.is_internal_symbol ()) {
generate_enum_declaration (en, header_declarations);
}
+ generate_enum_declaration (en, internal_header_declarations);
if (!en.has_type_id) {
return;
@@ -895,6 +930,7 @@ internal class Vala.CCodeBaseModule : CCodeModule {
if (!f.is_internal_symbol ()) {
generate_field_declaration (f, header_declarations);
}
+ generate_field_declaration (f, internal_header_declarations);
lhs = new CCodeIdentifier (f.get_cname ());
@@ -1174,6 +1210,7 @@ internal class Vala.CCodeBaseModule : CCodeModule {
|| acc.access == SymbolAccessibility.PROTECTED)) {
generate_property_accessor_declaration (acc, header_declarations);
}
+ generate_property_accessor_declaration (acc, internal_header_declarations);
}
var this_type = new ObjectType (t);
diff --git a/gobject/valaccodemethodmodule.vala b/gobject/valaccodemethodmodule.vala
index bac46ec..4efab19 100644
--- a/gobject/valaccodemethodmodule.vala
+++ b/gobject/valaccodemethodmodule.vala
@@ -303,6 +303,7 @@ internal class Vala.CCodeMethodModule : CCodeStructModule {
if (!m.is_internal_symbol ()) {
generate_method_declaration (m, header_declarations);
}
+ generate_method_declaration (m, internal_header_declarations);
}
function = new CCodeFunction (m.get_real_cname ());
diff --git a/gobject/valaccodestructmodule.vala b/gobject/valaccodestructmodule.vala
index 9b6412e..bbc2c94 100644
--- a/gobject/valaccodestructmodule.vala
+++ b/gobject/valaccodestructmodule.vala
@@ -87,6 +87,7 @@ internal class Vala.CCodeStructModule : CCodeBaseModule {
if (!st.is_internal_symbol ()) {
generate_struct_declaration (st, header_declarations);
}
+ generate_struct_declaration (st, internal_header_declarations);
st.accept_children (codegen);
diff --git a/gobject/valagobjectmodule.vala b/gobject/valagobjectmodule.vala
index 39810a4..5214307 100644
--- a/gobject/valagobjectmodule.vala
+++ b/gobject/valagobjectmodule.vala
@@ -452,6 +452,7 @@ internal class Vala.GObjectModule : GTypeModule {
if (!cl.is_internal_symbol ()) {
generate_class_struct_declaration (cl, header_declarations);
}
+ generate_class_struct_declaration (cl, internal_header_declarations);
cl.accept_children (codegen);
diff --git a/vala/valacodecontext.vala b/vala/valacodecontext.vala
index e040630..abf1719 100644
--- a/vala/valacodecontext.vala
+++ b/vala/valacodecontext.vala
@@ -78,7 +78,12 @@ public class Vala.CodeContext {
/**
* Output C header file.
*/
- public string header_filename { get; set; }
+ public string? header_filename { get; set; }
+
+ /**
+ * Output internal C header file.
+ */
+ public string? internal_header_filename { get; set; }
/**
* Compile but do not link.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]