Skip to content

Commit af28d2c

Browse files
owen-mcCopilot
andcommitted
Go: deprecate ParenExpr and remove all references
Since the extractor no longer produces ParenExpr nodes, deprecate the class so existing user code gets a warning rather than breaking, and remove all references from library code where it was used to look through parentheses. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 0eeddc3 commit af28d2c

7 files changed

Lines changed: 6 additions & 52 deletions

File tree

go/docs/language/learn-ql/go/ast-class-reference.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,8 +450,6 @@ Miscellaneous
450450
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
451451
| ``...`` | `Ellipsis <https://help.semmle.com/qldoc/go/semmle/go/Expr.qll/type.Expr$Ellipsis.html>`__ | | |
452452
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
453-
| ``(``\ `Expr <https://help.semmle.com/qldoc/go/semmle/go/Expr.qll/type.Expr$Expr.html>`__\ ``)`` | `ParenExpr <https://help.semmle.com/qldoc/go/semmle/go/Expr.qll/type.Expr$ParenExpr.html>`__ | | |
454-
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
455453
| `Ident <https://help.semmle.com/qldoc/go/semmle/go/Expr.qll/type.Expr$Ident.html>`__\ ``.``\ `Ident <https://help.semmle.com/qldoc/go/semmle/go/Expr.qll/type.Expr$Ident.html>`__ | `SelectorExpr <https://help.semmle.com/qldoc/go/semmle/go/Expr.qll/type.Expr$SelectorExpr.html>`__ | | |
456454
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
457455
| `Expr <https://help.semmle.com/qldoc/go/semmle/go/Expr.qll/type.Expr$Expr.html>`__\ ``[``\ `Expr <https://help.semmle.com/qldoc/go/semmle/go/Expr.qll/type.Expr$Expr.html>`__\ ``]`` | `IndexExpr <https://help.semmle.com/qldoc/go/semmle/go/Expr.qll/type.Expr$IndexExpr.html>`__ | | |

go/ql/lib/semmle/go/Expr.qll

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -544,15 +544,11 @@ class SliceLit extends ArrayOrSliceLit {
544544
}
545545

546546
/**
547-
* A parenthesized expression.
548-
*
549-
* Examples:
550-
*
551-
* ```go
552-
* (x + y)
553-
* ```
547+
* DEPRECATED: `ParenExpr` is no longer extracted. Parenthesized expressions are
548+
* transparent in the AST; the child expression takes the place of the parenthesized
549+
* expression directly.
554550
*/
555-
class ParenExpr extends @parenexpr, Expr {
551+
deprecated class ParenExpr extends @parenexpr, Expr {
556552
/** Gets the expression between parentheses. */
557553
Expr getExpr() { result = this.getChildExpr(0) }
558554

@@ -2137,8 +2133,6 @@ private predicate isTypeExprBottomUp(Expr e) {
21372133
or
21382134
e instanceof @indexexpr and isTypeExprBottomUp(e.getChildExpr(0))
21392135
or
2140-
isTypeExprBottomUp(e.(ParenExpr).getExpr())
2141-
or
21422136
isTypeExprBottomUp(e.(StarExpr).getBase())
21432137
or
21442138
isTypeExprBottomUp(e.(Ellipsis).getOperand())
@@ -2189,8 +2183,6 @@ private predicate isTypeExprTopDown(Expr e) {
21892183
or
21902184
e = any(SelectorExpr sel | isTypeExprTopDown(sel)).getBase()
21912185
or
2192-
e = any(ParenExpr pe | isTypeExprTopDown(pe)).getExpr()
2193-
or
21942186
e = any(StarExpr se | isTypeExprTopDown(se)).getBase()
21952187
or
21962188
e = any(Ellipsis ell | isTypeExprTopDown(ell)).getOperand()
@@ -2239,8 +2231,6 @@ class ReferenceExpr extends Expr {
22392231
not this = any(MethodSpec md).getNameExpr() and
22402232
not this = any(StructLit sl).getKey(_)
22412233
or
2242-
this.(ParenExpr).getExpr() instanceof ReferenceExpr
2243-
or
22442234
this.(StarExpr).getBase() instanceof ReferenceExpr
22452235
or
22462236
this instanceof DerefExpr
@@ -2290,7 +2280,6 @@ class ValueExpr extends Expr {
22902280
this instanceof BasicLit or
22912281
this instanceof FuncLit or
22922282
this instanceof CompositeLit or
2293-
this.(ParenExpr).getExpr() instanceof ValueExpr or
22942283
this instanceof SliceExpr or
22952284
this instanceof TypeAssertExpr or
22962285
this instanceof CallOrConversionExpr or

go/ql/lib/semmle/go/controlflow/ControlFlowGraph.qll

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,6 @@ module ControlFlow {
259259
private predicate ensuresAux(Expr expr, boolean b) {
260260
expr = cond and b = outcome
261261
or
262-
expr = any(ParenExpr par | this.ensuresAux(par, b)).getExpr()
263-
or
264262
expr = any(NotExpr ne | this.ensuresAux(ne, b.booleanNot())).getOperand()
265263
or
266264
expr = any(LandExpr land | this.ensuresAux(land, true)).getAnOperand() and

go/ql/lib/semmle/go/controlflow/ControlFlowGraphImpl.qll

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ private predicate isCondRoot(Expr e) {
4646
*/
4747
private predicate isCond(Expr e) {
4848
isCondRoot(e) or
49-
e = any(LogicalBinaryExpr lbe | isCond(lbe)).getRightOperand() or
50-
e = any(ParenExpr par | isCond(par)).getExpr()
49+
e = any(LogicalBinaryExpr lbe | isCond(lbe)).getRightOperand()
5150
}
5251

5352
/**
@@ -586,9 +585,6 @@ module CFG {
586585
// `else` block, so there is no control-flow step where `x && y` is specifically calculated)
587586
e instanceof LogicalBinaryExpr and
588587
isCond(e)
589-
or
590-
// Purely concrete-syntactic structural expression:
591-
e instanceof ParenExpr
592588
}
593589

594590
/**
@@ -774,7 +770,6 @@ module CFG {
774770
this instanceof ExprStmt or
775771
this instanceof KeyValueExpr or
776772
this instanceof LabeledStmt or
777-
this instanceof ParenExpr or
778773
this instanceof PlainBlock or
779774
this instanceof VarDecl
780775
}
@@ -811,8 +806,6 @@ module CFG {
811806
or
812807
i = 0 and result = this.(LabeledStmt).getStmt()
813808
or
814-
i = 0 and result = this.(ParenExpr).getExpr()
815-
or
816809
result = this.(PlainBlock).getStmt(i)
817810
}
818811
}

go/ql/lib/semmle/go/controlflow/IR.qll

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,10 +1511,7 @@ module IR {
15111511
* value is not stored in a variable or used to compute the value of a non-shortcircuiting
15121512
* expression) do not have a final instruction either.
15131513
*/
1514-
Instruction evalExprInstruction(Expr e) {
1515-
result = MkExprNode(e) or
1516-
result = evalExprInstruction(e.(ParenExpr).getExpr())
1517-
}
1514+
Instruction evalExprInstruction(Expr e) { result = MkExprNode(e) }
15181515

15191516
/**
15201517
* Gets the instruction corresponding to the initialization of `r`.

go/ql/lib/semmle/go/dataflow/Properties.qll

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ class Property extends TProperty {
3232
// then !test = !outcome ==> nd matches this
3333
this.checkOnExpr(test.(NotExpr).getOperand(), outcome.booleanNot(), nd)
3434
or
35-
// if test = outcome ==> nd matches this
36-
// then (test) = outcome ==> nd matches this
37-
this.checkOnExpr(test.(ParenExpr).getExpr(), outcome, nd)
38-
or
3935
// if test = true ==> nd matches this
4036
// then (test && e) = true ==> nd matches this
4137
outcome = true and

go/ql/src/experimental/IntegerOverflow/RangeAnalysis.qll

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,6 @@ float getAnUpperBound(Expr expr) {
3131
if expr.isConst()
3232
then result = expr.getNumericValue()
3333
else (
34-
//if an expression with parenthesis, strip the parenthesis first
35-
exists(ParenExpr paren |
36-
paren = expr and
37-
result = getAnUpperBound(paren.stripParens())
38-
)
39-
or
4034
//if this expression is an identifier
4135
exists(SsaVariable v, Ident identifier |
4236
identifier = expr and
@@ -188,11 +182,6 @@ float getALowerBound(Expr expr) {
188182
result = expr.getIntValue() or
189183
result = expr.getExactValue().toFloat()
190184
else (
191-
exists(ParenExpr paren |
192-
paren = expr and
193-
result = getALowerBound(paren.stripParens())
194-
)
195-
or
196185
//if this expression is an identifer
197186
exists(SsaVariable v, Ident identifier |
198187
identifier = expr and
@@ -571,12 +560,6 @@ predicate ssaDependsOnExpr(SsaDefinition def, Expr expr) {
571560
if expr.isConst()
572561
then none()
573562
else (
574-
//if an expression with parenthesis, strip the parenthesis
575-
exists(ParenExpr paren |
576-
paren = expr and
577-
ssaDependsOnExpr(def, paren.stripParens())
578-
)
579-
or
580563
exists(Ident ident |
581564
ident = expr and
582565
getAUse(def) = ident

0 commit comments

Comments
 (0)