mirror of
https://github.com/github/codeql.git
synced 2026-02-20 08:53:49 +01:00
CFG: model if-modifier and unless
This commit is contained in:
@@ -41,7 +41,8 @@ class LogicalOrAstNode extends Binary {
|
||||
AstNode getAnOperand() { result in [left, right] }
|
||||
}
|
||||
|
||||
private class If_or_elisif = @if or @elsif or @conditional;
|
||||
private class If_or_elisif =
|
||||
@if or @elsif or @conditional or @if_modifier or @unless or @unless_modifier;
|
||||
|
||||
class IfElsifAstNode extends AstNode, If_or_elisif {
|
||||
AstNode getConditionNode() { none() }
|
||||
@@ -75,6 +76,26 @@ private class ConditionalAstNode extends IfElsifAstNode, Conditional {
|
||||
override AstNode getAlternativeNode() { result = this.getAlternative() }
|
||||
}
|
||||
|
||||
private class IfModifierAstNode extends IfElsifAstNode, IfModifier {
|
||||
override AstNode getConditionNode() { result = this.getCondition() }
|
||||
|
||||
override AstNode getConsequenceNode() { result = this.getBody() }
|
||||
}
|
||||
|
||||
private class UnlessAstNode extends IfElsifAstNode, Unless {
|
||||
override AstNode getConditionNode() { result = this.getCondition() }
|
||||
|
||||
override AstNode getConsequenceNode() { result = this.getAlternative() }
|
||||
|
||||
override AstNode getAlternativeNode() { result = this.getConsequence() }
|
||||
}
|
||||
|
||||
private class UnlessModifierAstNode extends IfElsifAstNode, UnlessModifier {
|
||||
override AstNode getConditionNode() { result = this.getCondition() }
|
||||
|
||||
override AstNode getAlternativeNode() { result = this.getBody() }
|
||||
}
|
||||
|
||||
private class CondLoop = @while or @while_modifier or @until or @until_modifier;
|
||||
|
||||
class ConditionalLoopAstNode extends AstNode, CondLoop {
|
||||
|
||||
@@ -405,6 +405,10 @@ private module Trees {
|
||||
c instanceof FalseCompletion and
|
||||
not exists(this.getAlternativeNode())
|
||||
or
|
||||
last(this.getConditionNode(), last, c) and
|
||||
c instanceof TrueCompletion and
|
||||
not exists(this.getConsequenceNode())
|
||||
or
|
||||
last(this.getConsequenceNode(), last, c)
|
||||
or
|
||||
last(this.getAlternativeNode(), last, c)
|
||||
|
||||
Reference in New Issue
Block a user