diff options
author | Petteri Aimonen <jpa@git.mail.kapsi.fi> | 2015-11-14 22:23:48 +0200 |
---|---|---|
committer | Petteri Aimonen <jpa@git.mail.kapsi.fi> | 2015-11-14 22:23:48 +0200 |
commit | c1aa8aa980daea732c4683c2593d130d6bee7a79 (patch) | |
tree | df8ea9bb1f8fb765fc8a2ec1428447990c8a0808 /generator | |
parent | 9a8cc59703b227ff418cc55b4dc24f63eda64b62 (diff) |
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 ##.
Diffstat (limited to 'generator')
-rwxr-xr-x | generator/nanopb_generator.py | 16 |
1 files changed, 11 insertions, 5 deletions
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 |