File tree Expand file tree Collapse file tree 3 files changed +39
-7
lines changed
tests/examples/find-global-state Expand file tree Collapse file tree 3 files changed +39
-7
lines changed Original file line number Diff line number Diff line change @@ -388,6 +388,10 @@ def add_complex_getter(name, doc):
388
388
add_simple_getter ('%s_equivalent' % qual ,
389
389
'PyGccTree_New(gcc_private_make_tree(build_qualified_type(self->t.inner, TYPE_QUAL_%s)))' % qual .upper (),
390
390
'The gcc.Type for the %s version of this type' % qual )
391
+ if tree_type .SYM == 'RECORD_TYPE' :
392
+ add_simple_getter ('const' ,
393
+ 'PyBool_FromLong(TYPE_READONLY(self->t.inner))' ,
394
+ "Boolean: does this type have the 'const' modifier?" )
391
395
392
396
if tree_type .SYM == 'INTEGER_TYPE' :
393
397
add_simple_getter ('unsigned' ,
Original file line number Diff line number Diff line change @@ -57,3 +57,14 @@ int test6()
57
57
{
58
58
return bar .f ;
59
59
}
60
+
61
+ struct banana {
62
+ int f ;
63
+ };
64
+
65
+ const struct banana a_banana ;
66
+
67
+ int test7 ()
68
+ {
69
+ return a_banana .f ;
70
+ }
Original file line number Diff line number Diff line change 20
20
21
21
DEBUG = 0
22
22
23
+ def is_const (type_ ):
24
+ if DEBUG :
25
+ type_ .debug ()
26
+
27
+ if hasattr (type_ , 'const' ):
28
+ if type_ .const :
29
+ return True
30
+
31
+ # Don't bother warning about an array of const e.g.
32
+ # const char []
33
+ if isinstance (type_ , gcc .ArrayType ):
34
+ item_type = type_ .dereference
35
+ if is_const (item_type ):
36
+ return True
37
+
38
+
23
39
class StateFinder :
24
40
def __init__ (self ):
25
41
# Locate all declarations of variables holding "global" state:
@@ -28,13 +44,14 @@ def __init__(self):
28
44
for var in gcc .get_variables ():
29
45
type_ = var .decl .type
30
46
31
- # Don't bother warning about an array of const e.g.
32
- # const char []
33
- if isinstance (type_ , gcc .ArrayType ):
34
- item_type = type_ .dereference
35
- if hasattr (item_type , 'const' ):
36
- if item_type .const :
37
- continue
47
+ if DEBUG :
48
+ print ('var.decl: %r' % var .decl )
49
+ print (type_ )
50
+
51
+ # Don't bother warning about const data:
52
+ if is_const (type_ ):
53
+ continue
54
+
38
55
self .global_decls .add (var .decl )
39
56
if DEBUG :
40
57
print ('self.global_decls: %r' % self .global_decls )
You can’t perform that action at this time.
0 commit comments