File tree 3 files changed +17
-8
lines changed
docs/examples/function-pointer
3 files changed +17
-8
lines changed Original file line number Diff line number Diff line change 29
29
decls = parser .parse ([filename ], xml_generator_config )
30
30
global_namespace = declarations .get_global_namespace (decls )
31
31
32
- function = global_namespace .variables ()[0 ]
32
+ function_ptr = global_namespace .variables ()[0 ]
33
33
34
34
# Print the name of the function pointer
35
- print (function .name )
35
+ print (function_ptr .name )
36
36
# > myFuncPointer
37
37
38
- # Print the type of the declaration (it's just a pointer)
39
- print (type (function .decl_type ))
38
+ # Print the type of the declaration
39
+ print (function_ptr .decl_type )
40
+ # > void (*)( int,double )
41
+
42
+ # Print the real type of the declaration (it's just a pointer)
43
+ print (type (function_ptr .decl_type ))
40
44
# > <class 'pygccxml.declarations.cpptypes.pointer_t'>
41
45
42
46
# Check if this is a function pointer
43
- print (declarations .is_calldef_pointer (function .decl_type ))
47
+ print (declarations .is_calldef_pointer (function_ptr .decl_type ))
44
48
# > True
45
49
46
50
# Remove the pointer part, to access the function's type
47
- f_type = declarations .remove_pointer (function .decl_type )
51
+ f_type = declarations .remove_pointer (function_ptr .decl_type )
48
52
49
53
# Print the type
50
54
print (type (f_type ))
Original file line number Diff line number Diff line change @@ -574,7 +574,12 @@ def __init__(self, base):
574
574
compound_t .__init__ (self , base )
575
575
576
576
def build_decl_string (self , with_defaults = True ):
577
- return self .base .build_decl_string (with_defaults ) + ' *'
577
+ decl_string = self .base .build_decl_string (with_defaults )
578
+ if isinstance (self .base , calldef_type_t ):
579
+ # This is a function pointer. Do not add supplementary *
580
+ return decl_string
581
+ else :
582
+ return decl_string + " *"
578
583
579
584
def _clone_impl (self ):
580
585
return pointer_t (self .base .clone ())
Original file line number Diff line number Diff line change @@ -33,7 +33,7 @@ def test_function_pointer(self):
33
33
self .assertTrue (
34
34
isinstance (variables [0 ].decl_type , declarations .pointer_t ))
35
35
self .assertTrue (
36
- str (variables [0 ].decl_type ) == "void (*)( int,double ) * " )
36
+ str (variables [0 ].decl_type ) == "void (*)( int,double )" )
37
37
self .assertTrue (
38
38
declarations .is_calldef_pointer (variables [0 ].decl_type ))
39
39
self .assertTrue (
You can’t perform that action at this time.
0 commit comments