1
+ /** Contains the internal IPA type backing the various values tracked by the points-to implementation. */
2
+
1
3
import python
2
4
private import semmle.python.types.Builtins
3
5
private import semmle.python.objects.ObjectInternal
@@ -10,19 +12,19 @@ private import semmle.python.pointsto.PointsToContext
10
12
*/
11
13
cached
12
14
newtype TObject =
13
- /* Builtin class objects */
15
+ /** Builtin class objects */
14
16
TBuiltinClassObject ( Builtin bltn ) {
15
17
bltn .isClass ( ) and
16
18
not bltn = Builtin:: unknownType ( ) and
17
19
not bltn = Builtin:: special ( "type" )
18
20
} or
19
- /* Builtin function objects (module members) */
21
+ /** Builtin function objects (module members) */
20
22
TBuiltinFunctionObject ( Builtin bltn ) { bltn .isFunction ( ) } or
21
- /* Builtin method objects (class members) */
23
+ /** Builtin method objects (class members) */
22
24
TBuiltinMethodObject ( Builtin bltn ) { bltn .isMethod ( ) } or
23
- /* Builtin module objects */
25
+ /** Builtin module objects */
24
26
TBuiltinModuleObject ( Builtin bltn ) { bltn .isModule ( ) } or
25
- /* Other builtin objects from the interpreter */
27
+ /** Other builtin objects from the interpreter */
26
28
TBuiltinOpaqueObject ( Builtin bltn ) {
27
29
not bltn .isClass ( ) and
28
30
not bltn .isFunction ( ) and
@@ -34,31 +36,31 @@ newtype TObject =
34
36
not exists ( bltn .strValue ( ) ) and
35
37
not py_special_objects ( bltn , _)
36
38
} or
37
- /* Python function objects (including lambdas) */
39
+ /** Python function objects (including lambdas) */
38
40
TPythonFunctionObject ( ControlFlowNode callable ) { callable .getNode ( ) instanceof CallableExpr } or
39
- /* Python class objects */
41
+ /** Python class objects */
40
42
TPythonClassObject ( ControlFlowNode classexpr ) { classexpr .getNode ( ) instanceof ClassExpr } or
41
- /* Package objects */
43
+ /** Package objects */
42
44
TPackageObject ( Folder f ) { isPreferredModuleForName ( f , _) } or
43
- /* Python module objects */
45
+ /** Python module objects */
44
46
TPythonModule ( Module m ) {
45
47
not m .isPackage ( ) and
46
48
isPreferredModuleForName ( m .getFile ( ) , _) and
47
49
not exists ( SyntaxError se | se .getFile ( ) = m .getFile ( ) )
48
50
} or
49
- /* `True` */
51
+ /** `True` */
50
52
TTrue ( ) or
51
- /* `False` */
53
+ /** `False` */
52
54
TFalse ( ) or
53
- /* `None` */
55
+ /** `None` */
54
56
TNone ( ) or
55
- /* Represents any value about which nothing useful is known */
57
+ /** Represents any value about which nothing useful is known */
56
58
TUnknown ( ) or
57
- /* Represents any value known to be a class, but not known to be any specific class */
59
+ /** Represents any value known to be a class, but not known to be any specific class */
58
60
TUnknownClass ( ) or
59
- /* Represents the absence of a value. Used by points-to for tracking undefined variables */
61
+ /** Represents the absence of a value. Used by points-to for tracking undefined variables */
60
62
TUndefined ( ) or
61
- /* The integer `n` */
63
+ /** The integer `n` */
62
64
TInt ( int n ) {
63
65
// Powers of 2 are used for flags
64
66
is_power_2 ( n )
@@ -76,9 +78,9 @@ newtype TObject =
76
78
or
77
79
n = any ( Builtin b ) .intValue ( )
78
80
} or
79
- /* The float `f` */
81
+ /** The float `f` */
80
82
TFloat ( float f ) { f = any ( FloatLiteral num ) .getValue ( ) } or
81
- /* The unicode string `s` */
83
+ /** The unicode string `s` */
82
84
TUnicode ( string s ) {
83
85
// Any string explicitly mentioned in the source code.
84
86
exists ( StrConst str |
@@ -94,7 +96,7 @@ newtype TObject =
94
96
or
95
97
s = "__main__"
96
98
} or
97
- /* The byte string `s` */
99
+ /** The byte string `s` */
98
100
TBytes ( string s ) {
99
101
// Any string explicitly mentioned in the source code.
100
102
exists ( StrConst str |
@@ -110,74 +112,74 @@ newtype TObject =
110
112
or
111
113
s = "__main__"
112
114
} or
113
- /* An instance of `cls`, instantiated at `instantiation` given the `context`. */
115
+ /** An instance of `cls`, instantiated at `instantiation` given the `context`. */
114
116
TSpecificInstance ( ControlFlowNode instantiation , ClassObjectInternal cls , PointsToContext context ) {
115
117
PointsToInternal:: pointsTo ( instantiation .( CallNode ) .getFunction ( ) , context , cls , _) and
116
118
cls .isSpecial ( ) = false
117
119
or
118
120
literal_instantiation ( instantiation , cls , context )
119
121
} or
120
- /* A non-specific instance `cls` which enters the scope at `def` given the callee `context`. */
122
+ /** A non-specific instance `cls` which enters the scope at `def` given the callee `context`. */
121
123
TSelfInstance ( ParameterDefinition def , PointsToContext context , PythonClassObjectInternal cls ) {
122
124
self_parameter ( def , context , cls )
123
125
} or
124
- /* A bound method */
126
+ /** A bound method */
125
127
TBoundMethod ( ObjectInternal self , CallableObjectInternal function ) {
126
128
any ( ObjectInternal obj ) .binds ( self , _, function ) and
127
129
function .isDescriptor ( ) = true
128
130
} or
129
- /* Represents any value whose class is known, but nothing else */
131
+ /** Represents any value whose class is known, but nothing else */
130
132
TUnknownInstance ( BuiltinClassObjectInternal cls ) {
131
133
cls != ObjectInternal:: superType ( ) and
132
134
cls != ObjectInternal:: builtin ( "bool" ) and
133
135
cls != ObjectInternal:: noneType ( )
134
136
} or
135
- /* Represents an instance of `super` */
137
+ /** Represents an instance of `super` */
136
138
TSuperInstance ( ObjectInternal self , ClassObjectInternal startclass ) {
137
139
super_instantiation ( _, self , startclass , _)
138
140
} or
139
- /* Represents an instance of `classmethod` */
141
+ /** Represents an instance of `classmethod` */
140
142
TClassMethod ( CallNode instantiation , CallableObjectInternal function ) {
141
143
class_method ( instantiation , function , _)
142
144
} or
143
- /* Represents an instance of `staticmethod` */
145
+ /** Represents an instance of `staticmethod` */
144
146
TStaticMethod ( CallNode instantiation , CallableObjectInternal function ) {
145
147
static_method ( instantiation , function , _)
146
148
} or
147
- /* Represents a builtin tuple */
149
+ /** Represents a builtin tuple */
148
150
TBuiltinTuple ( Builtin bltn ) { bltn .getClass ( ) = Builtin:: special ( "tuple" ) } or
149
- /* Represents a tuple in the Python source */
151
+ /** Represents a tuple in the Python source */
150
152
TPythonTuple ( TupleNode origin , PointsToContext context ) {
151
153
origin .isLoad ( ) and
152
154
context .appliesTo ( origin )
153
155
} or
154
- /* Varargs tuple */
156
+ /** Varargs tuple */
155
157
TVarargsTuple ( CallNode call , PointsToContext context , int offset , int length ) {
156
158
InterProceduralPointsTo:: varargs_tuple ( call , context , _, _, offset , length )
157
159
} or
158
- /* `type` */
160
+ /** `type` */
159
161
TType ( ) or
160
- /* Represents an instance of `property` */
162
+ /** Represents an instance of `property` */
161
163
TProperty ( CallNode call , Context ctx , CallableObjectInternal getter ) {
162
164
PointsToInternal:: pointsTo ( call .getFunction ( ) , ctx , ObjectInternal:: property ( ) , _) and
163
165
PointsToInternal:: pointsTo ( call .getArg ( 0 ) , ctx , getter , _)
164
166
} or
165
- /* Represents the `setter` or `deleter` method of a property object. */
167
+ /** Represents the `setter` or `deleter` method of a property object. */
166
168
TPropertySetterOrDeleter ( PropertyInternal property , string method ) {
167
169
exists ( AttrNode attr | PointsToInternal:: pointsTo ( attr .getObject ( method ) , _, property , _) ) and
168
170
( method = "setter" or method = "deleter" )
169
171
} or
170
- /* Represents a dynamically created class */
172
+ /** Represents a dynamically created class */
171
173
TDynamicClass ( CallNode instantiation , ClassObjectInternal metacls , PointsToContext context ) {
172
174
PointsToInternal:: pointsTo ( instantiation .getFunction ( ) , context , metacls , _) and
173
175
not count ( instantiation .getAnArg ( ) ) = 1 and
174
176
Types:: getMro ( metacls ) .contains ( TType ( ) )
175
177
} or
176
- /* Represents `sys.version_info`. Acts like a tuple with a range of values depending on the version being analysed. */
178
+ /** Represents `sys.version_info`. Acts like a tuple with a range of values depending on the version being analysed. */
177
179
TSysVersionInfo ( ) or
178
- /* Represents a module that is inferred to perhaps exist, but is not present in the database. */
180
+ /** Represents a module that is inferred to perhaps exist, but is not present in the database. */
179
181
TAbsentModule ( string name ) { missing_imported_module ( _, _, name ) } or
180
- /* Represents an attribute of a module that is inferred to perhaps exist, but is not present in the database. */
182
+ /** Represents an attribute of a module that is inferred to perhaps exist, but is not present in the database. */
181
183
TAbsentModuleAttribute ( AbsentModuleObjectInternal mod , string attrname ) {
182
184
(
183
185
PointsToInternal:: pointsTo ( any ( AttrNode attr ) .getObject ( attrname ) , _, mod , _)
@@ -189,16 +191,17 @@ newtype TObject =
189
191
not common_module_name ( modname + "." + attrname )
190
192
)
191
193
} or
192
- /* Opaque object representing the result of calling a decorator on a function that we don't understand */
194
+ /** Opaque object representing the result of calling a decorator on a function that we don't understand */
193
195
TDecoratedFunction ( CallNode call ) { call .isFunctionDecoratorCall ( ) } or
194
- /* Represents a subscript operation applied to a type. For type-hint analysis */
196
+ /** Represents a subscript operation applied to a type. For type-hint analysis */
195
197
TSubscriptedType ( ObjectInternal generic , ObjectInternal index ) {
196
198
isType ( generic ) and
197
199
generic .isNotSubscriptedType ( ) and
198
200
index .isNotSubscriptedType ( ) and
199
201
Expressions:: subscriptPartsPointsTo ( _, _, generic , index )
200
202
}
201
203
204
+ /** Holds if the object `t` is a type. */
202
205
predicate isType ( ObjectInternal t ) {
203
206
t .isClass ( ) = true
204
207
or
@@ -421,7 +424,7 @@ predicate missing_imported_module(ControlFlowNode imp, Context ctx, string name)
421
424
)
422
425
}
423
426
424
- /*
427
+ /**
425
428
* Helper for missing modules to determine if name `x.y` is a module `x.y` or
426
429
* an attribute `y` of module `x`. This list should be added to as required.
427
430
*/
0 commit comments