Merge pull request #21880 from owen-mc/shared/cfg/for-loop-stmt-init-update

Shared CFG: Make the init and update parts of a for loop statements
This commit is contained in:
Owen Mansel-Chan
2026-05-21 14:57:44 +01:00
committed by GitHub
3 changed files with 14 additions and 6 deletions

View File

@@ -175,7 +175,9 @@ module Ast implements AstSig<Location> {
final private class FinalForStmt = CS::ForStmt;
class ForStmt extends FinalForStmt {
Expr getInit(int index) { result = this.getInitializer(index) }
AstNode getInit(int index) { result = super.getInitializer(index) }
AstNode getUpdate(int index) { result = super.getUpdate(index) }
}
final private class FinalForeachStmt = CS::ForeachStmt;

View File

@@ -84,7 +84,13 @@ private module Ast implements AstSig<Location> {
class DoStmt = J::DoStmt;
class ForStmt = J::ForStmt;
final private class FinalForStmt = J::ForStmt;
class ForStmt extends FinalForStmt {
AstNode getInit(int index) { result = super.getInit(index) }
AstNode getUpdate(int index) { result = super.getUpdate(index) }
}
final private class FinalEnhancedForStmt = J::EnhancedForStmt;

View File

@@ -118,14 +118,14 @@ signature module AstSig<LocationSig Location> {
/** A traditional C-style `for` loop. */
class ForStmt extends LoopStmt {
/** Gets the initializer expression of the loop at the specified (zero-based) position, if any. */
Expr getInit(int index);
/** Gets the initializer of the loop at the specified (zero-based) position, if any. */
AstNode getInit(int index);
/** Gets the boolean condition of this `for` loop. */
Expr getCondition();
/** Gets the update expression of this loop at the specified (zero-based) position, if any. */
Expr getUpdate(int index);
/** Gets the update of this loop at the specified (zero-based) position, if any. */
AstNode getUpdate(int index);
}
/** A for-loop that iterates over the elements of a collection. */