public class LoopVariantASTTransformation
extends Object
implements ASTTransformation
Handles Decreases annotations placed on loop statements (for,
while, do-while). The closure must return a value that
strictly decreases on every iteration and remains non-negative.
The transformation injects code to:
Example:
int n = 10
@Decreases({ n })
while (n > 0) {
n--
}
| Type Params | Return Type | Name and description |
|---|---|---|
|
public static void |
checkDecreased(Object prev, Object curr)Runtime check called from generated code. |
|
public void |
visit(ASTNode[] nodes, SourceUnit source) |
Runtime check called from generated code. Throws LoopVariantViolation if the variant did not strictly decrease or became negative.
If both values are Lists, they are compared lexicographically: the first position where values differ must show a strict decrease; all earlier positions must be equal. If all positions are equal, the variant has not decreased and a violation is thrown.