1+ /** Contains the internal IPA type backing the various values tracked by the points-to implementation. */
2+
13import python
24private import semmle.python.types.Builtins
35private import semmle.python.objects.ObjectInternal
@@ -10,19 +12,19 @@ private import semmle.python.pointsto.PointsToContext
1012 */
1113cached
1214newtype TObject =
13- /* Builtin class objects */
15+ /** Builtin class objects */
1416 TBuiltinClassObject ( Builtin bltn ) {
1517 bltn .isClass ( ) and
1618 not bltn = Builtin:: unknownType ( ) and
1719 not bltn = Builtin:: special ( "type" )
1820 } or
19- /* Builtin function objects (module members) */
21+ /** Builtin function objects (module members) */
2022 TBuiltinFunctionObject ( Builtin bltn ) { bltn .isFunction ( ) } or
21- /* Builtin method objects (class members) */
23+ /** Builtin method objects (class members) */
2224 TBuiltinMethodObject ( Builtin bltn ) { bltn .isMethod ( ) } or
23- /* Builtin module objects */
25+ /** Builtin module objects */
2426 TBuiltinModuleObject ( Builtin bltn ) { bltn .isModule ( ) } or
25- /* Other builtin objects from the interpreter */
27+ /** Other builtin objects from the interpreter */
2628 TBuiltinOpaqueObject ( Builtin bltn ) {
2729 not bltn .isClass ( ) and
2830 not bltn .isFunction ( ) and
@@ -34,31 +36,31 @@ newtype TObject =
3436 not exists ( bltn .strValue ( ) ) and
3537 not py_special_objects ( bltn , _)
3638 } or
37- /* Python function objects (including lambdas) */
39+ /** Python function objects (including lambdas) */
3840 TPythonFunctionObject ( ControlFlowNode callable ) { callable .getNode ( ) instanceof CallableExpr } or
39- /* Python class objects */
41+ /** Python class objects */
4042 TPythonClassObject ( ControlFlowNode classexpr ) { classexpr .getNode ( ) instanceof ClassExpr } or
41- /* Package objects */
43+ /** Package objects */
4244 TPackageObject ( Folder f ) { isPreferredModuleForName ( f , _) } or
43- /* Python module objects */
45+ /** Python module objects */
4446 TPythonModule ( Module m ) {
4547 not m .isPackage ( ) and
4648 isPreferredModuleForName ( m .getFile ( ) , _) and
4749 not exists ( SyntaxError se | se .getFile ( ) = m .getFile ( ) )
4850 } or
49- /* `True` */
51+ /** `True` */
5052 TTrue ( ) or
51- /* `False` */
53+ /** `False` */
5254 TFalse ( ) or
53- /* `None` */
55+ /** `None` */
5456 TNone ( ) or
55- /* Represents any value about which nothing useful is known */
57+ /** Represents any value about which nothing useful is known */
5658 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 */
5860 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 */
6062 TUndefined ( ) or
61- /* The integer `n` */
63+ /** The integer `n` */
6264 TInt ( int n ) {
6365 // Powers of 2 are used for flags
6466 is_power_2 ( n )
@@ -76,9 +78,9 @@ newtype TObject =
7678 or
7779 n = any ( Builtin b ) .intValue ( )
7880 } or
79- /* The float `f` */
81+ /** The float `f` */
8082 TFloat ( float f ) { f = any ( FloatLiteral num ) .getValue ( ) } or
81- /* The unicode string `s` */
83+ /** The unicode string `s` */
8284 TUnicode ( string s ) {
8385 // Any string explicitly mentioned in the source code.
8486 exists ( StrConst str |
@@ -94,7 +96,7 @@ newtype TObject =
9496 or
9597 s = "__main__"
9698 } or
97- /* The byte string `s` */
99+ /** The byte string `s` */
98100 TBytes ( string s ) {
99101 // Any string explicitly mentioned in the source code.
100102 exists ( StrConst str |
@@ -110,74 +112,74 @@ newtype TObject =
110112 or
111113 s = "__main__"
112114 } or
113- /* An instance of `cls`, instantiated at `instantiation` given the `context`. */
115+ /** An instance of `cls`, instantiated at `instantiation` given the `context`. */
114116 TSpecificInstance ( ControlFlowNode instantiation , ClassObjectInternal cls , PointsToContext context ) {
115117 PointsToInternal:: pointsTo ( instantiation .( CallNode ) .getFunction ( ) , context , cls , _) and
116118 cls .isSpecial ( ) = false
117119 or
118120 literal_instantiation ( instantiation , cls , context )
119121 } 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`. */
121123 TSelfInstance ( ParameterDefinition def , PointsToContext context , PythonClassObjectInternal cls ) {
122124 self_parameter ( def , context , cls )
123125 } or
124- /* A bound method */
126+ /** A bound method */
125127 TBoundMethod ( ObjectInternal self , CallableObjectInternal function ) {
126128 any ( ObjectInternal obj ) .binds ( self , _, function ) and
127129 function .isDescriptor ( ) = true
128130 } or
129- /* Represents any value whose class is known, but nothing else */
131+ /** Represents any value whose class is known, but nothing else */
130132 TUnknownInstance ( BuiltinClassObjectInternal cls ) {
131133 cls != ObjectInternal:: superType ( ) and
132134 cls != ObjectInternal:: builtin ( "bool" ) and
133135 cls != ObjectInternal:: noneType ( )
134136 } or
135- /* Represents an instance of `super` */
137+ /** Represents an instance of `super` */
136138 TSuperInstance ( ObjectInternal self , ClassObjectInternal startclass ) {
137139 super_instantiation ( _, self , startclass , _)
138140 } or
139- /* Represents an instance of `classmethod` */
141+ /** Represents an instance of `classmethod` */
140142 TClassMethod ( CallNode instantiation , CallableObjectInternal function ) {
141143 class_method ( instantiation , function , _)
142144 } or
143- /* Represents an instance of `staticmethod` */
145+ /** Represents an instance of `staticmethod` */
144146 TStaticMethod ( CallNode instantiation , CallableObjectInternal function ) {
145147 static_method ( instantiation , function , _)
146148 } or
147- /* Represents a builtin tuple */
149+ /** Represents a builtin tuple */
148150 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 */
150152 TPythonTuple ( TupleNode origin , PointsToContext context ) {
151153 origin .isLoad ( ) and
152154 context .appliesTo ( origin )
153155 } or
154- /* Varargs tuple */
156+ /** Varargs tuple */
155157 TVarargsTuple ( CallNode call , PointsToContext context , int offset , int length ) {
156158 InterProceduralPointsTo:: varargs_tuple ( call , context , _, _, offset , length )
157159 } or
158- /* `type` */
160+ /** `type` */
159161 TType ( ) or
160- /* Represents an instance of `property` */
162+ /** Represents an instance of `property` */
161163 TProperty ( CallNode call , Context ctx , CallableObjectInternal getter ) {
162164 PointsToInternal:: pointsTo ( call .getFunction ( ) , ctx , ObjectInternal:: property ( ) , _) and
163165 PointsToInternal:: pointsTo ( call .getArg ( 0 ) , ctx , getter , _)
164166 } or
165- /* Represents the `setter` or `deleter` method of a property object. */
167+ /** Represents the `setter` or `deleter` method of a property object. */
166168 TPropertySetterOrDeleter ( PropertyInternal property , string method ) {
167169 exists ( AttrNode attr | PointsToInternal:: pointsTo ( attr .getObject ( method ) , _, property , _) ) and
168170 ( method = "setter" or method = "deleter" )
169171 } or
170- /* Represents a dynamically created class */
172+ /** Represents a dynamically created class */
171173 TDynamicClass ( CallNode instantiation , ClassObjectInternal metacls , PointsToContext context ) {
172174 PointsToInternal:: pointsTo ( instantiation .getFunction ( ) , context , metacls , _) and
173175 not count ( instantiation .getAnArg ( ) ) = 1 and
174176 Types:: getMro ( metacls ) .contains ( TType ( ) )
175177 } 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. */
177179 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. */
179181 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. */
181183 TAbsentModuleAttribute ( AbsentModuleObjectInternal mod , string attrname ) {
182184 (
183185 PointsToInternal:: pointsTo ( any ( AttrNode attr ) .getObject ( attrname ) , _, mod , _)
@@ -189,16 +191,17 @@ newtype TObject =
189191 not common_module_name ( modname + "." + attrname )
190192 )
191193 } 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 */
193195 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 */
195197 TSubscriptedType ( ObjectInternal generic , ObjectInternal index ) {
196198 isType ( generic ) and
197199 generic .isNotSubscriptedType ( ) and
198200 index .isNotSubscriptedType ( ) and
199201 Expressions:: subscriptPartsPointsTo ( _, _, generic , index )
200202 }
201203
204+ /** Holds if the object `t` is a type. */
202205predicate isType ( ObjectInternal t ) {
203206 t .isClass ( ) = true
204207 or
@@ -421,7 +424,7 @@ predicate missing_imported_module(ControlFlowNode imp, Context ctx, string name)
421424 )
422425}
423426
424- /*
427+ /**
425428 * Helper for missing modules to determine if name `x.y` is a module `x.y` or
426429 * an attribute `y` of module `x`. This list should be added to as required.
427430 */
0 commit comments