Skip to content

Commit

Permalink
wrap_type: For non-primitive types, wrap original type
Browse files Browse the repository at this point in the history
  • Loading branch information
kazarmy committed Oct 30, 2023
1 parent 3b7982c commit 49452b0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
11 changes: 6 additions & 5 deletions src/cparser_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,29 +100,30 @@ def wrap_type(type_: Type) -> CType:
"""
Wrap a type
"""
orig_type = type_
while type_.kind == TypeKind.ELABORATED:
type_ = type_.get_named_type()

# Complex types
if type_.kind == TypeKind.POINTER:
return CPointerType(type_, pointee=wrap_type(type_.get_pointee()))
return CPointerType(orig_type, pointee=wrap_type(type_.get_pointee()))

if type_.kind in [TypeKind.CONSTANTARRAY, TypeKind.INCOMPLETEARRAY]:
array_t = CArrayType(type_, element=wrap_type(type_.get_array_element_type()))
array_t = CArrayType(orig_type, element=wrap_type(type_.get_array_element_type()))
if type_.kind == TypeKind.CONSTANTARRAY:
array_t.element_count = type_.element_count
return array_t

if type_.kind == TypeKind.TYPEDEF:
return CTypedefType(
type_,
orig_type,
canonical=wrap_type(type_.get_canonical()),
cursor=type_.get_declaration(),
)

if type_.kind == TypeKind.FUNCTIONPROTO:
return CFunctionType(
type_,
orig_type,
result=wrap_type(type_.get_result()),
args=[wrap_type(arg) for arg in type_.argument_types()],
)
Expand All @@ -132,7 +133,7 @@ def wrap_type(type_: Type) -> CType:
if decl_spelling.startswith("const "):
decl_spelling = decl_spelling[len("const ") :]

return CRecordType(type_, decl_spelling=decl_spelling)
return CRecordType(orig_type, decl_spelling=decl_spelling)

# Primitive types
if type_.kind in [
Expand Down
5 changes: 0 additions & 5 deletions src/generator_swig.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,7 @@ def stringify_decl(expr: str, ctype: CType, generic: bool = False) -> str:

if isinstance(ctype, CPointerType):
expr = "*" + expr

# HACK!
pointee_type_ = ctype.type_.get_pointee()
ctype = ctype.pointee
ctype.type_ = pointee_type_

pointing = True
continue

Expand Down

0 comments on commit 49452b0

Please sign in to comment.