]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Add support for generating of a C header file for the internal API
authorAli Sabil <ali.sabil@gmail.com>
Thu, 2 Apr 2009 16:26:47 +0000 (18:26 +0200)
committerAli Sabil <ali.sabil@gmail.com>
Thu, 2 Apr 2009 16:26:47 +0000 (18:26 +0200)
Added the --internal-header compiler flag to enable the generation of a C
header file for the internal API.

compiler/valacompiler.vala
gobject/valaccodebasemodule.vala
gobject/valaccodemethodmodule.vala
gobject/valaccodestructmodule.vala
gobject/valagobjectmodule.vala
vala/valacodecontext.vala

index fe74b58bb5bd1d9cf4a5c9b98963d8cbc2f3bfb1..6becda937b22be5fb21da4392404365122aa1e94 100644 (file)
@@ -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 (".");
index 23af71493ed3b6e0ec58a6d2049eb5d6cdb559ef..c5d2df61b8c80b0f84090fb09f430de87b238f4e 100644 (file)
@@ -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);
index bac46ec2b82f36ab622b4af7e157e7f0825070ae..4efab199ba6e84b40ddc36a0ca176bc7973d2583 100644 (file)
@@ -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 ());
index 9b6412ed0b7754c59688d58633da299965c70e4a..bbc2c945614bed00c5a2a1d44013eb6341d0d499 100644 (file)
@@ -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);
 
index 39810a4942d5e66c59dbf55e2193552d7b77613d..521430769661a580f4f3eeef7d671930ecf072a5 100644 (file)
@@ -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);
 
index e04063034ed0974246b9c569fa58330e4ab6bc1a..abf171925a1951a9560547204999f2361a044293 100644 (file)
@@ -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.