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 fc43b77 commit 2dda233
Showing 1 changed file with 6 additions and 5 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

0 comments on commit 2dda233

Please sign in to comment.