Rust: Add helper predicates for accessing statements and expressions together.

This commit is contained in:
Geoffrey White
2025-09-24 16:13:05 +01:00
parent 85945dba29
commit 8debce0349

View File

@@ -1,4 +1,3 @@
// generated by codegen, remove this comment if you wish to edit this file
/**
* This module provides a hand-modifiable wrapper around the generated class `StmtList`.
*
@@ -26,5 +25,25 @@ module Impl {
* // ^^^^^^^^^
* ```
*/
class StmtList extends Generated::StmtList { }
class StmtList extends Generated::StmtList {
/**
* Gets the `index`th statement or expression of this statement list (0-based).
*/
AstNode getStmtOrExpr(int index) {
result = this.getStatement(index)
or
index = max(int i | exists(this.getStatement(i))) + 1 and
result = this.getTailExpr()
}
/**
* Gets any of the statements or expressions of this statement list.
*/
final AstNode getAStmtOrExpr() { result = this.getStmtOrExpr(_) }
/**
* Gets the number of statements or expressions of this statement list.
*/
final int getNumberOfStmtOrExpr() { result = count(int i | exists(this.getStmtOrExpr(i))) }
}
}