@@ -284,19 +284,46 @@ def remove_reference(type):
284284def is_const (type ):
285285 """returns True, if type represents C++ const type, False otherwise"""
286286 nake_type = remove_alias (type )
287- return isinstance (nake_type , cpptypes .const_t )
287+ if isinstance (nake_type , cpptypes .const_t ):
288+ return True
289+ elif isinstance (nake_type , cpptypes .volatile_t ):
290+ return is_const (nake_type .base )
291+ elif isinstance (nake_type , cpptypes .array_t ):
292+ return is_const (nake_type .base )
293+ return False
288294
289295
290- def remove_const (type ):
296+ def remove_const (type_ ):
291297 """removes const from the type definition
292298
293299 If type is not const type, it will be returned as is
294300 """
295301
296- nake_type = remove_alias (type )
302+ nake_type = remove_alias (type_ )
297303 if not is_const (nake_type ):
298- return type
304+ return type_
299305 else :
306+ # Handling for const and volatile qualified types. There is a
307+ # difference in behavior between GCCXML and CastXML for cv-qual arrays.
308+ # GCCXML produces the following nesting of types:
309+ # -> volatile_t(const_t(array_t))
310+ # while CastXML produces the following nesting:
311+ # -> array_t(volatile_t(const_t))
312+ # For both cases, we must unwrap the types, remove const_t, and add
313+ # back the outer layers
314+ if isinstance (nake_type , cpptypes .array_t ):
315+ is_v = is_volatile (nake_type )
316+ if is_v :
317+ result_type = nake_type .base .base .base
318+ else :
319+ result_type = nake_type .base .base
320+ if is_v :
321+ result_type = cpptypes .volatile_t (result_type )
322+ return cpptypes .array_t (result_type , nake_type .size )
323+
324+ elif isinstance (nake_type , cpptypes .volatile_t ):
325+ return cpptypes .volatile_t (nake_type .base .base )
326+
300327 return nake_type .base
301328
302329
@@ -322,7 +349,13 @@ def is_same(type1, type2):
322349def is_volatile (type ):
323350 """returns True, if type represents C++ volatile type, False otherwise"""
324351 nake_type = remove_alias (type )
325- return isinstance (nake_type , cpptypes .volatile_t )
352+ if isinstance (nake_type , cpptypes .volatile_t ):
353+ return True
354+ elif isinstance (nake_type , cpptypes .const_t ):
355+ return is_volatile (nake_type .base )
356+ elif isinstance (nake_type , cpptypes .array_t ):
357+ return is_volatile (nake_type .base )
358+ return False
326359
327360
328361def remove_volatile (type ):
@@ -334,6 +367,16 @@ def remove_volatile(type):
334367 if not is_volatile (nake_type ):
335368 return type
336369 else :
370+ if isinstance (nake_type , cpptypes .array_t ):
371+ is_c = is_const (nake_type )
372+ if is_c :
373+ base_type = nake_type .base .base .base
374+ else :
375+ base_type = nake_type .base .base
376+ result_type = base_type
377+ if is_c :
378+ result_type = cpptypes .const_t (result_type )
379+ return cpptypes .array_t (result_type , nake_type .size )
337380 return nake_type .base
338381
339382
@@ -344,12 +387,12 @@ def remove_cv(type):
344387 if not is_const (nake_type ) and not is_volatile (nake_type ):
345388 return type
346389 result = nake_type
347- if is_const (nake_type ):
348- result = nake_type . base
390+ if is_const (result ):
391+ result = remove_const ( result )
349392 if is_volatile (result ):
350- result = result . base
393+ result = remove_volatile ( result )
351394 if is_const (result ):
352- result = result . base
395+ result = remove_const ( result )
353396 return result
354397
355398
0 commit comments