import cpp class IndexLoopStmt extends ForStmt { IndexLoopStmt() { isIndexLoop(this) } Variable index() { result = this.getInitialization().(DeclStmt).getDeclaration(0).(Variable) } Expr bound() { result = this.getCondition().(LTExpr).getRightOperand() } } predicate isIndexInit(Variable v) { v.getInitializer().getExpr() instanceof Literal } predicate isIndexCond(ForStmt loop, Variable v) { loop.getCondition().(LTExpr).getLeftOperand().toString() = v.toString() } predicate isIndexInc(ForStmt loop, Variable v) { loop.getUpdate().(IncrementOperation).getOperand().toString() = v.toString() } predicate isIndexLoop(ForStmt loop) { exists(Variable v | v = loop.getInitialization().(DeclStmt).getDeclaration(0).(Variable) | isIndexInit(v) and isIndexCond(loop, v) and isIndexInc(loop, v) ) } from IndexLoopStmt loop where loop.bound().getNumChild() = 0 select loop, loop.index(), loop.bound()