Skip to content

Commit

Permalink
Attempt to support file coments for go, lua, and c#
Browse files Browse the repository at this point in the history
  • Loading branch information
judfs authored and nosracd committed Sep 22, 2024
1 parent 0aab43e commit f58268c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
25 changes: 25 additions & 0 deletions lcmgen/emit_csharp.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,29 @@
fprintf(f, "\n"); \
} while (0)

// ----------------------------------------------------------------------------

static void emit_comment(FILE *f, int indent, const char *comment)
{
if (!comment)
return;

gchar **lines = g_strsplit(comment, "\n", 0);
int num_lines = g_strv_length(lines);

emit(indent, "/**");
for (int line_ind = 0; lines[line_ind]; line_ind++) {
if (strlen(lines[line_ind])) {
emit(indent, " * %s", lines[line_ind]);
} else {
emit(indent, " *");
}
}
emit(indent, " */");

g_strfreev(lines);
}

static char *dots_to_slashes(const char *s)
{
char *p = strdup(s);
Expand Down Expand Up @@ -352,6 +375,8 @@ int emit_csharp(lcmgen_t *lcm)
" * DO NOT MODIFY BY HAND!!!!\n"
" */\n");

emit_comment(f, 0, lr->file_comment);

emit(0, "using System;");
emit(0, "using System.Collections.Generic;");
emit(0, "using System.IO;");
Expand Down
7 changes: 4 additions & 3 deletions lcmgen/emit_go.c
Original file line number Diff line number Diff line change
Expand Up @@ -566,9 +566,10 @@ static void emit_go_array_loops_end(FILE *f, unsigned int n)
/*
* Emits the header of the .go file.
*/
static void emit_go_header(FILE *f, const char *const gopackage)
static void emit_go_header(FILE *f, const char *const gopackage, char *file_comment)
{
emit_auto_generated_warning(f);
emit_comment(f, 0, file_comment);
emit(0, "package %s", gopackage);
emit_nl();
}
Expand Down Expand Up @@ -1338,7 +1339,7 @@ int emit_go_lcm(lcmgen_t *lcm, lcm_struct_t *ls, const char *const dir, int64_t
}

// Header
emit_go_header(f, gopackage);
emit_go_header(f, gopackage, ls->file_comment);

// Imports
emit_go_lcm_imports(f, lcm, ls);
Expand Down Expand Up @@ -1413,7 +1414,7 @@ int emit_go_gopacket(lcmgen_t *lcm, lcm_struct_t *ls, const char *const dir, int
return -1;

// Header
emit_go_header(f, gopackage);
emit_go_header(f, gopackage, ls->file_comment);

// Imports
emit(0, "import (");
Expand Down
9 changes: 8 additions & 1 deletion lcmgen/emit_lua.c
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,14 @@ static int emit_package(lcmgen_t *lcm, _package_contents_t *pc)
"LCM type definitions\n"
"This file automatically generated by lcm " LCM_VERSION_STRING
".\n"
"DO NOT MODIFY BY HAND!!!!\n"
"DO NOT MODIFY BY HAND!!!!\n");

if (ls->file_comment) {
fprintf(f, "\n%s\n", ls->file_comment);
}

fprintf(f,

"--]]\n"
"\n"
"local lcm = require('lcm')\n\n");
Expand Down

0 comments on commit f58268c

Please sign in to comment.