Skip to content

Remove Character.toChars, highSurrogate, lowSurrogate models #4534

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
20 changes: 20 additions & 0 deletions jbmc/regression/jbmc-strings/CharacterToChars/C.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
public class C {

public void test() {
char[] c = Character.toChars(5);
assert c.length == 1;
assert c[0] == 5;

char[] two_bytes = Character.toChars(0x10000);
assert two_bytes.length == 2;
assert two_bytes[0] == '\ud800';
assert two_bytes[1] == '\udc00';
}

public void shouldFail() {
char[] c = Character.toChars(20);
assert c.length == 1;
assert c[0] == 100;
}

}
10 changes: 10 additions & 0 deletions jbmc/regression/jbmc-strings/CharacterToChars/should_fail.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CORE
C.class
--function C.shouldFail --cp `../../../../scripts/format_classpath.sh . ../../../lib/java-models-library/target/core-models.jar`
^EXIT=10$
^SIGNAL=0$
^VERIFICATION FAILED$
\[java::C\.shouldFail:\(\)V\.assertion.1\] line 16 assertion at file C\.java line 16 function java::C\.shouldFail:\(\)V bytecode-index 12: SUCCESS
\[java::C\.shouldFail:\(\)V\.assertion.2\] line 17 assertion at file C\.java line 17 function java::C\.shouldFail:\(\)V bytecode-index 23: FAILURE
--
^warning: ignoring
8 changes: 8 additions & 0 deletions jbmc/regression/jbmc-strings/CharacterToChars/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
C.class
--function C.test --cp `../../../../scripts/format_classpath.sh . ../../../lib/java-models-library/target/core-models.jar`
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test will pass even if toChars is not implemented. because unreachable evaluates to true. Could we add an assertion that we expect to fail?

--
^warning: ignoring
56 changes: 0 additions & 56 deletions jbmc/src/java_bytecode/character_refine_preprocess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,15 +321,6 @@ exprt character_refine_preprocesst::expr_of_high_surrogate(
return std::move(high_surrogate);
}

/// Converts function call to an assignment of an expression corresponding to
/// the java method Character.highSurrogate:(C)Z
codet character_refine_preprocesst::convert_high_surrogate(
conversion_inputt &target)
{
return convert_char_function(
&character_refine_preprocesst::expr_of_high_surrogate, target);
}

/// Determines if the specified character is an ASCII lowercase character.
/// \param chr: An expression of type character
/// \param type: A type for the output
Expand Down Expand Up @@ -1141,16 +1132,6 @@ exprt character_refine_preprocesst::expr_of_low_surrogate(
return plus_exprt(uDC00, mod_exprt(chr, u0400));
}

/// Converts function call to an assignment of an expression corresponding to
/// the java method Character.lowSurrogate:(I)C
/// \param target: a position in a goto program
codet character_refine_preprocesst::convert_low_surrogate(
conversion_inputt &target)
{
return convert_char_function(
&character_refine_preprocesst::expr_of_low_surrogate, target);
}

/// Returns the value obtained by reversing the order of the bytes in the
/// specified char value.
/// \param chr: An expression of type character
Expand All @@ -1174,37 +1155,6 @@ codet character_refine_preprocesst::convert_reverse_bytes(
&character_refine_preprocesst::expr_of_reverse_bytes, target);
}

/// Converts the specified character (Unicode code point) to its UTF-16
/// representation stored in a char array. If the specified code point is a BMP
/// (Basic Multilingual Plane or Plane 0) value, the resulting char array has
/// the same value as codePoint. If the specified code point is a supplementary
/// code point, the resulting char array has the corresponding surrogate pair.
/// \param chr: An expression of type character
/// \param type: A type for the output
/// \return A character array expression of the given type
exprt character_refine_preprocesst::expr_of_to_chars(
const exprt &chr, const typet &type)
{
array_typet array_type=to_array_type(type);
const typet &char_type=array_type.subtype();
exprt low_surrogate=expr_of_low_surrogate(chr, char_type);
array_exprt case1({low_surrogate}, array_type);
exprt high_surrogate = expr_of_high_surrogate(chr, char_type);
array_exprt case2(
{std::move(low_surrogate), std::move(high_surrogate)}, array_type);
return if_exprt(
expr_of_is_bmp_code_point(chr, type), std::move(case1), std::move(case2));
}

/// Converts function call to an assignment of an expression corresponding to
/// the java method Character.toChars:(I)[C
/// \param target: a position in a goto program
codet character_refine_preprocesst::convert_to_chars(conversion_inputt &target)
{
return convert_char_function(
&character_refine_preprocesst::expr_of_to_chars, target);
}

/// Converts function call to an assignment of an expression corresponding to
/// the java method Character.toCodePoint:(CC)I
/// \param target: a position in a goto program
Expand Down Expand Up @@ -1433,8 +1383,6 @@ void character_refine_preprocesst::initialize_conversion_table()
&character_refine_preprocesst::convert_get_type_int;
conversion_table["java::java.lang.Character.hashCode:()I"]=
&character_refine_preprocesst::convert_hash_code;
conversion_table["java::java.lang.Character.highSurrogate:(I)C"]=
&character_refine_preprocesst::convert_high_surrogate;
conversion_table["java::java.lang.Character.isAlphabetic:(I)Z"]=
&character_refine_preprocesst::convert_is_alphabetic;
conversion_table["java::java.lang.Character.isBmpCodePoint:(I)Z"]=
Expand Down Expand Up @@ -1523,17 +1471,13 @@ void character_refine_preprocesst::initialize_conversion_table()
&character_refine_preprocesst::convert_is_whitespace_char;
conversion_table["java::java.lang.Character.isWhitespace:(I)Z"]=
&character_refine_preprocesst::convert_is_whitespace_int;
conversion_table["java::java.lang.Character.lowSurrogate:(I)C"]=
&character_refine_preprocesst::convert_is_low_surrogate;

// Not supported "java::java.lang.Character.offsetByCodePoints:([CIIII)I"
// Not supported "java::java.lang.Character.offsetByCodePoints:"
// "(Ljava.lang.CharacterSequence;II)I"

conversion_table["java::java.lang.Character.reverseBytes:(C)C"]=
&character_refine_preprocesst::convert_reverse_bytes;
conversion_table["java::java.lang.Character.toChars:(I)[C"]=
&character_refine_preprocesst::convert_to_chars;

// Not supported "java::java.lang.Character.toChars:(I[CI)I"

Expand Down