Skip to content

Commit

Permalink
TruffleStrings: fix missing docs
Browse files Browse the repository at this point in the history
  • Loading branch information
djoooooe committed Jul 11, 2022
1 parent 1a6c7e9 commit 1010a05
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.ArrayList;
import java.util.Arrays;

import com.oracle.truffle.api.profiles.ConditionProfile;
import org.graalvm.compiler.replacements.amd64.AMD64CalcStringAttributesNode;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -134,8 +135,8 @@ public TStringOpsCalcStringAttributesUTF8Test(Object array, int offset, int leng

@Test
public void testUtf8() {
ResolvedJavaMethod method = getTStringOpsMethod("calcStringAttributesUTF8", Object.class, int.class, int.class, boolean.class, boolean.class);
test(method, null, DUMMY_LOCATION, array, offset, length, true, false);
test(method, null, DUMMY_LOCATION, array, offset, length, false, false);
ResolvedJavaMethod method = getTStringOpsMethod("calcStringAttributesUTF8", Object.class, int.class, int.class, boolean.class, boolean.class, ConditionProfile.class);
test(method, null, DUMMY_LOCATION, array, offset, length, true, false, ConditionProfile.getUncached());
test(method, null, DUMMY_LOCATION, array, offset, length, false, false, ConditionProfile.getUncached());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ static String doBoxedString(Object input,
}
}

@Deprecated
// Deprecated
@Specialization(guards = "inputs.hasArrayElements(input)", limit = "2")
static Object doBoxedCharArray(Object input,
@CachedLibrary("input") InteropLibrary inputs) throws UnsupportedTypeException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ int utf8Valid(AbstractTruffleString a, Object arrayA, @SuppressWarnings("unused"
}

@Specialization(guards = {"isUTF8(encoding)", "isBrokenMultiByte(codeRangeA)"})
int utf8Broken(AbstractTruffleString a, Object arrayA, @SuppressWarnings("unused") int codeRangeA, @SuppressWarnings("unused") int encoding, int offset, int index,
int utf8Broken(@SuppressWarnings("unused") AbstractTruffleString a, Object arrayA, @SuppressWarnings("unused") int codeRangeA, @SuppressWarnings("unused") int encoding, int offset, int index,
@Cached ConditionProfile brokenProfile) {
return StringAttributes.getCodePointLength(TStringOps.calcStringAttributesUTF8(this, arrayA, offset, index, false, false, brokenProfile));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1481,10 +1481,38 @@ private static void checkMaskLength(AbstractTruffleString string, int length) {
}
}

/**
* Error handling instructions for operations that return integer values, such as indices or
* code points.
*
* @since 22.3
*/
public enum ErrorHandling {

/**
* This mode generally means that the operation will try to determine the "most reasonable"
* or "most useful" return value in respect to the expected encoding and the error that
* occurred.
*
* For example: best-effort error handling will cause {@link CodePointAtByteIndexNode} to
* return the value of the integer read when reading an invalid codepoint from a
* {@link Encoding#UTF_32} string.
*
* @since 22.3
*/
BEST_EFFORT,

/**
* This mode will cause a negative value to be returned in all error cases.
*
* For example: return-negative error handling will cause {@link CodePointAtByteIndexNode}
* to return a negative value when reading an invalid codepoint from a
* {@link Encoding#UTF_32} string.
*
* @since 22.3
*/
RETURN_NEGATIVE
};
}

/**
* Node to create a new {@link TruffleString} from a single codepoint.
Expand Down Expand Up @@ -4894,12 +4922,54 @@ public static final class NumberFormatException extends Exception {
* @since 22.3
*/
public enum Reason {

/**
* The string was empty, or contained no digits.
*
* @since 22.3
*/
EMPTY("no digits found"),

/**
* An invalid codepoint was encountered during parsing.
*
* @since 22.3
*/
INVALID_CODEPOINT("invalid codepoint"),

/**
* A '+' or '-' sign without any subsequent digits was encountered.
*
* @since 22.3
*/
LONE_SIGN("lone '+' or '-'"),

/**
* The parsed number was too large to fit in an {@code int}/{@code long}.
*
* @since 22.3
*/
OVERFLOW("overflow"),

/**
* Invalid codepoints encountered when parsing a hex number.
*
* @since 22.3
*/
MALFORMED_HEX_ESCAPE("malformed hex escape sequence"),

/**
* Multiple decimal points encountered.
*
* @since 22.3
*/
MULTIPLE_DECIMAL_POINTS("multiple decimal points"),

/**
* The given radix is unsupported.
*
* @since 22.3
*/
UNSUPPORTED_RADIX("unsupported radix");

private final String message;
Expand Down Expand Up @@ -4971,6 +5041,13 @@ public int getRegionByteLength() {
return regionOffset < 0 ? regionOffset : regionOffset << string.stride();
}

/**
* Returns a default error message comprised of all information available through
* {@link #getString()}, {@link #getReason()}, {@link #getRegionByteOffset()} and
* {@link #getRegionByteLength()}. Not designed to be used on fast paths.
*
* @since 22.3
*/
@TruffleBoundary
@Override
public String getMessage() {
Expand Down

0 comments on commit 1010a05

Please sign in to comment.