From c1aa8aa980daea732c4683c2593d130d6bee7a79 Mon Sep 17 00:00:00 2001 From: Petteri Aimonen <jpa@git.mail.kapsi.fi> Date: Sat, 14 Nov 2015 22:23:48 +0200 Subject: Add testcase for anonymous unions + few fixes. Fixes compilation error with anonymous unions when it is not the last field in message. Also fixes extraneous newlines in header file. Cleanup the pb.h extraneous use of ##. --- generator/nanopb_generator.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'generator/nanopb_generator.py') diff --git a/generator/nanopb_generator.py b/generator/nanopb_generator.py index a21257b5..13217462 100755 --- a/generator/nanopb_generator.py +++ b/generator/nanopb_generator.py @@ -492,6 +492,9 @@ class Field: return result + def get_last_field_name(self): + return self.name + def largest_field_value(self): '''Determine if this field needs 16bit or 32bit pb_field_t structure to compile properly. Returns numeric value or a C-expression for assert.''' @@ -704,12 +707,18 @@ class OneOf(Field): return None def tags(self): - return '\n'.join([f.tags() for f in self.fields]) + return ''.join([f.tags() for f in self.fields]) def pb_field_t(self, prev_field_name): result = ',\n'.join([f.pb_field_t(prev_field_name) for f in self.fields]) return result + def get_last_field_name(self): + if self.anonymous: + return self.fields[-1].name + else: + return self.name + '.' + self.fields[-1].name + def largest_field_value(self): largest = FieldMaxSize() for f in self.fields: @@ -860,10 +869,7 @@ class Message: for field in self.ordered_fields: result += field.pb_field_t(prev) result += ',\n' - if isinstance(field, OneOf): - prev = field.name + '.' + field.fields[-1].name - else: - prev = field.name + prev = field.get_last_field_name() result += ' PB_LAST_FIELD\n};' return result -- cgit 1.2.3-korg