mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
Shared: Use shared SuccessorType in shared Cfg and BasicBlock libs.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
* Provides classes that specify the conditions under which control flows along a given edge.
|
||||
*/
|
||||
|
||||
private import codeql.controlflow.SuccessorType
|
||||
private import internal.EdgeKindInternal
|
||||
|
||||
private newtype TEdgeKind =
|
||||
@@ -28,6 +29,21 @@ abstract private class EdgeKindImpl extends TEdgeKind {
|
||||
|
||||
final class EdgeKind = EdgeKindImpl;
|
||||
|
||||
private SuccessorType getAMatchingSpecificSuccessorType(EdgeKind k) {
|
||||
result.(BooleanSuccessor).getValue() = true and k instanceof TrueEdge
|
||||
or
|
||||
result.(BooleanSuccessor).getValue() = false and k instanceof FalseEdge
|
||||
or
|
||||
result instanceof ExceptionSuccessor and k instanceof ExceptionEdge
|
||||
}
|
||||
|
||||
SuccessorType getAMatchingSuccessorType(EdgeKind k) {
|
||||
result = getAMatchingSpecificSuccessorType(k)
|
||||
or
|
||||
not exists(getAMatchingSpecificSuccessorType(k)) and
|
||||
result instanceof DirectSuccessor
|
||||
}
|
||||
|
||||
/**
|
||||
* A "goto" edge, representing the unconditional successor of an `Instruction`
|
||||
* or `IRBlock`.
|
||||
|
||||
@@ -265,9 +265,9 @@ private predicate isEntryBlock(TIRBlock block) {
|
||||
}
|
||||
|
||||
module IRCfg implements BB::CfgSig<Language::Location> {
|
||||
class ControlFlowNode = Instruction;
|
||||
private import codeql.controlflow.SuccessorType
|
||||
|
||||
class SuccessorType = EdgeKind;
|
||||
class ControlFlowNode = Instruction;
|
||||
|
||||
final private class FinalIRBlock = IRBlock;
|
||||
|
||||
@@ -280,7 +280,12 @@ module IRCfg implements BB::CfgSig<Language::Location> {
|
||||
|
||||
BasicBlock getASuccessor() { result = super.getASuccessor() }
|
||||
|
||||
BasicBlock getASuccessor(SuccessorType t) { result = super.getSuccessor(t) }
|
||||
BasicBlock getASuccessor(SuccessorType t) {
|
||||
exists(EdgeKind k |
|
||||
result = super.getSuccessor(k) and
|
||||
t = getAMatchingSuccessorType(k)
|
||||
)
|
||||
}
|
||||
|
||||
predicate strictlyDominates(BasicBlock bb) { super.strictlyDominates(bb) }
|
||||
|
||||
|
||||
@@ -265,9 +265,9 @@ private predicate isEntryBlock(TIRBlock block) {
|
||||
}
|
||||
|
||||
module IRCfg implements BB::CfgSig<Language::Location> {
|
||||
class ControlFlowNode = Instruction;
|
||||
private import codeql.controlflow.SuccessorType
|
||||
|
||||
class SuccessorType = EdgeKind;
|
||||
class ControlFlowNode = Instruction;
|
||||
|
||||
final private class FinalIRBlock = IRBlock;
|
||||
|
||||
@@ -280,7 +280,12 @@ module IRCfg implements BB::CfgSig<Language::Location> {
|
||||
|
||||
BasicBlock getASuccessor() { result = super.getASuccessor() }
|
||||
|
||||
BasicBlock getASuccessor(SuccessorType t) { result = super.getSuccessor(t) }
|
||||
BasicBlock getASuccessor(SuccessorType t) {
|
||||
exists(EdgeKind k |
|
||||
result = super.getSuccessor(k) and
|
||||
t = getAMatchingSuccessorType(k)
|
||||
)
|
||||
}
|
||||
|
||||
predicate strictlyDominates(BasicBlock bb) { super.strictlyDominates(bb) }
|
||||
|
||||
|
||||
@@ -265,9 +265,9 @@ private predicate isEntryBlock(TIRBlock block) {
|
||||
}
|
||||
|
||||
module IRCfg implements BB::CfgSig<Language::Location> {
|
||||
class ControlFlowNode = Instruction;
|
||||
private import codeql.controlflow.SuccessorType
|
||||
|
||||
class SuccessorType = EdgeKind;
|
||||
class ControlFlowNode = Instruction;
|
||||
|
||||
final private class FinalIRBlock = IRBlock;
|
||||
|
||||
@@ -280,7 +280,12 @@ module IRCfg implements BB::CfgSig<Language::Location> {
|
||||
|
||||
BasicBlock getASuccessor() { result = super.getASuccessor() }
|
||||
|
||||
BasicBlock getASuccessor(SuccessorType t) { result = super.getSuccessor(t) }
|
||||
BasicBlock getASuccessor(SuccessorType t) {
|
||||
exists(EdgeKind k |
|
||||
result = super.getSuccessor(k) and
|
||||
t = getAMatchingSuccessorType(k)
|
||||
)
|
||||
}
|
||||
|
||||
predicate strictlyDominates(BasicBlock bb) { super.strictlyDominates(bb) }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user