From 2dda233c6425e9b44cb5de3f35d82fb4229febb7 Mon Sep 17 00:00:00 2001 From: Khairul Azhar Kasmiran Date: Mon, 30 Oct 2023 19:35:55 +0800 Subject: [PATCH] wrap_type: For non-primitive types, wrap original type --- src/cparser_types.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/cparser_types.py b/src/cparser_types.py index 4f484e1..1a60151 100644 --- a/src/cparser_types.py +++ b/src/cparser_types.py @@ -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()], ) @@ -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 [