Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for empty struct (#66) #254

Merged
merged 6 commits into from Apr 28, 2018
Merged

Add support for empty struct (#66) #254

merged 6 commits into from Apr 28, 2018

Conversation

ldore
Copy link
Contributor

@ldore ldore commented Apr 26, 2018

Support empty struct in parser and c generator.

Though not allowed by C99, empty structs can be found in android headers.
(Look for __bionic_zero_size_is_okay_t in android code).

Note:
Issue #66 was closed because the original poster found a workaround.
As @eliben welcomed pull requests in comments, #66 could be reopened/reclosed as fixed.

# Empty structs are not pure-C99, but accepted.
p[0] = klass(
name=p[2],
decls=[],
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth mentioning in a comment that a distinction is now made between None and [] for the decls?

@eliben
Copy link
Owner

eliben commented Apr 26, 2018

Thanks! Please fix the failures to proceed

@ldore
Copy link
Contributor Author

ldore commented Apr 27, 2018

Fixed, and slightly simplified the grammar.
Also added comments.

decls=p[3],
coord=self._token_coord(p, 2))
if len(p) == 4:
# None means no members
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the code has changed, there's no None assignment now - is this comment still relevant?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still relevant, but not in this function.
Comment moved to p_struct_or_union_specifier_1 (which handles the None case)

body_function = self._generate_enum_body
s = name + ' ' + (n.name or '')
if members is not None:
# None means no members
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this comment refer to now, in the current revision of the code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing as before.

  • None still means that no curly-braces-enclosed members are present (handled by p_struct_or_union_specifier_1 in the parser.
  • Non-empty sequence means curly braces with members.
  • Empty sequence means curly braces with no members.

Line 303 (translating None to an empty tuple) caused enums to always be suffixed with (possibly empty) curly braces.

@eliben eliben merged commit 81a12ca into eliben:master Apr 28, 2018
@eliben
Copy link
Owner

eliben commented Apr 28, 2018

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants