Skip to content

Commit a10731c

Browse files
authored
Java: introduce more-intuitive names for ClassInstanceExpr, L/RValue and MethodAccess.
1 parent 4e823b4 commit a10731c

File tree

1 file changed

+37
-15
lines changed

1 file changed

+37
-15
lines changed

java/ql/lib/semmle/code/java/Expr.qll

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,6 +1251,14 @@ class ClassInstanceExpr extends Expr, ConstructorCall, @classinstancexpr {
12511251
override string getAPrimaryQlClass() { result = "ClassInstanceExpr" }
12521252
}
12531253

1254+
/**
1255+
* An explicit `new ClassName(...)` expression.
1256+
*
1257+
* Note this does not include implicit instance creation such as lambda expressions
1258+
* or `instanceVar::methodName` references. To include those too, use `ClassInstanceExpr`.
1259+
*/
1260+
class NewClassExpr extends @newexpr, ClassInstanceExpr { }
1261+
12541262
/** A functional expression is either a lambda expression or a member reference expression. */
12551263
abstract class FunctionalExpr extends ClassInstanceExpr {
12561264
/** Gets the implicit method corresponding to this functional expression. */
@@ -1768,24 +1776,29 @@ class VarAccess extends Expr, @varaccess {
17681776
Variable getVariable() { variableBinding(this, result) }
17691777

17701778
/**
1771-
* Holds if this variable access is an l-value.
1779+
* Holds if this variable access is a write access.
17721780
*
1773-
* An l-value is a write access to a variable, which occurs as the destination of an assignment.
1781+
* That means the access is the destination of an assignment.
17741782
*/
1775-
predicate isLValue() {
1783+
predicate isVarWrite() {
17761784
exists(Assignment a | a.getDest() = this) or
17771785
exists(UnaryAssignExpr e | e.getExpr() = this)
17781786
}
17791787

1788+
/** DEPRECATED: Alias for `isVarWrite`. */
1789+
deprecated predicate isLValue() { this.isVarWrite() }
1790+
17801791
/**
1781-
* Holds if this variable access is an r-value.
1792+
* Holds if this variable access is a read access.
17821793
*
1783-
* An r-value is a read access to a variable.
17841794
* In other words, it is a variable access that does _not_ occur as the destination of
17851795
* a simple assignment, but it may occur as the destination of a compound assignment
17861796
* or a unary assignment.
17871797
*/
1788-
predicate isRValue() { not exists(AssignExpr a | a.getDest() = this) }
1798+
predicate isVarRead() { not exists(AssignExpr a | a.getDest() = this) }
1799+
1800+
/** DEPRECATED: Alias for `isVarRead`. */
1801+
deprecated predicate isRValue() { this.isVarRead() }
17891802

17901803
/** Gets a printable representation of this expression. */
17911804
override string toString() {
@@ -1831,37 +1844,43 @@ class ExtensionReceiverAccess extends VarAccess {
18311844
}
18321845

18331846
/**
1834-
* An l-value is a write access to a variable, which occurs as the destination of an assignment.
1847+
* A write access to a variable, which occurs as the destination of an assignment.
18351848
*/
1836-
class LValue extends VarAccess {
1837-
LValue() { this.isLValue() }
1849+
class VarWrite extends VarAccess {
1850+
VarWrite() { this.isVarWrite() }
18381851

18391852
/**
1840-
* Gets a source expression used in an assignment to this l-value.
1853+
* Gets the right-hand side of the assignment that executes this variable write.
18411854
*
18421855
* For assignments using the `=` operator, the source expression
18431856
* is simply the RHS of the assignment.
18441857
*
1845-
* Note that for l-values occurring on the LHS of compound assignment operators
1858+
* Note that for writes occurring on the LHS of compound assignment operators
18461859
* (such as (`+=`), both the RHS and the LHS of the compound assignment
18471860
* are source expressions of the assignment.
18481861
*/
18491862
Expr getRhs() { exists(Assignment e | e.getDest() = this and e.getSource() = result) }
18501863
}
18511864

1865+
/** DEPRECATED: Alias for `VarWrite`. */
1866+
deprecated class LValue = VarWrite;
1867+
18521868
/**
1853-
* An r-value is a read access to a variable.
1869+
* A read access to a variable.
18541870
*
18551871
* In other words, it is a variable access that does _not_ occur as the destination of
18561872
* a simple assignment, but it may occur as the destination of a compound assignment
18571873
* or a unary assignment.
18581874
*/
1859-
class RValue extends VarAccess {
1860-
RValue() { this.isRValue() }
1875+
class VarRead extends VarAccess {
1876+
VarRead() { this.isVarRead() }
18611877
}
18621878

1879+
/** DEPRECATED: Alias for `VarRead`. */
1880+
deprecated class RValue = VarRead;
1881+
18631882
/** A method access is an invocation of a method with a list of arguments. */
1864-
class MethodAccess extends Expr, Call, @methodaccess {
1883+
class MethodCall extends Expr, Call, @methodaccess {
18651884
/** Gets the qualifying expression of this method access, if any. */
18661885
override Expr getQualifier() { result.isNthChildOf(this, -1) }
18671886

@@ -1924,6 +1943,9 @@ class MethodAccess extends Expr, Call, @methodaccess {
19241943
override string getAPrimaryQlClass() { result = "MethodAccess" }
19251944
}
19261945

1946+
/** DEPRECATED: Alias for `MethodCall`. */
1947+
deprecated class MethodAccess = MethodCall;
1948+
19271949
/** A type access is a (possibly qualified) reference to a type. */
19281950
class TypeAccess extends Expr, Annotatable, @typeaccess {
19291951
/** Gets the qualifier of this type access, if any. */

0 commit comments

Comments
 (0)