mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
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.
This commit is contained in:
committed by
Rusty Russell
parent
fe3f4f52a0
commit
ade594e941
@@ -6,8 +6,11 @@
|
|||||||
#include <ccan/mem/mem.h>
|
#include <ccan/mem/mem.h>
|
||||||
#include <ccan/tal/str/str.h>
|
#include <ccan/tal/str/str.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
% for comment in top_comments:
|
||||||
|
/*${comment} */
|
||||||
|
% endfor
|
||||||
% for enum_set in enum_sets:
|
% for enum_set in enum_sets:
|
||||||
|
|
||||||
const char *${enum_set['name']}_name(int e)
|
const char *${enum_set['name']}_name(int e)
|
||||||
{
|
{
|
||||||
static char invalidbuf[sizeof("INVALID ") + STR_MAX_CHARS(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:
|
% for subtype in subtypes:
|
||||||
/* SUBTYPE: ${subtype.name.upper()} */
|
/* SUBTYPE: ${subtype.name.upper()} */
|
||||||
% for c in subtype.type_comments:
|
% for c in subtype.type_comments:
|
||||||
/* ${c} */
|
/*${c} */
|
||||||
% endfor
|
% endfor
|
||||||
<% static = '' if options.expose_subtypes else 'static ' %>
|
<% static = '' if options.expose_subtypes else 'static ' %>
|
||||||
${static}void towire_${subtype.name}(u8 **p, const struct ${subtype.name} *${subtype.name})
|
${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});
|
${f.type_obj.type_name()} ${f.name} = tal_count(${subtype.name}->${f.len_field_of});
|
||||||
% endfor
|
% endfor
|
||||||
|
|
||||||
## FIXME: abstract this out? (semi-shared with towire_msg, minus the optional bits)
|
|
||||||
% for f in subtype.fields.values():
|
% for f in subtype.fields.values():
|
||||||
% for c in f.field_comments:
|
% for c in f.field_comments:
|
||||||
/* ${c} */
|
/*${c} */
|
||||||
% endfor
|
% endfor
|
||||||
<%
|
<%
|
||||||
fieldname = '{}->{}'.format(subtype.name,f.name)
|
fieldname = '{}->{}'.format(subtype.name,f.name)
|
||||||
|
|||||||
@@ -33,9 +33,7 @@ def next_line(args, lines):
|
|||||||
lines = fileinput.input(args)
|
lines = fileinput.input(args)
|
||||||
|
|
||||||
for i, line in enumerate(lines):
|
for i, line in enumerate(lines):
|
||||||
if not bool(line.strip()):
|
yield i + 1, line.strip()
|
||||||
continue
|
|
||||||
yield i, line.strip()
|
|
||||||
|
|
||||||
|
|
||||||
# Class definitions, to keep things classy
|
# Class definitions, to keep things classy
|
||||||
@@ -285,6 +283,10 @@ class Master(object):
|
|||||||
messages = {}
|
messages = {}
|
||||||
extension_msgs = {}
|
extension_msgs = {}
|
||||||
inclusions = []
|
inclusions = []
|
||||||
|
top_comments = []
|
||||||
|
|
||||||
|
def add_comments(self, comments):
|
||||||
|
self.top_comments += comments
|
||||||
|
|
||||||
def add_include(self, inclusion):
|
def add_include(self, inclusion):
|
||||||
self.inclusions.append(inclusion)
|
self.inclusions.append(inclusion)
|
||||||
@@ -362,6 +364,7 @@ class Master(object):
|
|||||||
'set': tlv.messages.values(),
|
'set': tlv.messages.values(),
|
||||||
})
|
})
|
||||||
stuff = {}
|
stuff = {}
|
||||||
|
stuff['top_comments'] = self.top_comments
|
||||||
stuff['options'] = options
|
stuff['options'] = options
|
||||||
stuff['idem'] = re.sub(r'[^A-Z]+', '_', options.header_filename.upper())
|
stuff['idem'] = re.sub(r'[^A-Z]+', '_', options.header_filename.upper())
|
||||||
stuff['header_filename'] = options.header_filename
|
stuff['header_filename'] = options.header_filename
|
||||||
@@ -388,6 +391,12 @@ def main(options, args=None, output=sys.stdout, lines=None):
|
|||||||
ln, line = next(genline)
|
ln, line = next(genline)
|
||||||
tokens = line.split(',')
|
tokens = line.split(',')
|
||||||
token_type = tokens[0]
|
token_type = tokens[0]
|
||||||
|
|
||||||
|
if not bool(line):
|
||||||
|
master.add_comments(comment_set)
|
||||||
|
comment_set = []
|
||||||
|
continue
|
||||||
|
|
||||||
if token_type == 'subtype':
|
if token_type == 'subtype':
|
||||||
subtype, _ = master.add_type(tokens[1])
|
subtype, _ = master.add_type(tokens[1])
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user