Skip to content

Commit 32d4595

Browse files
committed
Refactor: add Expr.getControlFlowNode and Expr.getBasicBlock
1 parent be72021 commit 32d4595

2 files changed

Lines changed: 12 additions & 19 deletions

File tree

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ overlay[local]
55
module;
66

77
import go
8+
private import semmle.go.controlflow.ControlFlowGraphImpl
9+
private import semmle.go.controlflow.IR
810

911
/**
1012
* An expression.
@@ -17,6 +19,12 @@ import go
1719
* ```
1820
*/
1921
class Expr extends @expr, ExprParent {
22+
/** Gets the control-flow node associated with this expression. */
23+
CfgImpl::Cfg::ControlFlowNode getControlFlowNode() { result = IR::evalExprInstruction(this) }
24+
25+
/** Gets the basic block containing this expression. */
26+
CfgImpl::Cfg::BasicBlock getBasicBlock() { result = this.getControlFlowNode().getBasicBlock() }
27+
2028
/**
2129
* Gets the kind of this expression, which is an integer value representing the expression's
2230
* node type.

‎go/ql/lib/semmle/go/controlflow/Guards.qll‎

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,7 @@ private module GuardsInput implements
2424

2525
class AstNode = G::AstNode;
2626

27-
class Expr extends G::Expr {
28-
/** Gets the associated control flow node. */
29-
CfgImpl::Cfg::ControlFlowNode getControlFlowNode() { result = IR::evalExprInstruction(this) }
30-
31-
/** Gets the basic block containing this expression. */
32-
CfgImpl::Cfg::BasicBlock getBasicBlock() { result = this.getControlFlowNode().getBasicBlock() }
33-
}
27+
class Expr = G::Expr;
3428

3529
predicate booleanOutcomeBlock(Expr guard, CfgImpl::Cfg::BasicBlock outcomeBlock, boolean branch) {
3630
exists(CfgImpl::Cfg::ControlFlowNode outcomeNode |
@@ -204,20 +198,11 @@ private module GuardsInput implements
204198
)
205199
}
206200

207-
class AndExpr extends Expr instanceof G::LandExpr {
208-
/** Gets an operand of this expression. */
209-
Expr getAnOperand() { result = super.getAnOperand() }
210-
}
201+
class AndExpr = G::LandExpr;
211202

212-
class OrExpr extends Expr instanceof G::LorExpr {
213-
/** Gets an operand of this expression. */
214-
Expr getAnOperand() { result = super.getAnOperand() }
215-
}
203+
class OrExpr = G::LorExpr;
216204

217-
class NotExpr extends Expr instanceof G::NotExpr {
218-
/** Gets the operand of this expression. */
219-
Expr getOperand() { result = super.getOperand() }
220-
}
205+
class NotExpr = G::NotExpr;
221206

222207
private predicate sameNumericTypeFamily(G::NumericType source, G::NumericType target) {
223208
source instanceof G::SignedIntegerType and target instanceof G::SignedIntegerType

0 commit comments

Comments
 (0)