]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Append doc comments to generated C files
authorJürg Billeter <j@bitron.ch>
Tue, 27 Jul 2010 19:56:30 +0000 (21:56 +0200)
committerJürg Billeter <j@bitron.ch>
Tue, 27 Jul 2010 20:07:22 +0000 (22:07 +0200)
ccode/valaccodewriter.vala
codegen/valaccodebasemodule.vala
codegen/valaccodemethodmodule.vala
codegen/valagobjectmodule.vala
codegen/valagtypemodule.vala
vala/valaparser.vala
vala/valapropertyaccessor.vala
vala/valascanner.vala

index 8f2575437370a7919a005597606bfc06b04a16c0..93f4a4261fffb7ab2fb2708a4265149984871ccf 100644 (file)
@@ -217,30 +217,37 @@ public class Vala.CCodeWriter {
         * @param text the comment text
         */
        public void write_comment (string text) {
-               write_indent ();
-               stream.puts ("/*");
-               bool first = true;
-               
-               /* separate declaration due to missing memory management in foreach statements */
-               var lines = text.split ("\n");
+               try {
+                       write_indent ();
+                       stream.puts ("/*");
+                       bool first = true;
+
+                       // discard tabs at beginning of line
+                       var regex = new GLib.Regex ("^\t+");
+
+                       /* separate declaration due to missing memory management in foreach statements */
+                       var lines = text.split ("\n");
                
-               foreach (string line in lines) {
-                       if (!first) {
-                               write_indent ();
-                       } else {
-                               first = false;
-                       }
+                       foreach (string line in lines) {
+                               if (!first) {
+                                       write_indent ();
+                               } else {
+                                       first = false;
+                               }
 
-                       var lineparts = line.split ("*/");
+                               var lineparts = regex.replace_literal (line, -1, 0, "").split ("*/");
 
-                       for (int i = 0; lineparts[i] != null; i++) {
-                               stream.puts (lineparts[i]);
-                               if (lineparts[i+1] != null) {
-                                       stream.puts ("* /");
+                               for (int i = 0; lineparts[i] != null; i++) {
+                                       stream.puts (lineparts[i]);
+                                       if (lineparts[i+1] != null) {
+                                               stream.puts ("* /");
+                                       }
                                }
                        }
+                       stream.puts ("*/");
+                       write_newline ();
+               } catch (RegexError e) {
+                       // ignore
                }
-               stream.puts ("*/");
-               write_newline ();
        }
 }
index 50127b638a7ff67fbe95abb56226710c5d34433e..8f78e15f7d0df50bf8a842bb95e13c1f75494078 100644 (file)
@@ -1349,6 +1349,10 @@ public class Vala.CCodeBaseModule : CCodeModule {
 
                var prop = (Property) acc.prop;
 
+               if (acc.comment != null) {
+                       source_type_member_definition.append (new CCodeComment (acc.comment.content));
+               }
+
                bool returns_real_struct = acc.readable && prop.property_type.is_real_non_null_struct_type ();
 
                acc.accept_children (codegen);
index a07ac05b92479a9416c98ecb0f933792d85cda4a..0b35b9960585524c439d99c592c3d179002a7557 100644 (file)
@@ -420,6 +420,10 @@ public class Vala.CCodeMethodModule : CCodeStructModule {
                        }
                }
 
+               if (m.comment != null) {
+                       source_type_member_definition.append (new CCodeComment (m.comment.content));
+               }
+
                function = new CCodeFunction (m.get_real_cname ());
                m.ccodenode = function;
 
index bd527fd22e062923c8341d064400c6261efdff9e..d1c2eea29fc3074c6c9b43d09223cf2208858edb 100644 (file)
@@ -137,6 +137,10 @@ public class Vala.GObjectModule : GTypeModule {
                                continue;
                        }
 
+                       if (prop.comment != null) {
+                               init_block.add_statement (new CCodeComment (prop.comment.content));
+                       }
+
                        if (prop.overrides || prop.base_interface_property != null) {
                                var cinst = new CCodeFunctionCall (new CCodeIdentifier ("g_object_class_override_property"));
                                cinst.add_argument (ccall);
index e2a001e0f0e4d17cc920defdfc355706a1d9dc68..5781cd70ebc46d969330fb0f7bf35776fcbed88e 100644 (file)
@@ -590,6 +590,10 @@ public class Vala.GTypeModule : GErrorModule {
                                add_finalize_function (cl);
                        }
 
+                       if (cl.comment != null) {
+                               source_type_member_definition.append (new CCodeComment (cl.comment.content));
+                       }
+
                        var type_fun = new ClassRegisterFunction (cl, context);
                        type_fun.init_from_type (in_plugin);
                        source_declarations.add_type_member_declaration (type_fun.get_source_declaration ());
@@ -1295,6 +1299,9 @@ public class Vala.GTypeModule : GErrorModule {
                if (!cl.is_compact) {
                        /* create signals */
                        foreach (Signal sig in cl.get_signals ()) {
+                               if (sig.comment != null) {
+                                       init_block.add_statement (new CCodeComment (sig.comment.content));
+                               }
                                init_block.add_statement (new CCodeExpressionStatement (head.get_signal_creation (sig, cl)));
                        }
                }
@@ -1932,6 +1939,10 @@ public class Vala.GTypeModule : GErrorModule {
 
                add_interface_base_init_function (iface);
 
+               if (iface.comment != null) {
+                       source_type_member_definition.append (new CCodeComment (iface.comment.content));
+               }
+
                var type_fun = create_interface_register_function (iface);
                type_fun.init_from_type (in_plugin);
                source_declarations.add_type_member_declaration (type_fun.get_source_declaration ());
@@ -1970,6 +1981,10 @@ public class Vala.GTypeModule : GErrorModule {
                                                continue;
                                        }
 
+                                       if (prop.comment != null) {
+                                               init_block.add_statement (new CCodeComment (prop.comment.content));
+                                       }
+
                                        var cinst = new CCodeFunctionCall (new CCodeIdentifier ("g_object_interface_install_property"));
                                        cinst.add_argument (new CCodeIdentifier ("iface"));
                                        cinst.add_argument (head.get_param_spec (prop));
@@ -1981,6 +1996,9 @@ public class Vala.GTypeModule : GErrorModule {
 
                /* create signals */
                foreach (Signal sig in iface.get_signals ()) {
+                       if (sig.comment != null) {
+                               init_block.add_statement (new CCodeComment (sig.comment.content));
+                       }
                        init_block.add_statement (new CCodeExpressionStatement (head.get_signal_creation (sig, iface)));
                }
 
index 9161da2f72551d2838ae3ad68c04e2b8603caf5c..8d375cc787e96a5cbe11bc4fff454c56b644b2c5 100644 (file)
@@ -2746,6 +2746,8 @@ public class Vala.Parser : CodeVisitor {
                                prop.initializer = parse_expression ();
                                expect (TokenType.SEMICOLON);
                        } else {
+                               comment = scanner.pop_comment ();
+
                                var accessor_begin = get_location ();
                                var accessor_attrs = parse_attributes ();
                                var accessor_access = parse_access_modifier (SymbolAccessibility.PUBLIC);
@@ -2767,7 +2769,7 @@ public class Vala.Parser : CodeVisitor {
                                                block = parse_block ();
                                                prop.external = false;
                                        }
-                                       prop.get_accessor = new PropertyAccessor (true, false, false, value_type, block, get_src (accessor_begin));
+                                       prop.get_accessor = new PropertyAccessor (true, false, false, value_type, block, get_src (accessor_begin), comment);
                                        set_attributes (prop.get_accessor, accessor_attrs);
                                        prop.get_accessor.access = accessor_access;
                                } else {
@@ -2789,7 +2791,7 @@ public class Vala.Parser : CodeVisitor {
                                                block = parse_block ();
                                                prop.external = false;
                                        }
-                                       prop.set_accessor = new PropertyAccessor (false, writable, _construct, value_type, block, get_src (accessor_begin));
+                                       prop.set_accessor = new PropertyAccessor (false, writable, _construct, value_type, block, get_src (accessor_begin), comment);
                                        set_attributes (prop.set_accessor, accessor_attrs);
                                        prop.set_accessor.access = accessor_access;
                                }
index 9e3944e39c5b554b9f073752ab9b90e5f97690ea..ca0a1c5a6f466263db4f26cebed185bbaa7da592 100644 (file)
@@ -128,8 +128,8 @@ public class Vala.PropertyAccessor : Symbol {
         * @param source       reference to source code
         * @return             newly created property accessor
         */
-       public PropertyAccessor (bool readable, bool writable, bool construction, DataType? value_type, Block? body, SourceReference? source_reference) {
-               base (null, source_reference);
+       public PropertyAccessor (bool readable, bool writable, bool construction, DataType? value_type, Block? body, SourceReference? source_reference, Comment? comment = null) {
+               base (null, source_reference, comment);
                this.readable = readable;
                this.writable = writable;
                this.construction = construction;
index 0f097e8a61696621425515f31cc49567da490b45..e5fd0db7a0d12f42d4ff34fbec39d3e3f5a91560 100644 (file)
@@ -1562,6 +1562,10 @@ public class Vala.Scanner {
 
        void push_comment (string comment_item, SourceReference source_reference, bool file_comment) {
                if (comment_item[0] == '*') {
+                       if (_comment != null) {
+                               // extra doc comment, add it to source file comments
+                               source_file.add_comment (_comment);
+                       }
                        _comment = new Comment (comment_item, source_reference);
                }