summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Wiedenhöft <richard@wiedenhoeft.xyz>2014-09-03 18:56:28 +0200
committerFlorian Brosch <flo.brosch@gmail.com>2014-09-03 18:56:28 +0200
commit343340b65668f3c33d940840e0e7bd28d47aef0b (patch)
treed5efdef08efffa0085c5bc8274392262c5cb91b4
parent7022319cdced4d2a180a8cff93ebb823df46c124 (diff)
downloadvala-343340b65668f3c33d940840e0e7bd28d47aef0b.tar.gz
Added option --vapi-comments to include comments in vapi-files
-rw-r--r--compiler/valacompiler.vala3
-rw-r--r--vala/valacodecontext.vala5
-rw-r--r--vala/valacodewriter.vala97
3 files changed, 105 insertions, 0 deletions
diff --git a/compiler/valacompiler.vala b/compiler/valacompiler.vala
index 4a20ea1ba..9c50fcb0e 100644
--- a/compiler/valacompiler.vala
+++ b/compiler/valacompiler.vala
@@ -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;
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;