mirror of
https://github.com/github/codeql.git
synced 2026-02-22 18:03:39 +01:00
Add ConditionalLoop base class
This commit is contained in:
@@ -308,6 +308,17 @@ class Loop extends ControlExpr {
|
||||
Expr getBody() { result = range.getBody() }
|
||||
}
|
||||
|
||||
/**
|
||||
* A loop using a condition expression. That is, a `while` or `until` loop, or
|
||||
* their expression-modifier variants.
|
||||
*/
|
||||
class ConditionalLoop extends Loop {
|
||||
override ConditionalLoop::Range range;
|
||||
|
||||
/** Gets the condition expression of this loop. */
|
||||
final Expr getCondition() { result = range.getCondition() }
|
||||
}
|
||||
|
||||
/**
|
||||
* A `while` loop.
|
||||
* ```rb
|
||||
@@ -317,7 +328,7 @@ class Loop extends ControlExpr {
|
||||
* end
|
||||
* ```
|
||||
*/
|
||||
class WhileExpr extends Loop, @while {
|
||||
class WhileExpr extends ConditionalLoop, @while {
|
||||
final override WhileExpr::Range range;
|
||||
|
||||
final override string getAPrimaryQlClass() { result = "WhileExpr" }
|
||||
@@ -326,9 +337,6 @@ class WhileExpr extends Loop, @while {
|
||||
|
||||
/** Gets the body of this `while` loop. */
|
||||
final override ExprSequence getBody() { result = range.getBody() }
|
||||
|
||||
/** Gets the condition expression of this `while` loop. */
|
||||
final Expr getCondition() { result = range.getCondition() }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -340,7 +348,7 @@ class WhileExpr extends Loop, @while {
|
||||
* end
|
||||
* ```
|
||||
*/
|
||||
class UntilExpr extends Loop, @until {
|
||||
class UntilExpr extends ConditionalLoop, @until {
|
||||
final override UntilExpr::Range range;
|
||||
|
||||
final override string getAPrimaryQlClass() { result = "UntilExpr" }
|
||||
@@ -349,9 +357,6 @@ class UntilExpr extends Loop, @until {
|
||||
|
||||
/** Gets the body of this `until` loop. */
|
||||
final override ExprSequence getBody() { result = range.getBody() }
|
||||
|
||||
/** Gets the condition expression of this `until` loop. */
|
||||
final Expr getCondition() { result = range.getCondition() }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -360,21 +365,12 @@ class UntilExpr extends Loop, @until {
|
||||
* foo while bar
|
||||
* ```
|
||||
*/
|
||||
class WhileModifierExpr extends Loop, @while_modifier {
|
||||
class WhileModifierExpr extends ConditionalLoop, @while_modifier {
|
||||
final override WhileModifierExpr::Range range;
|
||||
|
||||
final override string getAPrimaryQlClass() { result = "WhileModifierExpr" }
|
||||
|
||||
final override string toString() { result = "... while ..." }
|
||||
|
||||
/**
|
||||
* Gets the condition expression of this `while`-modifier. In the following
|
||||
* example, the result is the `Expr` for `bar`.
|
||||
* ```rb
|
||||
* foo while bar
|
||||
* ```
|
||||
*/
|
||||
final Expr getCondition() { result = range.getCondition() }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -383,21 +379,12 @@ class WhileModifierExpr extends Loop, @while_modifier {
|
||||
* foo until bar
|
||||
* ```
|
||||
*/
|
||||
class UntilModifierExpr extends Loop, @until_modifier {
|
||||
class UntilModifierExpr extends ConditionalLoop, @until_modifier {
|
||||
final override UntilModifierExpr::Range range;
|
||||
|
||||
final override string getAPrimaryQlClass() { result = "UntilModifierExpr" }
|
||||
|
||||
final override string toString() { result = "... until ..." }
|
||||
|
||||
/**
|
||||
* Gets the condition expression of this `until`-modifier. In the following
|
||||
* example, the result is the `Expr` for `bar`.
|
||||
* ```rb
|
||||
* foo until bar
|
||||
* ```
|
||||
*/
|
||||
final Expr getCondition() { result = range.getCondition() }
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -141,43 +141,49 @@ module Loop {
|
||||
}
|
||||
}
|
||||
|
||||
module ConditionalLoop {
|
||||
abstract class Range extends Loop::Range {
|
||||
abstract Expr getCondition();
|
||||
}
|
||||
}
|
||||
|
||||
module WhileExpr {
|
||||
class Range extends Loop::Range, @while {
|
||||
class Range extends ConditionalLoop::Range, @while {
|
||||
final override Generated::While generated;
|
||||
|
||||
final override ExprSequence getBody() { result = generated.getBody() }
|
||||
|
||||
final Expr getCondition() { result = generated.getCondition() }
|
||||
final override Expr getCondition() { result = generated.getCondition() }
|
||||
}
|
||||
}
|
||||
|
||||
module UntilExpr {
|
||||
class Range extends Loop::Range, @until {
|
||||
class Range extends ConditionalLoop::Range, @until {
|
||||
final override Generated::Until generated;
|
||||
|
||||
final override ExprSequence getBody() { result = generated.getBody() }
|
||||
|
||||
final Expr getCondition() { result = generated.getCondition() }
|
||||
final override Expr getCondition() { result = generated.getCondition() }
|
||||
}
|
||||
}
|
||||
|
||||
module WhileModifierExpr {
|
||||
class Range extends Loop::Range, @while_modifier {
|
||||
class Range extends ConditionalLoop::Range, @while_modifier {
|
||||
final override Generated::WhileModifier generated;
|
||||
|
||||
final override Expr getBody() { result = generated.getBody() }
|
||||
|
||||
final Expr getCondition() { result = generated.getCondition() }
|
||||
final override Expr getCondition() { result = generated.getCondition() }
|
||||
}
|
||||
}
|
||||
|
||||
module UntilModifierExpr {
|
||||
class Range extends Loop::Range, @until_modifier {
|
||||
class Range extends ConditionalLoop::Range, @until_modifier {
|
||||
final override Generated::UntilModifier generated;
|
||||
|
||||
final override Expr getBody() { result = generated.getBody() }
|
||||
|
||||
final Expr getCondition() { result = generated.getCondition() }
|
||||
final override Expr getCondition() { result = generated.getCondition() }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user