Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions go/docs/language/learn-ql/go/ast-class-reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,6 @@ Miscellaneous
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| ``...`` | `Ellipsis <https://help.semmle.com/qldoc/go/semmle/go/Expr.qll/type.Expr$Ellipsis.html>`__ | | |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| ``(``\ `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>`__ | | |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| `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>`__ | | |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| `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>`__ | | |
Expand Down
9 changes: 6 additions & 3 deletions go/extractor/extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,12 @@ func extractExpr(tw *trap.Writer, expr ast.Expr, parent trap.Label, idx int, ski
return
}

// Skip parenthesised expressions and extract their child directly in their place
if paren, ok := expr.(*ast.ParenExpr); ok {
extractExpr(tw, paren.X, parent, idx, skipExtractingValue)
return
}

lbl := tw.Labeler.LocalID(expr)
extractTypeOf(tw, expr, lbl)

Expand Down Expand Up @@ -1087,9 +1093,6 @@ func extractExpr(tw *trap.Writer, expr ast.Expr, parent trap.Label, idx int, ski
kind = dbscheme.CompositeLitExpr.Index()
extractExpr(tw, expr.Type, lbl, 0, false)
extractExprs(tw, expr.Elts, lbl, 1, 1)
case *ast.ParenExpr:
kind = dbscheme.ParenExpr.Index()
extractExpr(tw, expr.X, lbl, 0, false)
case *ast.SelectorExpr:
kind = dbscheme.SelectorExpr.Index()
extractExpr(tw, expr.X, lbl, 0, false)
Expand Down
19 changes: 4 additions & 15 deletions go/ql/lib/semmle/go/Expr.qll
Original file line number Diff line number Diff line change
Expand Up @@ -544,15 +544,11 @@ class SliceLit extends ArrayOrSliceLit {
}

/**
* A parenthesized expression.
*
* Examples:
*
* ```go
* (x + y)
* ```
* DEPRECATED: `ParenExpr` is no longer extracted. Parenthesized expressions are
* transparent in the AST; the child expression takes the place of the parenthesized
* expression directly.
*/
class ParenExpr extends @parenexpr, Expr {
deprecated class ParenExpr extends @parenexpr, Expr {
/** Gets the expression between parentheses. */
Expr getExpr() { result = this.getChildExpr(0) }

Expand Down Expand Up @@ -2137,8 +2133,6 @@ private predicate isTypeExprBottomUp(Expr e) {
or
e instanceof @indexexpr and isTypeExprBottomUp(e.getChildExpr(0))
or
isTypeExprBottomUp(e.(ParenExpr).getExpr())
or
isTypeExprBottomUp(e.(StarExpr).getBase())
or
isTypeExprBottomUp(e.(Ellipsis).getOperand())
Expand Down Expand Up @@ -2189,8 +2183,6 @@ private predicate isTypeExprTopDown(Expr e) {
or
e = any(SelectorExpr sel | isTypeExprTopDown(sel)).getBase()
or
e = any(ParenExpr pe | isTypeExprTopDown(pe)).getExpr()
or
e = any(StarExpr se | isTypeExprTopDown(se)).getBase()
or
e = any(Ellipsis ell | isTypeExprTopDown(ell)).getOperand()
Expand Down Expand Up @@ -2239,8 +2231,6 @@ class ReferenceExpr extends Expr {
not this = any(MethodSpec md).getNameExpr() and
not this = any(StructLit sl).getKey(_)
or
this.(ParenExpr).getExpr() instanceof ReferenceExpr
or
this.(StarExpr).getBase() instanceof ReferenceExpr
or
this instanceof DerefExpr
Expand Down Expand Up @@ -2290,7 +2280,6 @@ class ValueExpr extends Expr {
this instanceof BasicLit or
this instanceof FuncLit or
this instanceof CompositeLit or
this.(ParenExpr).getExpr() instanceof ValueExpr or
this instanceof SliceExpr or
this instanceof TypeAssertExpr or
this instanceof CallOrConversionExpr or
Expand Down
2 changes: 0 additions & 2 deletions go/ql/lib/semmle/go/controlflow/ControlFlowGraph.qll
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,6 @@ module ControlFlow {
private predicate ensuresAux(Expr expr, boolean b) {
expr = cond and b = outcome
or
expr = any(ParenExpr par | this.ensuresAux(par, b)).getExpr()
or
expr = any(NotExpr ne | this.ensuresAux(ne, b.booleanNot())).getOperand()
or
expr = any(LandExpr land | this.ensuresAux(land, true)).getAnOperand() and
Expand Down
9 changes: 1 addition & 8 deletions go/ql/lib/semmle/go/controlflow/ControlFlowGraphImpl.qll
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ private predicate isCondRoot(Expr e) {
*/
private predicate isCond(Expr e) {
isCondRoot(e) or
e = any(LogicalBinaryExpr lbe | isCond(lbe)).getRightOperand() or
e = any(ParenExpr par | isCond(par)).getExpr()
e = any(LogicalBinaryExpr lbe | isCond(lbe)).getRightOperand()
}

/**
Expand Down Expand Up @@ -586,9 +585,6 @@ module CFG {
// `else` block, so there is no control-flow step where `x && y` is specifically calculated)
e instanceof LogicalBinaryExpr and
isCond(e)
or
// Purely concrete-syntactic structural expression:
e instanceof ParenExpr
}

/**
Expand Down Expand Up @@ -774,7 +770,6 @@ module CFG {
this instanceof ExprStmt or
this instanceof KeyValueExpr or
this instanceof LabeledStmt or
this instanceof ParenExpr or
this instanceof PlainBlock or
this instanceof VarDecl
}
Expand Down Expand Up @@ -811,8 +806,6 @@ module CFG {
or
i = 0 and result = this.(LabeledStmt).getStmt()
or
i = 0 and result = this.(ParenExpr).getExpr()
or
result = this.(PlainBlock).getStmt(i)
}
}
Expand Down
5 changes: 1 addition & 4 deletions go/ql/lib/semmle/go/controlflow/IR.qll
Original file line number Diff line number Diff line change
Expand Up @@ -1511,10 +1511,7 @@ module IR {
* value is not stored in a variable or used to compute the value of a non-shortcircuiting
* expression) do not have a final instruction either.
*/
Instruction evalExprInstruction(Expr e) {
result = MkExprNode(e) or
result = evalExprInstruction(e.(ParenExpr).getExpr())
}
Instruction evalExprInstruction(Expr e) { result = MkExprNode(e) }

/**
* Gets the instruction corresponding to the initialization of `r`.
Expand Down
4 changes: 0 additions & 4 deletions go/ql/lib/semmle/go/dataflow/Properties.qll
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ class Property extends TProperty {
// then !test = !outcome ==> nd matches this
this.checkOnExpr(test.(NotExpr).getOperand(), outcome.booleanNot(), nd)
or
// if test = outcome ==> nd matches this
// then (test) = outcome ==> nd matches this
this.checkOnExpr(test.(ParenExpr).getExpr(), outcome, nd)
or
// if test = true ==> nd matches this
// then (test && e) = true ==> nd matches this
outcome = true and
Expand Down
17 changes: 0 additions & 17 deletions go/ql/src/experimental/IntegerOverflow/RangeAnalysis.qll
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ float getAnUpperBound(Expr expr) {
if expr.isConst()
then result = expr.getNumericValue()
else (
//if an expression with parenthesis, strip the parenthesis first
exists(ParenExpr paren |
paren = expr and
result = getAnUpperBound(paren.stripParens())
)
or
//if this expression is an identifier
exists(SsaVariable v, Ident identifier |
identifier = expr and
Expand Down Expand Up @@ -188,11 +182,6 @@ float getALowerBound(Expr expr) {
result = expr.getIntValue() or
result = expr.getExactValue().toFloat()
else (
exists(ParenExpr paren |
paren = expr and
result = getALowerBound(paren.stripParens())
)
or
//if this expression is an identifer
exists(SsaVariable v, Ident identifier |
identifier = expr and
Expand Down Expand Up @@ -571,12 +560,6 @@ predicate ssaDependsOnExpr(SsaDefinition def, Expr expr) {
if expr.isConst()
then none()
else (
//if an expression with parenthesis, strip the parenthesis
exists(ParenExpr paren |
paren = expr and
ssaDependsOnExpr(def, paren.stripParens())
)
or
exists(Ident ident |
ident = expr and
getAUse(def) = ident
Expand Down
Loading