]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Added option --vapi-comments to include comments in vapi-files
authorRichard Wiedenhöft <richard@wiedenhoeft.xyz>
Wed, 3 Sep 2014 16:56:28 +0000 (18:56 +0200)
committerFlorian Brosch <flo.brosch@gmail.com>
Wed, 3 Sep 2014 16:56:28 +0000 (18:56 +0200)
compiler/valacompiler.vala
vala/valacodecontext.vala
vala/valacodewriter.vala

index 4a20ea1ba2d0ce9e55eed0cab74fd2b1f398b573..9c50fcb0e54e2beb1bfda9151a0d6c5df51b905a 100644 (file)
@@ -53,6 +53,7 @@ class Vala.Compiler {
        static string internal_header_filename;
        static string internal_vapi_filename;
        static string fast_vapi_filename;
+       static bool vapi_comments;
        static string symbols_filename;
        static string includedir;
        static bool compile_only;
@@ -111,6 +112,7 @@ class Vala.Compiler {
                { "internal-vapi", 0, 0, OptionArg.FILENAME, ref internal_vapi_filename, "Output vapi with internal api", "FILE" },
                { "fast-vapi", 0, 0, OptionArg.STRING, ref fast_vapi_filename, "Output vapi without performing symbol resolution", null },
                { "use-fast-vapi", 0, 0, OptionArg.STRING_ARRAY, ref fast_vapis, "Use --fast-vapi output during this compile", null },
+               { "vapi-comments", 0, 0, OptionArg.NONE, ref vapi_comments, "Include comments in generated vapi", null },
                { "deps", 0, 0, OptionArg.STRING, ref dependencies, "Write make-style dependency information to this file", null },
                { "symbols", 0, 0, OptionArg.FILENAME, ref symbols_filename, "Output symbols file", "FILE" },
                { "compile", 'c', 0, OptionArg.NONE, ref compile_only, "Compile but do not link", null },
@@ -217,6 +219,7 @@ class Vala.Compiler {
                        context.directory = context.basedir;
                }
                context.vapi_directories = vapi_directories;
+               context.vapi_comments = vapi_comments;
                context.gir_directories = gir_directories;
                context.metadata_directories = metadata_directories;
                context.debug = debug;
index 965e8125cded9bdba3c738e50e6e6c90e63ab327..00c242c5076e9c1707e788a1f8d1693761f4ac94 100644 (file)
@@ -173,6 +173,11 @@ public class Vala.CodeContext {
 
        public bool use_fast_vapi { get; set; }
 
+       /**
+        * Include comments in generated vapi.
+        */
+       public bool vapi_comments { get; set; }
+
        /**
         * Returns true if the target version of glib is greater than or 
         * equal to the specified version.
index 0cfa469a9bdbf0469b4e77587708e6c53a8674e2..2fce86f71869cfb7b2d84b5e7d3944b33878cafe 100644 (file)
@@ -2,6 +2,7 @@
  *
  * Copyright (C) 2006-2014  Jürg Billeter
  * Copyright (C) 2006-2008  Raffaele Sandrini
+ * Copyright (C) 2014       Richard Wiedenhöft
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -155,6 +156,24 @@ public class Vala.CodeWriter : CodeVisitor {
                        return;
                }
 
+               var comments = ns.get_comments ();
+               if (context.vapi_comments && comments.size > 0) {
+                       bool first = true;
+                       SourceReference? first_reference = null;
+                       foreach (Comment comment in comments) {
+                               if (comment.source_reference.file.file_type == SourceFileType.SOURCE) {
+                                       if (first) {
+                                               write_comment (comment);
+                                               first = false;
+                                               first_reference = comment.source_reference;
+                                       } else {
+                                               Report.warning (comment.source_reference, "Comment describes namespace, that was already described by another comment.");
+                                               Report.notice (first_reference, "Previous comment was here.");
+                                       }
+                               }
+                       }
+               }
+
                write_attributes (ns);
 
                write_indent ();
@@ -208,6 +227,10 @@ public class Vala.CodeWriter : CodeVisitor {
                        return;
                }
 
+               if (context.vapi_comments && cl.comment != null) {
+                       write_comment (cl.comment);
+               }
+
                write_attributes (cl);
                
                write_indent ();
@@ -301,6 +324,10 @@ public class Vala.CodeWriter : CodeVisitor {
                        return;
                }
 
+               if (context.vapi_comments && st.comment != null) {
+                       write_comment (st.comment);
+               }
+
                write_attributes (st);
 
                write_indent ();
@@ -341,6 +368,10 @@ public class Vala.CodeWriter : CodeVisitor {
                        return;
                }
 
+               if (context.vapi_comments && iface.comment != null) {
+                       write_comment (iface.comment);
+               }
+
                write_attributes (iface);
 
                write_indent ();
@@ -393,6 +424,10 @@ public class Vala.CodeWriter : CodeVisitor {
                        return;
                }
 
+               if (context.vapi_comments && en.comment != null) {
+                       write_comment (en.comment);
+               }
+
                write_attributes (en);
 
                write_indent ();
@@ -410,6 +445,10 @@ public class Vala.CodeWriter : CodeVisitor {
                                write_newline ();
                        }
 
+                       if (context.vapi_comments && ev.comment != null) {
+                               write_comment (ev.comment);
+                       }
+
                        write_attributes (ev);
 
                        write_indent ();
@@ -450,6 +489,10 @@ public class Vala.CodeWriter : CodeVisitor {
                        return;
                }
 
+               if (context.vapi_comments && edomain.comment != null) {
+                       write_comment (edomain.comment);
+               }
+
                write_attributes (edomain);
 
                write_indent ();
@@ -467,6 +510,10 @@ public class Vala.CodeWriter : CodeVisitor {
                                write_newline ();
                        }
 
+                       if (context.vapi_comments && ecode.comment != null) {
+                               write_comment (ecode.comment);
+                       }
+
                        write_attributes (ecode);
 
                        write_indent ();
@@ -499,6 +546,10 @@ public class Vala.CodeWriter : CodeVisitor {
                        return;
                }
 
+               if (context.vapi_comments && c.comment != null) {
+                       write_comment (c.comment);
+               }
+
                write_attributes (c);
 
                write_indent ();
@@ -527,6 +578,10 @@ public class Vala.CodeWriter : CodeVisitor {
                        return;
                }
 
+               if (context.vapi_comments && f.comment != null) {
+                       write_comment (f.comment);
+               }
+
                write_attributes (f);
 
                write_indent ();
@@ -629,6 +684,10 @@ public class Vala.CodeWriter : CodeVisitor {
                        return;
                }
 
+               if (context.vapi_comments && cb.comment != null) {
+                       write_comment (cb.comment);
+               }
+
                write_attributes (cb);
 
                write_indent ();
@@ -659,6 +718,10 @@ public class Vala.CodeWriter : CodeVisitor {
                        return;
                }
 
+               if (context.vapi_comments && c.comment != null) {
+                       write_comment (c.comment);
+               }
+
                write_indent ();
                write_string ("construct");
                write_code_block (c.body);
@@ -677,6 +740,10 @@ public class Vala.CodeWriter : CodeVisitor {
                        }
                }
 
+               if (context.vapi_comments && m.comment != null) {
+                       write_comment (m.comment);
+               }
+
                write_attributes (m);
 
                write_indent ();
@@ -743,6 +810,10 @@ public class Vala.CodeWriter : CodeVisitor {
                        return;
                }
 
+               if (context.vapi_comments && prop.comment != null) {
+                       write_comment (prop.comment);
+               }
+
                write_attributes (prop);
 
                write_indent ();
@@ -801,6 +872,10 @@ public class Vala.CodeWriter : CodeVisitor {
                        return;
                }
                
+               if (context.vapi_comments && sig.comment != null) {
+                       write_comment (sig.comment);
+               }
+
                write_attributes (sig);
                
                write_indent ();
@@ -1430,6 +1505,28 @@ public class Vala.CodeWriter : CodeVisitor {
                
                bol = false;
        }
+
+       private void write_comment (Comment comment) {
+               Regex fix_indent_regex;
+               try {
+                       fix_indent_regex = new Regex ("\\n[\\t ]*");
+               } catch (Error e) {
+                       assert_not_reached ();
+               }
+
+               string replacement = "\n" + string.nfill (indent, '\t') + " ";
+               string fixed_content;
+               try {
+                       fixed_content = fix_indent_regex.replace (comment.content, comment.content.length, 0, replacement);
+               } catch (Error e) {
+                       assert_not_reached();
+               }
+
+               write_indent ();
+               write_string ("/*");
+               write_string (fixed_content);
+               write_string ("*/");
+       }
        
        private void write_identifier (string s) {
                char* id = (char*)s;