11import python
22private import semmle.python.pointsto.PointsTo
3+ private import semmle.python.objects.ObjectInternal
34
45/** An expression */
56class Expr extends Expr_ , AstNode {
@@ -71,7 +72,8 @@ class Expr extends Expr_, AstNode {
7172 result = this .getASubExpression ( )
7273 }
7374
74- /** Gets what this expression might "refer-to". Performs a combination of localized (intra-procedural) points-to
75+ /** NOTE: `refersTo` will be deprecated in 2019. Use `pointsTo` instead.
76+ * Gets what this expression might "refer-to". Performs a combination of localized (intra-procedural) points-to
7577 * analysis and global module-level analysis. This points-to analysis favours precision over recall. It is highly
7678 * precise, but may not provide information for a significant number of flow-nodes.
7779 * If the class is unimportant then use `refersTo(value)` or `refersTo(value, origin)` instead.
@@ -82,13 +84,15 @@ class Expr extends Expr_, AstNode {
8284 this .refersTo ( _, obj , cls , origin )
8385 }
8486
85- /** Gets what this expression might "refer-to" in the given `context`.
87+ /** NOTE: `refersTo` will be deprecated in 2019. Use `pointsTo` instead.
88+ * Gets what this expression might "refer-to" in the given `context`.
8689 */
8790 predicate refersTo ( Context context , Object obj , ClassObject cls , AstNode origin ) {
8891 this .getAFlowNode ( ) .refersTo ( context , obj , cls , origin .getAFlowNode ( ) )
8992 }
9093
91- /** Whether this expression might "refer-to" to `value` which is from `origin`
94+ /** NOTE: `refersTo` will be deprecated in 2019. Use `pointsTo` instead.
95+ * Holds if this expression might "refer-to" to `value` which is from `origin`
9296 * Unlike `this.refersTo(value, _, origin)`, this predicate includes results
9397 * where the class cannot be inferred.
9498 */
@@ -97,11 +101,31 @@ class Expr extends Expr_, AstNode {
97101 this .getAFlowNode ( ) .refersTo ( obj , origin .getAFlowNode ( ) )
98102 }
99103
100- /** Equivalent to `this.refersTo(value, _)` */
104+ /** NOTE: `refersTo` will be deprecated in 2019. Use `pointsTo` instead.
105+ * Equivalent to `this.refersTo(value, _)` */
101106 predicate refersTo ( Object obj ) {
102107 this .refersTo ( obj , _)
103108 }
104109
110+ /** Holds if this expression might "point-to" to `value` which is from `origin`
111+ * in the given `context`.
112+ */
113+ predicate pointsTo ( Context context , Value value , AstNode origin ) {
114+ this .getAFlowNode ( ) .pointsTo ( context , value , origin .getAFlowNode ( ) )
115+ }
116+
117+ /** Holds if this expression might "point-to" to `value` which is from `origin`.
118+ */
119+ predicate pointsTo ( Value value , AstNode origin ) {
120+ this .getAFlowNode ( ) .pointsTo ( value , origin .getAFlowNode ( ) )
121+ }
122+
123+ /** Holds if this expression might "point-to" to `value`.
124+ */
125+ predicate pointsTo ( Value value ) {
126+ this .pointsTo ( value , _)
127+ }
128+
105129}
106130
107131/** An attribute expression, such as `value.attr` */
@@ -346,6 +370,11 @@ abstract class ImmutableLiteral extends Expr {
346370 abstract Object getLiteralObject ( ) ;
347371
348372 abstract boolean booleanValue ( ) ;
373+
374+ final Value getLiteralValue ( ) {
375+ result .( ConstantObjectInternal ) .getLiteral ( ) = this
376+ }
377+
349378}
350379
351380/** A numerical constant expression, such as `7` or `4.2` */
@@ -472,8 +501,10 @@ class NegativeIntegerLiteral extends ImmutableLiteral, UnaryExpr {
472501 py_cobjectnames ( result , "-" + this .getOperand ( ) .( IntegerLiteral ) .getN ( ) )
473502 }
474503
504+ /** Gets the (integer) value of this constant. Will not return a result if the value does not fit into
505+ a 32 bit signed value */
475506 int getValue ( ) {
476- result = - this .getOperand ( ) .( IntegerLiteral ) .getValue ( )
507+ result = - ( this .getOperand ( ) .( IntegerLiteral ) .getValue ( ) )
477508 }
478509
479510}
0 commit comments