-
Notifications
You must be signed in to change notification settings - Fork 356
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
checker/src/org/checkerframework/checker/index/qual/IndexOrLow.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.checkerframework.checker.index.qual; | ||
|
||
/** | ||
* An integer that is either -1 or is a valid index for each of the given sequences. | ||
* | ||
* <p>Writing {@code @IndexOrLow("arr")} is equivalent to writing {@link | ||
* GTENegativeOne @GTENegativeOne} {@link LTLengthOf @LTLengthOf("arr")}, and that is how it is | ||
* treated internally by the checker. Thus, if you write an {@code @IndexOrLow("arr")} annotation, | ||
* you might see warnings about {@code @GTENegativeOne} or {@code @LTLengthOf}. | ||
* | ||
* @see GTENegativeOne | ||
* @see LTLengthOf | ||
* @checker_framework.manual #index-checker Index Checker | ||
*/ | ||
public @interface IndexOrLow { | ||
/** Sequences that the annotated expression is a valid index for (or it's -1). */ | ||
String[] value() default {}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import org.checkerframework.checker.index.qual.GTENegativeOne; | ||
import org.checkerframework.checker.index.qual.IndexOrLow; | ||
import org.checkerframework.checker.index.qual.LTLengthOf; | ||
|
||
public class IndexOrLowTests { | ||
int[] array = {1, 2}; | ||
|
||
@IndexOrLow("array") | ||
int index = -1; | ||
|
||
void test() { | ||
//:: error: (array.access.unsafe.low) | ||
array[index] = 1; | ||
|
||
int y = index + 1; | ||
array[y] = 1; | ||
if (y < array.length) { | ||
array[y] = 1; | ||
} | ||
//:: error: (assignment.type.incompatible) | ||
index = -4; | ||
} | ||
|
||
void test2(@LTLengthOf("array") @GTENegativeOne int param) { | ||
index = array.length - 1; | ||
@LTLengthOf("array") @GTENegativeOne int x = index; | ||
index = param; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import org.checkerframework.checker.index.qual.GTENegativeOne; | ||
import org.checkerframework.checker.index.qual.IndexOrLow; | ||
import org.checkerframework.checker.index.qual.LTLengthOf; | ||
|
||
public class IndexOrLowTests { | ||
int[] array = {1, 2}; | ||
|
||
@IndexOrLow("array") | ||
int index = -1; | ||
|
||
void test() { | ||
array[index] = 1; | ||
|
||
int y = index + 1; | ||
//:: error: (array.access.unsafe.high) | ||
array[y] = 1; | ||
if (y < array.length) { | ||
array[y] = 1; | ||
} | ||
//:: error: (assignment.type.incompatible) | ||
index = array.length; | ||
} | ||
|
||
void test2(@LTLengthOf("array") @GTENegativeOne int param) { | ||
index = array.length - 1; | ||
@LTLengthOf("array") @GTENegativeOne int x = index; | ||
index = param; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters