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

Continuation of #117 desired functionality #118

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion ctypeslib/codegen/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,39 @@ def make_python_name(self, name):
return "_" + name
return name

def _get_parent_typedef_name(self, cursor):
"""Retrieves a typedef name for a given parent node, if one exists."""
field_name = None
parent = cursor.semantic_parent
if parent is None:
return field_name

parent_fields = parent.type.get_fields()
for p in parent_fields:
curr_decl = p.type.get_declaration()
if curr_decl == cursor.type.get_declaration():
if p.spelling:
field_name = p.spelling
log.debug('_get_parent_typedef_name: Got parent typedef name %s',field_name)

return field_name

def _make_unknown_name(self, cursor, field_name):
"""Creates a name for unnamed type """
parent = cursor.lexical_parent
pname = self.get_unique_name(parent)
# since parents are computed using `get_unique_name` recursively,
# we need to also check if a typedef exists for the parent.
parent_typedef_name = self._get_parent_typedef_name(parent)
pname = self.get_unique_name(parent, field_name=parent_typedef_name)

log.debug('_make_unknown_name: Got parent get_unique_name %s',pname)
# we only look at types declarations
_cursor_decl = cursor.type.get_declaration()
# we had the field index from the parent record, as to differenciate
# between unnamed siblings of a same struct
_i = 0
found = False

# Look at the parent fields to find myself
for m in parent.get_children():
# FIXME: make the good indices for fields
Expand Down