Commit f6b39547 authored by Jürg Billeter's avatar Jürg Billeter

Append doc comments to generated C files

parent 861ff92d
......@@ -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 ();
}
}
......@@ -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);
......
......@@ -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;
......
......@@ -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);
......
......@@ -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)));
}
......
......@@ -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;
}
......
......@@ -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;
......
......@@ -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);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment