mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 05:12:45 +01:00
tools/generate-wire.py: style cleanups.
Suggested-by: @cdecker Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
28c3706f87
commit
ab28972aee
@ -174,9 +174,6 @@ class Field(object):
|
|||||||
def needs_ptr_to_ptr(self):
|
def needs_ptr_to_ptr(self):
|
||||||
return self.is_variable_size() or self.optional
|
return self.is_variable_size() or self.optional
|
||||||
|
|
||||||
def is_optional(self):
|
|
||||||
return self.optional
|
|
||||||
|
|
||||||
def is_assignable(self):
|
def is_assignable(self):
|
||||||
if self.is_array() or self.needs_ptr_to_ptr():
|
if self.is_array() or self.needs_ptr_to_ptr():
|
||||||
return False
|
return False
|
||||||
@ -262,7 +259,7 @@ class Message(object):
|
|||||||
|
|
||||||
def checkLenField(self, field):
|
def checkLenField(self, field):
|
||||||
# Optional fields don't have a len.
|
# Optional fields don't have a len.
|
||||||
if field.is_optional():
|
if field.optional:
|
||||||
return
|
return
|
||||||
for f in self.fields:
|
for f in self.fields:
|
||||||
if f.name == field.lenvar:
|
if f.name == field.lenvar:
|
||||||
@ -285,9 +282,7 @@ class Message(object):
|
|||||||
if field.is_variable_size():
|
if field.is_variable_size():
|
||||||
self.checkLenField(field)
|
self.checkLenField(field)
|
||||||
self.has_variable_fields = True
|
self.has_variable_fields = True
|
||||||
elif field.basetype() in varlen_structs:
|
elif field.basetype() in varlen_structs or field.optional:
|
||||||
self.has_variable_fields = True
|
|
||||||
elif field.is_optional():
|
|
||||||
self.has_variable_fields = True
|
self.has_variable_fields = True
|
||||||
self.fields.append(field)
|
self.fields.append(field)
|
||||||
|
|
||||||
@ -357,7 +352,7 @@ class Message(object):
|
|||||||
self.print_fromwire_array(subcalls, basetype, f, '*' + f.name,
|
self.print_fromwire_array(subcalls, basetype, f, '*' + f.name,
|
||||||
f.lenvar)
|
f.lenvar)
|
||||||
else:
|
else:
|
||||||
if f.is_optional():
|
if f.optional:
|
||||||
subcalls.append("\tif (!fromwire_bool(&cursor, &plen))\n"
|
subcalls.append("\tif (!fromwire_bool(&cursor, &plen))\n"
|
||||||
"\t\t*{} = NULL;\n"
|
"\t\t*{} = NULL;\n"
|
||||||
"\telse {{\n"
|
"\telse {{\n"
|
||||||
@ -445,7 +440,7 @@ class Message(object):
|
|||||||
elif f.is_variable_size():
|
elif f.is_variable_size():
|
||||||
self.print_towire_array(subcalls, basetype, f, f.lenvar)
|
self.print_towire_array(subcalls, basetype, f, f.lenvar)
|
||||||
else:
|
else:
|
||||||
if f.is_optional():
|
if f.optional:
|
||||||
subcalls.append("\tif (!{})\n"
|
subcalls.append("\tif (!{})\n"
|
||||||
"\t\ttowire_bool(&p, false);\n"
|
"\t\ttowire_bool(&p, false);\n"
|
||||||
"\telse {{\n"
|
"\telse {{\n"
|
||||||
@ -527,7 +522,7 @@ class Message(object):
|
|||||||
self.add_truncate_check(subcalls)
|
self.add_truncate_check(subcalls)
|
||||||
else:
|
else:
|
||||||
indent = '\t'
|
indent = '\t'
|
||||||
if f.is_optional():
|
if f.optional:
|
||||||
subcalls.append("\tif (fromwire_bool(&cursor, &plen)) {")
|
subcalls.append("\tif (fromwire_bool(&cursor, &plen)) {")
|
||||||
indent += '\t'
|
indent += '\t'
|
||||||
|
|
||||||
@ -545,7 +540,7 @@ class Message(object):
|
|||||||
self.add_truncate_check(subcalls, indent=indent)
|
self.add_truncate_check(subcalls, indent=indent)
|
||||||
subcalls.append(indent + 'printwire_{}(tal_fmt(NULL, "%s.{}", fieldname), &{});'
|
subcalls.append(indent + 'printwire_{}(tal_fmt(NULL, "%s.{}", fieldname), &{});'
|
||||||
.format(basetype, f.name, f.name))
|
.format(basetype, f.name, f.name))
|
||||||
if f.is_optional():
|
if f.optional:
|
||||||
subcalls.append("\t} else {")
|
subcalls.append("\t} else {")
|
||||||
self.add_truncate_check(subcalls, indent='\t\t')
|
self.add_truncate_check(subcalls, indent='\t\t')
|
||||||
subcalls.append("\t}")
|
subcalls.append("\t}")
|
||||||
|
Loading…
Reference in New Issue
Block a user