Skip to content

more instanceof extensions #6866

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 13, 2021
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -219,15 +219,13 @@ class DataFlowExpr = Expr;
class DataFlowType = Type;

/** A function call relevant for data flow. */
class DataFlowCall extends Expr {
DataFlowCall() { this instanceof Call }

class DataFlowCall extends Expr instanceof Call {
/**
* Gets the nth argument for this call.
*
* The range of `n` is from `0` to `getNumberOfArguments() - 1`.
*/
Expr getArgument(int n) { result = this.(Call).getArgument(n) }
Expr getArgument(int n) { result = super.getArgument(n) }

/** Gets the data flow node corresponding to this call. */
ExprNode getNode() { result.getExpr() = this }
Expand Down
6 changes: 2 additions & 4 deletions cpp/ql/src/AlertSuppression.ql
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ class SuppressionComment extends Comment {
/**
* The scope of an alert suppression comment.
*/
class SuppressionScope extends ElementBase {
SuppressionScope() { this instanceof SuppressionComment }

class SuppressionScope extends ElementBase instanceof SuppressionComment {
/**
* Holds if this element is at the specified location.
* The location spans column `startcolumn` of line `startline` to
Expand All @@ -73,7 +71,7 @@ class SuppressionScope extends ElementBase {
predicate hasLocationInfo(
string filepath, int startline, int startcolumn, int endline, int endcolumn
) {
this.(SuppressionComment).covers(filepath, startline, startcolumn, endline, endcolumn)
super.covers(filepath, startline, startcolumn, endline, endcolumn)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -940,13 +940,9 @@ private module ParameterNodes {
import ParameterNodes

/** A data-flow node that represents a call argument. */
class ArgumentNode extends Node {
ArgumentNode() { this instanceof ArgumentNodeImpl }

class ArgumentNode extends Node instanceof ArgumentNodeImpl {
/** Holds if this argument occurs at the given position in the given call. */
final predicate argumentOf(DataFlowCall call, int pos) {
this.(ArgumentNodeImpl).argumentOf(call, pos)
}
final predicate argumentOf(DataFlowCall call, int pos) { super.argumentOf(call, pos) }
}

abstract private class ArgumentNodeImpl extends Node {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,7 @@ class ExprNode extends Node, TExprNode_ {
* The value of a parameter at function entry, viewed as a node in a data
* flow graph.
*/
class ParameterNode extends Node {
ParameterNode() { this instanceof ParameterNodeImpl }

class ParameterNode extends Node instanceof ParameterNodeImpl {
/** Gets the parameter corresponding to this node, if any. */
DotNet::Parameter getParameter() {
exists(DataFlowCallable c, int i | this.isParameterOf(c, i) and result = c.getParameter(i))
Expand All @@ -110,9 +108,7 @@ class ParameterNode extends Node {
* Holds if this node is the parameter of callable `c` at the specified
* (zero-based) position.
*/
predicate isParameterOf(DataFlowCallable c, int i) {
this.(ParameterNodeImpl).isParameterOf(c, i)
}
predicate isParameterOf(DataFlowCallable c, int i) { super.isParameterOf(c, i) }
}

/** A definition, viewed as a node in a data flow graph. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,12 @@ private module Impl {
}

/** An expression whose value may control the execution of another element. */
class Guard extends Expr {
Guard() { this instanceof G::Guard }

class Guard extends Expr instanceof G::Guard {
/**
* Holds if basic block `bb` is guarded by this guard having value `v`.
*/
predicate controlsBasicBlock(ControlFlow::BasicBlock bb, G::AbstractValue v) {
this.(G::Guard).controlsBasicBlock(bb, v)
super.controlsBasicBlock(bb, v)
}

/**
Expand All @@ -108,7 +106,7 @@ private module Impl {
exists(Expr e1_, Expr e2_ |
e1 = unique(ExprNode cfn | hasChild(this, e1_, _, cfn) | cfn) and
e2 = unique(ExprNode cfn | hasChild(this, e2_, _, cfn) | cfn) and
this.(G::Guard).isEquality(e1_, e2_, polarity)
super.isEquality(e1_, e2_, polarity)
)
}
}
Expand Down