mirror of
https://github.com/github/codeql.git
synced 2026-04-25 16:55:19 +02:00
Rust: Use shared SuccessorType.
This commit is contained in:
@@ -1,25 +1,9 @@
|
||||
/** Provides classes representing the control flow graph. */
|
||||
|
||||
private import internal.ControlFlowGraphImpl
|
||||
private import internal.SuccessorType
|
||||
private import internal.Scope as Scope
|
||||
import codeql.controlflow.SuccessorType
|
||||
|
||||
final class CfgScope = Scope::CfgScope;
|
||||
|
||||
final class SuccessorType = SuccessorTypeImpl;
|
||||
|
||||
final class NormalSuccessor = NormalSuccessorImpl;
|
||||
|
||||
final class ConditionalSuccessor = ConditionalSuccessorImpl;
|
||||
|
||||
final class BooleanSuccessor = BooleanSuccessorImpl;
|
||||
|
||||
final class MatchSuccessor = MatchSuccessorImpl;
|
||||
|
||||
final class BreakSuccessor = BreakSuccessorImpl;
|
||||
|
||||
final class ContinueSuccessor = ContinueSuccessorImpl;
|
||||
|
||||
final class ReturnSuccessor = ReturnSuccessorImpl;
|
||||
|
||||
final class CfgNode = Node;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
private import codeql.util.Boolean
|
||||
private import codeql.rust.controlflow.ControlFlowGraph
|
||||
private import rust
|
||||
private import SuccessorType
|
||||
|
||||
newtype TCompletion =
|
||||
TSimpleCompletion() or
|
||||
@@ -32,7 +31,7 @@ abstract class NormalCompletion extends Completion { }
|
||||
|
||||
/** A simple (normal) completion. */
|
||||
class SimpleCompletion extends NormalCompletion, TSimpleCompletion {
|
||||
override NormalSuccessor getAMatchingSuccessorType() { any() }
|
||||
override DirectSuccessor getAMatchingSuccessorType() { any() }
|
||||
|
||||
// `SimpleCompletion` is the "default" completion type, thus it is valid for
|
||||
// any node where there isn't another more specific completion type.
|
||||
@@ -184,7 +183,7 @@ class MatchCompletion extends TMatchCompletion, ConditionalCompletion {
|
||||
e instanceof TryExpr and value = true
|
||||
}
|
||||
|
||||
override MatchSuccessor getAMatchingSuccessorType() { result.getValue() = value }
|
||||
override MatchingSuccessor getAMatchingSuccessorType() { result.getValue() = value }
|
||||
|
||||
/** Gets the dual match completion. */
|
||||
override MatchCompletion getDual() { result = TMatchCompletion(value.booleanNot()) }
|
||||
|
||||
@@ -37,7 +37,7 @@ private module CfgInput implements InputSig<Location> {
|
||||
/**
|
||||
* Hold if `c` represents simple (normal) evaluation of a statement or an expression.
|
||||
*/
|
||||
predicate successorTypeIsSimple(SuccessorType t) { t instanceof Cfg::NormalSuccessor }
|
||||
predicate successorTypeIsSimple(SuccessorType t) { t instanceof Cfg::DirectSuccessor }
|
||||
|
||||
/** Holds if `t` is an abnormal exit type out of a CFG scope. */
|
||||
predicate isAbnormalExitType(SuccessorType t) { none() }
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
private import rust
|
||||
private import codeql.util.Boolean
|
||||
private import Completion
|
||||
private import codeql.rust.internal.CachedStages
|
||||
|
||||
cached
|
||||
newtype TSuccessorType =
|
||||
TNormalSuccessor() { Stages::CfgStage::ref() } or
|
||||
TBooleanSuccessor(Boolean b) or
|
||||
TMatchSuccessor(Boolean b) or
|
||||
TBreakSuccessor() or
|
||||
TContinueSuccessor() or
|
||||
TReturnSuccessor()
|
||||
|
||||
/** The type of a control flow successor. */
|
||||
abstract class SuccessorTypeImpl extends TSuccessorType {
|
||||
/** Gets a textual representation of successor type. */
|
||||
abstract string toString();
|
||||
}
|
||||
|
||||
/** A normal control flow successor. */
|
||||
class NormalSuccessorImpl extends SuccessorTypeImpl, TNormalSuccessor {
|
||||
override string toString() { result = "successor" }
|
||||
}
|
||||
|
||||
/** A conditional control flow successor. */
|
||||
abstract class ConditionalSuccessorImpl extends SuccessorTypeImpl {
|
||||
boolean value;
|
||||
|
||||
bindingset[value]
|
||||
ConditionalSuccessorImpl() { exists(value) }
|
||||
|
||||
/** Gets the Boolean value of this successor. */
|
||||
boolean getValue() { result = value }
|
||||
}
|
||||
|
||||
/** A Boolean control flow successor for a boolean conditon. */
|
||||
class BooleanSuccessorImpl extends ConditionalSuccessorImpl, TBooleanSuccessor {
|
||||
BooleanSuccessorImpl() { this = TBooleanSuccessor(value) }
|
||||
|
||||
override string toString() { result = this.getValue().toString() }
|
||||
}
|
||||
|
||||
/**
|
||||
* A control flow successor of a pattern match.
|
||||
*/
|
||||
class MatchSuccessorImpl extends ConditionalSuccessorImpl, TMatchSuccessor {
|
||||
MatchSuccessorImpl() { this = TMatchSuccessor(value) }
|
||||
|
||||
override string toString() {
|
||||
if this.getValue() = true then result = "match" else result = "no-match"
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A control flow successor of a `break` expression.
|
||||
*/
|
||||
class BreakSuccessorImpl extends SuccessorTypeImpl, TBreakSuccessor {
|
||||
override string toString() { result = "break" }
|
||||
}
|
||||
|
||||
/**
|
||||
* A control flow successor of a `continue` expression.
|
||||
*/
|
||||
class ContinueSuccessorImpl extends SuccessorTypeImpl, TContinueSuccessor {
|
||||
override string toString() { result = "continue" }
|
||||
}
|
||||
|
||||
/**
|
||||
* A `return` control flow successor.
|
||||
*/
|
||||
class ReturnSuccessorImpl extends SuccessorTypeImpl, TReturnSuccessor {
|
||||
override string toString() { result = "return" }
|
||||
}
|
||||
@@ -65,7 +65,6 @@ module Stages {
|
||||
cached
|
||||
module CfgStage {
|
||||
private import codeql.rust.controlflow.internal.Splitting
|
||||
private import codeql.rust.controlflow.internal.SuccessorType
|
||||
private import codeql.rust.controlflow.internal.ControlFlowGraphImpl
|
||||
private import codeql.rust.controlflow.CfgNodes
|
||||
|
||||
@@ -87,8 +86,6 @@ module Stages {
|
||||
or
|
||||
exists(TConditionalCompletionSplitKind())
|
||||
or
|
||||
exists(TNormalSuccessor())
|
||||
or
|
||||
exists(AstCfgNode n)
|
||||
or
|
||||
exists(CallExprCfgNode n | exists(n.getFunction()))
|
||||
|
||||
Reference in New Issue
Block a user