diff options
author | Richard Wiedenhöft <richard@wiedenhoeft.xyz> | 2014-09-03 18:56:28 +0200 |
---|---|---|
committer | Florian Brosch <flo.brosch@gmail.com> | 2014-09-03 18:56:28 +0200 |
commit | 343340b65668f3c33d940840e0e7bd28d47aef0b (patch) | |
tree | d5efdef08efffa0085c5bc8274392262c5cb91b4 /vala | |
parent | 7022319cdced4d2a180a8cff93ebb823df46c124 (diff) | |
download | vala-343340b65668f3c33d940840e0e7bd28d47aef0b.tar.gz |
Added option --vapi-comments to include comments in vapi-files
Diffstat (limited to 'vala')
-rw-r--r-- | vala/valacodecontext.vala | 5 | ||||
-rw-r--r-- | vala/valacodewriter.vala | 97 |
2 files changed, 102 insertions, 0 deletions
diff --git a/vala/valacodecontext.vala b/vala/valacodecontext.vala index 965e8125c..00c242c50 100644 --- a/vala/valacodecontext.vala +++ b/vala/valacodecontext.vala @@ -174,6 +174,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. */ diff --git a/vala/valacodewriter.vala b/vala/valacodewriter.vala index 0cfa469a9..2fce86f71 100644 --- a/vala/valacodewriter.vala +++ b/vala/valacodewriter.vala @@ -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; |