@@ -49,28 +49,45 @@ predicate side_effecting_descriptor_type(ClassObject descriptor) {
4949 * side-effecting unless we know otherwise.
5050 */
5151predicate side_effecting_binary ( Expr b ) {
52- exists ( Expr sub , string method_name |
53- sub = b .( BinaryExpr ) .getLeft ( ) and
54- method_name = b .( BinaryExpr ) .getOp ( ) .getSpecialMethodName ( )
52+ exists ( Expr sub , ClassObject cls , string method_name |
53+ binary_operator_special_method ( b , sub , cls , method_name )
5554 or
56- exists ( Cmpop op |
57- b .( Compare ) .compares ( sub , op , _) and
58- method_name = op .getSpecialMethodName ( )
59- )
55+ comparison_special_method ( b , sub , cls , method_name )
6056 |
61- exists ( ClassObject cls |
62- sub .refersTo ( _, cls , _) and
63- cls .hasAttribute ( method_name )
64- and
65- not exists ( ClassObject declaring |
66- declaring .declaresAttribute ( method_name )
67- and declaring = cls .getAnImproperSuperType ( ) and
68- declaring .isBuiltin ( ) and not declaring = theObjectType ( )
69- )
57+ method_name = special_method ( ) and
58+ cls .hasAttribute ( method_name )
59+ and
60+ not exists ( ClassObject declaring |
61+ declaring .declaresAttribute ( method_name )
62+ and declaring = cls .getAnImproperSuperType ( ) and
63+ declaring .isBuiltin ( ) and not declaring = theObjectType ( )
7064 )
7165 )
7266}
7367
68+ pragma [ nomagic]
69+ private predicate binary_operator_special_method ( BinaryExpr b , Expr sub , ClassObject cls , string method_name ) {
70+ method_name = special_method ( ) and
71+ sub = b .getLeft ( ) and
72+ method_name = b .getOp ( ) .getSpecialMethodName ( ) and
73+ sub .refersTo ( _, cls , _)
74+ }
75+
76+ pragma [ nomagic]
77+ private predicate comparison_special_method ( Compare b , Expr sub , ClassObject cls , string method_name ) {
78+ exists ( Cmpop op |
79+ b .compares ( sub , op , _) and
80+ method_name = op .getSpecialMethodName ( )
81+ ) and
82+ sub .refersTo ( _, cls , _)
83+ }
84+
85+ private string special_method ( ) {
86+ result = any ( Cmpop c ) .getSpecialMethodName ( )
87+ or
88+ result = any ( BinaryExpr b ) .getOp ( ) .getSpecialMethodName ( )
89+ }
90+
7491predicate is_notebook ( File f ) {
7592 exists ( Comment c |
7693 c .getLocation ( ) .getFile ( ) = f |
0 commit comments