Browse Source

bolt-gen: add 'top-line' file comments to output

if there are any comments that aren't "attached" to a message,
print them at the top of the generated file. we need this for
the fancy auto-gen'd dependencies in the tool-wiregen tests.
pull/2938/head
lisa neigut 6 years ago
committed by Rusty Russell
parent
commit
ade594e941
  1. 10
      tools/gen/impl_template
  2. 15
      tools/generate-bolts.py

10
tools/gen/impl_template

@ -6,8 +6,11 @@
#include <ccan/mem/mem.h>
#include <ccan/tal/str/str.h>
#include <stdio.h>
% for comment in top_comments:
/*${comment} */
% endfor
% for enum_set in enum_sets:
const char *${enum_set['name']}_name(int e)
{
static char invalidbuf[sizeof("INVALID ") + STR_MAX_CHARS(e)];
@ -29,7 +32,7 @@ const char *${enum_set['name']}_name(int e)
% for subtype in subtypes:
/* SUBTYPE: ${subtype.name.upper()} */
% for c in subtype.type_comments:
/* ${c} */
/*${c} */
% endfor
<% static = '' if options.expose_subtypes else 'static ' %>
${static}void towire_${subtype.name}(u8 **p, const struct ${subtype.name} *${subtype.name})
@ -38,10 +41,9 @@ ${static}void towire_${subtype.name}(u8 **p, const struct ${subtype.name} *${sub
${f.type_obj.type_name()} ${f.name} = tal_count(${subtype.name}->${f.len_field_of});
% endfor
## FIXME: abstract this out? (semi-shared with towire_msg, minus the optional bits)
% for f in subtype.fields.values():
% for c in f.field_comments:
/* ${c} */
/*${c} */
% endfor
<%
fieldname = '{}->{}'.format(subtype.name,f.name)

15
tools/generate-bolts.py

@ -33,9 +33,7 @@ def next_line(args, lines):
lines = fileinput.input(args)
for i, line in enumerate(lines):
if not bool(line.strip()):
continue
yield i, line.strip()
yield i + 1, line.strip()
# Class definitions, to keep things classy
@ -285,6 +283,10 @@ class Master(object):
messages = {}
extension_msgs = {}
inclusions = []
top_comments = []
def add_comments(self, comments):
self.top_comments += comments
def add_include(self, inclusion):
self.inclusions.append(inclusion)
@ -362,6 +364,7 @@ class Master(object):
'set': tlv.messages.values(),
})
stuff = {}
stuff['top_comments'] = self.top_comments
stuff['options'] = options
stuff['idem'] = re.sub(r'[^A-Z]+', '_', options.header_filename.upper())
stuff['header_filename'] = options.header_filename
@ -388,6 +391,12 @@ def main(options, args=None, output=sys.stdout, lines=None):
ln, line = next(genline)
tokens = line.split(',')
token_type = tokens[0]
if not bool(line):
master.add_comments(comment_set)
comment_set = []
continue
if token_type == 'subtype':
subtype, _ = master.add_type(tokens[1])

Loading…
Cancel
Save